summary refs log tree commit diff stats
path: root/lisp/acdw.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/acdw.el')
-rw-r--r--lisp/acdw.el129
1 files changed, 71 insertions, 58 deletions
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