From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: New optional arg to [async-]shell-command[-on-region] Date: Wed, 13 Jul 2016 23:09:17 +0900 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1468419359 2115 80.91.229.3 (13 Jul 2016 14:15:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Jul 2016 14:15:59 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 13 16:15:56 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bNKx9-0000vN-CI for ged-emacs-devel@m.gmane.org; Wed, 13 Jul 2016 16:15:55 +0200 Original-Received: from localhost ([::1]:47917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNKx8-00031s-Hd for ged-emacs-devel@m.gmane.org; Wed, 13 Jul 2016 10:15:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNKqs-0002wA-MP for emacs-devel@gnu.org; Wed, 13 Jul 2016 10:09:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNKqn-0005JR-8j for emacs-devel@gnu.org; Wed, 13 Jul 2016 10:09:25 -0400 Original-Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]:36673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNKqm-0005JE-UA for emacs-devel@gnu.org; Wed, 13 Jul 2016 10:09:21 -0400 Original-Received: by mail-pf0-x22f.google.com with SMTP id t190so19116717pfb.3 for ; Wed, 13 Jul 2016 07:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=wnJn5hcRd/AlftcAcP1nkNC7v+05VsZljYIg319JW28=; b=VEqitXYG45x0p9J0qaQJT1AvNDqIylkP8RtLSsMeHOmdFmbbnDetUn9iYpWUKsCCJx 6qLsgOPy0z1NWuCEgRBoZKhMc9/QTN9ZXTMQxb6tml1dPdhgoZqd/trfqU+ZBC8ZeFqE rJsHmq3DLMcaiPbOmnTS+7WIzyWYnFD7omhKiPjYt4IrKPZWhWba/6YqPzty0QWltkPF WNcGtnUD1h5BI/uwGo6ZSeXQeXDSpNCNnxai6uniwjpZho3p6Gh0lhCQWompIAru2wbX rtuibHi5q0AB0Ow1ZuN7WXglHhWtn763WRx3VgIQfBwDUgCTGofGUirHIYSKqZsp4DBl WnwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=wnJn5hcRd/AlftcAcP1nkNC7v+05VsZljYIg319JW28=; b=TodJV0a6tURxvAUM+A312oBvrFajWiS9PzLLB5uAGxz7YB9adHjEW6EgofjomP98Rb Gs6hMWWI6ogjynty2W9B+f5eYYeLefJwlP8O2UldP2H9eHUCMOSOJnYkCHvzEoyrUpz7 xK3XvDsVd4i0dSljLmBSlK2TS8GDzs57Cv01urS+kFaiZ3NAWWOIqmTbZovJNCtWQdN5 kxtaxMUdyL25KfM0P4uakrMROq6XYlduZnE2QRa66eHBmy3CgKAtC0nPwMPVBcMLIjet +HgwNw88bakUZd+BXyelUnfbPWgkCQZvaR7HwFu5FNViSiA6zAwudLPi8Y7NHJpnZoEM N+gQ== X-Gm-Message-State: ALyK8tLpm3HNQ0D0JK78ZLZPkAGRLnHIcDbLPzymaaqFRUSpyHy95mS4Yi4wqQE0neF3mw== X-Received: by 10.98.74.201 with SMTP id c70mr3770845pfj.113.1468418959972; Wed, 13 Jul 2016 07:09:19 -0700 (PDT) Original-Received: from ?IPv6:240f:6e:c00e:1:6875:2e94:598b:96cb? ([240f:6e:c00e:1:6875:2e94:598b:96cb]) by smtp.gmail.com with ESMTPSA id m5sm5244604paw.40.2016.07.13.07.09.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2016 07:09:19 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::22f X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:205625 Archived-At: I would like to propose a patch adding a new optional argument KEEP for commands: `shell-command,' `async-shell-command' and `shell-command-on-region'. The new argument, when non-nil, prevent to erase the output buffer before inserting the new output, i.e., allow the callers to concatenate the output of several consecutive commands in the same buffer. One example where this change is useful is Bug#22679; the fix becomes trivial: just adjust the callers to pass a non-nil KEEP argument. Following is the patch i propose: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From c200d7b2eebcadc0c3108252b30fe6ffc6627b12 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Wed, 13 Jul 2016 22:02:45 +0900 Subject: [PATCH] Allow not erasing output buffer on shell commands * lisp/simple.el (async-shell-command) (shell-command, shell-command-on-region): Added optional arg KEEP. --- lisp/simple.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 6d7f00f..91bcb13 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3175,7 +3175,7 @@ async-shell-command-buffer :group 'shell :version "24.3") -(defun async-shell-command (command &optional output-buffer error-buffer) +(defun async-shell-command (command &optional output-buffer error-buffer keep) "Execute string COMMAND asynchronously in background. Like `shell-command', but adds `&' at the end of COMMAND @@ -3206,9 +3206,9 @@ async-shell-command shell-command-default-error-buffer)) (unless (string-match "&[ \t]*\\'" command) (setq command (concat command " &"))) - (shell-command command output-buffer error-buffer)) + (shell-command command output-buffer error-buffer keep)) -(defun shell-command (command &optional output-buffer error-buffer) +(defun shell-command (command &optional output-buffer error-buffer keep) "Execute string COMMAND in inferior shell; display output, if any. With prefix argument, insert the COMMAND's output at point. @@ -3262,6 +3262,9 @@ shell-command In an interactive call, the variable `shell-command-default-error-buffer' specifies the value of ERROR-BUFFER. +If the optional fourth argument KEEP is non-nil, the output buffer +is not erased before inserting the output. + In Elisp, you will often be better served by calling `call-process' or `start-process' directly, since it offers more control and does not impose the use of a shell (with its need to quote arguments)." @@ -3379,7 +3382,7 @@ shell-command ;; if some text has a non-nil read-only property, ;; which comint sometimes adds for prompts. (let ((inhibit-read-only t)) - (erase-buffer)) + (or keep (erase-buffer))) (display-buffer buffer '(nil (allow-no-window . t))) (setq default-directory directory) (setq proc (start-process "Shell" buffer shell-file-name @@ -3393,7 +3396,7 @@ shell-command )) ;; Otherwise, command is executed synchronously. (shell-command-on-region (point) (point) command - output-buffer nil error-buffer))))))) + output-buffer nil error-buffer nil nil keep))))))) (defun display-message-or-buffer (message &optional buffer-name action frame) "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer. @@ -3473,7 +3476,7 @@ shell-command-sentinel (defun shell-command-on-region (start end command &optional output-buffer replace error-buffer display-error-buffer - region-noncontiguous-p) + region-noncontiguous-p keep) "Execute string COMMAND in inferior shell with region as input. Normally display output (if any) in temp buffer `*Shell Command Output*'; Prefix arg means replace the region with it. Return the exit code of @@ -3521,7 +3524,10 @@ shell-command-on-region Optional seventh arg DISPLAY-ERROR-BUFFER, if non-nil, means to display the error buffer if there were any errors. When called -interactively, this is t." +interactively, this is t. + +Optional ninth arg KEEP, if non-nil, then the output buffer is +not erased before inserting the output." (interactive (let (string) (unless (mark) (user-error "The mark is not set now, so there is no region")) @@ -3606,7 +3612,9 @@ shell-command-on-region (setq buffer-read-only nil) (if (not output-buffer) (setq default-directory directory)) - (erase-buffer))) + (if keep + (goto-char (point-max)) + (erase-buffer)))) (setq exit-status (call-process-region start end shell-file-name nil (if error-file -- 2.8.1 In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.20.6) of 2016-07-13 Repository revision: a36ed9b5e95afea5716256bac24d883263aefbaf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Please, let me know your opinion/concerns about this proposal. Thank you, Tino