From 3a100209daa7f43cc2476c348b8f5d1b06b3a971 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 10 Aug 2021 14:47:00 -0500 Subject: Add acdw-modeline/position --- init.el | 2 +- lisp/acdw-modeline.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index e495803..4395c64 100644 --- a/init.el +++ b/init.el @@ -1275,7 +1275,7 @@ if ripgrep is installed, otherwise `consult-grep'." simple-modeline-segments '((acdw-modeline/modified acdw-modeline/buffer-name acdw-modeline/vc-branch - simple-modeline-segment-position) + acdw-modeline/position) (simple-modeline-segment-misc-info acdw-modeline/erc acdw-modeline/word-count diff --git a/lisp/acdw-modeline.el b/lisp/acdw-modeline.el index 104ea28..4e6b002 100644 --- a/lisp/acdw-modeline.el +++ b/lisp/acdw-modeline.el @@ -94,6 +94,35 @@ indicator in the mode-line." 'mouse-2 #'mode-line-widen)) 'mouse-face 'mode-line-highlight)))) +(defun acdw-modeline/position () + "Displays the current cursor position in the mode-line. + +Unlike `simple-modeline-segment-position', this changes the first +character from '+' to '-' if the region goes 'backward' -- that +is, if point < mark." + `((line-number-mode + ((column-number-mode + (column-number-indicator-zero-based + (8 " %l:%c") + (8 " %l:%C")) + (5 " L%l"))) + ((column-number-mode + (column-number-indicator-zero-based + (5 " C%c") + (5 " C%C"))))) + ,(if (region-active-p) + (propertize (format "%s%s" + (if (and (mark) + (< (point) (mark))) + "-" + "+") + (apply #'+ (mapcar + (lambda (pos) + (- (cdr pos) + (car pos))) + (region-bounds)))) + 'font-lock-face 'font-lock-variable-name-face)))) + (defun acdw-modeline/text-scale () ;; adapted from https://github.com/seagle0128/doom-modeline (when (and (boundp 'text-scale-mode-amount) -- cgit 1.4.1-21-gabe81