Count words in region or buffer

Highlight (mark) a region and use M-= to count the number of lines, words and characters in the region. Results are reported in the mini buffer at the bottom of the window.

As pointed out over at irreal, this default command (count-words-region) has the undesirable behaviour that it counts words in a region even when there is no region highlighted (it basically uses the last region you selected). Really, if there is no region highlighted, we would like it to count the words in the whole buffer. To do this, we can set M-= to a slightly different built-in function (count-words) by adding the following to your emacs config file:

;; use count-words instead of count-words-region as it works on buffer
;; if no region is selected
(global-set-key (kbd "M-=") 'count-words)