Home About Résumé

Word Counting in Emacs

It's really easy, see, you could just write
some lisp to do it for you. Failing that
try this: C-space will set a mark to fix
the current start of region, then just hit
M-pipe and enter after relocating
the cursor to the end. All that remains
is wc -w then enter
to count them up! What's that? You say that you
don't know what "C" or "M" or "pipe" might mean?
Too bad! I've told you all you really need
to know. And they say open source is hard...

I've used Emacs and various work-alikes (mg, joe, etc) for nearly twenty years and am still learning new things. I'm currently using it as in text-mode for my novel, which I work on mostly using my netbook (Asus Eee, highly recommended) where heavier-weight food processors like LibreOffice (isn't that what we're calling it this week?) won't do. I've tried AbiWord but it has a number of bugs that range from annoying (a tendency to put close-quotes on their own line) to disastrous (removing the first capital letter after every open-quote when I changed the font, believe it or not.)

Since all I really want to do is get words on the page, Emacs is the obvious choice, although the flyspell-mode is sometimes laggy on trivial mis-spellings, particularly words beginning with "th".

But there's no native word-count command, and while I did find some elisp code that will do the job the instructions described in the poem were in a comment on the blog post that contained it. The comment reads, in full:

Or, if you wanna make it really easy, just go to the start of the region you want to count, then C-space (then move to end of region) M-| Enter (then type) wc -w Enter and it tells you.

In fairness, it is presumably aimed at Emacs-literate people, but it struck me how absurd it was to call such arcane esoterica "easy".

The poem really does scan as iambic pentameter, although I've taken a few liberties with the Emacs vernacular to do it. "C" and "M" are read in the poem as "see" and "em", not "control" and "meta". "Pipe" is the "|" character (of course... what else would it be?!?) The dashes after C and M are not voiced. "wc -w" is read as "double-you see dash double-you", as one would normally read it from the command line.

In keeping with my thoughts of digital longevity in the the poem of a couple of days ago, it's curious to think that decades after the last DECScope/VT-52 has gone out of service, parts of its keyboard terminology live on.

Contact Home
Copyright (C) 2018 TJ Radcliffe