diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+apheleia.el | 23 | ||||
-rw-r--r-- | lisp/acdw.el | 72 | ||||
-rw-r--r-- | lisp/user-save.el | 22 |
3 files changed, 72 insertions, 45 deletions
diff --git a/lisp/+apheleia.el b/lisp/+apheleia.el index 3428a72..51cf145 100644 --- a/lisp/+apheleia.el +++ b/lisp/+apheleia.el | |||
@@ -3,6 +3,7 @@ | |||
3 | ;;; Code: | 3 | ;;; Code: |
4 | 4 | ||
5 | (require 'cl-lib) | 5 | (require 'cl-lib) |
6 | (require 'el-patch) | ||
6 | (require 'user-save) | 7 | (require 'user-save) |
7 | 8 | ||
8 | ;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 | 9 | ;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 |
@@ -14,13 +15,31 @@ | |||
14 | (point-max)) | 15 | (point-max)) |
15 | (funcall callback))) | 16 | (funcall callback))) |
16 | 17 | ||
18 | ;;; Why does the original function have to check for `apheleia-mode' ? | ||
19 | (el-patch-defun apheleia--format-after-save () | ||
20 | "Run code formatter for current buffer if any configured, then save." | ||
21 | (unless apheleia--format-after-save-in-progress | ||
22 | (when (el-patch-swap apheleia-mode | ||
23 | (or apheleia-mode | ||
24 | +apheleia/user-save-mode)) | ||
25 | (when-let ((formatters (apheleia--get-formatters))) | ||
26 | (apheleia-format-buffer | ||
27 | formatters | ||
28 | (lambda () | ||
29 | (with-demoted-errors "Apheleia: %s" | ||
30 | (when buffer-file-name | ||
31 | (let ((apheleia--format-after-save-in-progress t)) | ||
32 | (apheleia--save-buffer-silently))) | ||
33 | (run-hooks 'apheleia-post-format-hook)))))))) | ||
34 | |||
35 | |||
17 | (define-minor-mode +apheleia/user-save-mode | 36 | (define-minor-mode +apheleia/user-save-mode |
18 | "Minor mode for reformatting code on `user-save'. | 37 | "Minor mode for reformatting code on `user-save'. |
19 | Customize with `apheleia-mode-alist' and `apheleia-formatters'." | 38 | Customize with `apheleia-mode-alist' and `apheleia-formatters'." |
20 | :lighter " Apheleia/US" | 39 | :lighter " Apheleia/US" |
21 | (if +apheleia/user-save-mode | 40 | (if +apheleia/user-save-mode |
22 | (add-hook 'user-save-hook #'apheleia--format-after-save nil 'local) | 41 | (add-hook 'user-save-after-save-hook #'apheleia--format-after-save nil 'local) |
23 | (remove-hook 'user-save-hook #'apheleia--format-after-save 'local))) | 42 | (remove-hook 'user-save-after-save-hook #'apheleia--format-after-save 'local))) |
24 | 43 | ||
25 | (define-globalized-minor-mode +apheleia/user-save-global-mode | 44 | (define-globalized-minor-mode +apheleia/user-save-global-mode |
26 | +apheleia/user-save-mode +apheleia/user-save-mode) | 45 | +apheleia/user-save-mode +apheleia/user-save-mode) |
diff --git a/lisp/acdw.el b/lisp/acdw.el index 26d1494..99ab733 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el | |||
@@ -297,44 +297,44 @@ always nil; this function is mostly intended for use in init." | |||
297 | (setq r (concat r str))) | 297 | (setq r (concat r str))) |
298 | r)) | 298 | r)) |
299 | 299 | ||
300 | (defun chat-disconnect () | 300 | ;; (defun chat-disconnect () |
301 | "Disconnect from all chats." | 301 | ;; "Disconnect from all chats." |
302 | (interactive) | 302 | ;; (interactive) |
303 | (+with-progress "Quitting circe..." | 303 | ;; (+with-progress "Quitting circe..." |
304 | (ignore-errors | 304 | ;; (ignore-errors |
305 | (circe-command-GQUIT "peace love bread") | 305 | ;; (circe-command-GQUIT "peace love bread") |
306 | (cancel-timer (irc-connection-get conn :flood-timer)))) | 306 | ;; (cancel-timer (irc-connection-get conn :flood-timer)))) |
307 | (+with-progress "Quitting jabber..." | 307 | ;; (+with-progress "Quitting jabber..." |
308 | (ignore-errors | 308 | ;; (ignore-errors |
309 | (jabber-disconnect))) | 309 | ;; (jabber-disconnect))) |
310 | (when (boundp '+slack-teams) | 310 | ;; (when (boundp '+slack-teams) |
311 | (+with-progress "Quitting-slack..." | 311 | ;; (+with-progress "Quitting-slack..." |
312 | (dolist (team +slack-teams) | 312 | ;; (dolist (team +slack-teams) |
313 | (ignore-errors | 313 | ;; (ignore-errors |
314 | (slack-team-disconnect team))) | 314 | ;; (slack-team-disconnect team))) |
315 | (ignore-errors (slack-ws-close)))) | 315 | ;; (ignore-errors (slack-ws-close)))) |
316 | (+with-progress "Killing buffers..." | 316 | ;; (+with-progress "Killing buffers..." |
317 | (ignore-errors | 317 | ;; (ignore-errors |
318 | (+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally." | 318 | ;; (+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally." |
319 | (let ((kill-buffer-query-functions nil)) | 319 | ;; (let ((kill-buffer-query-functions nil)) |
320 | (tracking-remove-buffer (current-buffer)) | 320 | ;; (tracking-remove-buffer (current-buffer)) |
321 | (kill-buffer))) | 321 | ;; (kill-buffer))) |
322 | (lambda () "Return t if derived from the following modes." | 322 | ;; (lambda () "Return t if derived from the following modes." |
323 | (derived-mode-p 'lui-mode | 323 | ;; (derived-mode-p 'lui-mode |
324 | 'jabber-chat-mode | 324 | ;; 'jabber-chat-mode |
325 | 'jabber-roster-mode | 325 | ;; 'jabber-roster-mode |
326 | 'jabber-browse-mode | 326 | ;; 'jabber-browse-mode |
327 | 'slack-mode)))))) | 327 | ;; 'slack-mode)))))) |
328 | 328 | ||
329 | ;; I can never remember all the damn chat things I run, so this just does all of em. | 329 | ;; I can never remember all the damn chat things I run, so this just does all of em. |
330 | (defun chat (&optional arg) | 330 | ;; (defun chat (&optional arg) |
331 | "Initiate all chat functions. | 331 | ;; "Initiate all chat functions. |
332 | With optional ARG, kill all chat-related buffers first." | 332 | ;; With optional ARG, kill all chat-related buffers first." |
333 | (interactive "P") | 333 | ;; (interactive "P") |
334 | (when arg (chat-disconnect)) | 334 | ;; (when arg (chat-disconnect)) |
335 | (dolist-with-progress-reporter (fn chat-functions) | 335 | ;; (dolist-with-progress-reporter (fn chat-functions) |
336 | "Connecting to chat..." | 336 | ;; "Connecting to chat..." |
337 | (call-interactively fn))) | 337 | ;; (call-interactively fn))) |
338 | 338 | ||
339 | (defun +forward-paragraph (arg) | 339 | (defun +forward-paragraph (arg) |
340 | "Move forward ARG (simple) paragraphs. | 340 | "Move forward ARG (simple) paragraphs. |
diff --git a/lisp/user-save.el b/lisp/user-save.el index 1c04c9d..674abac 100644 --- a/lisp/user-save.el +++ b/lisp/user-save.el | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | (defgroup user-save nil | 21 | (defgroup user-save nil |
22 | "Group for `user-save-mode' customizations." | 22 | "Group for `user-save-mode' customizations." |
23 | :group 'emacs | 23 | :group 'files |
24 | :prefix "user-save-") | 24 | :prefix "user-save-") |
25 | 25 | ||
26 | (defcustom user-save-hook-into-kill-emacs nil | 26 | (defcustom user-save-hook-into-kill-emacs nil |
@@ -39,8 +39,13 @@ Each predicate will be called with no arguments, and if it | |||
39 | returns t, will inhibit `user-save-mode' from activating." | 39 | returns t, will inhibit `user-save-mode' from activating." |
40 | :type '(repeat function)) | 40 | :type '(repeat function)) |
41 | 41 | ||
42 | (defvar user-save-hook nil | 42 | (defcustom user-save-before-save-hook nil |
43 | "Hook to run when the user, not Emacs, saves the buffer.") | 43 | "Hook to run before the user, not Emacs, saves the buffer." |
44 | :type 'hook) | ||
45 | |||
46 | (defcustom user-save-after-save-hook nil | ||
47 | "Hook to run after the user, not Emacs, saves the buffer." | ||
48 | :type 'hook) | ||
44 | 49 | ||
45 | (defvar user-save-mode-map (let ((map (make-sparse-keymap))) | 50 | (defvar user-save-mode-map (let ((map (make-sparse-keymap))) |
46 | (define-key map (kbd "C-x C-s") #'user-save-buffer) | 51 | (define-key map (kbd "C-x C-s") #'user-save-buffer) |
@@ -49,11 +54,13 @@ returns t, will inhibit `user-save-mode' from activating." | |||
49 | "Keymap for `user-save-mode'. | 54 | "Keymap for `user-save-mode'. |
50 | This map shadows the default map for `save-buffer'.") | 55 | This map shadows the default map for `save-buffer'.") |
51 | 56 | ||
52 | (defun user-save-run-hooks (&rest _) | 57 | (defun user-save-run-hooks (which &rest _) |
53 | "Run the hooks in `user-save-hook'. | 58 | "Run the hooks in one of the user-save-hooks. |
59 | If WHICH is `'before', run `user-save-before-save-hook'; | ||
60 | if it's `after', run `user-save-after-save-hook'. | ||
54 | This does /not/ also save the buffer." | 61 | This does /not/ also save the buffer." |
55 | (with-demoted-errors "User-save-hook error: %S" | 62 | (with-demoted-errors "User-save-hook error: %S" |
56 | (run-hooks 'user-save-hook))) | 63 | (run-hooks (intern (format "user-save-%s-save-hook" which))))) |
57 | 64 | ||
58 | (defun user-save-non-file-buffer-p (&optional buffer-or-name) | 65 | (defun user-save-non-file-buffer-p (&optional buffer-or-name) |
59 | "Return whether BUFFER-OR-NAME is a non-file buffer. | 66 | "Return whether BUFFER-OR-NAME is a non-file buffer. |
@@ -74,8 +81,9 @@ run all the time, put them in `user-save-hook'. | |||
74 | ARG is passed directly to `save-buffer'." | 81 | ARG is passed directly to `save-buffer'." |
75 | (interactive '(called-interactively)) | 82 | (interactive '(called-interactively)) |
76 | (message "User-Saving the buffer...") | 83 | (message "User-Saving the buffer...") |
77 | (user-save-run-hooks) | 84 | (user-save-run-hooks 'before) |
78 | (save-buffer arg) | 85 | (save-buffer arg) |
86 | (user-save-run-hooks 'after) | ||
79 | (message "User-Saving the buffer...Done.")) | 87 | (message "User-Saving the buffer...Done.")) |
80 | 88 | ||
81 | (defun user-save-some-buffers (&optional pred) | 89 | (defun user-save-some-buffers (&optional pred) |