统计单词数量

 

(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))))))

 

posted @ 2013-06-05 23:24  WendellYih  阅读(265)  评论(0编辑  收藏  举报