diff options
Diffstat (limited to 'lisp/+modeline.el')
-rw-r--r-- | lisp/+modeline.el | 157 |
1 files changed, 157 insertions, 0 deletions
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 @@ | |||
1 | ;;; +modeline.el --- my modeline customizations -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; `+modeline.el' is kind of a dumping ground for various | ||
6 | ;; modeline-related functions. I probably don't use everything in | ||
7 | ;; here. Credit given where possible. | ||
8 | |||
9 | ;;; Code: | ||
10 | |||
11 | (require '+util) | ||
12 | (require 'simple-modeline) | ||
13 | (require 'minions) | ||
14 | |||
15 | (defgroup +modeline nil | ||
16 | "Various customization options for my modeline things." | ||
17 | :prefix "+modeline-" | ||
18 | :group 'simple-modeline) | ||
19 | |||
20 | (defun +modeline-buffer-name () ; gonsie | ||
21 | "Display the buffer name." | ||
22 | (propertize | ||
23 | (+string-align (buffer-name) 20 :before " " :ellipsis "… ") | ||
24 | 'face 'bold | ||
25 | 'help-echo (or (buffer-file-name) | ||
26 | (buffer-name)) | ||
27 | 'mouse-face 'mode-line-highlight)) | ||
28 | |||
29 | (defcustom +modeline-minions-icon "&" | ||
30 | "The \"icon\" for `+modeline-minions' button." | ||
31 | :type 'string) | ||
32 | |||
33 | (defun +modeline-minions () | ||
34 | "Display a button for `minions-minor-modes-menu'." | ||
35 | (concat " " | ||
36 | (propertize | ||
37 | +modeline-minions-icon | ||
38 | 'help-echo "Minor modes menu\nmouse-1: show menu." | ||
39 | 'local-map (purecopy (simple-modeline-make-mouse-map | ||
40 | 'mouse-1 | ||
41 | (lambda (event) | ||
42 | (interactive "e") | ||
43 | (with-selected-window | ||
44 | (posn-window (event-start event)) | ||
45 | (minions-minor-modes-menu))))) | ||
46 | 'mouse-face 'mode-line-highlight))) | ||
47 | |||
48 | (defun +modeline-major-mode () | ||
49 | "Display the current `major-mode'." | ||
50 | (concat " " | ||
51 | (propertize (+string-truncate (format-mode-line mode-name) | ||
52 | 12 "…") | ||
53 | 'face 'bold | ||
54 | 'keymap mode-line-major-mode-keymap | ||
55 | 'mouse-face 'mode-line-highlight))) | ||
56 | |||
57 | (defcustom +modeline-modified-icon-alist '((ephemeral . "*") | ||
58 | (readonly . "=") | ||
59 | (modified . "+") | ||
60 | (special . "~") | ||
61 | (t . "-")) | ||
62 | "\"Icons\" to display depending on buffer status in modeline. | ||
63 | The CAR of each field is one of `readonly', `modified', | ||
64 | `special', `ephemeral', or t, and the CDR is a string to display | ||
65 | in that mode. | ||
66 | |||
67 | `readonly' is true if the buffer is read-only and visiting a file. | ||
68 | `modified' is true if the buffer is modified. | ||
69 | `special' is true if the buffer is a special-mode or derived buffer. | ||
70 | `ephemeral' is true if the buffer is not visiting a file. | ||
71 | t is the fall-back, shown when nothing else in the alist applies. | ||
72 | |||
73 | The order of elements matters: whichever one matches first is applied." | ||
74 | :type '(alist :key-type symbol | ||
75 | :value-type string) | ||
76 | :options '("readonly" "modified" "special" "t")) | ||
77 | |||
78 | (defcustom +modeline-modified-icon-special-modes '(special-mode) | ||
79 | "Modes to apply the `special-mode' icon to in the | ||
80 | `+modeline-modified'." | ||
81 | :type '(repeat function)) | ||
82 | |||
83 | (defun +modeline-modified () ; modified from `simple-modeline-status-modified' | ||
84 | "Display a color-coded \"icon\" indicator for the buffer's status." | ||
85 | (let* ((icon (catch :icon | ||
86 | (dolist (cell +modeline-modified-icon-alist) | ||
87 | (when (pcase (car cell) | ||
88 | ('ephemeral (not (buffer-file-name))) | ||
89 | ('readonly buffer-read-only) | ||
90 | ('modified (buffer-modified-p)) | ||
91 | ('special | ||
92 | (apply 'derived-mode-p | ||
93 | +modeline-modified-icon-special-modes)) | ||
94 | ('t t) | ||
95 | (_ nil)) | ||
96 | (throw :icon (cdr cell))))))) | ||
97 | (concat " " | ||
98 | (propertize (or icon "") | ||
99 | 'mouse-face 'mode-line-highlight)))) | ||
100 | |||
101 | (defun +modeline-narrowed () | ||
102 | "Display an indication that the buffer is narrowed." | ||
103 | (when (buffer-narrowed-p) | ||
104 | (concat " " | ||
105 | (propertize "N" | ||
106 | 'help-echo (format "%s\n%s" | ||
107 | "Buffer is narrowed." | ||
108 | "mouse-2: widen buffer.") | ||
109 | 'local-map (purecopy (simple-modeline-make-mouse-map | ||
110 | 'mouse-2 'mode-line-widen)) | ||
111 | 'mouse-face 'mode-line-highlight)))) | ||
112 | |||
113 | (define-minor-mode file-percentage-mode | ||
114 | "Toggle the percentage display in the mode line (File Percentage Mode)." | ||
115 | :init-value t :global t :group 'mode-line) | ||
116 | |||
117 | (defun +modeline-position () ; adapted from `simple-modeline' | ||
118 | "Display the current cursor position." | ||
119 | (list '((line-number-mode | ||
120 | ((column-number-mode | ||
121 | (column-number-indicator-zero-based | ||
122 | (9 " %l:%c") | ||
123 | (9 " %l:%C")) | ||
124 | (6 " %l:"))) | ||
125 | ((column-number-mode | ||
126 | (column-number-indicator-zero-based | ||
127 | (5 " :%c") | ||
128 | (5 " :%C")))))) | ||
129 | '(file-percentage-mode | ||
130 | ((-3 "%p") "%% ")) | ||
131 | (if (region-active-p) | ||
132 | (propertize (format "%s%-5d" | ||
133 | (if (and (mark) (< (point) (mark))) "-" "+") | ||
134 | (apply '+ (mapcar | ||
135 | (lambda (pos) | ||
136 | (- (cdr pos) | ||
137 | (car pos))) | ||
138 | (region-bounds)))) | ||
139 | 'font-lock-face 'font-lock-variable-name-face)))) | ||
140 | |||
141 | (defun +modeline-vc () | ||
142 | "Display the version control branch of the current buffer in the modeline." | ||
143 | ;; from https://www.gonsie.com/blorg/modeline.html, from Doom | ||
144 | (if-let ((backend (vc-backend buffer-file-name))) | ||
145 | (concat " " (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) | ||
146 | |||
147 | (defun +modeline-track () | ||
148 | "Display `tracking-mode' information." | ||
149 | '(tracking-mode | ||
150 | tracking-mode-line-buffers)) | ||
151 | |||
152 | (defun +modeline-anzu () | ||
153 | "Display `anzu--update-mode-line'." | ||
154 | (anzu--update-mode-line)) | ||
155 | |||
156 | (provide '+modeline) | ||
157 | ;;; +modeline.el ends here | ||