From fae8e9168fd716c2b05afe6e8b6ee45b407afc9f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 16 Feb 2022 23:17:56 -0600 Subject: Change modeline --- init.el | 19 ++++++++--- lisp/+modeline.el | 96 +++++++++++++++++++++++++++++++------------------------ 2 files changed, 68 insertions(+), 47 deletions(-) diff --git a/init.el b/init.el index 6c41689..2312109 100644 --- a/init.el +++ b/init.el @@ -744,8 +744,8 @@ tab-bar-tab-name-ellipsis truncate-string-ellipsis tab-bar-show t tab-bar-close-button-show t - +tab-bar-menu-bar-icon " Ɛ " - tab-bar-close-button (propertize " - " + +tab-bar-menu-bar-icon " ☰ " + tab-bar-close-button (propertize " ¬ " 'display t 'close-tab t) tab-bar-new-button (propertize "+ " 'display t)) @@ -1816,13 +1816,18 @@ See also `crux-reopen-as-root-mode'." :host github :repo "gexplorer/simple-modeline" :fork (:host github :repo "duckwork/simple-modeline"))) (:require +modeline) - (:option +modeline-minions-icon ";" + (:option +modeline-modified-icon-alist '((ephemeral . "🥞") + (special . "🥐") + (readonly . "🦞") + (modified . "🥪") + (t . "🍞")) + +modeline-minions-icon ";" simple-modeline-segments `(( ; left +modeline-ace-window-display +modeline-modified +modeline-buffer-name - (lambda () (+modeline-vc ": ")) + (lambda () (+modeline-vc " : ")) ,(+modeline-concat '(+modeline-minions +modeline-major-mode)) @@ -1842,7 +1847,11 @@ See also `crux-reopen-as-root-mode'." +modeline-reading-mode +modeline-narrowed) ",") - +modeline-position))) + ,(+modeline-concat + '(+modeline-region + +modeline-line-column + +modeline-file-percentage)) + ))) (simple-modeline-mode +1)) (setup (:straight slack) 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