Skip to content

Commit

Permalink
Add smiley support (Fix #1)
Browse files Browse the repository at this point in the history
frowny.el now supports smileys (i.e., ":)") as well as frownies.  Why anyone
would want to express happiness is beyond this author, but frowny.el is for the
people.

In order to do so, `frowny-self-insert' is now deprecated, and will be removed
in a future version.  Users are encouraged to convert their code to use
`frowny-self-insert-frowny' instead.

In addition, the key definition to insert a smiley has been added to
`frowny-mode-map'.
  • Loading branch information
Case Duckworth committed Sep 30, 2021
1 parent 84c55c0 commit cde94d4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
11 changes: 7 additions & 4 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ This package ships `frowny-mode', which enables inserting a single "(" when
after a ":" -- meaning it'll insert :( without closing the parentheses for
modes like =electric-pair-mode=, =paredit-mode=, and others.

* Version 0.2

Just released: Version 0.2, /now with smileys/! Yes, if you're one of those
happy-go-lucky people who just /has/ to smile all the time, frowny.el is now for
you as well. Go nuts, ya filthy animal.

* Installation

I use [[https://github.com/raxod502/straight.el][straight.el]], which looks like this:
Expand Down Expand Up @@ -42,7 +48,7 @@ There are a (growing?) number of customization options available for
I'd recommend replacing it with an =rx= form, like this:

#+begin_src emacs-lisp
(setq frowny-eyes (rx (or “:” “:-” “=” “:'-)))=.
(setq frowny-eyes (rx (or ":" ":-" "=" ":'-")))=.
#+end_src

- =frowny-eyes-looking-back-limit=: =frowny= uses =looking-back= to determine whether
Expand All @@ -62,6 +68,3 @@ Of course, you can always customize these options using Emacs's Customize functi
modes /not/ to apply frowny to.
- I could do a =frowny-prog-mode= that checks whether the point is in a comment
or not, and frowny accordingly.
- It's been brought to my attention that there are cases in which a smiley =:)=
might be messed up when using =electric-pair-mode= … so although it pains me,
=frowny= will also support smileys. /blech/ !
32 changes: 24 additions & 8 deletions frowny.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Homepage: https://github.com/duckwork/frowny.el
;; Keywords: convenience

;; Package-Version: 0.1
;; Package-Version: 0.2
;; Package-Requires: ((emacs "24.1"))

;;; License:
Expand Down Expand Up @@ -49,14 +49,29 @@ With an value of t, enable it in all modes."
:type '(choice (const :tag "All modes" t)
(repeat :tag "Modes" function)))

(defun frowny-self-insert (N)
"Insert a frowny, or insert the character \"(\" N times."
(interactive "p")
(defun frowny--insert-character (character number)
"Insert CHARACTER NUMBER times, depending on frowniness.
Internal: use `frowny-self-insert-frowny' or
`frowny-self-insert-smiley' instead."
(cond
((looking-back frowny-eyes frowny-eyes-looking-back-limit)
(dotimes (_ N)
(insert "(")))
(t (self-insert-command N ?\())))
(dotimes (_ number)
(insert character)))
(t (self-insert-command number character))))

(defun frowny-self-insert-frowny (N)
"Insert \"(\" N times."
(interactive "p")
(frowny--insert-character ?\( N))

(define-obsolete-function-alias 'frowny-self-insert 'frowny-self-insert-frowny
"0.2"
"Insert a frowny, or insert the character \"(\" N times.")

(defun frowny-self-insert-smiley (N)
"Insert \")\" N times."
(interactive "p")
(frowny--insert-character ?\) N))

(defun frowny-mode--turn-on ()
"Turn on function `frowny-mode'."
Expand All @@ -68,7 +83,8 @@ With an value of t, enable it in all modes."
:init t
:lighter ":("
:keymap (let ((map (make-sparse-keymap)))
(define-key map "(" #'frowny-self-insert)
(define-key map "(" #'frowny-self-insert-frowny)
(define-key map ")" #'frowny-self-insert-smiley)
map))

;;;###autoload
Expand Down

0 comments on commit cde94d4

Please sign in to comment.