From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#39067: shell-command-dont-erase-buffer strange behaviour Date: Sat, 11 Jan 2020 11:25:18 +0200 Message-ID: <834kx28hvl.fsf@gnu.org> References: Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="1689"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 39067@debbugs.gnu.org To: Madhu , Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 11 10:27:37 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iqD27-000sGf-67 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Jan 2020 10:26:15 +0100 Original-Received: from localhost ([::1]:55580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iqD25-0002V9-Gt for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Jan 2020 04:26:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53197) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iqD1v-0002Ra-Ix for bug-gnu-emacs@gnu.org; Sat, 11 Jan 2020 04:26:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iqD1u-00040E-Ek for bug-gnu-emacs@gnu.org; Sat, 11 Jan 2020 04:26:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49378) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iqD1u-0003zP-A4 for bug-gnu-emacs@gnu.org; Sat, 11 Jan 2020 04:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iqD1u-0005iQ-6R for bug-gnu-emacs@gnu.org; Sat, 11 Jan 2020 04:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Jan 2020 09:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39067 X-GNU-PR-Package: emacs Original-Received: via spool by 39067-submit@debbugs.gnu.org id=B39067.157873472621921 (code B ref 39067); Sat, 11 Jan 2020 09:26:02 +0000 Original-Received: (at 39067) by debbugs.gnu.org; 11 Jan 2020 09:25:26 +0000 Original-Received: from localhost ([127.0.0.1]:55351 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iqD1K-0005hV-3J for submit@debbugs.gnu.org; Sat, 11 Jan 2020 04:25:26 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42401) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iqD1H-0005hH-Sm for 39067@debbugs.gnu.org; Sat, 11 Jan 2020 04:25:24 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:46316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iqD1C-00012m-7O; Sat, 11 Jan 2020 04:25:18 -0500 Original-Received: from [176.228.60.248] (port=2052 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1iqD1A-0000Hi-PS; Sat, 11 Jan 2020 04:25:17 -0500 In-reply-to: (message from Madhu on Fri, 10 Jan 2020 05:34:18 +0000) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:174467 Archived-At: > From: Madhu > Date: Fri, 10 Jan 2020 05:34:18 +0000 > > C-h v shell-command-dont-erase-buffer > C-h f shell-command > > Cut to the chase with the test case: > > (let ((shell-command-dont-erase-buffer 'beg-last-out)) > (with-current-buffer (get-buffer-create "OUT") > (erase-buffer) > (shell-command "/bin/echo FOO" t) > (shell-command "/bin/echo FOO" t))) > > The result (as expected) is a buffer named OUT with 2 lines FOO. > The same result is expected with the following code: > > (let ((shell-command-dont-erase-buffer 'beg-last-out)) > (with-current-buffer (get-buffer-create "OUT") > (erase-buffer) > (shell-command "/bin/echo FOO" "OUT") > (shell-command "/bin/echo FOO" "OUT"))) > > However in this case (and in some other cases) shell-command erases the > "OUT" buffer despite a non-NIL binding of > shell-command-dont-erase-buffer > > (at least since emacs 25.2) AFAICT, there's a small mess here. shell-command sometimes calls shell-command-on-region, and sometimes calls call-process-shell-command. The shell-command-dont-erase-buffer option is only tested in shell-command-on-region, and it only prevents erasing the buffer if OUTPUT-BUFFER is _different_ from the current buffer. Which explains why the second recipe does still erase the buffer: remove the with-current-buffer part, and it will work as you expected. When shell-command calls call-process-shell-command, which happens in the first case, the buffer is _never_ erased, regardless of the value of shell-command-dont-erase-buffer. IOW, this feature is not working as advertised in several important use case, and never did AFAICT. Its implementation is incomplete. Tino, could you please look into this, and fix this stuff so that this variable affects all invocations of shell-command? Thanks.