From fae8e9168fd716c2b05afe6e8b6ee45b407afc9f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 16 Feb 2022 23:17:56 -0600 Subject: Change modeline --- lisp/+modeline.el | 96 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 42 deletions(-) (limited to 'lisp') diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 0cea55c..537c68b 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el @@ -64,12 +64,9 @@ This function makes a lambda, so you can throw it straight into (defun +modeline-buffer-name (&optional spacer) ; gonsie "Display the buffer name." - (let ((bufname (string-replace "%" "" (buffer-name)))) + (let ((bufname (string-trim (string-replace "%" "" (buffer-name))))) (concat (or spacer +modeline-default-spacer) - (propertize - (truncate-string-to-width bufname - (min 24 (/ (window-width) 3)) - nil ?\ t) + (propertize bufname 'help-echo (or (buffer-file-name) (buffer-name)) 'mouse-face 'mode-line-highlight)))) @@ -142,16 +139,15 @@ The order of elements matters: whichever one matches first is applied." +modeline-modified-icon-special-modes)) ('t t) (_ nil)) - (throw :icon (cdr cell))))))) + (throw :icon cell)))))) (concat (or spacer +modeline-default-spacer) - (propertize (or icon "") - 'mouse-face 'mode-line-highlight)))) - -(defun +modeline-buffer-modes (&optional spacer) - "Display various buffer-specific stuff cleanly." - ;; This is clunky and should probably be improved. - (concat (+modeline-reading-mode) - (+modeline-narrowed (when reading-mode ",")))) + (propertize (or (cdr-safe icon) "") + 'help-echo (format "Buffer \"%s\" is %s." + (buffer-name) + (pcase (car-safe icon) + ('t "unmodified") + ('nil "unknown") + (_ (car-safe icon)))))))) (defun +modeline-narrowed (&optional spacer) "Display an indication that the buffer is narrowed." @@ -193,9 +189,27 @@ The order of elements matters: whichever one matches first is applied." (defun +modeline-file-percentage (&optional spacer) "Display the position in the current file." - (if file-percentage-mode - (list (or spacer +modeline-default-spacer) '(-3 "%p") "%%") - '(" "))) + (when file-percentage-mode + (let* ((tot (count-lines (point-min) (point-max) :ignore-invisible)) + (perc (/ (* 100 (line-number-at-pos)) tot)) + (window-min (save-excursion (move-to-window-line 0) + (point))) + (window-max (save-excursion (move-to-window-line -1) + (point)))) + (propertize (concat (or spacer +modeline-default-spacer) + (cond + ((and (<= window-min (point-min)) + (>= window-max (point-max))) + "█") + ((= perc 0) "▇") + ((< perc 20) "▆") + ((< perc 40) "▅") + ((< perc 60) "▄") + ((< perc 80) "▃") + ((< perc 100) "▂") + ((>= perc 100) "▁"))) + 'help-echo (format "Point is %d%% through the buffer." + perc))))) (define-minor-mode region-indicator-mode "Toggle the region indicator in the mode line." @@ -203,33 +217,30 @@ The order of elements matters: whichever one matches first is applied." (defun +modeline-region (&optional spacer) "Display an indicator if the region is active." - (when (and region-indicator-mode - (region-active-p)) - (list - (format "%s%s" - (or spacer +modeline-default-spacer) - (propertize (format "%s%d" - (if (and (< (point) (mark))) "-" "+") - (apply '+ (mapcar (lambda (pos) - (- (cdr pos) - (car pos))) - (region-bounds)))) - 'font-lock-face 'font-lock-variable-name-face))))) + (if (and region-indicator-mode + (region-active-p)) + (format "%s%s" + (or spacer +modeline-default-spacer) + (propertize (format "%s%d" + (if (and (< (point) (mark))) "-" "+") + (apply '+ (mapcar (lambda (pos) + (- (cdr pos) + (car pos))) + (region-bounds)))) + 'font-lock-face 'font-lock-variable-name-face)) + "")) (defun +modeline-line-column (&optional spacer) ; adapted from `simple-modeline' "Display the current cursor line and column depending on modes." - (let ((sep "|") (before " [") (after "]")) - `(,(or spacer +modeline-default-spacer) - (:propertize (line-number-mode - ((column-number-mode - (column-number-indicator-zero-based - ,(concat before "%2l" sep "%2c" after) - ,(concat before "%2l" sep "%2C" after)) - ,(concat before "%2l" sep "" after))) - ((column-number-mode - (column-number-indicator-zero-based - ,(concat before sep "%2c" after) - ,(concat before sep "%2C" after))))))))) + (let ((sep "|") (before "") (after "") + (line-fmt (if line-number-mode "%2l" "")) + (col-fmt (if column-number-mode + (if column-number-indicator-zero-based + "%2c" + "%2C") + ""))) + (concat (or spacer +modeline-default-spacer) + before line-fmt sep col-fmt after))) (defun +modeline-position (&optional _) "Display the current cursor position. @@ -243,7 +254,8 @@ See `line-number-mode', `column-number-mode', `file-percentage-mode'" ;; from https://www.gonsie.com/blorg/modeline.html, from Doom (if-let ((backend (vc-backend buffer-file-name))) (concat (or spacer +modeline-default-spacer) - (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) + (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))) + "")) (defun +modeline-track (&optional spacer) "Display `tracking-mode' information." -- cgit 1.4.1-21-gabe81