From a3601ca1d84c4c48bbbdd36f8c293bebfe9edc09 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 13 Aug 2021 17:06:36 -0500 Subject: Edit `acdw-org/count-words-stupidly' to be even MOAR stupider --- init.el | 10 +++++++--- lisp/acdw-org.el | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/init.el b/init.el index 68683cb..69aafac 100644 --- a/init.el +++ b/init.el @@ -1498,14 +1498,18 @@ if ripgrep is installed, otherwise `consult-grep'." (setup (:straight wc-mode) ; TODO: move some of this stuff around (:option wc-modeline-format "[%tww]" - wc-idle-wait 1) + wc-idle-wait 0) (:hook-into text-mode) (add-hook 'org-mode-hook (defun org-mode@wc-stupid () - (setq-local wc-count-words-function - #'acdw-org/count-words-stupidly))) + (setq-local + wc-count-words-function + (lambda (start end) "Count words stupidly with a limit." + (acdw-org/count-words-stupidly start + end + 999))))) (defun acdw-modeline/wc () "Display current `wc-buffer-stats'." diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 6a11c4d..9f35dbc 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el @@ -305,16 +305,23 @@ the deletion might narrow the column." (acdw-org/count-words (point-min) (point-max)))))) ;; This isn't the best code, but it'll do. -(defun acdw-org/count-words-stupidly (start end) - "Count words between START and END, ignoring a lot." +(defun acdw-org/count-words-stupidly (start end &optional limit) + "Count words between START and END, ignoring a lot. + +Since this function is, for some reason, pricy, the optional +parameter LIMIT sets a word limit at which to stop counting. +Once the function hits that number, it'll return \"-LIMIT\" +instead of the true count." (interactive (list nil nil)) (cond ((not (called-interactively-p 'any)) - (let ((words 0)) + (let ((words 0) + (continue t)) (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) - (while (< (point) (point-max)) + (while (and continue + (< (point) (point-max))) (cond ;; Ignore comments ((or (org-at-comment-p) @@ -329,6 +336,10 @@ the deletion might narrow the column." (search-forward ":END:")) ;; Count everything else (t (setq words (1+ words)) + (if (and limit + (< words limit)) + (setq words limit + continue nil)) (forward-word-strictly)))))) words)) ((use-region-p) -- cgit 1.4.1-21-gabe81