summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-12-04 23:09:33 -0600
committerCase Duckworth2021-12-04 23:09:33 -0600
commitb1d307126913cbd4d8af818f7aec7ada6a0ea4ad (patch)
treefdbedcf62596ad56d8bc1a36ea4c4d993ddc3168 /lisp
parentChange defaults (diff)
downloademacs-b1d307126913cbd4d8af818f7aec7ada6a0ea4ad.tar.gz
emacs-b1d307126913cbd4d8af818f7aec7ada6a0ea4ad.zip
uhhhhhhhh
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+elisp.el18
-rw-r--r--lisp/+modeline.el157
-rw-r--r--lisp/+pulse.el50
3 files changed, 225 insertions, 0 deletions
diff --git a/lisp/+elisp.el b/lisp/+elisp.el new file mode 100644 index 0000000..d2f018a --- /dev/null +++ b/lisp/+elisp.el
@@ -0,0 +1,18 @@
1;;; +elisp.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(defun +elisp-eval-region-or-buffer ()
6 (interactive)
7 (if (region-active-p)
8 (eval-region (region-beginning) (region-end))
9 (eval-buffer)))
10
11;; Should I move this to `+pulse' ?
12(defun +eval-region@pulse (advised beg end &rest args)
13 "ADVICE to pulse an eval'd region."
14 (apply advised beg end args)
15 (pulse-momentary-highlight-region beg end))
16
17(provide '+elisp)
18;;; +elisp.el ends here
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.
63The CAR of each field is one of `readonly', `modified',
64`special', `ephemeral', or t, and the CDR is a string to display
65in 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.
71t is the fall-back, shown when nothing else in the alist applies.
72
73The 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
diff --git a/lisp/+pulse.el b/lisp/+pulse.el new file mode 100644 index 0000000..6ba7ded --- /dev/null +++ b/lisp/+pulse.el
@@ -0,0 +1,50 @@
1;;; +pulse.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(defgroup +pulse nil
6 "Extra customizations for `pulse'."
7 :group 'pulse
8 :prefix "+pulse-")
9
10(defcustom +pulse-location-commands '(scroll-up-command
11 scroll-down-command
12 recenter-top-bottom
13 other-window
14 switch-to-buffer
15 redraw-frame)
16 "Commands to pulse the current line after.
17Good for finding location."
18 :type '(repeat function))
19
20(defcustom +pulse-location-function '+pulse-line-current-window
21 "What function to call after `+pulse-location-commands'."
22 :type 'function)
23
24;; XXX: this doesn't work yet. I only want to pulse the line in the
25;; active window, so when I have the same buffer viewed in multiple
26;; windows I can still see where my cursor is. To see the issue, C-x
27;; 2 then C-x o a few times.
28(defun +pulse-line-current-window (&rest _)
29 "Pulse the current line, but only if this window is active."
30 (pulse-momentary-highlight-one-line
31 (window-point (selected-window))))
32
33(defun +pulse--advice-remove (symbol where function &optional props)
34 "Remove advice SYMBOL from FUNCTION.
35This uses the same args as `advice-add' for easy toggling.
36WHERE and PROPS are discarded."
37 (ignore where props)
38 (advice-remove symbol function))
39
40(define-minor-mode +pulse-location-mode
41 "After moving locations, pulse where we are."
42 :global t
43 :keymap nil
44 (dolist (command +pulse-location-commands)
45 (funcall
46 (if +pulse-location-mode 'advice-add '+pulse--advice-remove)
47 command :after +pulse-location-function)))
48
49(provide '+pulse)
50;;; +pulse.el ends here