summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-modeline.el92
-rw-r--r--lisp/acdw-re.el66
-rw-r--r--lisp/acdw.el129
3 files changed, 181 insertions, 106 deletions
diff --git a/lisp/acdw-modeline.el b/lisp/acdw-modeline.el index c7b904f..79249bb 100644 --- a/lisp/acdw-modeline.el +++ b/lisp/acdw-modeline.el
@@ -22,64 +22,60 @@
22(require 'simple-modeline) 22(require 'simple-modeline)
23(require 'minions) 23(require 'minions)
24 24
25;; modified from `simple-modeline' 25(defun acdw-modeline/buffer-name () ; gonsie
26(defun acdw-modeline/modified () 26 (propertize " %b "
27 "Displays a color-coded buffer modification/read-only 27 'face
28 (if (buffer-modified-p)
29 'font-lock-warning-face
30 'font-lock-type-face)
31 'help-echo (buffer-file-name)))
32
33(defun acdw-modeline/god-mode-indicator ()
34 (when (bound-and-true-p god-local-mode)
35 " God"))
36
37(defun acdw-modeline/modified () ; modified from `simple-modeline'
38 "Displays a color-coded buffer modification/read-only
28indicator in the mode-line." 39indicator in the mode-line."
29 (if (not (string-match-p "\\*.*\\*" (buffer-name))) 40 (if (not (string-match-p "\\*.*\\*" (buffer-name)))
30 (let* ((read-only (and buffer-read-only (buffer-file-name))) 41 (let* ((read-only (and buffer-read-only (buffer-file-name)))
31 (modified (buffer-modified-p))) 42 (modified (buffer-modified-p)))
32 (propertize 43 (propertize
33 (if read-only " =" (if modified " +" " -")) 44 (if read-only " =" (if modified " +" " -"))
34 'help-echo (format 45 'help-echo (format
35 (concat "Buffer is %s and %smodified\n" 46 (concat "Buffer is %s and %smodified\n"
36 "mouse-1: Toggle read-only status.") 47 "mouse-1: Toggle read-only status.")
37 (if read-only "read-only" "writable") 48 (if read-only "read-only" "writable")
38 (if modified "" "not ")) 49 (if modified "" "not "))
39 'local-map (purecopy (simple-modeline-make-mouse-map 50 'local-map (purecopy (simple-modeline-make-mouse-map
40 'mouse-1 51 'mouse-1
41 (lambda (event) 52 (lambda (event)
42 (interactive "e") 53 (interactive "e")
43 (with-selected-window 54 (with-selected-window
44 (posn-window (event-start event)) 55 (posn-window (event-start event))
45 (read-only-mode 'toggle))))) 56 (read-only-mode 'toggle)))))
46 'mouse-face 'mode-line-highlight)))) 57 'mouse-face 'mode-line-highlight))))
47 58
48;; all me, baby 59(defun acdw-modeline/minions () ; by me
49(defun acdw-modeline/minions () 60 "Display a button for `minions-minor-modes-menu'."
50 "Display a button for `minions-minor-modes-menu'." 61 (concat
51 (concat 62 " "
52 " " 63 (propertize
53 (propertize 64 "&"
54 "&" 65 'help-echo (format
55 'help-echo (format 66 "Minor modes menu\nmouse-1: show menu.")
56 "Minor modes menu\nmouse-1: show menu.") 67 'local-map (purecopy (simple-modeline-make-mouse-map
57 'local-map (purecopy (simple-modeline-make-mouse-map 68 'mouse-1
58 'mouse-1 69 (lambda (event)
59 (lambda (event) 70 (interactive "e")
60 (interactive "e") 71 (with-selected-window (posn-window
61 (with-selected-window (posn-window 72 (event-start event))
62 (event-start event)) 73 (minions-minor-modes-menu)))))
63 (minions-minor-modes-menu))))) 74 'mouse-face 'mode-line-highlight)))
64 'mouse-face 'mode-line-highlight)))
65 75
66;; from https://www.gonsie.com/blorg/modeline.html, from Doom
67(defun acdw-modeline/vc-branch () 76(defun acdw-modeline/vc-branch ()
77 ;; from https://www.gonsie.com/blorg/modeline.html, from Doom
68 (if-let ((backend (vc-backend buffer-file-name))) 78 (if-let ((backend (vc-backend buffer-file-name)))
69 (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)))) 79 (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))
70
71;; from gonsie
72(defun acdw-modeline/buffer-name ()
73 (propertize " %b "
74 'face
75 (if (buffer-modified-p)
76 'font-lock-warning-face
77 'font-lock-type-face)
78 'help-echo (buffer-file-name)))
79
80;; god-mode indicator
81(defun acdw-modeline/god-mode-indicator ()
82 (when (bound-and-true-p god-local-mode)
83 " God"))
84 80
85(provide 'acdw-modeline) 81(provide 'acdw-modeline)
diff --git a/lisp/acdw-re.el b/lisp/acdw-re.el new file mode 100644 index 0000000..ea1c42a --- /dev/null +++ b/lisp/acdw-re.el
@@ -0,0 +1,66 @@
1;;; acdw-re.el -*- lexical-binding: t; coding: utf-8-unix -*-
2;; Author: Case Duckworth <acdw@acdw.net>
3;; Created: 2021-04-29
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;; Pulled mostly from karthinks:
18;; https://karthinks.com/software/bridging-islands-in-emacs-1/
19
20;;; Code:
21
22(defvar acdw/re-builder-positions nil
23 "Store point and region bounds before calling re-builder")
24
25(defun acdw/re-builder-save-state (&rest _)
26 "Save into `acdw/re-builder-positions' the point and region
27positions before calling `re-builder'."
28 (setq acdw/re-builder-positions
29 (cons (point)
30 (when (region-active-p)
31 (list (region-beginning)
32 (region-end))))))
33
34(defun reb-replace-regexp (&optional delimited)
35 "Run `query-replace-regexp' with the contents of re-builder. With
36non-nil optional argument DELIMITED, only replace matches
37surrounded by word boundaries."
38 (interactive "P")
39 (reb-update-regexp)
40 (let* ((re (reb-target-binding reb-regexp))
41 (replacement (query-replace-read-to
42 re
43 (concat "Query replace"
44 (if current-prefix-arg
45 (if (eq current-prefix-arg '-)
46 " backward"
47 " word")
48 "")
49 " regexp"
50 (if (with-selected-window reb-target-window
51 (region-active-p)) " in region" ""))
52 t))
53 (pnt (car acdw/re-builder-positions))
54 (beg (cadr acdw/re-builder-positions))
55 (end (caddr acdw/re-builder-positions)))
56 (with-selected-window reb-target-window
57 ;; replace with (goto-char (match-beginning 0)) if you want to control
58 ;; where in the buffer the replacement starts with re-builder
59 (goto-char pnt)
60 (setq acdw/re-builder-positions nil)
61 (reb-quit)
62 (query-replace-regexp re replacement delimited beg end))))
63
64(provide 'acdw-re)
65
66;;; acdw-re.el ends here
diff --git a/lisp/acdw.el b/lisp/acdw.el index 54b139c..1093a8d 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -19,7 +19,7 @@
19 19
20;;; Code: 20;;; Code:
21 21
22;; Utility constants 22;;; Variables
23 23
24(defconst acdw/system (pcase system-type 24(defconst acdw/system (pcase system-type
25 ('gnu/linux :home) 25 ('gnu/linux :home)
@@ -28,19 +28,15 @@
28 "Which computer system is currently being used.") 28 "Which computer system is currently being used.")
29 29
30 30
31;; Utility functions 31;;; Utility functions
32 32
33(defmacro when-unfocused (name &rest forms) 33(defun expand-file-name-exists-p (&rest expand-file-name-args)
34 "Define a function NAME, executing FORMS, that fires when Emacs 34 "Call `expand-file-name' on EXPAND-FILE-NAME-ARGS, returning
35is unfocused." 35 its name if it exists, or NIL otherwise."
36 (declare (indent 1)) 36 (let ((file (apply #'expand-file-name expand-file-name-args)))
37 (let ((func-name (intern (concat "when-unfocused-" (symbol-name name))))) 37 (if (file-exists-p file)
38 `(progn 38 file
39 (defun ,func-name () "Defined by `when-unfocused'." 39 nil)))
40 (when (seq-every-p #'null
41 (mapcar #'frame-focus-state (frame-list)))
42 ,@forms))
43 (add-function :after after-focus-change-function #',func-name))))
44 40
45(defmacro hook-defun (name hooks &rest forms) 41(defmacro hook-defun (name hooks &rest forms)
46 "Define a function NAME that executes FORMS, and add it to 42 "Define a function NAME that executes FORMS, and add it to
@@ -88,13 +84,17 @@ With a prefix argument, run git pull on the repo first."
88 (when (file-exists-p file) 84 (when (file-exists-p file)
89 (load-file file)))))) 85 (load-file file))))))
90 86
91(defun expand-file-name-exists-p (&rest expand-file-name-args) 87(defmacro when-unfocused (name &rest forms)
92 "Call `expand-file-name' on EXPAND-FILE-NAME-ARGS, returning 88 "Define a function NAME, executing FORMS, that fires when Emacs
93 its name if it exists, or NIL otherwise." 89is unfocused."
94 (let ((file (apply #'expand-file-name expand-file-name-args))) 90 (declare (indent 1))
95 (if (file-exists-p file) 91 (let ((func-name (intern (concat "when-unfocused-" (symbol-name name)))))
96 file 92 `(progn
97 nil))) 93 (defun ,func-name () "Defined by `when-unfocused'."
94 (when (seq-every-p #'null
95 (mapcar #'frame-focus-state (frame-list)))
96 ,@forms))
97 (add-function :after after-focus-change-function #',func-name))))
98 98
99(defmacro with-message (message &rest body) 99(defmacro with-message (message &rest body)
100 "Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after." 100 "Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after."
@@ -105,6 +105,9 @@ With a prefix argument, run git pull on the repo first."
105 ,@body) 105 ,@body)
106 (message "%s... Done." ,message))) 106 (message "%s... Done." ,message)))
107 107
108
109;;; Specialized functions
110
108(defun acdw/dir (&optional file make-directory) 111(defun acdw/dir (&optional file make-directory)
109 "Place Emacs files in one place. 112 "Place Emacs files in one place.
110 113
@@ -122,37 +125,6 @@ if MAKE-DIRECTORY is non-nil."
122 file-name) 125 file-name)
123 dir))) 126 dir)))
124 127
125(defun acdw/gc-enable ()
126 "Enable the Garbage collector."
127 (setq gc-cons-threshold (* 800 1024 1024)
128 gc-cons-percentage 0.1))
129
130(defun acdw/gc-disable ()
131 "Functionally disable the Garbage collector."
132 (setq gc-cons-threshold most-positive-fixnum
133 gc-cons-percentage 0.8))
134
135(defun acdw/sunrise-sunset (sunrise-command sunset-command)
136 "Run commands at sunrise and sunset."
137 (let* ((times-regex (rx (* nonl)
138 (: (any ?s ?S) "unrise") " "
139 (group (repeat 1 2 digit) ":"
140 (repeat 1 2 digit)
141 (: (any ?a ?A ?p ?P) (any ?m ?M)))
142 (* nonl)
143 (: (any ?s ?S) "unset") " "
144 (group (repeat 1 2 digit) ":"
145 (repeat 1 2 digit)
146 (: (any ?a ?A ?p ?P) (any ?m ?M)))
147 (* nonl)))
148 (ss (sunrise-sunset))
149 (_m (string-match times-regex ss))
150 (sunrise-time (match-string 1 ss))
151 (sunset-time (match-string 2 ss)))
152 (run-at-time sunrise-time (* 60 60 24) sunrise-command)
153 (run-at-time sunset-time (* 60 60 24) sunset-command)
154 (run-at-time "12:00am" (* 60 60 24) sunset-command)))
155
156(defun acdw/find-emacs-dotfiles () 128(defun acdw/find-emacs-dotfiles ()
157 "Finds lisp files in `user-emacs-directory' and passes them to 129 "Finds lisp files in `user-emacs-directory' and passes them to
158 `completing-read'." 130 `completing-read'."
@@ -161,6 +133,30 @@ if MAKE-DIRECTORY is non-nil."
161 (directory-files-recursively 133 (directory-files-recursively
162 user-emacs-directory "\.el$")))) 134 user-emacs-directory "\.el$"))))
163 135
136(defun acdw/find-emacs-source ()
137 "Find where Emacs keeps its source tree."
138 (pcase acdw/system
139 (:work (expand-file-name
140 (concat "~/src/emacs-" emacs-version "/src")))
141 (:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src"))
142 (:other nil)))
143
144(defun acdw/gc-disable ()
145 "Functionally disable the Garbage collector."
146 (setq gc-cons-threshold most-positive-fixnum
147 gc-cons-percentage 0.8))
148
149(defun acdw/gc-enable ()
150 "Enable the Garbage collector."
151 (setq gc-cons-threshold (* 800 1024 1024)
152 gc-cons-percentage 0.1))
153
154(defun acdw/insert-iso-date (with-time)
155 "Insert the ISO-8601-formatted date, with optional time."
156 (interactive "P")
157 (let ((format (if with-time "%FT%T%z" "%F")))
158 (insert (format-time-string format (current-time)))))
159
164(defun acdw/kill-a-buffer (&optional prefix) 160(defun acdw/kill-a-buffer (&optional prefix)
165 "Kill a buffer based on the following rules: 161 "Kill a buffer based on the following rules:
166 162
@@ -179,14 +175,30 @@ Prompt only if there are unsaved changes."
179 (16 (mapc 'kill-buffer (delq (current-buffer) (buffer-list))) 175 (16 (mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
180 (delete-other-windows)))) 176 (delete-other-windows))))
181 177
182(defun acdw/insert-iso-date (with-time) 178(defun acdw/sunrise-sunset (sunrise-command sunset-command)
183 "Insert the ISO-8601-formatted date, with optional time." 179 "Run commands at sunrise and sunset."
184 (interactive "P") 180 (let* ((times-regex (rx (* nonl)
185 (let ((format (if with-time "%FT%T%z" "%F"))) 181 (: (any ?s ?S) "unrise") " "
186 (insert (format-time-string format (current-time))))) 182 (group (repeat 1 2 digit) ":"
183 (repeat 1 2 digit)
184 (: (any ?a ?A ?p ?P) (any ?m ?M)))
185 (* nonl)
186 (: (any ?s ?S) "unset") " "
187 (group (repeat 1 2 digit) ":"
188 (repeat 1 2 digit)
189 (: (any ?a ?A ?p ?P) (any ?m ?M)))
190 (* nonl)))
191 (ss (sunrise-sunset))
192 (_m (string-match times-regex ss))
193 (sunrise-time (match-string 1 ss))
194 (sunset-time (match-string 2 ss)))
195 (run-at-time sunrise-time (* 60 60 24) sunrise-command)
196 (run-at-time sunset-time (* 60 60 24) sunset-command)
197 (run-at-time "12:00am" (* 60 60 24) sunset-command)))
187 198
188 199
189;; Make `C-z' more useful 200;;; Keymaps
201
190(defvar acdw/leader 202(defvar acdw/leader
191 (let ((map (make-sparse-keymap)) 203 (let ((map (make-sparse-keymap))
192 (c-z (global-key-binding "\C-z"))) 204 (c-z (global-key-binding "\C-z")))
@@ -195,7 +207,8 @@ Prompt only if there are unsaved changes."
195 map)) 207 map))
196 208
197 209
198;; `acdw/reading-mode' 210;;; Minor modes
211
199(define-minor-mode acdw/reading-mode 212(define-minor-mode acdw/reading-mode
200 "A mode for reading." 213 "A mode for reading."
201 :init-value nil 214 :init-value nil