From b1d307126913cbd4d8af818f7aec7ada6a0ea4ad Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 4 Dec 2021 23:09:33 -0600 Subject: uhhhhhhhh --- lisp/+modeline.el | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 lisp/+modeline.el (limited to 'lisp/+modeline.el') diff --git a/lisp/+modeline.el b/lisp/+modeline.el new file mode 100644 index 0000000..b417e50 --- /dev/null +++ b/lisp/+modeline.el @@ -0,0 +1,157 @@ +;;; +modeline.el --- my modeline customizations -*- lexical-binding: t; -*- + +;;; Commentary: + +;; `+modeline.el' is kind of a dumping ground for various +;; modeline-related functions. I probably don't use everything in +;; here. Credit given where possible. + +;;; Code: + +(require '+util) +(require 'simple-modeline) +(require 'minions) + +(defgroup +modeline nil + "Various customization options for my modeline things." + :prefix "+modeline-" + :group 'simple-modeline) + +(defun +modeline-buffer-name () ; gonsie + "Display the buffer name." + (propertize + (+string-align (buffer-name) 20 :before " " :ellipsis "… ") + 'face 'bold + 'help-echo (or (buffer-file-name) + (buffer-name)) + 'mouse-face 'mode-line-highlight)) + +(defcustom +modeline-minions-icon "&" + "The \"icon\" for `+modeline-minions' button." + :type 'string) + +(defun +modeline-minions () + "Display a button for `minions-minor-modes-menu'." + (concat " " + (propertize + +modeline-minions-icon + 'help-echo "Minor modes menu\nmouse-1: show menu." + '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))) + +(defun +modeline-major-mode () + "Display the current `major-mode'." + (concat " " + (propertize (+string-truncate (format-mode-line mode-name) + 12 "…") + 'face 'bold + 'keymap mode-line-major-mode-keymap + 'mouse-face 'mode-line-highlight))) + +(defcustom +modeline-modified-icon-alist '((ephemeral . "*") + (readonly . "=") + (modified . "+") + (special . "~") + (t . "-")) + "\"Icons\" to display depending on buffer status in modeline. +The CAR of each field is one of `readonly', `modified', +`special', `ephemeral', or t, and the CDR is a string to display +in that mode. + +`readonly' is true if the buffer is read-only and visiting a file. +`modified' is true if the buffer is modified. +`special' is true if the buffer is a special-mode or derived buffer. +`ephemeral' is true if the buffer is not visiting a file. +t is the fall-back, shown when nothing else in the alist applies. + +The order of elements matters: whichever one matches first is applied." + :type '(alist :key-type symbol + :value-type string) + :options '("readonly" "modified" "special" "t")) + +(defcustom +modeline-modified-icon-special-modes '(special-mode) + "Modes to apply the `special-mode' icon to in the +`+modeline-modified'." + :type '(repeat function)) + +(defun +modeline-modified () ; modified from `simple-modeline-status-modified' + "Display a color-coded \"icon\" indicator for the buffer's status." + (let* ((icon (catch :icon + (dolist (cell +modeline-modified-icon-alist) + (when (pcase (car cell) + ('ephemeral (not (buffer-file-name))) + ('readonly buffer-read-only) + ('modified (buffer-modified-p)) + ('special + (apply 'derived-mode-p + +modeline-modified-icon-special-modes)) + ('t t) + (_ nil)) + (throw :icon (cdr cell))))))) + (concat " " + (propertize (or icon "") + 'mouse-face 'mode-line-highlight)))) + +(defun +modeline-narrowed () + "Display an indication that the buffer is narrowed." + (when (buffer-narrowed-p) + (concat " " + (propertize "N" + 'help-echo (format "%s\n%s" + "Buffer is narrowed." + "mouse-2: widen buffer.") + 'local-map (purecopy (simple-modeline-make-mouse-map + 'mouse-2 'mode-line-widen)) + 'mouse-face 'mode-line-highlight)))) + +(define-minor-mode file-percentage-mode + "Toggle the percentage display in the mode line (File Percentage Mode)." + :init-value t :global t :group 'mode-line) + +(defun +modeline-position () ; adapted from `simple-modeline' + "Display the current cursor position." + (list '((line-number-mode + ((column-number-mode + (column-number-indicator-zero-based + (9 " %l:%c") + (9 " %l:%C")) + (6 " %l:"))) + ((column-number-mode + (column-number-indicator-zero-based + (5 " :%c") + (5 " :%C")))))) + '(file-percentage-mode + ((-3 "%p") "%% ")) + (if (region-active-p) + (propertize (format "%s%-5d" + (if (and (mark) (< (point) (mark))) "-" "+") + (apply '+ (mapcar + (lambda (pos) + (- (cdr pos) + (car pos))) + (region-bounds)))) + 'font-lock-face 'font-lock-variable-name-face)))) + +(defun +modeline-vc () + "Display the version control branch of the current buffer in the modeline." + ;; from https://www.gonsie.com/blorg/modeline.html, from Doom + (if-let ((backend (vc-backend buffer-file-name))) + (concat " " (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) + +(defun +modeline-track () + "Display `tracking-mode' information." + '(tracking-mode + tracking-mode-line-buffers)) + +(defun +modeline-anzu () + "Display `anzu--update-mode-line'." + (anzu--update-mode-line)) + +(provide '+modeline) +;;; +modeline.el ends here -- cgit 1.4.1-21-gabe81