about summary refs log tree commit diff stats
path: root/lisp/acdw-modeline.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/acdw-modeline.el')
-rw-r--r--lisp/acdw-modeline.el232
1 files changed, 0 insertions, 232 deletions
diff --git a/lisp/acdw-modeline.el b/lisp/acdw-modeline.el deleted file mode 100644 index 0dc23ff..0000000 --- a/lisp/acdw-modeline.el +++ /dev/null
@@ -1,232 +0,0 @@
1;;; acdw-modeline.el -*- lexical-binding: t; coding: utf-8-unix -*-
2;; Author: Case Duckworth <(rot13-string "npqj@npqj.arg")>
3;; Created: Sometime during Covid-19, 2020
4;; Keywords: configuration
5;; URL: https://tildegit.org/acdw/emacs
6
7;; This file is NOT part of GNU Emacs.
8
9;;; License:
10;; Everyone is permitted to do whatever with this software, without
11;; limitation. This software comes without any warranty whatsoever,
12;; but with two pieces of advice:
13;; - Don't hurt yourself.
14;; - Make good choices.
15
16;;; Commentary:
17;; `acdw-modeline' is a dumping ground for extra modeline functions, so they
18;; don't clutter up `init.el'.
19
20;;; Code:
21
22(require 'simple-modeline)
23(require 'minions)
24
25(defcustom acdw-modeline/word-count-modes
26 (mapcar (lambda (m) (cons m nil)) simple-modeline-word-count-modes)
27 "Alist of modes to functions that `acdw-modeline/word-count' should dispatch.
28If the cdr of the cons cell is nil, use the default function (`count-words').
29Otherwise, cdr should be a function that takes two points (see `count-words')."
30 :type '(alist :key-type (symbol :tag "Major-Mode")
31 :value-type function)
32 :group 'simple-modeline)
33
34(defun acdw-modeline/buffer-name () ; gonsie
35 "Display the buffer name in a face reflecting its modified status."
36 (propertize
37 (concat
38 (format " %-20s"
39 (truncate-string 20
40 (string-trim (buffer-name) "*" "*")
41 "~")))
42 'face 'bold
43 ;; (if (buffer-modified-p)
44 ;; 'font-lock-warning-face
45 ;; 'font-lock-type-face)
46 'help-echo (or (buffer-file-name)
47 (buffer-name))))
48
49(defun acdw-modeline/erc ()
50 "ERC indicator for the modeline."
51 (when (and (bound-and-true-p erc-track-mode)
52 (boundp 'erc-modified-channels-object))
53 (format-mode-line erc-modified-channels-object)))
54
55(defun acdw-modeline/god-mode-indicator ()
56 "Display an indicator if `god-local-mode' is active."
57 (when (bound-and-true-p god-local-mode)
58 " Ω"))
59
60(defun acdw-modeline/major-mode ()
61 "Displays the current major mode in the mode-line."
62 (propertize
63 (concat " "
64 (or (and (boundp 'delighted-modes)
65 (cadr (assq major-mode delighted-modes)))
66 (format-mode-line mode-name)))
67 'face 'bold
68 'keymap mode-line-major-mode-keymap
69 'mouse-face 'mode-line-highlight))
70
71(defun acdw-modeline/minions () ; by me
72 "Display a button for `minions-minor-modes-menu'."
73 (concat
74 " "
75 (propertize
76 "&"
77 'help-echo (format
78 "Minor modes menu\nmouse-1: show menu.")
79 'local-map (purecopy (simple-modeline-make-mouse-map
80 'mouse-1
81 (lambda (event)
82 (interactive "e")
83 (with-selected-window (posn-window
84 (event-start event))
85 (minions-minor-modes-menu)))))
86 'mouse-face 'mode-line-highlight)))
87
88(defun acdw-modeline/nyan-cat ()
89 "Display the nyan cat from function `nyan-mode' in the mode-line."
90 (when (bound-and-true-p nyan-mode)
91 (if (eq (bound-and-true-p actually-selected-window)
92 (get-buffer-window))
93 '(" " (:eval (list (nyan-create))))
94 `(:propertize " "
95 display
96 (space ;; pixel perfect babeeeee
97 . (:width (,(+ 9 (* 8 (or
98 (bound-and-true-p nyan-bar-length)
99 20))))))))))
100
101(defun acdw-modeline/modified () ; modified from `simple-modeline'
102 "Displays a color-coded buffer modification/read-only
103indicator in the mode-line."
104 (let* ((read-only (and buffer-read-only (buffer-file-name)))
105 (modified (buffer-modified-p)))
106 (propertize
107 (concat " "
108 (cond
109 ((string-match-p "\\*.*\\*" (buffer-name))
110 "*")
111 ((derived-mode-p 'special-mode
112 'lui-mode)
113 "~")
114 (read-only "=")
115 (modified "+")
116 (t "-")))
117 'help-echo (format
118 (concat "Buffer is %s and %smodified\n"
119 "mouse-1: Toggle read-only status.")
120 (if read-only "read-only" "writable")
121 (if modified "" "not "))
122 'local-map (purecopy (simple-modeline-make-mouse-map
123 'mouse-1
124 (lambda (event)
125 (interactive "e")
126 (with-selected-window
127 (posn-window (event-start event))
128 (read-only-mode 'toggle)))))
129 'mouse-face 'mode-line-highlight)))
130
131(defun acdw-modeline/narrowed ()
132 "Display an indication if the buffer is narrowed."
133 (when (buffer-narrowed-p)
134 (concat
135 ""
136 (propertize
137 "N"
138 'help-echo (format "%s\n%s"
139 "Buffer is narrowed"
140 "mouse-2: widen buffer.")
141 'local-map (purecopy (simple-modeline-make-mouse-map
142 'mouse-2 #'mode-line-widen))
143 'mouse-face 'mode-line-highlight))))
144
145(define-minor-mode file-percentage-mode
146 "Toggle the percentage display in the mode line (File Percentage Mode)."
147 :init-value t :global t :group 'mode-line)
148
149(defun acdw-modeline/position ()
150 "Displays the current cursor position in the mode-line.
151
152Unlike `simple-modeline-segment-position', this changes the first
153character from '+' to '-' if the region goes 'backward' -- that
154is, if point < mark."
155 `((line-number-mode
156 ((column-number-mode
157 (column-number-indicator-zero-based
158 (9 " %l/%c")
159 (9 " %l/%C"))
160 (6 " L%l")))
161 ((column-number-mode
162 (column-number-indicator-zero-based
163 (5 " C%c")
164 (5 " C%C")))
165 " "))
166 (file-percentage-mode
167 ((-3 "%p") "%% "))
168 ,(if (region-active-p)
169 (propertize (format "%s%-5d"
170 (if (and (mark)
171 (< (point) (mark)))
172 "-"
173 "+")
174 (apply #'+ (mapcar
175 (lambda (pos)
176 (- (cdr pos)
177 (car pos)))
178 (region-bounds))))
179 'font-lock-face 'font-lock-variable-name-face))))
180
181(defun acdw-modeline/reading-mode ()
182 "Display an indicator if currently in reading mode, mine or EWW's."
183 (concat (if reading-mode "R" "") (if eww-readable-p "w" "")))
184
185(defun acdw-modeline/text-scale ()
186 "Display the text scaling from the modeline, if scaled."
187 ;; adapted from https://github.com/seagle0128/doom-modeline
188 (when (and (boundp 'text-scale-mode-amount)
189 (/= text-scale-mode-amount 0))
190 (format
191 (if (> text-scale-mode-amount 0)
192 " (%+d)"
193 " (%-d)")
194 text-scale-mode-amount)))
195
196(defun acdw-modeline/track ()
197 "Display `tracking-mode' information."
198 '(tracking-mode
199 tracking-mode-line-buffers))
200
201(defun acdw-modeline/vc-branch ()
202 "Display the version control branch of the current buffer in the modeline."
203 ;; from https://www.gonsie.com/blorg/modeline.html, from Doom
204 (if-let ((backend (vc-backend buffer-file-name)))
205 (concat " " (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)))))
206
207(defun acdw-modeline/wc ()
208 "Display current `wc-buffer-stats'."
209 (when (bound-and-true-p wc-mode)
210 (format "%8s" (or (cadr wc-buffer-stats) "[w]"))))
211
212(defun acdw-modeline/winum ()
213 "Show the `winum' number of the current window in the modeline.
214Only shows if there is more than one window."
215 (when (and (bound-and-true-p winum-mode)
216 (> winum--window-count 1))
217 (format winum-format (winum-get-number-string))))
218
219(defun acdw-modeline/word-count ()
220 "Display a buffer word count, depending on the major mode.
221Uses `acdw-modeline/word-count-modes' to determine which function to use."
222 (when-let ((modefun
223 (assoc major-mode acdw-modeline/word-count-modes #'equal)))
224 (let* ((fn (or (cdr modefun)
225 #'count-words))
226 (r (region-active-p))
227 (min (if r (region-beginning) (point-min)))
228 (max (if r (region-end) (point-max))))
229 (format " %s%dW" (if r "+" "") (funcall fn min max)))))
230
231(provide 'acdw-modeline)
232;;; acdw-modeline.el ends here