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)
|
||||
(save-excursion
|
||||
(when pos (goto-char pos))
|
||||
(current-column)))
|
||||
(save-excursion (goto-char pos)
|
||||
(current-column)))
|
||||
|
||||
(defvar evil-state)
|
||||
(defvar evil-visual-selection)
|
||||
(def-modeline-segment! selection-info
|
||||
"Information about the current selection, such as how many characters and
|
||||
lines are selected, or the NxM dimensions of a block selection."
|
||||
(when mark-active
|
||||
(let ((evil-p (featurep 'evil)))
|
||||
(concat
|
||||
" "
|
||||
(propertize
|
||||
(let ((reg-beg (region-beginning))
|
||||
(reg-end (region-end))
|
||||
(evil (and evil-p (eq 'visual evil-state))))
|
||||
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
|
||||
(chars (- (1+ reg-end) reg-beg))
|
||||
(cols (1+ (abs (- (doom-column reg-end)
|
||||
(doom-column reg-beg))))))
|
||||
(cond
|
||||
;; rectangle selection
|
||||
((or (bound-and-true-p rectangle-mark-mode)
|
||||
(and evil (eq 'block evil-visual-selection)))
|
||||
(format " %dx%dB " lines (if evil cols (1- cols))))
|
||||
;; 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)))))
|
||||
(when (and (active) (or mark-active (eq evil-state 'visual)))
|
||||
(let ((reg-beg (region-beginning))
|
||||
(reg-end (region-end)))
|
||||
(propertize
|
||||
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max)))))
|
||||
(cond ((or (bound-and-true-p rectangle-mark-mode)
|
||||
(eq 'block evil-visual-selection))
|
||||
(let ((cols (abs (- (doom-column reg-end)
|
||||
(doom-column reg-beg)))))
|
||||
(format "%dx%dB" lines cols)))
|
||||
((eq 'line evil-visual-selection)
|
||||
(format "%dL" lines))
|
||||
((> lines 1)
|
||||
(format "%dC %dL" (- (1+ reg-end) reg-beg) lines))
|
||||
(t
|
||||
(format "%dC" (- (1+ reg-end) reg-beg)))))
|
||||
'face 'doom-modeline-highlight))))
|
||||
|
||||
|
||||
(defun +doom-modeline--macro-recording ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue