Emacs does not seem to provide a method for counting the number of words. Therefore, we need to use some extensions or elisp functions.
1) use external Program To calculate
Set the following Code Add it to the Emacs configuration file:
(Defun word-count nil "count words in buffer" (interactive) (shell-command-on-region (point-min) (point-max) "WC-W "))
Therefore, in Emacs, M-x word-count can be used to call the WC program to calculate the number of words. This method is relatively simple. Of course, the disadvantage is also obvious, that is, your shell must be able to call the WC program. If it is in Windows, you have to install cygwin. If you have other word count statistics programs, you can replace them as appropriate.
This method counts the number of words, which is related to external applications.
2) count words with word-count.el Extension
Word-count.el is an extension of a relatively good statistical word count in Emacs, after marking the beginning, Jump directly to the end of the part you want to count, below will show such as wc111/22/1 content, it contains 111 characters, 22 words, and 1 line (empty rows are not counted ).
Usage:
(1 ). m-+ (m-x word-count-mode) starts the word-count mode. After this command is used, an initial flag will be made immediately. As the cursor moves, count the number of words between the current position of the cursor and the initial mark. Use this command again to disable the word-count mode.
(2). M-[space] (M-x word-count-set-area.
(3). M-x word-count-set-region: Set the interval or section for counting the number of words.
(4). M-x word-count-set-marker: Set the initial mark position for counting the number of words. This command can reset the position of the initial tag so that you can start statistics at the new location.
This method does not seem to perfectly count the number of Chinese characters. It uses spaces to Break English characters.
3) Use WC. El extension to count words
You just need to throw the WC. El extension to your Emacs directory and add the following statement to the. emacs file to activate the extension:
(Load "WC ")
This extension provides several commands to count the number of words:
M-x WC-buffer: count the number of words in the full text;
M-x WC-region: count the number of words in the selected area;
M-x WC-dwin: this command is a combination of the first two commands. If no region is selected, the words in the full text are counted. If a region is selected, the words in the area are counted.
This method is equally inaccurate in Chinese Word Count statistics.
4) http://iquaid.org/2008/02/08/counting-words-in-emacs/
This web page provides several word count functions, put them in the. emacs file, you can use. However, this method seems to have a problem in counting the number of Chinese characters and is not carefully verified.
the preceding methods do not have much problem in the statistics of English words, but there is basically nothing to do with the statistics of Chinese words. When I have time, I will try again.