From: Tino Calancha <f92capac@gmail.com>
To: 22679@debbugs.gnu.org, Tino Calancha <f92capac@gmail.com>
Subject: bug#22679: 25.0.91; ibuffer-do-shell-command-pipe truncate output
Date: Fri, 10 Jun 2016 18:08:28 +0900 [thread overview]
Message-ID: <CAMn5WmYphFUjBv6eqjv09ckrNEWAMxSFV+5aSZx3g7WzaHd3GA@mail.gmail.com> (raw)
In-Reply-To: <CAMn5WmYDL0CrDppLc_Vs+EM5CkA_wfdb1z+QCmNj_=v6PiYM-g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 13605 bytes --]
>This seems like it would be a lot simpler if shell-command(-on-region)
>did not unconditionally erase its output buffer. Although that behaviour
>is long-standing, it seems unfriendly. It would be easier for callers
>that wanted that to erase their own output buffers. It's less simple for
>callers that want to preserve existing output to do so with the current
>system.
Adding an extra optional arg KEEP to shell-command family would do the job
straightforward (see below patch). Maybe someone may complaint about one
function having 9 (***) arguments (shell-command-on-region) inside a file
called
'simple'.
(***) I have noticed arg REGION-NONCONTIGUOUS-P is not mentioned in the doc
string.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From b14efc632dfafbbc61863c060b9840a752704320 Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Fri, 10 Jun 2016 17:44:48 +0900
Subject: [PATCH 1/2] Allow not erasing output buffer on shell-command
* lisp/simple.el (async-shell-command)
(shell-command, shell-command-on-region): Added optional
arg KEEP (Bug#22679).
---
lisp/simple.el | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 6c30929..59fa851 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3187,7 +3187,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
@@ -3218,9 +3218,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.
@@ -3274,6 +3274,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)."
@@ -3391,7 +3394,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
@@ -3405,7 +3408,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.
@@ -3485,7 +3488,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
@@ -3533,7 +3536,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 nineth 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"))
@@ -3618,7 +3624,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
From 56f57e6321a7e37389329c6f8c54c340d12ee419 Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Fri, 10 Jun 2016 17:56:30 +0900
Subject: [PATCH 2/2] Do not truncate output (Bug#22679)
* lisp/ibuf-ext.el (shell-command-pipe, shell-command-file):
---
lisp/ibuf-ext.el | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 0baab6b..9dd1eea 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -325,7 +325,8 @@ shell-command-pipe
:modifier-p nil)
(shell-command-on-region
(point-min) (point-max) command
- (get-buffer-create "* ibuffer-shell-output*")))
+ (get-buffer-create "* ibuffer-shell-output*")
+ nil nil nil nil 'keep))
;;;###autoload (autoload 'ibuffer-do-shell-command-pipe-replace "ibuf-ext")
(define-ibuffer-op shell-command-pipe-replace (command)
@@ -354,7 +355,7 @@ shell-command-file
(buffer-name) 0
(min 10 (length (buffer-name)))))))
(write-region nil nil file nil 0)
- file))))))
+ file)))) nil nil 'keep))
;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext")
(define-ibuffer-op eval (form)
--
2.8.1
On Fri, Jun 10, 2016 at 6:04 PM, Tino Calancha <f92capac@gmail.com> wrote:
> >This seems like it would be a lot simpler if shell-command(-on-region)
> >did not unconditionally erase its output buffer. Although that behaviour
> >is long-standing, it seems unfriendly. It would be easier for callers
> >that wanted that to erase their own output buffers. It's less simple for
> >callers that want to preserve existing output to do so with the current
> >system.
>
> Adding an extra optional arg KEEP to shell-command family would do the job
> straightforward (see below patch). Maybe someone may complaint about one
> function having 9 (***) arguments (shell-command-on-region) inside a file
> called
> 'simple'.
>
> (***) I have noticed arg REGION-NONCONTIGUOUS-P is not mentioned in the
> doc string.
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> From b14efc632dfafbbc61863c060b9840a752704320 Mon Sep 17 00:00:00 2001
> From: Tino Calancha <f92capac@gmail.com>
> Date: Fri, 10 Jun 2016 17:44:48 +0900
> Subject: [PATCH 1/2] Allow not erasing output buffer on shell-command
>
> * lisp/simple.el (async-shell-command)
> (shell-command, shell-command-on-region): Added optional
> arg KEEP (Bug#22679).
> ---
> lisp/simple.el | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/lisp/simple.el b/lisp/simple.el
> index 6c30929..59fa851 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -3187,7 +3187,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
> @@ -3218,9 +3218,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.
>
> @@ -3274,6 +3274,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)."
> @@ -3391,7 +3394,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
> @@ -3405,7 +3408,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.
> @@ -3485,7 +3488,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
> @@ -3533,7 +3536,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 nineth 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"))
> @@ -3618,7 +3624,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
>
> From 56f57e6321a7e37389329c6f8c54c340d12ee419 Mon Sep 17 00:00:00 2001
> From: Tino Calancha <f92capac@gmail.com>
> Date: Fri, 10 Jun 2016 17:56:30 +0900
> Subject: [PATCH 2/2] Do not truncate output (Bug#22679)
>
> * lisp/ibuf-ext.el (shell-command-pipe, shell-command-file):
> ---
> lisp/ibuf-ext.el | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
> index 0baab6b..9dd1eea 100644
> --- a/lisp/ibuf-ext.el
> +++ b/lisp/ibuf-ext.el
> @@ -325,7 +325,8 @@ shell-command-pipe
> :modifier-p nil)
> (shell-command-on-region
> (point-min) (point-max) command
> - (get-buffer-create "* ibuffer-shell-output*")))
> + (get-buffer-create "* ibuffer-shell-output*")
> + nil nil nil nil 'keep))
>
> ;;;###autoload (autoload 'ibuffer-do-shell-command-pipe-replace
> "ibuf-ext")
> (define-ibuffer-op shell-command-pipe-replace (command)
> @@ -354,7 +355,7 @@ shell-command-file
> (buffer-name) 0
> (min 10 (length (buffer-name)))))))
> (write-region nil nil file nil 0)
> - file))))))
> + file)))) nil nil 'keep))
>
> ;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext")
> (define-ibuffer-op eval (form)
> --
> 2.8.1
>
>
>
> On Fri, Jun 10, 2016 at 2:02 PM, Glenn Morris <rgm@gnu.org> wrote:
>
>>
>> This seems like it would be a lot simpler if shell-command(-on-region)
>> did not unconditionally erase its output buffer. Although that behaviour
>> is long-standing, it seems unfriendly. It would be easier for callers
>> that wanted that to erase their own output buffers. It's less simple for
>> callers that want to preserve existing output to do so with the current
>> system.
>>
>
>
[-- Attachment #2: Type: text/html, Size: 16848 bytes --]
next prev parent reply other threads:[~2016-06-10 9:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-15 13:21 bug#22679: 25.0.91; ibuffer-do-shell-command-pipe truncate output Tino Calancha
2016-06-10 5:02 ` Glenn Morris
[not found] ` <CAMn5WmYDL0CrDppLc_Vs+EM5CkA_wfdb1z+QCmNj_=v6PiYM-g@mail.gmail.com>
2016-06-10 9:08 ` Tino Calancha [this message]
2016-07-05 15:58 ` Glenn Morris
2016-07-05 16:27 ` Tino Calancha
2016-07-09 17:28 ` Glenn Morris
2016-07-13 15:27 ` Stefan Monnier
2016-08-19 8:33 ` Tino Calancha
2016-08-19 13:52 ` Stefan Monnier
2016-08-20 3:28 ` Tino Calancha
2016-08-20 10:28 ` Tino Calancha
2016-08-20 12:46 ` Stefan Monnier
2016-08-21 14:37 ` Tino Calancha
2016-08-22 16:06 ` Stefan Monnier
2016-08-23 15:08 ` Tino Calancha
2016-08-24 17:05 ` Stefan Monnier
2016-08-25 9:39 ` Tino Calancha
2016-08-25 12:36 ` Stefan Monnier
2016-08-25 13:26 ` Tino Calancha
2017-01-27 6:26 ` Tino Calancha
2017-02-03 4:25 ` Tino Calancha
2017-02-09 9:24 ` Tino Calancha
2016-06-11 3:48 ` C. Calancha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMn5WmYphFUjBv6eqjv09ckrNEWAMxSFV+5aSZx3g7WzaHd3GA@mail.gmail.com \
--to=f92capac@gmail.com \
--cc=22679@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).