Word-count Mode

There is a fun little journal website called 750words that encourages writing at 750 words at a time. I think the idea is great, but I do not want my writing in the cloud. So, I created wc-mode.

It is a little mode that provides a word/line/character count in the modeline. The mode captures the changes in the buffer and present them to you, the user.

Additionally, wc-mode lets you define goals for content and alerts you (via the modeline) when you reach that goal.

Installation

To install, grab it from Github or use one of the following commands.

> git clone git://github.com/bnbeckwith/wc-mode.git
> git clone http://github.com/bnbeckwith/wc-mode.git

Use the following code to add it to emacs.

;; Supply the path to the mode repository
(add-to-list 'load-path "location/of/wc-mode")
(require 'wc-mode)
;; (Optionally) setup a global key
(global-set-key "\C-cw" 'wc-mode)

When you want to check your added words or set goals, turn on the mode with your global key.

Usage

There are two different ways to use this package. First, you can use it as a minor mode (preferred method). But, if you do not want the full power of a mode, you can just call the wc-count function which will show a message of the current words, lines and characters in the current buffer.

The rest of this section focuses on the minor-mode usage.

Keystrokes

After enabling wc-mode, a small set of commands are available via the following keymap.

Key Function
C-c C-w w Set word goal
C-c C-w l Set line goal
C-c C-w a Set character goal
C-c C-w c Do a 'wc' on the buffer

The first three keys set specific goals. The modeline displayed will highlight when upon goal completion. These goals are in relation to the delta of what is already on the page. Because of that, you are free to set a negative goal – useful for text that needs editing.

The final key just runs the wc-count function to get a message in the mini-buffer.

Modeline

The modeline format string, wc-modeline-format describes how to display the pieces of data. The following table defines the format-codes used.

Format Code What is displayed
%W Original word count (before changes)
%L Original line count
%C Original character count
%w Change in words
%l Change in lines
%c Change in characters
%gc Character change goal
%gl Line change goal
%gw Word change goal
%tw Total words in buffer
%tl Total lines in buffer
%tc Total characters in buffer

The default setting is "WC[%W%w/%tw]". This displays a "WC[" followed by the original word count, then the change in word count, followed by a slash and the total number of words in the buffer.