From dd3afe747ecf51f87d33318c2ad68953d153495f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 23 May 2022 20:12:53 -0500 Subject: meh --- lisp/+org-wc.el | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'lisp/+org-wc.el') 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 @@ (defcustom +org-wc-update-after-funcs '(org-narrow-to-subtree org-narrow-to-block org-narrow-to-element - org-capture-narrow - org-taskwise-narrow-to-task) + org-capture-narrow) "Functions after which to update the word count." :type '(repeat function)) @@ -32,6 +31,16 @@ "Number of characters that constitute a \"huge\" insertion." :type 'number) +(defcustom +org-wc-huge-buffer 10000 + "Number of words past which we're not going to try to count." + :type 'number) + +(defvar +org-wc-correction -5 + "Number to add to `+org-wc-word-count', for some reason? +`+org-wc-word-count' seems to consistently be off by 5. Thus +this correction. (At some point I should correct the underlying +code... probably).") + (defvar-local +org-wc-update-timer nil) (defun +org-wc-delayed-update (&rest _) @@ -48,7 +57,7 @@ (+org-wc-update) (message "Counting words...done")) -(defun +org-wc-update () +(defun +org-wc-update (&rest _) ; Needs variadic parameters, since it's advice (dlet ((+org-wc-counting t)) (+org-wc-buffer) (force-mode-line-update) @@ -59,9 +68,14 @@ (defun +org-wc-buffer () "Count the words in the buffer." - (when (derived-mode-p 'org-mode) + (when (and (derived-mode-p 'org-mode) + (not (eq +org-wc-word-count 'huge))) (setq +org-wc-word-count - (org-word-count-aux (point-min) (point-max))))) + (cond + ((> (count-words (point-min) (point-max)) + +org-wc-huge-buffer) + 'huge) + (t (org-word-count-aux (point-min) (point-max))))))) (defvar +org-wc-counting nil "Are we currently counting?") @@ -71,8 +85,9 @@ (+org-wc-update))) (defun +org-wc-modeline () - (when +org-wc-word-count - (format " %sw" +org-wc-word-count))) + (cond + ((eq +org-wc-word-count 'huge) "huge") + (+org-wc-word-count (format " %sw" (max 0 (+ +org-wc-word-count +org-wc-correction)))))) (define-minor-mode +org-wc-mode "Count words in `org-mode' buffers in the mode-line." -- cgit 1.4.1-21-gabe81