From 66d0e6999cf3bd1bb45d5e121f2d1168e0c8a846 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 19 May 2021 15:28:58 -0500 Subject: Rewrite acdw-modeline/word-count to show region counts --- lisp/acdw-modeline.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lisp/acdw-modeline.el') diff --git a/lisp/acdw-modeline.el b/lisp/acdw-modeline.el index 81b808d..4f78816 100644 --- a/lisp/acdw-modeline.el +++ b/lisp/acdw-modeline.el @@ -93,4 +93,24 @@ indicator in the mode-line." (> winum--window-count 1)) (format winum-format (winum-get-number-string)))) +(defcustom acdw-modeline/word-count-modes + (mapcar (lambda (m) (cons m nil)) simple-modeline-word-count-modes) + "Alist of modes to functions that `acdw-modeline/word-count' should dispatch. +If the cdr of the cons cell is nil, use the default function (`count-words'). +Otherwise, cdr should be a function that takes two points (see `count-words')." + :type '(alist :key-type (symbol :tag "Major-Mode") + :value-type function) + :group 'simple-modeline) + +(defun acdw-modeline/word-count () + "Display a buffer word count, depending on the major mode. +Uses `acdw-modeline/word-count-modes' to determine which function to use." + (when-let ((modefun + (assoc major-mode acdw-modeline/word-count-modes #'equal))) + (let ((fn (or (cdr modefun) + #'count-words)) + (min (if (region-active-p) (region-beginning) (point-min))) + (max (if (region-active-p) (region-end) (point-max)))) + (format "%dW" (funcall fn min max))))) + (provide 'acdw-modeline) -- cgit 1.4.1-21-gabe81