(or emacs irrelevant)

abel.el - abbrevs for Elisp

This is a follow-up to an older post about abbrevs.

I did try to make Elisp abbrevs work, but after a few times of getting is expanded to indent-sexp in strings or comments, I just could take it no longer.

Luckily and timely, Artur Malabarba revealed his speed-of-thought-lisp. This package does many things, but the main idea that I liked was that the abbrevs should only expand when in the function position, i.e. the abbrev is:

  • right after opening parenthesis
  • not in a comment
  • not in a string
  • not in the arguments list

With that idea, I've "refactored" my old abbrevs into Abel. It's a minor mode add-on for abbrev-mode. When you activate it, around a hundred abbrevs are added to your abbrev list for emacs-lisp-mode. When you deactivate it, these abbrevs are disabled, and your original abbrev list is restored. It even overrides the mode-line description to Abbrev -> Abel while it's active, thanks to diminish.

So while you should try sotl, which provides many other things, keep abel in mind: it's a simple upgrade to abbrev-mode that binds no bindings and asks no questions.

Here's the current list:

(defcustom abel-abbrevs
  '(
    ;; basics
    ("a" "and")
    ("bp" "boundp")
    ("c" "concat")
    ("fp" "fboundp")
    ("ii" "interactive")
    ("i" "insert")
    ("l" "lambda")
    ("m" "message")
    ("n" "not")
    ("f" "format")
    ("u" "unless")
    ("up" "unwind-protect")
    ("w" "when")
    ("wl" "while")
    ("r" "require")
    ("ci" "call-interactively")
    ("cc" "condition-case")
    ("pg" "plist-get")
    ("sa" "save-excursion")
    ("sr" "save-restriction")
    ("smd" "save-match-data")
    ;; defines
    ("de" "declare-function")
    ("df" "defface")
    ("da" "defmacro")
    ("du" "defcustom")
    ("dv" "defvar")
    ;; everything with char
    ("bc" "backward-char")
    ("scb" "skip-chars-backward")
    ("scf" "skip-chars-forward")
    ("gc" "goto-char")
    ("fc" "forward-char")
    ("dc" "delete-char")
    ("ca" "char-after")
    ;; everything with region
    ("ra" "region-active-p")
    ("rb" "region-beginning")
    ("re" "region-end")
    ("ntr" "narrow-to-region")
    ("dr" "delete-region")
    ("ir" "indent-region")
    ;; error related
    ("ie" "ignore-errors")
    ("e" "error")
    ;; regex match related
    ("la" "looking-at")
    ("lb" "looking-back")
    ("mb" "match-beginning")
    ("me" "match-end")
    ("ms" "match-string")
    ("msn" "match-string-no-properties")
    ("rm" "replace-match")
    ("ro" "regexp-opt")
    ("rq" "regexp-quote")
    ("rr" "replace-regexp-in-string")
    ("rsb" "re-search-backward")
    ("rsf" "re-search-forward")
    ("sf" "search-forward")
    ("sm" "string-match")
    ;; words
    ("fw" "forward-word")
    ("bw" "backward-word")
    ;; lines
    ("eol" "end-of-line")
    ("fl" "forward-line")
    ("lbp" "line-beginning-position")
    ("lep" "line-end-position")
    ("nai" "newline-and-indent")
    ;; buffer
    ("bfn" "buffer-file-name")
    ("bn" "buffer-name")
    ("bs" "buffer-substring")
    ("bsn" "buffer-substring-no-properties")
    ("cb" "current-buffer")
    ("wcb" "with-current-buffer")
    ("wtb" "with-temp-buffer")
    ("efn" "expand-file-name")
    ("ff" "find-file")
    ("ffn" "find-file-noselect")
    ;; window
    ("ow" "other-window")
    ("sw" "selected-window")
    ;; string
    ("ssn" "substring-no-properties")
    ("ss" "substring")
    ("si" "split-string")
    ("se" "string=")
    ("sl" "string<")
    ("sp" "stringp")
    ;; point
    ("pi" "point-min")
    ("pa" "point-max")
    ("p" "point")
    ;; key
    ("gk" "global-set-key")
    ("dk" "define-key")
    ;; rest
    ("ah" "add-hook")
    ("atl" "add-to-list")
    ("bod" "beginning-of-defun")
    ("bol" "beginning-of-line")
    ("dm" "deactivate-mark")
    ("fs" "forward-sexp")
    ("jos" "just-one-space")
    ("kn" "kill-new")
    ("lp" "load-path")
    ("mm" "major-mode")
    ("sic" "self-insert-command")
    ("sn" "symbol-name")
    ("tap" "thing-at-point")
    ("tc" "this-command")
    ("ul" "up-list"))
  "List of (ABBREV EXPANSION) used by `abel'."
  :set (lambda (symbol value)
         "Update abbrevs accoring to `abel-abbrevs'."
         (set symbol value)
         (mapc #'abel-define value))
  :group 'abel)