Posts from November 26, 2008
-
Emacs Wonderful Little Tip™ #n – Don’t Manually Capitalize… Manual Capitalization Is For L00s3rs!
From November 26, 2008 @ 6:00 am
I recently picked up Emacs again after being Internet-Slapped by Yegge. It’s funny, but way back in the day after I got my first 13″ iBook (still, in my opinion, the cutest computer every made, which is saying a lot) and began to dive into wondrous Unix (we were still tcsh back then), Emacs was the first program I attempted to learn. Who’s masochistic? /me raises both hands and jumps up and down.
Anyway, I didn’t know any better at the time and over the years I got tired of trying to integrate Console based Emacs into my daily work flow. All that has thankfully changed, and my cheek still hurts like heck.
Intros aside, what I have today is a Wonderful Little Tip™ that will be accompanied by other Wonderful Little Tips™ because Emacs is the kind of app that allows you to find Wonderful Little Tips™ all the time.
I often find myself typing in a title or something to that effect which I would like to have most or all of the words capitalized. The title of this post would be an example. In regular editors, the way to do this is to capitalize every word as you go along manually. This presents a few problems.
- Because you’re in an editor other than Emacs, when you forget to capitalize things, it’s a messy process to either arrow-key or delete key backwards to the mistake, delete the mistake, and then reenter as a capital.
- Typing capital letters is hard (OK… It’s a bit of a stretch, but I wanted a list, so I needed it), requiring precise and dexterous finger movements which even for seasoned Dvorak touch-typists like myself, every once in awhile goes awry.
What is the answer to this morass of efficiency conundrums? Who will deliver my hands from this editing of death!? Enter Emacs (OK, now I feel slightly uncomfortable with the subtle Emacs=Jesus suggestion there… That’s just weird, although RMS might actually think that, after all Emacs helps people more than babies do)! Emacs provides these nice text transformation functions that work like magic. They are bound as follows
- M-u: upcase-word
- M-l: downcase-word
- M-c: capitalize-word
The relevant control sequence for our tip here is M-c. The magic of this is quite simple; Type out a phrase, and then either M-b back through the words, M-a back to the beginning of the sentence, or if it’s all on one line, C-a to the beginning of the line. Then, using a combination of M-f and M-c, capitalize to your heart’s content.
This is so much faster than actually typing out the capitalized words. I can’t verify that it would save you time to do this for every capitalization everywhere, but for a long string of them, the added benefit of not having to type a separate key sequence each time you want to capitalize a word is astonishing. In fact, it’s so astonishing that I’m going to put together a little video of this function in action…
You know… because it’s that cool.
OK, here’s the video:
Emacs Wonder: Text Transformation Control Sequences. from Tim Visher on Vimeo.
