ui/doom-modeline: fix word count in evil line-wise selection #364

This commit is contained in:
Henrik Lissner
2018-04-18 19:51:37 -04:00
parent 61865d0646
commit 1751c84559

View File

@@ -464,24 +464,26 @@ segment.")
(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."
(when (and (active) (or mark-active (eq evil-state 'visual))) (when (and mark-active (active))
(let ((reg-beg (region-beginning)) (cl-destructuring-bind (beg . end)
(reg-end (region-end))) (if (eq evil-state 'visual)
(cons evil-visual-beginning evil-visual-end)
(cons (region-beginning) (region-end)))
(propertize (propertize
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))) (let ((lines (count-lines beg (min (1+ end) (point-max)))))
(concat (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 end)
(doom-column reg-beg))))) (doom-column 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+ end) beg) lines))
(t (t
(format "%dC" (- (1+ reg-end) reg-beg)))) (format "%dC" (- (1+ end) beg))))
(when +doom-modeline-enable-word-count (when +doom-modeline-enable-word-count
(format " %dW" (count-words reg-beg reg-end))))) (format " %dW" (count-words beg end)))))
'face 'doom-modeline-highlight)))) 'face 'doom-modeline-highlight))))