wendellyi

 

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

 

分类:

技术点:

相关文章:

  • 2021-06-30
  • 2021-07-23
  • 2022-02-15
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-03-09
相关资源
相似解决方案