Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#131] Ignore interrupted processes #139

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions apheleia.el
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,13 @@ This points into a log buffer.")
(&key name stdin stdout stderr command
remote noquery connection-type callback)
"Helper to run a formatter process asynchronously.
This starts a formatter process using COMMAND and then connects STDIN,
STDOUT and STDERR buffers to the processes different streams. Once the
process is finished CALLBACK will be invoked with the exit-code of the
formatter process. REMOTE if supplied will be passed as the FILE-HANDLER
argument to `make-process'.
This starts a formatter process using COMMAND and then connects
STDIN, STDOUT and STDERR buffers to the processes different
streams. Once the process is finished CALLBACK will be invoked
with the exit-code of the formatter process as well as a boolean
saying whether the process was interrupted before completion.
REMOTE if supplied will be passed as the FILE-HANDLER argument to
`make-process'.

See `make-process' for a description of the NAME and NOQUERY arguments."
(let ((proc
Expand All @@ -331,7 +333,10 @@ See `make-process' for a description of the NAME and NOQUERY arguments."
:sentinel
(lambda (proc _event)
(unless (process-live-p proc)
(funcall callback (process-exit-status proc)))))))
(funcall
callback
(process-exit-status proc)
(process-get proc :interrupted)))))))
(set-process-sentinel (get-buffer-process stderr) #'ignore)
(when stdin
(set-process-coding-system
Expand Down Expand Up @@ -424,7 +429,10 @@ NO-QUERY, and CONNECTION-TYPE."
;; Save stderr from STDERR-FILE back into the STDERR buffer.
(with-current-buffer stderr
(insert-file-contents stderr-file))
(funcall callback exit-status)
;; I don't think it's possible to get here if the process
;; was interrupted, since we were running it synchronously,
;; so it should be ok to assume we pass nil to the callback.
(funcall callback exit-status nil)
;; We return nil because there's no live process that can be
;; returned.
nil)
Expand All @@ -449,6 +457,7 @@ formatter buffers file-handler, allowing the process to be
spawned on remote machines."
(when (process-live-p apheleia--current-process)
(message "Interrupting %s" apheleia--current-process)
(process-put apheleia--current-process :interrupted t)
(interrupt-process apheleia--current-process)
(accept-process-output apheleia--current-process 0.1 nil 'just-this-one)
(when (process-live-p apheleia--current-process)
Expand Down Expand Up @@ -477,10 +486,12 @@ spawned on remote machines."
:connection-type 'pipe
:noquery t
:callback
(lambda (proc-exit-status)
(let ((exit-ok (funcall
(or exit-status #'zerop)
proc-exit-status)))
(lambda (proc-exit-status proc-interrupted)
(let ((exit-ok (and
(not proc-interrupted)
(funcall
(or exit-status #'zerop)
proc-exit-status))))
;; Append standard-error from current formatter
;; to log buffer when
;; `apheleia-log-only-errors' is nil or the
Expand Down