统计单词数量

(defun count-words-region (beginning end)
  "Print number of words in the region."
  (interactive "r")
  (message "Counting words in region ... ")
  (save-excursion
    (let ((count 0))
        (goto-char beginning)
        
        (while (and (< (point) end) (re-search-forward "\\w+\\W*" end t))
            (setq count (1+ count)))
            
        (cond ((zerop count)
               (message "The region does NOT have any words."))
              
              ((= 1 count)
               (message "The region has 1 word."))
               
              (t
               (message "The region has %d words." count))))))
原文地址:https://www.cnblogs.com/wendellyi/p/3120168.html