summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-08-13 17:06:36 -0500
committerCase Duckworth2021-08-13 17:06:36 -0500
commita3601ca1d84c4c48bbbdd36f8c293bebfe9edc09 (patch)
tree173cf306aa7cd43ba866557a06b4fee157fa2bec /lisp
parentProvide for when wc-mode isn't bound yet (diff)
downloademacs-a3601ca1d84c4c48bbbdd36f8c293bebfe9edc09.tar.gz
emacs-a3601ca1d84c4c48bbbdd36f8c293bebfe9edc09.zip
Edit `acdw-org/count-words-stupidly' to be even MOAR stupider
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-org.el19
1 files changed, 15 insertions, 4 deletions
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."
305 (acdw-org/count-words (point-min) (point-max)))))) 305 (acdw-org/count-words (point-min) (point-max))))))
306 306
307;; This isn't the best code, but it'll do. 307;; This isn't the best code, but it'll do.
308(defun acdw-org/count-words-stupidly (start end) 308(defun acdw-org/count-words-stupidly (start end &optional limit)
309 "Count words between START and END, ignoring a lot." 309 "Count words between START and END, ignoring a lot.
310
311Since this function is, for some reason, pricy, the optional
312parameter LIMIT sets a word limit at which to stop counting.
313Once the function hits that number, it'll return \"-LIMIT\"
314instead of the true count."
310 (interactive (list nil nil)) 315 (interactive (list nil nil))
311 (cond ((not (called-interactively-p 'any)) 316 (cond ((not (called-interactively-p 'any))
312 (let ((words 0)) 317 (let ((words 0)
318 (continue t))
313 (save-excursion 319 (save-excursion
314 (save-restriction 320 (save-restriction
315 (narrow-to-region start end) 321 (narrow-to-region start end)
316 (goto-char (point-min)) 322 (goto-char (point-min))
317 (while (< (point) (point-max)) 323 (while (and continue
324 (< (point) (point-max)))
318 (cond 325 (cond
319 ;; Ignore comments 326 ;; Ignore comments
320 ((or (org-at-comment-p) 327 ((or (org-at-comment-p)
@@ -329,6 +336,10 @@ the deletion might narrow the column."
329 (search-forward ":END:")) 336 (search-forward ":END:"))
330 ;; Count everything else 337 ;; Count everything else
331 (t (setq words (1+ words)) 338 (t (setq words (1+ words))
339 (if (and limit
340 (< words limit))
341 (setq words limit
342 continue nil))
332 (forward-word-strictly)))))) 343 (forward-word-strictly))))))
333 words)) 344 words))
334 ((use-region-p) 345 ((use-region-p)