From cb9cfc5731d7f9e47d00fe5f3ff0077e99b668f7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 21 Jul 2022 00:04:47 -0500 Subject: bleh --- lisp/+apheleia.el | 23 ++++++++++++++++-- lisp/acdw.el | 72 +++++++++++++++++++++++++++---------------------------- lisp/user-save.el | 22 +++++++++++------ 3 files changed, 72 insertions(+), 45 deletions(-) (limited to 'lisp') 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 @@ ;;; Code: (require 'cl-lib) +(require 'el-patch) (require 'user-save) ;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 @@ -14,13 +15,31 @@ (point-max)) (funcall callback))) +;;; Why does the original function have to check for `apheleia-mode' ? +(el-patch-defun apheleia--format-after-save () + "Run code formatter for current buffer if any configured, then save." + (unless apheleia--format-after-save-in-progress + (when (el-patch-swap apheleia-mode + (or apheleia-mode + +apheleia/user-save-mode)) + (when-let ((formatters (apheleia--get-formatters))) + (apheleia-format-buffer + formatters + (lambda () + (with-demoted-errors "Apheleia: %s" + (when buffer-file-name + (let ((apheleia--format-after-save-in-progress t)) + (apheleia--save-buffer-silently))) + (run-hooks 'apheleia-post-format-hook)))))))) + + (define-minor-mode +apheleia/user-save-mode "Minor mode for reformatting code on `user-save'. Customize with `apheleia-mode-alist' and `apheleia-formatters'." :lighter " Apheleia/US" (if +apheleia/user-save-mode - (add-hook 'user-save-hook #'apheleia--format-after-save nil 'local) - (remove-hook 'user-save-hook #'apheleia--format-after-save 'local))) + (add-hook 'user-save-after-save-hook #'apheleia--format-after-save nil 'local) + (remove-hook 'user-save-after-save-hook #'apheleia--format-after-save 'local))) (define-globalized-minor-mode +apheleia/user-save-global-mode +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." (setq r (concat r str))) r)) -(defun chat-disconnect () - "Disconnect from all chats." - (interactive) - (+with-progress "Quitting circe..." - (ignore-errors - (circe-command-GQUIT "peace love bread") - (cancel-timer (irc-connection-get conn :flood-timer)))) - (+with-progress "Quitting jabber..." - (ignore-errors - (jabber-disconnect))) - (when (boundp '+slack-teams) - (+with-progress "Quitting-slack..." - (dolist (team +slack-teams) - (ignore-errors - (slack-team-disconnect team))) - (ignore-errors (slack-ws-close)))) - (+with-progress "Killing buffers..." - (ignore-errors - (+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally." - (let ((kill-buffer-query-functions nil)) - (tracking-remove-buffer (current-buffer)) - (kill-buffer))) - (lambda () "Return t if derived from the following modes." - (derived-mode-p 'lui-mode - 'jabber-chat-mode - 'jabber-roster-mode - 'jabber-browse-mode - 'slack-mode)))))) +;; (defun chat-disconnect () +;; "Disconnect from all chats." +;; (interactive) +;; (+with-progress "Quitting circe..." +;; (ignore-errors +;; (circe-command-GQUIT "peace love bread") +;; (cancel-timer (irc-connection-get conn :flood-timer)))) +;; (+with-progress "Quitting jabber..." +;; (ignore-errors +;; (jabber-disconnect))) +;; (when (boundp '+slack-teams) +;; (+with-progress "Quitting-slack..." +;; (dolist (team +slack-teams) +;; (ignore-errors +;; (slack-team-disconnect team))) +;; (ignore-errors (slack-ws-close)))) +;; (+with-progress "Killing buffers..." +;; (ignore-errors +;; (+mapc-some-buffers (lambda () "Remove the buffer from tracking and kill it unconditionally." +;; (let ((kill-buffer-query-functions nil)) +;; (tracking-remove-buffer (current-buffer)) +;; (kill-buffer))) +;; (lambda () "Return t if derived from the following modes." +;; (derived-mode-p 'lui-mode +;; 'jabber-chat-mode +;; 'jabber-roster-mode +;; 'jabber-browse-mode +;; 'slack-mode)))))) ;; I can never remember all the damn chat things I run, so this just does all of em. -(defun chat (&optional arg) - "Initiate all chat functions. -With optional ARG, kill all chat-related buffers first." - (interactive "P") - (when arg (chat-disconnect)) - (dolist-with-progress-reporter (fn chat-functions) - "Connecting to chat..." - (call-interactively fn))) +;; (defun chat (&optional arg) +;; "Initiate all chat functions. +;; With optional ARG, kill all chat-related buffers first." +;; (interactive "P") +;; (when arg (chat-disconnect)) +;; (dolist-with-progress-reporter (fn chat-functions) +;; "Connecting to chat..." +;; (call-interactively fn))) (defun +forward-paragraph (arg) "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 @@ (defgroup user-save nil "Group for `user-save-mode' customizations." - :group 'emacs + :group 'files :prefix "user-save-") (defcustom user-save-hook-into-kill-emacs nil @@ -39,8 +39,13 @@ Each predicate will be called with no arguments, and if it returns t, will inhibit `user-save-mode' from activating." :type '(repeat function)) -(defvar user-save-hook nil - "Hook to run when the user, not Emacs, saves the buffer.") +(defcustom user-save-before-save-hook nil + "Hook to run before the user, not Emacs, saves the buffer." + :type 'hook) + +(defcustom user-save-after-save-hook nil + "Hook to run after the user, not Emacs, saves the buffer." + :type 'hook) (defvar user-save-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-x C-s") #'user-save-buffer) @@ -49,11 +54,13 @@ returns t, will inhibit `user-save-mode' from activating." "Keymap for `user-save-mode'. This map shadows the default map for `save-buffer'.") -(defun user-save-run-hooks (&rest _) - "Run the hooks in `user-save-hook'. +(defun user-save-run-hooks (which &rest _) + "Run the hooks in one of the user-save-hooks. +If WHICH is `'before', run `user-save-before-save-hook'; +if it's `after', run `user-save-after-save-hook'. This does /not/ also save the buffer." (with-demoted-errors "User-save-hook error: %S" - (run-hooks 'user-save-hook))) + (run-hooks (intern (format "user-save-%s-save-hook" which))))) (defun user-save-non-file-buffer-p (&optional buffer-or-name) "Return whether BUFFER-OR-NAME is a non-file buffer. @@ -74,8 +81,9 @@ run all the time, put them in `user-save-hook'. ARG is passed directly to `save-buffer'." (interactive '(called-interactively)) (message "User-Saving the buffer...") - (user-save-run-hooks) + (user-save-run-hooks 'before) (save-buffer arg) + (user-save-run-hooks 'after) (message "User-Saving the buffer...Done.")) (defun user-save-some-buffers (&optional pred) -- cgit 1.4.1-21-gabe81