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 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lisp/+apheleia.el') 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) -- cgit 1.4.1-21-gabe81