Subject: bug#22679: closed (Re: bug#22679: 25.0.91; ibuffer-do-shell-command-pipe truncate output)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 09 Feb 2017 09:25:01 +0000

Your bug report

#22679: 25.0.91; ibuffer-do-shell-command-pipe truncate output

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
22679: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22679
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#22679: 25.0.91; ibuffer-do-shell-command-pipe truncate output
From: Tino Calancha <[email-masked]>
To: [email-masked]
Date: Thu, 09 Feb 2017 18:24:41 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

Tino Calancha <[email-masked]> writes:

> Following is the updated patch.  I'd like to push it into master
> branch in a few days if there is no objections.

Pushed fix to master branch as commits:
1e23bf5c513fafb9d14a8e07232101515386a912
d9fd1d32632816aa7833bcfcc116a0a01a53a4b7

Subject: 25.0.91; ibuffer-do-shell-command-pipe truncate output
From: Tino Calancha <[email-masked]>
To: [email-masked]
Date: Mon, 15 Feb 2016 22:21:29 +0900 (JST)
List-Id: <debbugs-submit.debbugs.gnu.org>

Only the output of the last processed buffer is shown.
Maybe better if it is shown the concatenation of the output
of all of them.

emacs -Q --eval="(mapc (lambda(x) (switch-to-buffer x) (insert x)) '(\"foo\" \"bar\"))" --eval='(ibuffer)'
% n ^\(foo\|bar\)$ RET
| cat RET
g
C-x b * ibuffer-shell-output*
;;just show one word

In GNU Emacs 25.0.91.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29)
Repository revision: 23ca48d3d867cfff9f49ef600e2aad7a26c7a870

diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index f537561..8b1d4d2 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -323,9 +323,15 @@ shell-command-pipe
   (:interactive "sPipe to shell command: "
    :opstring "Shell command executed on"
    :modifier-p nil)
-  (shell-command-on-region
-   (point-min) (point-max) command
-   (get-buffer-create "* ibuffer-shell-output*")))
+  (let* ((out-buf (get-buffer-create "* ibuffer-shell-output*"))
+         (buffers (with-current-buffer "*Ibuffer*" (ibuffer-get-marked-buffers))))
+    (let ((string (with-temp-buffer
+                    (insert-buffer-substring buf)
+                    (shell-command-on-region (point-min) (point-max) command nil t)
+                    (buffer-substring-no-properties (point-min) (point-max)))))
+      (with-current-buffer out-buf
+        (when (eq buf (car buffers)) (erase-buffer))
+        (insert string)))))
 
 ;;;###autoload (autoload 'ibuffer-do-shell-command-pipe-replace "ibuf-ext")
 (define-ibuffer-op shell-command-pipe-replace (command)
@@ -345,12 +351,19 @@ shell-command-file
   (:interactive "sShell command on buffer's file: "
    :opstring "Shell command executed on"
    :modifier-p nil)
-  (shell-command (concat command " "
-			 (shell-quote-argument
-			  (if buffer-file-name
-			      buffer-file-name
-			    (make-temp-file
-			     (substring (buffer-name) 0 (min 10 (length (buffer-name))))))))))
+  (let* ((out-buf (get-buffer-create "*Shell Command Output*")) ; This function and shell-command-pipe
+                                                                ; should have same out buffer name.
+         (buffers (with-current-buffer "*Ibuffer*" (ibuffer-get-marked-buffers))))
+    (let* ((fname  (or buffer-file-name
+                       (let ((file (make-temp-file
+                                    (substring (buffer-name) 0 (min 10 (length (buffer-name)))))))
+                         (write-region (point-min) (point-max) file) file)))
+           (cmd    (format "%s %s" command (shell-quote-argument fname)))
+           (string (shell-command-to-string cmd)))
+
+      (with-current-buffer out-buf
+        (when (eq buf (car buffers)) (erase-buffer))
+        (insert string)))))
 
 ;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext")
 (define-ibuffer-op eval (form)