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:
parent
523c6ae4cc
commit
50ce083696
1 changed files with 20 additions and 11 deletions
|
@ -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,17 +458,19 @@ 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)))))
|
||||||
(format "%dx%dB" lines cols)))
|
(format "%dx%dB" lines cols)))
|
||||||
((eq 'line evil-visual-selection)
|
((eq 'line evil-visual-selection)
|
||||||
(format "%dL" lines))
|
(format "%dL" lines))
|
||||||
((> 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))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue