aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBasil L. Contovounesios2017-11-03 11:50:13 +0200
committerEli Zaretskii2017-11-03 11:50:13 +0200
commit9f4f130b793e3a6ef7abef99e3e892271128e4b2 (patch)
tree3d0ebf60f46612751038c7087e17475950f9e83c
parentc911b27aff8dd15cd47a063dc958e6dae74dde06 (diff)
downloademacs-9f4f130b793e3a6ef7abef99e3e892271128e4b2.tar.gz
emacs-9f4f130b793e3a6ef7abef99e3e892271128e4b2.zip
Fix buffer name comparison in async shell-command
* lisp/simple.el (shell-command): Keep track of output-buffer by its name, not by its object. (Bug#28997)
-rw-r--r--lisp/simple.el40
1 files changed, 17 insertions, 23 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 372e153d626..4db81071b58 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3487,10 +3487,11 @@ the use of a shell (with its need to quote arguments)."
3487 (save-match-data 3487 (save-match-data
3488 (if (string-match "[ \t]*&[ \t]*\\'" command) 3488 (if (string-match "[ \t]*&[ \t]*\\'" command)
3489 ;; Command ending with ampersand means asynchronous. 3489 ;; Command ending with ampersand means asynchronous.
3490 (let ((buffer (get-buffer-create 3490 (let* ((buffer (get-buffer-create
3491 (or output-buffer "*Async Shell Command*"))) 3491 (or output-buffer "*Async Shell Command*")))
3492 (directory default-directory) 3492 (bname (buffer-name buffer))
3493 proc) 3493 (directory default-directory)
3494 proc)
3494 ;; Remove the ampersand. 3495 ;; Remove the ampersand.
3495 (setq command (substring command 0 (match-beginning 0))) 3496 (setq command (substring command 0 (match-beginning 0)))
3496 ;; Ask the user what to do with already running process. 3497 ;; Ask the user what to do with already running process.
@@ -3505,30 +3506,24 @@ the use of a shell (with its need to quote arguments)."
3505 ((eq async-shell-command-buffer 'confirm-new-buffer) 3506 ((eq async-shell-command-buffer 'confirm-new-buffer)
3506 ;; If will create a new buffer, query first. 3507 ;; If will create a new buffer, query first.
3507 (if (yes-or-no-p "A command is running in the default buffer. Use a new buffer? ") 3508 (if (yes-or-no-p "A command is running in the default buffer. Use a new buffer? ")
3508 (setq buffer (generate-new-buffer 3509 (setq buffer (generate-new-buffer bname))
3509 (or (and (bufferp output-buffer) (buffer-name output-buffer))
3510 output-buffer "*Async Shell Command*")))
3511 (error "Shell command in progress"))) 3510 (error "Shell command in progress")))
3512 ((eq async-shell-command-buffer 'new-buffer) 3511 ((eq async-shell-command-buffer 'new-buffer)
3513 ;; It will create a new buffer. 3512 ;; It will create a new buffer.
3514 (setq buffer (generate-new-buffer 3513 (setq buffer (generate-new-buffer bname)))
3515 (or (and (bufferp output-buffer) (buffer-name output-buffer))
3516 output-buffer "*Async Shell Command*"))))
3517 ((eq async-shell-command-buffer 'confirm-rename-buffer) 3514 ((eq async-shell-command-buffer 'confirm-rename-buffer)
3518 ;; If will rename the buffer, query first. 3515 ;; If will rename the buffer, query first.
3519 (if (yes-or-no-p "A command is running in the default buffer. Rename it? ") 3516 (if (yes-or-no-p "A command is running in the default buffer. Rename it? ")
3520 (progn 3517 (progn
3521 (with-current-buffer buffer 3518 (with-current-buffer buffer
3522 (rename-uniquely)) 3519 (rename-uniquely))
3523 (setq buffer (get-buffer-create 3520 (setq buffer (get-buffer-create bname)))
3524 (or output-buffer "*Async Shell Command*"))))
3525 (error "Shell command in progress"))) 3521 (error "Shell command in progress")))
3526 ((eq async-shell-command-buffer 'rename-buffer) 3522 ((eq async-shell-command-buffer 'rename-buffer)
3527 ;; It will rename the buffer. 3523 ;; It will rename the buffer.
3528 (with-current-buffer buffer 3524 (with-current-buffer buffer
3529 (rename-uniquely)) 3525 (rename-uniquely))
3530 (setq buffer (get-buffer-create 3526 (setq buffer (get-buffer-create bname)))))
3531 (or output-buffer "*Async Shell Command*"))))))
3532 (with-current-buffer buffer 3527 (with-current-buffer buffer
3533 (shell-command--save-pos-or-erase) 3528 (shell-command--save-pos-or-erase)
3534 (setq default-directory directory) 3529 (setq default-directory directory)
@@ -3537,19 +3532,18 @@ the use of a shell (with its need to quote arguments)."
3537 (setq mode-line-process '(":%s")) 3532 (setq mode-line-process '(":%s"))
3538 (require 'shell) (shell-mode) 3533 (require 'shell) (shell-mode)
3539 (set-process-sentinel proc 'shell-command-sentinel) 3534 (set-process-sentinel proc 'shell-command-sentinel)
3540 ;; Use the comint filter for proper handling of carriage motion 3535 ;; Use the comint filter for proper handling of
3541 ;; (see `comint-inhibit-carriage-motion'),. 3536 ;; carriage motion (see comint-inhibit-carriage-motion).
3542 (set-process-filter proc 'comint-output-filter) 3537 (set-process-filter proc 'comint-output-filter)
3543 (if async-shell-command-display-buffer 3538 (if async-shell-command-display-buffer
3544 (display-buffer buffer '(nil (allow-no-window . t))) 3539 (display-buffer buffer '(nil (allow-no-window . t)))
3545 (add-function :before (process-filter proc) 3540 (add-function :before (process-filter proc)
3546 `(lambda (process string) 3541 (lambda (process _string)
3547 (when (and (= 0 (buffer-size (process-buffer process))) 3542 (let ((buf (process-buffer process)))
3548 (string= (buffer-name (process-buffer process)) 3543 (when (and (zerop (buffer-size buf))
3549 ,(or output-buffer "*Async Shell Command*"))) 3544 (string= (buffer-name buf)
3550 (display-buffer (process-buffer process)))) 3545 bname))
3551 )) 3546 (display-buffer buf))))))))
3552 ))
3553 ;; Otherwise, command is executed synchronously. 3547 ;; Otherwise, command is executed synchronously.
3554 (shell-command-on-region (point) (point) command 3548 (shell-command-on-region (point) (point) command
3555 output-buffer nil error-buffer))))))) 3549 output-buffer nil error-buffer)))))))