diff options
Diffstat (limited to 'lisp/+org-wc.el')
-rw-r--r-- | lisp/+org-wc.el | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lisp/+org-wc.el b/lisp/+org-wc.el index 7ab0050..edd88f0 100644 --- a/lisp/+org-wc.el +++ b/lisp/+org-wc.el | |||
@@ -19,8 +19,7 @@ | |||
19 | (defcustom +org-wc-update-after-funcs '(org-narrow-to-subtree | 19 | (defcustom +org-wc-update-after-funcs '(org-narrow-to-subtree |
20 | org-narrow-to-block | 20 | org-narrow-to-block |
21 | org-narrow-to-element | 21 | org-narrow-to-element |
22 | org-capture-narrow | 22 | org-capture-narrow) |
23 | org-taskwise-narrow-to-task) | ||
24 | "Functions after which to update the word count." | 23 | "Functions after which to update the word count." |
25 | :type '(repeat function)) | 24 | :type '(repeat function)) |
26 | 25 | ||
@@ -32,6 +31,16 @@ | |||
32 | "Number of characters that constitute a \"huge\" insertion." | 31 | "Number of characters that constitute a \"huge\" insertion." |
33 | :type 'number) | 32 | :type 'number) |
34 | 33 | ||
34 | (defcustom +org-wc-huge-buffer 10000 | ||
35 | "Number of words past which we're not going to try to count." | ||
36 | :type 'number) | ||
37 | |||
38 | (defvar +org-wc-correction -5 | ||
39 | "Number to add to `+org-wc-word-count', for some reason? | ||
40 | `+org-wc-word-count' seems to consistently be off by 5. Thus | ||
41 | this correction. (At some point I should correct the underlying | ||
42 | code... probably).") | ||
43 | |||
35 | (defvar-local +org-wc-update-timer nil) | 44 | (defvar-local +org-wc-update-timer nil) |
36 | 45 | ||
37 | (defun +org-wc-delayed-update (&rest _) | 46 | (defun +org-wc-delayed-update (&rest _) |
@@ -48,7 +57,7 @@ | |||
48 | (+org-wc-update) | 57 | (+org-wc-update) |
49 | (message "Counting words...done")) | 58 | (message "Counting words...done")) |
50 | 59 | ||
51 | (defun +org-wc-update () | 60 | (defun +org-wc-update (&rest _) ; Needs variadic parameters, since it's advice |
52 | (dlet ((+org-wc-counting t)) | 61 | (dlet ((+org-wc-counting t)) |
53 | (+org-wc-buffer) | 62 | (+org-wc-buffer) |
54 | (force-mode-line-update) | 63 | (force-mode-line-update) |
@@ -59,9 +68,14 @@ | |||
59 | 68 | ||
60 | (defun +org-wc-buffer () | 69 | (defun +org-wc-buffer () |
61 | "Count the words in the buffer." | 70 | "Count the words in the buffer." |
62 | (when (derived-mode-p 'org-mode) | 71 | (when (and (derived-mode-p 'org-mode) |
72 | (not (eq +org-wc-word-count 'huge))) | ||
63 | (setq +org-wc-word-count | 73 | (setq +org-wc-word-count |
64 | (org-word-count-aux (point-min) (point-max))))) | 74 | (cond |
75 | ((> (count-words (point-min) (point-max)) | ||
76 | +org-wc-huge-buffer) | ||
77 | 'huge) | ||
78 | (t (org-word-count-aux (point-min) (point-max))))))) | ||
65 | 79 | ||
66 | (defvar +org-wc-counting nil | 80 | (defvar +org-wc-counting nil |
67 | "Are we currently counting?") | 81 | "Are we currently counting?") |
@@ -71,8 +85,9 @@ | |||
71 | (+org-wc-update))) | 85 | (+org-wc-update))) |
72 | 86 | ||
73 | (defun +org-wc-modeline () | 87 | (defun +org-wc-modeline () |
74 | (when +org-wc-word-count | 88 | (cond |
75 | (format " %sw" +org-wc-word-count))) | 89 | ((eq +org-wc-word-count 'huge) "huge") |
90 | (+org-wc-word-count (format " %sw" (max 0 (+ +org-wc-word-count +org-wc-correction)))))) | ||
76 | 91 | ||
77 | (define-minor-mode +org-wc-mode | 92 | (define-minor-mode +org-wc-mode |
78 | "Count words in `org-mode' buffers in the mode-line." | 93 | "Count words in `org-mode' buffers in the mode-line." |