upcase-word, you so silly
23 Dec 2014Do you know what the
most frequently used
Emacs commands are? I can confirm by my own experience that they are
next-line
and previous-line
(in that order).
So why do M-u - upcase-word
, M-l - downcase-word
, and
M-c - capitalize-word
have such terrible synergy with Emacs's best commands?
No, upcase-word
, this is not what I had in mind:
Learn basic key | M-u |
Learn basic keySTROKE |
If you say:
But how did you get the cursor in such a crazy position in the first place? You should have used M-b/M-f.
Well, I got there with previous-line
- one of the best Emacs commands!
Resolve the *-word
malarkey with defadvice
Here are some simple advice commands that I've just rolled:
(defadvice upcase-word (before upcase-word-advice activate)
(unless (looking-back "\\b")
(backward-word)))
(defadvice downcase-word (before downcase-word-advice activate)
(unless (looking-back "\\b")
(backward-word)))
(defadvice capitalize-word (before capitalize-word-advice activate)
(unless (looking-back "\\b")
(backward-word)))
Small explanation to the Elisp novices:
- before
upcase-word
is called, execute the body ofupcase-word-advice
unless
we are at the beginning of the wordbackward-word
once to move to the beginning of the word
I'm intentionally not using the newest advice system here, since not everyone has yet upgraded to Emacs 24.4. In fact, I saw this gem today at Stack Overflow:
I am using Emacs 23 and cedet 1.0.1 ...