diff options
author | Case Duckworth | 2021-08-13 17:06:36 -0500 |
---|---|---|
committer | Case Duckworth | 2021-08-13 17:06:36 -0500 |
commit | a3601ca1d84c4c48bbbdd36f8c293bebfe9edc09 (patch) | |
tree | 173cf306aa7cd43ba866557a06b4fee157fa2bec | |
parent | Provide for when wc-mode isn't bound yet (diff) | |
download | emacs-a3601ca1d84c4c48bbbdd36f8c293bebfe9edc09.tar.gz emacs-a3601ca1d84c4c48bbbdd36f8c293bebfe9edc09.zip |
Edit `acdw-org/count-words-stupidly' to be even MOAR stupider
-rw-r--r-- | init.el | 10 | ||||
-rw-r--r-- | 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'." | |||
1498 | (setup (:straight wc-mode) ; TODO: move some of this stuff around | 1498 | (setup (:straight wc-mode) ; TODO: move some of this stuff around |
1499 | 1499 | ||
1500 | (:option wc-modeline-format "[%tww]" | 1500 | (:option wc-modeline-format "[%tww]" |
1501 | wc-idle-wait 1) | 1501 | wc-idle-wait 0) |
1502 | 1502 | ||
1503 | (:hook-into text-mode) | 1503 | (:hook-into text-mode) |
1504 | 1504 | ||
1505 | (add-hook 'org-mode-hook | 1505 | (add-hook 'org-mode-hook |
1506 | (defun org-mode@wc-stupid () | 1506 | (defun org-mode@wc-stupid () |
1507 | (setq-local wc-count-words-function | 1507 | (setq-local |
1508 | #'acdw-org/count-words-stupidly))) | 1508 | wc-count-words-function |
1509 | (lambda (start end) "Count words stupidly with a limit." | ||
1510 | (acdw-org/count-words-stupidly start | ||
1511 | end | ||
1512 | 999))))) | ||
1509 | 1513 | ||
1510 | (defun acdw-modeline/wc () | 1514 | (defun acdw-modeline/wc () |
1511 | "Display current `wc-buffer-stats'." | 1515 | "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." | |||
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 | |||
311 | Since this function is, for some reason, pricy, the optional | ||
312 | parameter LIMIT sets a word limit at which to stop counting. | ||
313 | Once the function hits that number, it'll return \"-LIMIT\" | ||
314 | instead 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) |