summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-08-07 15:07:04 -0500
committerCase Duckworth2021-08-07 15:07:04 -0500
commit41b48c481471406470268209220019a4c3331a3f (patch)
tree9158134e7871ceb43362f071eea7d8f2c5b4354d /lisp
parentTruncate less of ERC nick (diff)
downloademacs-41b48c481471406470268209220019a4c3331a3f.tar.gz
emacs-41b48c481471406470268209220019a4c3331a3f.zip
Add `acdw-org/count-words-stupidly'
To count words in an Org-mode buffer, disregarding headings and drawers
completely.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-org.el36
1 files changed, 36 insertions, 0 deletions
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."
304 (message "%d words in buffer" 304 (message "%d words in buffer"
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.
308(defun acdw-org/count-words-stupidly (start end)
309 "Count words between START and END, ignoring a lot."
310 (interactive (list nil nil))
311 (cond ((not (called-interactively-p 'any))
312 (let ((words 0))
313 (save-excursion
314 (save-restriction
315 (narrow-to-region start end)
316 (goto-char (point-min))
317 (while (< (point) (point-max))
318 (cond
319 ;; Ignore comments
320 ((or (org-at-comment-p)
321 (org-in-commented-heading-p))
322 (forward-line))
323 ;; Ignore headings
324 ((or (org-at-heading-p))
325 (forward-line))
326 ;; Ignore drawers
327 ((or (looking-at org-drawer-regexp)
328 (looking-at org-clock-drawer-re))
329 (search-forward ":END:"))
330 ;; Count everything else
331 (t (setq words (1+ words))
332 (forward-word-strictly))))))
333 words))
334 ((use-region-p)
335 (message "%d words in region"
336 (acdw-org/count-words-stupidly (region-beginning)
337 (region-end))))
338 (t
339 (message "%d words in buffer"
340 (acdw-org/count-words-stupidly (point-min)
341 (point-max))))))
342
307 343
308;;; Zero-width spaces 344;;; Zero-width spaces
309;; https://blog.tecosaur.com/tmio/2021-05-31-async.html#easy-zero-width 345;; https://blog.tecosaur.com/tmio/2021-05-31-async.html#easy-zero-width