summary refs log tree commit diff stats
path: root/lisp/acdw-modeline.el
diff options
context:
space:
mode:
authorCase Duckworth2021-05-19 15:28:58 -0500
committerCase Duckworth2021-05-19 15:28:58 -0500
commit66d0e6999cf3bd1bb45d5e121f2d1168e0c8a846 (patch)
tree9dd2f71e18d76f7df6411b537e4b0bb80feec95c /lisp/acdw-modeline.el
parentAdd filledwithcreatures.wordpress.com RSS (diff)
downloademacs-66d0e6999cf3bd1bb45d5e121f2d1168e0c8a846.tar.gz
emacs-66d0e6999cf3bd1bb45d5e121f2d1168e0c8a846.zip
Rewrite acdw-modeline/word-count to show region counts
Diffstat (limited to 'lisp/acdw-modeline.el')
-rw-r--r--lisp/acdw-modeline.el20
1 files changed, 20 insertions, 0 deletions
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."
93 (> winum--window-count 1)) 93 (> winum--window-count 1))
94 (format winum-format (winum-get-number-string)))) 94 (format winum-format (winum-get-number-string))))
95 95
96(defcustom acdw-modeline/word-count-modes
97 (mapcar (lambda (m) (cons m nil)) simple-modeline-word-count-modes)
98 "Alist of modes to functions that `acdw-modeline/word-count' should dispatch.
99If the cdr of the cons cell is nil, use the default function (`count-words').
100Otherwise, cdr should be a function that takes two points (see `count-words')."
101 :type '(alist :key-type (symbol :tag "Major-Mode")
102 :value-type function)
103 :group 'simple-modeline)
104
105(defun acdw-modeline/word-count ()
106 "Display a buffer word count, depending on the major mode.
107Uses `acdw-modeline/word-count-modes' to determine which function to use."
108 (when-let ((modefun
109 (assoc major-mode acdw-modeline/word-count-modes #'equal)))
110 (let ((fn (or (cdr modefun)
111 #'count-words))
112 (min (if (region-active-p) (region-beginning) (point-min)))
113 (max (if (region-active-p) (region-end) (point-max))))
114 (format "%dW" (funcall fn min max)))))
115
96(provide 'acdw-modeline) 116(provide 'acdw-modeline)