summaryrefslogtreecommitdiff
path: root/lisp/ibuf-ext.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2017-02-09 18:14:10 +0900
committerTino Calancha <tino.calancha@gmail.com>2017-02-09 18:14:10 +0900
commitd9fd1d32632816aa7833bcfcc116a0a01a53a4b7 (patch)
tree4a8cab4c595931f6cdc485a0786bef78e22bc7f2 /lisp/ibuf-ext.el
parent1e23bf5c513fafb9d14a8e07232101515386a912 (diff)
downloademacs-d9fd1d32632816aa7833bcfcc116a0a01a53a4b7.tar.gz
Ibuffer: Erase output buffer before shell commands
* lisp/ibuf-macs.el (define-ibuffer-op): Add keyword arguments BEFORE and AFTER; they are forms to run before/after the operation. * lisp/ibuf-ext.el (ibuffer--maybe-erase-shell-cmd-output): New defun; if shell-command-dont-erase-buffer is nil, then erase shell command output buffer. (ibuffer-do-shell-command-pipe, ibuffer-do-shell-command-file): Use it.
Diffstat (limited to 'lisp/ibuf-ext.el')
-rw-r--r--lisp/ibuf-ext.el10
1 files changed, 9 insertions, 1 deletions
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 00cbf051d2e..2a68f777d95 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -506,11 +506,19 @@ the mode if ARG is omitted or nil."
(ibuffer-backward-filter-group 1))
(ibuffer-forward-line 0))
+(defun ibuffer--maybe-erase-shell-cmd-output ()
+ (let ((buf (get-buffer "*Shell Command Output*")))
+ (when (and (buffer-live-p buf)
+ (not shell-command-dont-erase-buffer)
+ (not (zerop (buffer-size buf))))
+ (with-current-buffer buf (erase-buffer)))))
+
;;;###autoload (autoload 'ibuffer-do-shell-command-pipe "ibuf-ext")
(define-ibuffer-op shell-command-pipe (command)
"Pipe the contents of each marked buffer to shell command COMMAND."
(:interactive "sPipe to shell command: "
:opstring "Shell command executed on"
+ :before (ibuffer--maybe-erase-shell-cmd-output)
:modifier-p nil)
(let ((out-buf (get-buffer-create "*Shell Command Output*")))
(with-current-buffer out-buf (goto-char (point-max)))
@@ -533,6 +541,7 @@ the mode if ARG is omitted or nil."
"Run shell command COMMAND separately on files of marked buffers."
(:interactive "sShell command on buffer's file: "
:opstring "Shell command executed on"
+ :before (ibuffer--maybe-erase-shell-cmd-output)
:modifier-p nil)
(let ((file (and (not (buffer-modified-p))
buffer-file-name))
@@ -551,7 +560,6 @@ the mode if ARG is omitted or nil."
(shell-quote-argument file))
nil out-buf nil)))
-
;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext")
(define-ibuffer-op eval (form)
"Evaluate FORM in each of the buffers.