[#46] Add apheleia-goto-error

This commit is contained in:
Radon Rosborough 2022-01-04 15:56:12 -08:00
parent 38fb69019f
commit a7e1b82777
2 changed files with 25 additions and 1 deletions

View file

@ -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:

View file

@ -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)