all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* New optional arg to [async-]shell-command[-on-region]
@ 2016-07-13 14:09 Tino Calancha
  2016-07-13 14:29 ` Clément Pit--Claudel
  0 siblings, 1 reply; 10+ messages in thread
From: Tino Calancha @ 2016-07-13 14:09 UTC (permalink / raw)
  To: emacs-devel

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 <tino.calancha@gmail.com>
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




^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-08-26  6:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-13 14:09 New optional arg to [async-]shell-command[-on-region] Tino Calancha
2016-07-13 14:29 ` Clément Pit--Claudel
2016-07-13 14:48   ` Tino Calancha
2016-07-13 15:06     ` Yuri Khan
2016-07-13 15:27       ` Tino Calancha
2016-07-13 15:58         ` Clément Pit--Claudel
2016-07-13 16:02           ` Clément Pit--Claudel
2016-07-28 12:53       ` New opt to allow not erase out buffer between shell cmds Tino Calancha
2016-08-24 15:10         ` Clément Pit--Claudel
2016-08-26  6:43           ` Tino Calancha

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.