From 41b48c481471406470268209220019a4c3331a3f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 7 Aug 2021 15:07:04 -0500 Subject: Add `acdw-org/count-words-stupidly' To count words in an Org-mode buffer, disregarding headings and drawers completely. --- lisp/acdw-org.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'lisp/acdw-org.el') diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 41073a9..6a11c4d 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el @@ -304,6 +304,42 @@ the deletion might narrow the column." (message "%d words in buffer" (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." + (interactive (list nil nil)) + (cond ((not (called-interactively-p 'any)) + (let ((words 0)) + (save-excursion + (save-restriction + (narrow-to-region start end) + (goto-char (point-min)) + (while (< (point) (point-max)) + (cond + ;; Ignore comments + ((or (org-at-comment-p) + (org-in-commented-heading-p)) + (forward-line)) + ;; Ignore headings + ((or (org-at-heading-p)) + (forward-line)) + ;; Ignore drawers + ((or (looking-at org-drawer-regexp) + (looking-at org-clock-drawer-re)) + (search-forward ":END:")) + ;; Count everything else + (t (setq words (1+ words)) + (forward-word-strictly)))))) + words)) + ((use-region-p) + (message "%d words in region" + (acdw-org/count-words-stupidly (region-beginning) + (region-end)))) + (t + (message "%d words in buffer" + (acdw-org/count-words-stupidly (point-min) + (point-max)))))) + ;;; Zero-width spaces ;; https://blog.tecosaur.com/tmio/2021-05-31-async.html#easy-zero-width -- cgit 1.4.1-21-gabe81