emacs: avoid passing around some redundant information

When running "notmuch" we use its full path but when displaying the
command to the user we show just its name for readability reasons.
Avoid passing around both representations because it is very easy
to get the name from the path.

Notmuch itself uses the involved functions just for "notmuch" but
there might be extensions that use them for other executable so we
forgo other potential simplifications.
This commit is contained in:
Jonas Bernoulli 2021-01-10 15:00:44 +01:00 committed by David Bremner
parent 778950872d
commit 904ffbc925

View file

@ -800,13 +800,20 @@ You may need to restart Emacs or upgrade your notmuch Emacs package."))
Emacs requested a newer output format than supported by the notmuch CLI. Emacs requested a newer output format than supported by the notmuch CLI.
You may need to restart Emacs or upgrade your notmuch package.")) You may need to restart Emacs or upgrade your notmuch package."))
(t (t
(let* ((command-string (pcase-let*
((`(,command . ,args) command)
(command (if (equal (file-name-nondirectory command)
notmuch-command)
notmuch-command
command))
(command-string
(mapconcat (lambda (arg) (mapconcat (lambda (arg)
(shell-quote-argument (shell-quote-argument
(cond ((stringp arg) arg) (cond ((stringp arg) arg)
((symbolp arg) (symbol-name arg)) ((symbolp arg) (symbol-name arg))
(t "*UNKNOWN ARGUMENT*")))) (t "*UNKNOWN ARGUMENT*"))))
command " ")) (cons command args)
" "))
(extra (extra
(concat "command: " command-string "\n" (concat "command: " command-string "\n"
(if (integerp exit-status) (if (integerp exit-status)
@ -821,7 +828,7 @@ You may need to restart Emacs or upgrade your notmuch package."))
;; We only have combined output from the CLI; don't inundate ;; We only have combined output from the CLI; don't inundate
;; the user with it. Mimic `process-lines'. ;; the user with it. Mimic `process-lines'.
(notmuch-logged-error (format "%s exited with status %s" (notmuch-logged-error (format "%s exited with status %s"
(car command) exit-status) command exit-status)
extra)) extra))
;; `notmuch-logged-error' does not return. ;; `notmuch-logged-error' does not return.
)))) ))))
@ -908,7 +915,6 @@ status."
(err-proc (get-buffer-process err-buffer))) (err-proc (get-buffer-process err-buffer)))
(process-put proc 'err-buffer err-buffer) (process-put proc 'err-buffer err-buffer)
(process-put proc 'sub-sentinel sentinel) (process-put proc 'sub-sentinel sentinel)
(process-put proc 'real-command (cons notmuch-command args))
(set-process-sentinel proc #'notmuch-start-notmuch-sentinel) (set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
(set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel) (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
proc)) proc))
@ -919,8 +925,7 @@ status."
(err (and (buffer-live-p err-buffer) (err (and (buffer-live-p err-buffer)
(not (zerop (buffer-size err-buffer))) (not (zerop (buffer-size err-buffer)))
(with-current-buffer err-buffer (buffer-string)))) (with-current-buffer err-buffer (buffer-string))))
(sub-sentinel (process-get proc 'sub-sentinel)) (sub-sentinel (process-get proc 'sub-sentinel)))
(real-command (process-get proc 'real-command)))
(condition-case err (condition-case err
(progn (progn
;; Invoke the sub-sentinel, if any ;; Invoke the sub-sentinel, if any
@ -932,7 +937,7 @@ status."
;; and there's no point in telling the user that (but we ;; and there's no point in telling the user that (but we
;; still check for and report stderr output below). ;; still check for and report stderr output below).
(when (buffer-live-p (process-buffer proc)) (when (buffer-live-p (process-buffer proc))
(notmuch-check-async-exit-status proc event real-command err)) (notmuch-check-async-exit-status proc event nil err))
;; If that didn't signal an error, then any error output was ;; If that didn't signal an error, then any error output was
;; really warning output. Show warnings, if any. ;; really warning output. Show warnings, if any.
(let ((warnings (let ((warnings