jwiegley/emacs-async

`async-start-process`: don't use `(current-buffer)` when killing the process buffer

hrehfeld opened this issue · 1 comments

When the async-start-process callback function accidentally kills the processes buffer itself, this kills one other (previous) buffer:

(defun async-when-done (proc &optional _change)
  "Process sentinel used to retrieve the value from the child process."
  (when (eq 'exit (process-status proc))
    (with-current-buffer (process-buffer proc)
      (let ((async-current-process proc))
        (if (= 0 (process-exit-status proc))
            (if async-callback-for-process
                (if async-callback
                    (prog1
                        (funcall async-callback proc)
                      (unless async-debug
                        (kill-buffer (current-buffer)))) ;; FIXME: this may erroneously kill the wrong buffer
                  (set (make-local-variable 'async-callback-value) proc)
                  (set (make-local-variable 'async-callback-value-set) t))
              (goto-char (point-max))
              (backward-sexp)
              (async-handle-result async-callback (read (current-buffer))
                                   (current-buffer)))
          (set (make-local-variable 'async-callback-value)
               (list 'error
                     (format "Async process '%s' failed with exit code %d"
                             (process-name proc) (process-exit-status proc))))
          (set (make-local-variable 'async-callback-value-set) t))))))

I believe the fix is to kill (process-buffer proc) instead. You probably should also check if it is still existing. 💥

Please also add to the documentation of async-start-process that user callbacks don't need to kill the process's buffer.

Thanks!