From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#30280: async-shell-command-display-buffer doesn't work anymore Date: Wed, 09 May 2018 12:54:51 +0100 Message-ID: <87zi1911tg.fsf@tcd.ie> References: <87a7wxd1g9.fsf@mail.linkov.net> <83607kinmx.fsf@gnu.org> <877erz41re.fsf@tcd.ie> <87zi4tu2ic.fsf@mail.linkov.net> <83lggbd661.fsf@gnu.org> <87tvuyqhz8.fsf@tcd.ie> <87tvuxojag.fsf@mail.linkov.net> <874ljkn4fb.fsf@tcd.ie> <87zi1budeg.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1525867196 11767 195.159.176.226 (9 May 2018 11:59:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 9 May 2018 11:59:56 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: rrt@sc3d.org, 30280@debbugs.gnu.org, Juri Linkov To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 09 13:59:52 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGNl8-0002xy-GD for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 May 2018 13:59:50 +0200 Original-Received: from localhost ([::1]:56010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGNnF-0008GB-Kg for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 May 2018 08:02:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGNhV-0003Vc-VM for bug-gnu-emacs@gnu.org; Wed, 09 May 2018 07:56:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGNhS-0002ap-R3 for bug-gnu-emacs@gnu.org; Wed, 09 May 2018 07:56:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47001) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGNhS-0002Zb-KE for bug-gnu-emacs@gnu.org; Wed, 09 May 2018 07:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fGNhS-0002Ri-A2 for bug-gnu-emacs@gnu.org; Wed, 09 May 2018 07:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 May 2018 11:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30280 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30280-submit@debbugs.gnu.org id=B30280.15258669039332 (code B ref 30280); Wed, 09 May 2018 11:56:02 +0000 Original-Received: (at 30280) by debbugs.gnu.org; 9 May 2018 11:55:03 +0000 Original-Received: from localhost ([127.0.0.1]:54898 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGNgU-0002QS-Uy for submit@debbugs.gnu.org; Wed, 09 May 2018 07:55:03 -0400 Original-Received: from mail-wm0-f53.google.com ([74.125.82.53]:40618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGNgS-0002Pv-TK for 30280@debbugs.gnu.org; Wed, 09 May 2018 07:55:01 -0400 Original-Received: by mail-wm0-f53.google.com with SMTP id j5-v6so27277588wme.5 for <30280@debbugs.gnu.org>; Wed, 09 May 2018 04:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:mail-followup-to:date:in-reply-to :message-id:user-agent:mime-version; bh=t+iiIj1zI45LD9HEGrWMWxRh3J588TqxX/iqtLcrQXA=; b=BAy6538sqoSZYPPxmmb7rNyHancTAcGtysy3dVMvQ9Dvksm0neZNGv3wbPQJRnYSUN wDFMoG8N6hjMBm37u7Prn44lFuq5W5TaHBcp1y8s5UkPxfy4RB4VuYFQtJnCwgO9nWWD aZsaCLnMlbkE0JXY0K1Q4GPh7B75nVA0wfEz1MGPAiAanjKmXjkUwXx1B5SMQp1L2jl0 BuXJZ4WlRXxFtCF2dNGNROJNAN9qNV17fyiKTcvPtz1YZvdaUTcU8m6ayBPPYICDzgqu SFuB9yM9F2I+m667DNwbxTQCaWHl7ZH71v6xXch31wbsPUZimDs2vhtzw3UBv2QbZY9f tmBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:mail-followup-to :date:in-reply-to:message-id:user-agent:mime-version; bh=t+iiIj1zI45LD9HEGrWMWxRh3J588TqxX/iqtLcrQXA=; b=t5YDAjB7RBY60LOMTjqvuTguV4iHf3WtECyWPyCjGF1pzZJqzpoCn7llW1PnBQCbqq rqstRseWp4nN1W9t/hHfRhyAilcBbazOa+vnMlr0TGOcrMW9C3buZnWVXnEhBItFxDDm ASE5FxCGShOKMJoEI8IqoplzcFkOaqhFDdi75fvjsh5xnoKmbnLHWwEkAGWS7tGwqYtH kQ6J7bcn8uFAW7WXBWsCMJsrPjehIlOe+gbWn8ofT0vCe7ECHhscecD/njgJOUSkOzKj 6tqnGckqvMFkcGwXQmEbx3Teq4xI4WWYE/viP2S2kQtIqk9Wa/BVmyAmzOCqJ5q/1dpy sMyg== X-Gm-Message-State: ALQs6tAHOGQrJ/ZyUIn7U7ipEY/sFmLGoj2B+GDY8+YMS1CYOc9p13mr TMW7FZ4cbqDhdPXSIyVZJn5BAQ== X-Google-Smtp-Source: AB8JxZrtW0vegimu6vhh2x2dxQZxLbnyWtRxQRDYg2plE+ZMIVlA0jt6R1Yfy9r7JR31FVN+Onh/iw== X-Received: by 2002:a50:944b:: with SMTP id q11-v6mr59543362eda.70.1525866895048; Wed, 09 May 2018 04:54:55 -0700 (PDT) Original-Received: from localhost ([178.62.40.52]) by smtp.gmail.com with ESMTPSA id k17-v6sm12233216ede.96.2018.05.09.04.54.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 04:54:54 -0700 (PDT) Mail-Followup-To: Tino Calancha , Eli Zaretskii , , <30280@debbugs.gnu.org>, Juri Linkov In-Reply-To: <87zi1budeg.fsf@gmail.com> (Tino Calancha's message of "Mon, 07 May 2018 16:35:03 +0900") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146089 Archived-At: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-failing-test-for-bug-30280.patch >From 77f70d788631c57823ab18fe7ae1b58f2583b400 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Fri, 20 Apr 2018 15:45:06 +0100 Subject: [PATCH 1/2] Fix failing test for bug#30280 * test/lisp/simple-tests.el (simple-tests-async-shell-command-30280): Fix failing test. --- test/lisp/simple-tests.el | 59 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index 7a10df2058..678d9b9385 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -521,30 +521,51 @@ simple-test-undo-with-switched-buffer (do-auto-fill) (should (string-equal (buffer-string) "foo bar")))) + +;;; Shell command. + (ert-deftest simple-tests-async-shell-command-30280 () "Test for https://debbugs.gnu.org/30280 ." - :expected-result :failed (let* ((async-shell-command-buffer 'new-buffer) (async-shell-command-display-buffer nil) - (str "*Async Shell Command*") - (buffers-name - (cl-loop repeat 2 - collect (buffer-name - (generate-new-buffer str)))) + (base "name") + (first (buffer-name (generate-new-buffer base))) + (second (generate-new-buffer-name base)) + ;; `save-window-excursion' doesn't restore frame configurations. + (pop-up-frames nil) (inhibit-message t)) - (mapc #'kill-buffer buffers-name) - (async-shell-command - (format "%s -Q -batch -eval '(progn (sleep-for 3600) (message \"foo\"))'" - invocation-name)) - (async-shell-command - (format "%s -Q -batch -eval '(progn (sleep-for 1) (message \"bar\"))'" - invocation-name)) - (let ((buffers (mapcar #'get-buffer buffers-name)) - (processes (mapcar #'get-buffer-process buffers-name))) - (unwind-protect - (should (memq (cadr buffers) (mapcar #'window-buffer (window-list)))) - (mapc #'delete-process processes) - (mapc #'kill-buffer buffers))))) + ;; Let `shell-command' create the buffer as needed. + (kill-buffer first) + (unwind-protect + (save-window-excursion + ;; One command has no output, the other does. + ;; Removing the -eval argument also yields no output, but + ;; then both commands exit simultaneously when + ;; `accept-process-output' is called on the second command. + (dolist (form '("(sleep-for 8)" "(message \"\")")) + (async-shell-command (format "%s -Q -batch -eval '%s'" + invocation-name form) + first)) + ;; First command should neither have nor display output. + (let* ((buffer (get-buffer first)) + (process (get-buffer-process buffer))) + (should (buffer-live-p buffer)) + (should process) + (should (zerop (buffer-size buffer))) + (should (not (get-buffer-window buffer)))) + ;; Second command should both have and display output. + (let* ((buffer (get-buffer second)) + (process (get-buffer-process buffer))) + (should (buffer-live-p buffer)) + (should process) + (should (accept-process-output process 4 nil t)) + (should (> (buffer-size buffer) 0)) + (should (get-buffer-window buffer)))) + (dolist (name (list first second)) + (let* ((buffer (get-buffer name)) + (process (and buffer (get-buffer-process buffer)))) + (when process (delete-process process)) + (when buffer (kill-buffer buffer))))))) (provide 'simple-test) ;;; simple-test.el ends here -- 2.17.0 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Minor-shell-command-simplifications.patch >From ad179cfbcbe81d8dd98e8d0dc1aeeeabf3f7aee8 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Wed, 9 May 2018 12:47:43 +0100 Subject: [PATCH 2/2] Minor shell-command simplifications * lisp/simple.el (shell-command): Use call-process-shell-command, start-process-shell-command, and file-attribute-size. (bug#30280) --- lisp/simple.el | 58 ++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index a0a6898e17..57e70a8d15 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3400,6 +3400,8 @@ async-shell-command (setq command (concat command " &"))) (shell-command command output-buffer error-buffer)) +(declare-function comint-output-filter "comint" (process string)) + (defun shell-command (command &optional output-buffer error-buffer) "Execute string COMMAND in inferior shell; display output, if any. With prefix argument, insert the COMMAND's output at point. @@ -3477,12 +3479,11 @@ shell-command (not (or (bufferp output-buffer) (stringp output-buffer)))) ;; Output goes in current buffer. (let ((error-file - (if error-buffer - (make-temp-file - (expand-file-name "scor" - (or small-temporary-file-directory - temporary-file-directory))) - nil))) + (and error-buffer + (make-temp-file + (expand-file-name "scor" + (or small-temporary-file-directory + temporary-file-directory)))))) (barf-if-buffer-read-only) (push-mark nil t) ;; We do not use -f for csh; we will not support broken use of @@ -3490,24 +3491,22 @@ shell-command ;; "if ($?prompt) exit" before things which are not useful ;; non-interactively. Besides, if someone wants their other ;; aliases for shell commands then they can still have them. - (call-process shell-file-name nil - (if error-file - (list t error-file) - t) - nil shell-command-switch command) + (call-process-shell-command command nil (if error-file + (list t error-file) + t)) (when (and error-file (file-exists-p error-file)) - (if (< 0 (nth 7 (file-attributes error-file))) - (with-current-buffer (get-buffer-create error-buffer) - (let ((pos-from-end (- (point-max) (point)))) - (or (bobp) - (insert "\f\n")) - ;; Do no formatting while reading error file, - ;; because that can run a shell command, and we - ;; don't want that to cause an infinite recursion. - (format-insert-file error-file nil) - ;; Put point after the inserted errors. - (goto-char (- (point-max) pos-from-end))) - (display-buffer (current-buffer)))) + (when (< 0 (file-attribute-size (file-attributes error-file))) + (with-current-buffer (get-buffer-create error-buffer) + (let ((pos-from-end (- (point-max) (point)))) + (or (bobp) + (insert "\f\n")) + ;; Do no formatting while reading error file, + ;; because that can run a shell command, and we + ;; don't want that to cause an infinite recursion. + (format-insert-file error-file nil) + ;; Put point after the inserted errors. + (goto-char (- (point-max) pos-from-end))) + (display-buffer (current-buffer)))) (delete-file error-file)) ;; This is like exchange-point-and-mark, but doesn't ;; activate the mark. It is cleaner to avoid activation, @@ -3526,12 +3525,11 @@ shell-command (let* ((buffer (get-buffer-create (or output-buffer "*Async Shell Command*"))) (bname (buffer-name buffer)) - (directory default-directory) - proc) + (proc (get-buffer-process buffer)) + (directory default-directory)) ;; Remove the ampersand. (setq command (substring command 0 (match-beginning 0))) ;; Ask the user what to do with already running process. - (setq proc (get-buffer-process buffer)) (when proc (cond ((eq async-shell-command-buffer 'confirm-kill-process) @@ -3563,14 +3561,14 @@ shell-command (with-current-buffer buffer (shell-command--save-pos-or-erase) (setq default-directory directory) - (setq proc (start-process "Shell" buffer shell-file-name - shell-command-switch command)) + (setq proc + (start-process-shell-command "Shell" buffer command)) (setq mode-line-process '(":%s")) (require 'shell) (shell-mode) - (set-process-sentinel proc 'shell-command-sentinel) + (set-process-sentinel proc #'shell-command-sentinel) ;; Use the comint filter for proper handling of ;; carriage motion (see comint-inhibit-carriage-motion). - (set-process-filter proc 'comint-output-filter) + (set-process-filter proc #'comint-output-filter) (if async-shell-command-display-buffer ;; Display buffer immediately. (display-buffer buffer '(nil (allow-no-window . t))) -- 2.17.0 --=-=-= Content-Type: text/plain Tino Calancha writes: > "Basil L. Contovounesios" writes: > >> I attach two patches. The first tries to make this test succeed in >> accordance with the resulting bugfix. The second suggests some >> simplifications to the logic in shell-command. WDYT? > > Basil, thank you for fixing that test! > > Concerning the 2nd patch; it adds a bug when > `async-shell-command-buffer' is > confirm-rename-buffer > ;; or > rename-buffer Right, that was silly of me; thanks for catching it. I reattach the patches with the buffer name changes removed. Thanks again, -- Basil --=-=-=--