Emacs: Interactive Abbrev

By Xah Lee. Date: . Last updated: .

If you have a lot abbrevs, one problem is that you forgot what's the abbrev.

[see Emacs: Abbrev Mode]

Solution is to have a prompt listing all abbreves. A Interactive abbrev.

emacs shell commands abbrev

Here's the code:

(defcustom xah-interactive-abbrev-alist nil "A alist for interactive abbreves. Key and value are strings. Key is for abbrev. Value is the text to be inserted." :group 'xah)

(setq xah-interactive-abbrev-alist
        ("ssh" . "ssh -l you example.org ")
        ("img1" . "convert -quality 85% ")
        ("imgScale" . "convert -scale 50% -quality 85% ")
        ("img256" . "convert +dither -colors 256 ")
        ("imgBatch" . "find . -name \"*png\" | xargs -l -i basename \"{}\" \".png\" | xargs -l -i  convert -quality 85% \"{}.png\" \"{}.jpg\"")
        ("img-bmp2png" . "find . -name \"*bmp\" | xargs -l -i basename \"{}\" \".bmp\" | xargs -l -i  convert \"{}.bmp\" \"{}.png\"")
        ("gif to webm" . "avconv -f gif -i cat.gif cat.webm")
        ("gif to mp4" . "avconv -f gif -i cat.gif cat.mp4")

        ("grep" . "grep -r -F \"xxx\" --include='*html' ~/web")
        ("firefox" . "setsid firefox &")

        ("delete empty file" . "find . -type f -empty")
        ("chmod file" . "find . -type f -exec chmod 644 {} ';'")
        ("delete emacs backup~" . "find ~/web/ -name \"*~\" -delete")
        ("find empty dir" . "find . -depth -empty -type d")
        ("delete empty dir" . "find . -depth -empty -type d -delete")

        ("empty trash" . "rm -r /home/xah/.local/share/Trash")

        ("chmod2" . "find . -type d -exec chmod 755 {} ';'")
        ("lynx" . "lynx -dump -assume_local_charset=utf-8 -display_charset=utf-8 -width=100")

        ("clojure" . "java -cp ~/apps/clojure-1.6.0/clojure-1.6.0.jar clojure.main")
(defun xah-interactive-abbrev ()
  "Prompt to insert string from a alist ‘xah-interactive-abbrev-alist’

URL ‘http://ergoemacs.org/emacs/emacs_interactive_abbrev.html’
version 2017-08-13"
  (let (($x
          (mapcar (lambda (x) (car x)) xah-interactive-abbrev-alist)
    (insert (cdr (assoc $x xah-interactive-abbrev-alist)))))

You must give a easy key for this command, such as F9.

(global-set-key (kbd "<f9>") 'xah-interactive-abbrev)

[see Emacs: How to Define Keys]

Also, modify the xah-interactive-abbrev-alist for your own abbrevs.

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode

ELisp Examples

Xah Commands

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples