ui/doom-modeline: add word-count to selection segment #364

Controlled by the buffer-local variable
+doom-modeline-enable-word-count. Use +doom-modeline|enable-word-count
to enable it in certain modes. By default, this is enabled in text-mode
derived buffers.
This commit is contained in:
Henrik Lissner 2018-01-31 04:23:17 -05:00
parent 523c6ae4cc
commit 50ce083696
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -443,6 +443,13 @@ icons."
(save-excursion (goto-char pos) (save-excursion (goto-char pos)
(current-column))) (current-column)))
(defvar-local +doom-modeline-enable-word-count nil
"If non-nil, a word count will be added to the selection-info modeline
segment.")
(defun +doom-modeline|enable-word-count () (setq +doom-modeline-enable-word-count t))
(add-hook 'text-mode-hook #'+doom-modeline|enable-word-count)
(def-modeline-segment! selection-info (def-modeline-segment! selection-info
"Information about the current selection, such as how many characters and "Information about the current selection, such as how many characters and
lines are selected, or the NxM dimensions of a block selection." lines are selected, or the NxM dimensions of a block selection."
@ -451,7 +458,7 @@ lines are selected, or the NxM dimensions of a block selection."
(reg-end (region-end))) (reg-end (region-end)))
(propertize (propertize
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max)))))
(cond ((or (bound-and-true-p rectangle-mark-mode) (concat (cond ((or (bound-and-true-p rectangle-mark-mode)
(eq 'block evil-visual-selection)) (eq 'block evil-visual-selection))
(let ((cols (abs (- (doom-column reg-end) (let ((cols (abs (- (doom-column reg-end)
(doom-column reg-beg))))) (doom-column reg-beg)))))
@ -461,7 +468,9 @@ lines are selected, or the NxM dimensions of a block selection."
((> lines 1) ((> lines 1)
(format "%dC %dL" (- (1+ reg-end) reg-beg) lines)) (format "%dC %dL" (- (1+ reg-end) reg-beg) lines))
(t (t
(format "%dC" (- (1+ reg-end) reg-beg))))) (format "%dC" (- (1+ reg-end) reg-beg))))
(when +doom-modeline-enable-word-count
(format " %dW" (count-words reg-beg reg-end)))))
'face 'doom-modeline-highlight)))) 'face 'doom-modeline-highlight))))