From 50ce0836969c908334131fc71bce256f05346fa9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 31 Jan 2018 04:23:17 -0500 Subject: [PATCH] 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. --- modules/ui/doom-modeline/config.el | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/modules/ui/doom-modeline/config.el b/modules/ui/doom-modeline/config.el index 22ff91d51..04d58968b 100644 --- a/modules/ui/doom-modeline/config.el +++ b/modules/ui/doom-modeline/config.el @@ -443,6 +443,13 @@ icons." (save-excursion (goto-char pos) (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 "Information about the current selection, such as how many characters and 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))) (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))))) + (concat (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)))) + (when +doom-modeline-enable-word-count + (format " %dW" (count-words reg-beg reg-end))))) 'face 'doom-modeline-highlight))))