From 2d6d3945a25a702707145f278f2edcb95d99dd5b Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Wed, 18 Mar 2020 09:09:40 -0600 Subject: [PATCH] [#8] Make sure to reformat correct buffer --- apheleia.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/apheleia.el b/apheleia.el index 5740474..33877bf 100644 --- a/apheleia.el +++ b/apheleia.el @@ -591,19 +591,22 @@ changes), CALLBACK, if provided, is invoked with no arguments." ;; error on `post-command-hook'. (unless (apheleia--disallowed-p) (setq-local apheleia--buffer-hash (apheleia--buffer-hash)) - (apheleia--run-formatter - command - (lambda (formatted-buffer) - ;; Short-circuit. - (when (equal apheleia--buffer-hash (apheleia--buffer-hash)) - (apheleia--create-rcs-patch - (current-buffer) formatted-buffer - (lambda (patch-buffer) - (when (equal apheleia--buffer-hash (apheleia--buffer-hash)) - (apheleia--apply-rcs-patch - (current-buffer) patch-buffer) - (when callback - (funcall callback)))))))))) + (let ((cur-buffer (current-buffer))) + (apheleia--run-formatter + command + (lambda (formatted-buffer) + (with-current-buffer cur-buffer + ;; Short-circuit. + (when (equal apheleia--buffer-hash (apheleia--buffer-hash)) + (apheleia--create-rcs-patch + (current-buffer) formatted-buffer + (lambda (patch-buffer) + (with-current-buffer cur-buffer + (when (equal apheleia--buffer-hash (apheleia--buffer-hash)) + (apheleia--apply-rcs-patch + (current-buffer) patch-buffer) + (when callback + (funcall callback))))))))))))) (defcustom apheleia-post-format-hook nil "Normal hook run after Apheleia formats a buffer."