Add another count words related function

This commit is contained in:
syl20bnr 2013-12-03 08:53:29 -05:00
parent c9b9c2552e
commit db6b1e941e
2 changed files with 19 additions and 0 deletions

View File

@ -303,4 +303,22 @@ For instance pass En as source for english."
(setq google-translate-default-source-language source)
(setq google-translate-default-target-language target))
;; from http://www.emacswiki.org/emacs/WordCount
(defun count-words-analysis (start end)
"Count how many times each word is used in the region.
Punctuation is ignored."
(interactive "r")
(let (words)
(save-excursion
(goto-char start)
(while (re-search-forward "\\w+" end t)
(let* ((word (intern (match-string 0)))
(cell (assq word words)))
(if cell
(setcdr cell (1+ (cdr cell)))
(setq words (cons (cons word 1) words))))))
(when (interactive-p)
(message "%S" words))
words))
(provide 'my-funcs)

View File

@ -219,6 +219,7 @@
(evil-leader/set-key "xtw" 'transpose-words)
(evil-leader/set-key "xU" 'upcase-region)
(evil-leader/set-key "xu" 'downcase-region)
(evil-leader/set-key "xwC" 'count-words-analysis)
(evil-leader/set-key "xwc" 'count-words-region)
;; google translate -----------------------------------------------------------
(evil-leader/set-key "xgl" 'set-google-translate-languages)