emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master d9fd1d3 2/2: Ibuffer: Erase output buffer before sh


From: Tino Calancha
Subject: [Emacs-diffs] master d9fd1d3 2/2: Ibuffer: Erase output buffer before shell commands
Date: Thu, 9 Feb 2017 04:20:51 -0500 (EST)

branch: master
commit d9fd1d32632816aa7833bcfcc116a0a01a53a4b7
Author: Tino Calancha <address@hidden>
Commit: Tino Calancha <address@hidden>

    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.
---
 lisp/ibuf-ext.el  | 10 +++++++++-
 lisp/ibuf-macs.el | 10 ++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 00cbf05..2a68f77 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.
diff --git a/lisp/ibuf-macs.el b/lisp/ibuf-macs.el
index 05e568e..2e751ce 100644
--- a/lisp/ibuf-macs.el
+++ b/lisp/ibuf-macs.el
@@ -169,6 +169,8 @@ value if and only if `a' is \"less than\" `b'.
                                  dangerous
                                  (opstring "operated on")
                                  (active-opstring "Operate on")
+                                  before
+                                  after
                                  complex)
                                 &rest body)
   "Generate a function which operates on a buffer.
@@ -198,6 +200,8 @@ operation is complete, in the form:
 ACTIVE-OPSTRING is a string which will be displayed to the user in a
 confirmation message, in the form:
  \"Really ACTIVE-OPSTRING x buffers?\"
+BEFORE is a form to evaluate before start the operation.
+AFTER is a form to evaluate once the operation is complete.
 COMPLEX means this function is special; if COMPLEX is nil BODY
 evaluates once for each marked buffer, MBUF, with MBUF current
 and saving the point.  If COMPLEX is non-nil, BODY evaluates
@@ -206,7 +210,7 @@ BODY define the operation; they are forms to evaluate per 
each
 marked buffer.  BODY is evaluated with `buf' bound to the
 buffer object.
 
-\(fn OP ARGS DOCUMENTATION (&key INTERACTIVE MARK MODIFIER-P DANGEROUS 
OPSTRING ACTIVE-OPSTRING COMPLEX) &rest BODY)"
+\(fn OP ARGS DOCUMENTATION (&key INTERACTIVE MARK MODIFIER-P DANGEROUS 
OPSTRING ACTIVE-OPSTRING BEFORE AFTER COMPLEX) &rest BODY)"
   (declare (indent 2) (doc-string 3))
   `(progn
      (defun ,(intern (concat (if (string-match "^ibuffer-do" (symbol-name op))
@@ -238,6 +242,7 @@ buffer object.
                          (if (eq modifier-p t)
                              '((setq ibuffer-did-modification t))
                            ())
+                          (and after `(,after)) ; post-operation form.
                          `((ibuffer-redisplay t)
                            (message ,(concat "Operation finished; " opstring " 
%s buffers") count))))
                 (inner-body (if complex
@@ -247,7 +252,8 @@ buffer object.
                                    (save-excursion
                                      ,@body))
                                  t)))
-                (body `(let ((count
+                (body `(let ((_ ,before) ; pre-operation form.
+                               (count
                               (,(pcase mark
                                   (:deletion
                                    'ibuffer-map-deletion-lines)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]