Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

Meta Binds Part 3: Smart string insertion

Have you ever stopped to consider what is the string you type most often?

In my case the answer is two-fold: “~/” and “.emacs.d/”. Minibuffer completion helps, but we can always make things better. The following snippet intelligently inserts both of these with a single key, and it's smart enough to know which one you want.

Besides its use in writing configurations, it's great for going straight to one of these directories inside the find-file prompt.

(global-set-key (kbd "M-ç") #'endless/~-or-emacs.d)
(defun endless/~-or-emacs.d ()
  "Insert '~/', then '.emacs.d/'."
  (interactive)
  (if (looking-back "~/")
      (insert ".emacs.d/")
    (insert "~/")))

The ç key is right under my right pinky, but find one that fits your need.

comments powered by Disqus