-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwordcount-mode.el
29 lines (24 loc) · 956 Bytes
/
wordcount-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(defvar wordcount-timer nil
"Timer to kick off word count recomputation.")
(defvar wordcount-current-count 0
"The result of the last word count.")
(defun wordcount-update-word-count ()
"Recompute the word count."
(setq wordcount-current-count (count-words (point-min) (point-max))))
(define-minor-mode wordcount-mode
"Toggle wordcount mode.
With no argument, this command toggles the mode.
A non-null prefix argument turns the mode on.
A null prefix argument turns it off.
When enabled, the word count for the current buffer
is displayed in the mode-line."
:init-value nil
:lighter (:eval (format " [%d words]" wordcount-current-count))
(if wordcount-mode
(progn
(set (make-local-variable 'wordcount-current-count)
(count-words (point-min) (point-max)))
(set (make-local-variable 'wordcount-timer)
(run-with-idle-timer 3 't #'wordcount-update-word-count)))
(cancel-timer wordcount-timer)))
(add-hook 'text-mode-hook (lambda () (wordcount-mode)))