Emacs: Interactive Abbrev

By Xah Lee. Date: . Last updated: .

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

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

screenshot 2022-06-02 200626 vP2Jd
xah-interactive-abbrev

Here's the code:

(defvar xah-interactive-abbrev-hashtable (make-hash-table :test 'equal) "A hashtable for `xah-interactive-abbrev'. Key is abbrev string. Value is the text to be inserted." )

(puthash "pwsh pull xahemacs" "cd //xpc/users/xah/git/xahemacs/ && git pull ~/git/xahemacs/" xah-interactive-abbrev-hashtable)
(puthash "pwsh pull xah_emacs_init" "cd //xpc/users/xah/git/xah_emacs_init/ && git pull ~/git/xah_emacs_init/" xah-interactive-abbrev-hashtable)
(puthash "pwsh subdir size" "dir -Directory | % { Write-Host $_.name \" \" -NoNewLine; \"{0:N0}\" -f ((dir $_ -File -Recurse | measure -Property Length -sum).sum / 1mb); }" xah-interactive-abbrev-hashtable)
(puthash "pwsh diff" "diff (cat f1) (cat f2) " xah-interactive-abbrev-hashtable)
(puthash "pwsh emacs backup~" "dir -Recurse -File -Include *~ " xah-interactive-abbrev-hashtable)
(puthash "pwsh dir size" "'{0:N0}' -f ((dir -Recurse | measure -Property Length -sum).sum / 1MB)" xah-interactive-abbrev-hashtable)
(puthash "pwsh .DS_Store" "dir -Recurse -Include '.DS_Store'" xah-interactive-abbrev-hashtable)
(puthash "pwsh #emacs_auto_save#" "dir -Recurse -Include '#*#'" xah-interactive-abbrev-hashtable)
(puthash "pwsh htaccess" "dir -Recurse -Include '.htaccess'" xah-interactive-abbrev-hashtable)
(puthash "pwsh xx temp file" "dir -Recurse -Include 'xx*'" xah-interactive-abbrev-hashtable)
(puthash "pwsh list empty dir" "dir -Directory -Recurse | ? { $_.GetFileSystemInfos().Count -eq 0 }" xah-interactive-abbrev-hashtable)
(puthash "pwsh sync web" "cd \\\\xpc\\users\\xah\\web && git pull ~/web/" xah-interactive-abbrev-hashtable)
(puthash "pwsh move images"
 "mv //xpc/users/xah/Documents/*png ~/Downloads/x_todo_pics/ &&
mv //xpc/users/xah/Documents/*jpg ~/Downloads/x_todo_pics/ &&
mv //xpc/users/xah/Pictures/*png ~/Downloads/x_todo_pics/ &&
mv //xpc/users/xah/Pictures/*jpg ~/Downloads/x_todo_pics/" xah-interactive-abbrev-hashtable)
(puthash "delete mac attribute" "xattr -c *png" xah-interactive-abbrev-hashtable)
(puthash "delete metadata" "exiftool -all= -overwrite_original *jpg" xah-interactive-abbrev-hashtable)
(puthash "gif to mp4" "ffmpeg -f gif -i x.gif x.mp4" xah-interactive-abbrev-hashtable)
(puthash "gif to webm" "ffmpeg -f gif -i x.gif x.webm" xah-interactive-abbrev-hashtable)
(puthash "gitdiff" "git --no-pager diff --color --no-index f1 f2" xah-interactive-abbrev-hashtable)
(puthash "image 256" "magick convert +dither -colors 256 " xah-interactive-abbrev-hashtable)
(puthash "image convert" "magick convert -quality 85% " xah-interactive-abbrev-hashtable)
(puthash "image scale" "magick convert -scale 50% -quality 85% " xah-interactive-abbrev-hashtable)
(puthash "lynx" "lynx -dump -assume_local_charset=utf-8 -display_charset=utf-8 -width=76 xxxxxxurl > xxfileName.txt" xah-interactive-abbrev-hashtable)
(puthash "mov to mp4" "ffmpeg -f mov -i x.mov x.mp4" xah-interactive-abbrev-hashtable)
(puthash "unix chmod file" "find . -type f -exec chmod 644 {} ';'" xah-interactive-abbrev-hashtable)
(puthash "unix chmod2" "find . -type d -exec chmod 755 {} ';'" xah-interactive-abbrev-hashtable)
(puthash "unix delete emacs backup~" "find . -name \"*~\" -delete" xah-interactive-abbrev-hashtable)
(puthash "unix delete empty dir" "find . -depth -empty -type d -delete" xah-interactive-abbrev-hashtable)
(puthash "unix delete empty file" "find . -type f -empty" xah-interactive-abbrev-hashtable)
(puthash "unix delete mac DS_Store" "find . -name \".DS_Store\" -delete;" xah-interactive-abbrev-hashtable)
(puthash "unix delete mac __MACOSX" "find . -depth -name \"__MACOSX\" -type d -exec rm -rf {} ';'" xah-interactive-abbrev-hashtable)
(puthash "unix grep" "grep -r -F \"hhhh\" --include='*html' ~/web" xah-interactive-abbrev-hashtable)
(puthash "unix image -bmp2png" "find . -name \"*bmp\" | xargs -l -i basename \"{}\" \".bmp\" | xargs -l -i magick convert \"{}.bmp\" \"{}.png\"" xah-interactive-abbrev-hashtable)
(puthash "unix image Batch" "find . -name \"*png\" | xargs -l -i basename \"{}\" \".png\" | xargs -l -i magick convert -quality 85% \"{}.png\" \"{}.jpg\"" xah-interactive-abbrev-hashtable)
(puthash "unix list empty dir" "find . -depth -empty -type d" xah-interactive-abbrev-hashtable)
(puthash "ytd" "youtube-dl -f 'bestvideo,bestaudio' -o 'f%(format_id)s.%(ext)s' url" xah-interactive-abbrev-hashtable)
(defun xah-interactive-abbrev ()
  "Prompt to insert string from `xah-interactive-abbrev-hashtable'.

URL `http://xahlee.info/emacs/emacs/emacs_interactive_abbrev.html'
Version: 2017-08-13 2021-10-22 2022-04-07 2022-04-16"
  (interactive)
  (require 'subr-x)
  (let (($input
         (completing-read
          "abbrevs:"
          (hash-table-keys xah-interactive-abbrev-hashtable) nil t)))
    (insert (gethash $input xah-interactive-abbrev-hashtable))))

You must give a easy key for this command, such as F9. [see Emacs: How to Define Keys]

also, you need to turn on fido-vertical-mode

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Xah Emacs Commands

buffer

file

edit

edit brackets

copy paste

whitespace

reformat

misc