GNU Info

Info Node: (emacs-lisp-intro.info)count-words-region

(emacs-lisp-intro.info)count-words-region


Next: recursive-count-words Prev: Why Count Words Up: Counting Words
Enter node , (file) or (file)node

The `count-words-region' Function
=================================

   A word count command could count words in a line, paragraph, region,
or buffer.  What should the command cover?  You could design the
command to count the number of words in a complete buffer.  However,
the Emacs tradition encourages flexibility--you may want to count words
in just a section, rather than all of a buffer.  So it makes more sense
to design the command to count the number of words in a region.  Once
you have a `count-words-region' command, you can, if you wish, count
words in a whole buffer by marking it with `C-x h'
(`mark-whole-buffer').

   Clearly, counting words is a repetitive act: starting from the
beginning of the region, you count the first word, then the second
word, then the third word, and so on, until you reach the end of the
region.  This means that word counting is ideally suited to recursion
or to a `while' loop.

Design count-words-region
The definition using a `while' loop.
Whitespace Bug
The Whitespace Bug in `count-words-region'.

automatically generated by info2www version 1.2.2.9