ui/doom-modeline: refactor selection-info segment

This commit is contained in:
Henrik Lissner 2017-03-03 16:53:16 -05:00
parent a509462d8b
commit 68c172dd92

View file

@ -382,37 +382,31 @@ icons."
))) )))
(defsubst doom-column (pos) (defsubst doom-column (pos)
(save-excursion (save-excursion (goto-char pos)
(when pos (goto-char pos))
(current-column))) (current-column)))
(defvar evil-state)
(defvar evil-visual-selection)
(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 mark-active (when (and (active) (or mark-active (eq evil-state 'visual)))
(let ((evil-p (featurep 'evil)))
(concat
" "
(propertize
(let ((reg-beg (region-beginning)) (let ((reg-beg (region-beginning))
(reg-end (region-end)) (reg-end (region-end)))
(evil (and evil-p (eq 'visual evil-state)))) (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)))))
(chars (- (1+ reg-end) reg-beg)) (cond ((or (bound-and-true-p rectangle-mark-mode)
(cols (1+ (abs (- (doom-column reg-end) (eq 'block evil-visual-selection))
(doom-column reg-beg)))))) (let ((cols (abs (- (doom-column reg-end)
(cond (doom-column reg-beg)))))
;; rectangle selection (format "%dx%dB" lines cols)))
((or (bound-and-true-p rectangle-mark-mode) ((eq 'line evil-visual-selection)
(and evil (eq 'block evil-visual-selection))) (format "%dL" lines))
(format " %dx%dB " lines (if evil cols (1- cols)))) ((> lines 1)
;; line selection (format "%dC %dL" (- (1+ reg-end) reg-beg) lines))
((or (> lines 1) (eq 'line evil-visual-selection)) (t
(if (and (eq evil-state 'visual) (eq evil-this-type 'line)) (format "%dC" (- (1+ reg-end) reg-beg)))))
(format " %dL " lines) 'face 'doom-modeline-highlight))))
(format " %dC %dL " chars lines)))
(t (format " %dC " (if evil chars (1- chars)))))))
'face 'doom-modeline-highlight)))))
(defun +doom-modeline--macro-recording () (defun +doom-modeline--macro-recording ()