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 --- lisp/acdw-org.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lisp') 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