From a7e1b82777b54185260236b6fc9eaf768958ed31 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Tue, 4 Jan 2022 15:56:12 -0800 Subject: [PATCH] [#46] Add apheleia-goto-error --- README.md | 8 +++++++- apheleia.el | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d717c58..2107fc9 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,11 @@ run. Apheleia does not currently support TRAMP, and is therefore automatically disabled for remote files. +If an error occurs while formatting, a message is displayed in the +echo area. You can jump to the error by invoking `M-x +apheleia-goto-error`, or manually switch to the log buffer mentioned +in the message. + You can configure error reporting using the following user options: * `apheleia-hide-log-buffers`: By default, errors from formatters are @@ -178,7 +183,8 @@ You can configure error reporting using the following user options: must type a space to see them). * `apheleia-log-only-errors`: By default, only failed formatter runs are logged. If you customize this user option to nil then all runs - are logged, along with whether or not they succeeded. + are logged, along with whether or not they succeeded. This could be + helpful in debugging. The following user options are also available: diff --git a/apheleia.el b/apheleia.el index 2158f78..6a7ff84 100644 --- a/apheleia.el +++ b/apheleia.el @@ -284,6 +284,10 @@ contains the patch." Keeping track of this helps avoid running more than one process at once.") +(defvar apheleia--last-error-marker nil + "Marker for the last error message for any formatter. +This points into a log buffer.") + (cl-defun apheleia--make-process (&key command stdin callback ensure exit-status formatter) "Wrapper for `make-process' that behaves a bit more nicely. @@ -352,6 +356,12 @@ correspond to a formatter." (unless (bobp) (insert "\n\n\C-l\n")) + (unless exit-ok + (unless apheleia--last-error-marker + (setq apheleia--last-error-marker + (make-marker)) + (move-marker + apheleia--last-error-marker (point)))) (insert (current-time-string) " :: " @@ -417,6 +427,14 @@ correspond to a formatter." (process-send-eof apheleia--current-process)) (error (message "Failed to run %s: %s" name (error-message-string e)))))) +(defun apheleia-goto-error () + "Go to the most recently reported formatter error message." + (interactive) + (unless apheleia--last-error-marker + (user-error "No error has happened yet")) + (pop-to-buffer (marker-buffer apheleia--last-error-marker)) + (goto-char apheleia--last-error-marker)) + (defun apheleia--write-region-silently (start end filename &optional append visit lockname mustbenew write-region)