>From 064e4e4d9958fcfc0980091f302a0dd31bdc4581 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Wed, 25 Oct 2017 16:15:19 +0100 Subject: [PATCH 1/2] Fix buffer name comparison in async shell-command When async-shell-command-display-buffer is nil, the async shell-command process filter passed output-buffer, which could be a buffer object, to string=, resulting in an error. * lisp/simple.el (shell-command): Keep track of output-buffer name to fix this and DRY. Replace quoted lambda with closure. --- lisp/simple.el | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 12d65e50c3..96f5a321f3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3487,10 +3487,11 @@ shell-command (save-match-data (if (string-match "[ \t]*&[ \t]*\\'" command) ;; Command ending with ampersand means asynchronous. - (let ((buffer (get-buffer-create - (or output-buffer "*Async Shell Command*"))) - (directory default-directory) - proc) + (let* ((buffer (get-buffer-create + (or output-buffer "*Async Shell Command*"))) + (name (buffer-name buffer)) + (directory default-directory) + proc) ;; Remove the ampersand. (setq command (substring command 0 (match-beginning 0))) ;; Ask the user what to do with already running process. @@ -3505,30 +3506,24 @@ shell-command ((eq async-shell-command-buffer 'confirm-new-buffer) ;; If will create a new buffer, query first. (if (yes-or-no-p "A command is running in the default buffer. Use a new buffer? ") - (setq buffer (generate-new-buffer - (or (and (bufferp output-buffer) (buffer-name output-buffer)) - output-buffer "*Async Shell Command*"))) + (setq buffer (generate-new-buffer name)) (error "Shell command in progress"))) ((eq async-shell-command-buffer 'new-buffer) ;; It will create a new buffer. - (setq buffer (generate-new-buffer - (or (and (bufferp output-buffer) (buffer-name output-buffer)) - output-buffer "*Async Shell Command*")))) + (setq buffer (generate-new-buffer name))) ((eq async-shell-command-buffer 'confirm-rename-buffer) ;; If will rename the buffer, query first. (if (yes-or-no-p "A command is running in the default buffer. Rename it? ") (progn (with-current-buffer buffer (rename-uniquely)) - (setq buffer (get-buffer-create - (or output-buffer "*Async Shell Command*")))) + (setq buffer (get-buffer-create name))) (error "Shell command in progress"))) ((eq async-shell-command-buffer 'rename-buffer) ;; It will rename the buffer. (with-current-buffer buffer (rename-uniquely)) - (setq buffer (get-buffer-create - (or output-buffer "*Async Shell Command*")))))) + (setq buffer (get-buffer-create name))))) (with-current-buffer buffer (shell-command--save-pos-or-erase) (setq default-directory directory) @@ -3543,13 +3538,11 @@ shell-command (if async-shell-command-display-buffer (display-buffer buffer '(nil (allow-no-window . t))) (add-function :before (process-filter proc) - `(lambda (process string) - (when (and (= 0 (buffer-size (process-buffer process))) - (string= (buffer-name (process-buffer process)) - ,(or output-buffer "*Async Shell Command*"))) - (display-buffer (process-buffer process)))) - )) - )) + (lambda (process _string) + (let ((buf (process-buffer process))) + (when (and (zerop (buffer-size buf)) + (string= (buffer-name buf) name)) + (display-buffer buf)))))))) ;; Otherwise, command is executed synchronously. (shell-command-on-region (point) (point) command output-buffer nil error-buffer))))))) -- 2.14.2