ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

Emacs Lisp: Hotkeys to Open File Fast

Xah Lee, , …,

Here's command that lets you open file fast, by typing a letter or digit:

(defvar xah-filelist nil "alist for files i need to open frequently. Key is a short abbrev, Value is file path.")
(setq xah-filelist
      '(
        ("3emacs" . "~/web/ergoemacs_org/emacs/blog.html" )
        ("4code" . "~/web/xahlee_info/comp/blog.html" )
        ("js" . "~/web/xahlee_info/js/blog.html" )
        ("math" . "~/web/xahlee_info/math/blog.html" )
        ("linguistics" . "~/web/wordyenglish_com/lit/blog.html" )
        ("chinese" . "~/web/wordyenglish_com/chinese/blog.html" )
        ("music" . "~/web/xahmusic_org/music/blog.html" )
        ("arts" . "~/web/xaharts_org/arts/blog.html" )
        ("sl" . "~/web/xahsl_org/sl/blog.html" )
        ("keys" . "~/git/xah_emacs_init/xah_emacs_keybinding.el" )
        ("ahk" . "~/git/xah_autohotkey_scripts/xah autohotkeys.ahk" )
        ("download" . "~/Downloads/" )
        ) )

(defun xah-open-file-fast (openCode)
  "Prompt to open a file from a pre-defined set."
  (interactive
   (list (ido-completing-read "Open:" (mapcar (lambda (x) (car x)) xah-filelist)))
   )
  (find-file (cdr (assoc openCode xah-filelist)) ) )

When called, it will prompt in the same way as ido-mode, with real-time name completion as you type.

You need to modify the file path for your own use. You can also easily modify the code above so that one letter opens several files at once, such as a coding project.

You might add a unique digit for each file's abbrev, so that opening files becomes muscle memory of key press.

Note: You should also use the following:

All the above requires eyeball. That is, spending half a second to look at the screen and make a choice.

The purpose of xah-open-file-fast is that you never need to look at the screen, just muscle memory, but you may want to be sure that the first chars of your file name abbrevs are unique.

blog comments powered by Disqus