ui/doom-modeline: refactor selection-info segment
This commit is contained in:
parent
a509462d8b
commit
68c172dd92
1 changed files with 21 additions and 27 deletions
|
@ -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)))
|
(let ((reg-beg (region-beginning))
|
||||||
(concat
|
(reg-end (region-end)))
|
||||||
" "
|
(propertize
|
||||||
(propertize
|
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max)))))
|
||||||
(let ((reg-beg (region-beginning))
|
(cond ((or (bound-and-true-p rectangle-mark-mode)
|
||||||
(reg-end (region-end))
|
(eq 'block evil-visual-selection))
|
||||||
(evil (and evil-p (eq 'visual evil-state))))
|
(let ((cols (abs (- (doom-column reg-end)
|
||||||
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
|
(doom-column reg-beg)))))
|
||||||
(chars (- (1+ reg-end) reg-beg))
|
(format "%dx%dB" lines cols)))
|
||||||
(cols (1+ (abs (- (doom-column reg-end)
|
((eq 'line evil-visual-selection)
|
||||||
(doom-column reg-beg))))))
|
(format "%dL" lines))
|
||||||
(cond
|
((> lines 1)
|
||||||
;; rectangle selection
|
(format "%dC %dL" (- (1+ reg-end) reg-beg) lines))
|
||||||
((or (bound-and-true-p rectangle-mark-mode)
|
(t
|
||||||
(and evil (eq 'block evil-visual-selection)))
|
(format "%dC" (- (1+ reg-end) reg-beg)))))
|
||||||
(format " %dx%dB " lines (if evil cols (1- cols))))
|
'face 'doom-modeline-highlight))))
|
||||||
;; line selection
|
|
||||||
((or (> lines 1) (eq 'line evil-visual-selection))
|
|
||||||
(if (and (eq evil-state 'visual) (eq evil-this-type 'line))
|
|
||||||
(format " %dL " lines)
|
|
||||||
(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 ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue