From 7136648d7e21769e488daa332888bf97f2da07c8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 12 Feb 2021 14:19:04 -0600 Subject: Customize mode-line --- config.org | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 171 insertions(+), 4 deletions(-) diff --git a/config.org b/config.org index ab7cef6..295e021 100644 --- a/config.org +++ b/config.org @@ -580,15 +580,16 @@ landed on a good one: =simple-modeline=. #+begin_src emacs-lisp :noweb-ref settings (setq-default simple-modeline-segments '(;; left side - (simple-modeline-segment-modified + (acdw/modeline/modified simple-modeline-segment-buffer-name - simple-modeline-segment-position) + acdw/modeline/vc-status + acdw/modeline/position) ;; right side (simple-modeline-segment-minor-modes simple-modeline-segment-input-method - simple-modeline-segment-vc simple-modeline-segment-misc-info simple-modeline-segment-process + acdw/modeline/acdw-minions simple-modeline-segment-major-mode))) #+end_src @@ -596,6 +597,8 @@ landed on a good one: =simple-modeline=. (simple-modeline-mode +1) #+end_src +**** Simple modeline custom segments + ***** COMMENT Functions to figure out what window is focused How is this not built into Emacs? Oh well, I have [[https://github.com/jamesnvc/dotfiles/blob/master/emacs.d/modules/cogent-modeline.el][Cogent]] to thank. @@ -626,6 +629,158 @@ How is this not built into Emacs? Oh well, I have [[https://github.com/jamesnvc (advice-add 'select-window :after #'cogent-line-set-selected-window) #+end_src +***** COMMENT Nyan mode + +#+begin_src emacs-lisp :noweb-ref packages + (straight-use-package 'nyan-mode) +#+end_src + +#+begin_src emacs-lisp :noweb-ref settings + (setq-default nyan-bar-length 24) +#+end_src + +#+begin_src emacs-lisp :noweb-ref modes + (nyan-mode +1) +#+end_src + +#+begin_src emacs-lisp :noweb-ref functions + (defun acdw/modeline/nyan () + "Show `nyan-mode' cat in the selected window, or position." + (if (and ;nyan-mode + (cogent-line-selected-window-active-p)) + (nyan-create) + "%p%%")) +#+end_src + +****** Rewrite =simple-modeline--format= + +#+begin_src emacs-lisp :noweb-ref functions + (defun simple-modeline--format (left-segments right-segments) + "Return a string of `window-width' length containing + LEFT-SEGMENTS and RIGHT-SEGMENTS, aligned respectively. + + This version is fixed for `nyan-mode' ... maybe??" + (let* ((left (simple-modeline--format-segments left-segments)) + (right (simple-modeline--format-segments right-segments)) + (reserve (+ 1 (length right)))) + (when (and window-system (eq 'right (get-scroll-bar-mode))) + (setq reserve (- reserve 3))) + (concat + left + (propertize " " + 'display `((space + :align-to (- (+ right right-fringe right-margin) + ,reserve))) + 'face '(:inherit simple-modeline-space)) + right))) +#+end_src + +***** Tweak =simple-modeline-segment-modified= + +#+begin_src emacs-lisp :noweb-ref functions + (defun acdw/modeline/modified () + "Show the modified/readonly state in the modeline. + See `simple-modeline-status-modified'." + (if (not (string-match-p "\\*.*\\*" (buffer-name))) + (let* ((read-only (and buffer-read-only (buffer-file-name))) + (modified (buffer-modified-p))) + (propertize + (if read-only " ×" (if modified " ●" " ○")) + 'face `(:inherit + ,(if modified 'simple-modeline-status-modified + (if read-only 'simple-modeline-status-error + 'simple-modeline-unimportant))) + 'help-echo (format + "Buffer is %s and %smodified\nmouse-1: Toggle read-only status." + (if read-only "read-only" "writable") + (if modified "" "not ")) + 'local-map (purecopy (simple-modeline-make-mouse-map + 'mouse-1 + (lambda (event) + (interactive "e") + (with-selected-window (posn-window (event-start event)) + (read-only-mode 'toggle))))) + 'mouse-face 'mode-line-highlight)) + "_")) +#+end_src + +***** Easier minor-modes + +#+begin_src emacs-lisp :noweb-ref functions + (defun acdw/modeline/acdw-minions () + "Show `acdw/mode' icon as a button to enable `minions-minor-modes-menu'. + + This enables me to `blackout' all global minor-mode + lighters (including `acdw/mode'), and hide them behind a button, + saving space in the mode line." + (propertize " ⱷ" + 'help-echo "Minor modes" + 'local-map (purecopy (simple-modeline-make-mouse-map + 'mouse-1 + (lambda (event) + (interactive "e") + (with-selected-window (posn-window + (event-start event)) + (minions-minor-modes-menu))))) + 'mouse-face 'mode-line-highlight)) +#+end_src + +***** Shorter VC-mode segment + +#+begin_src emacs-lisp :noweb-ref functions + (defun acdw/modeline/vc-status () + "Displays the VC status in the modeline." + '(vc-mode (:eval + (let ((branch-name (replace-regexp-in-string + (format "^\s*%s:?-?" + (vc-backend buffer-file-name)) + "" vc-mode)) + (f (cond ((string= "up-to-date" + (vc-state buffer-file-name)) + '((:slant normal))) + (t + '((:slant italic)))))) + (propertize (concat " " branch-name) + 'face f + 'help-echo (format + "%s: %s\nmouse-1: Run magit-status" + vc-mode + (vc-state buffer-file-name)) + 'local-map (purecopy + (simple-modeline-make-mouse-map + 'mouse-1 + (lambda (ev) + (interactive "e") + (with-selected-window + (posn-window + (event-start ev)) + (magit-status-setup-buffer + (file-name-directory + buffer-file-name)))))) + 'mouse-face 'mode-line-highlight))))) +#+end_src + +***** Position in file + +#+begin_src emacs-lisp :noweb-ref functions + (defun acdw/modeline/position () + "Displays the current cursor position in the mode-line." + `((line-number-mode (-6 " %l")) + ((column-number-mode + (column-number-indicator-zero-based + (4 ":%c") + (4 ":%C")))) + " " mode-line-percent-position "%% " + ,(if (region-active-p) + (propertize (format "+%s " + (apply #'+ (mapcar + (lambda (pos) + (- (cdr pos) + (car pos))) + (region-bounds)))) + 'font-lock-face 'font-lock-variable-name-face)))) +#+end_src + **** Blackout some modes :package: Like =diminish= or =delight=, =blackout= allows me to remove some @@ -965,12 +1120,16 @@ on as I please. (define-minor-mode acdw/mode "A mode for `acdw/map'." :init-value t - :lighter " ⱷ" + :lighter " acdw" :keymap acdw/map) (define-globalized-minor-mode acdw/global-mode acdw/mode acdw/mode) #+end_src +#+begin_src emacs-lisp :noweb-ref modes + (blackout 'acdw/mode) +#+end_src + **** Turn off acdw/mode in the minibuffer #+begin_src emacs-lisp :noweb-ref acdw-mode @@ -1350,6 +1509,10 @@ I think that'll work -- I only care about line aesthetics with text. Programming modes should be /allowed/ to have long lines, regardless of how /terrible/ it is to have them. +#+begin_src emacs-lisp :noweb-ref modes + (blackout 'auto-fill-mode) +#+end_src + *** Visual fill column mode In reading-intensive views, this mode keeps the text from getting too @@ -1654,6 +1817,10 @@ Let's use =hunspell=. (add-hook 'prog-mode-hook #'flyspell-prog-mode) #+end_src +#+begin_src emacs-lisp :noweb-ref modes + (blackout 'flyspell-mode) +#+end_src + *** Flyspell-correct :package: Display corrections with =completing-read=. -- cgit 1.4.1-21-gabe81