Subject: bug#22678: 25.0.91; ibuffer-do-shell-command-file no output for non-visiting buffers

From: Tino Calancha <[email-masked]>
Date: Mon, 15 Feb 2016 22:20:04 +0900 (JST)

This function creates all temporary files empty which doesn't
seem the intended behaviour.

emacs -Q --eval="(mapc (lambda(x) (switch-to-buffer x) (insert x)) '(\"foo\" \"bar\"))" --eval='(ibuffer)'w
% n ^\(foo\|bar\)$ RET
! cat RET
g
C-x b *Shell Command Output*
;; empty buffer

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..86f57f9 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -347,10 +347,10 @@ shell-command-file
    :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))))))))))
+                          (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))))))
 
 ;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext")
 (define-ibuffer-op eval (form)