diff options
| author | Tino Calancha | 2017-02-09 18:14:10 +0900 |
|---|---|---|
| committer | Tino Calancha | 2017-02-09 18:14:10 +0900 |
| commit | d9fd1d32632816aa7833bcfcc116a0a01a53a4b7 (patch) | |
| tree | 4a8cab4c595931f6cdc485a0786bef78e22bc7f2 | |
| parent | 1e23bf5c513fafb9d14a8e07232101515386a912 (diff) | |
| download | emacs-d9fd1d32632816aa7833bcfcc116a0a01a53a4b7.tar.gz emacs-d9fd1d32632816aa7833bcfcc116a0a01a53a4b7.zip | |
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.
| -rw-r--r-- | lisp/ibuf-ext.el | 10 | ||||
| -rw-r--r-- | 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 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." | |||
| 506 | (ibuffer-backward-filter-group 1)) | 506 | (ibuffer-backward-filter-group 1)) |
| 507 | (ibuffer-forward-line 0)) | 507 | (ibuffer-forward-line 0)) |
| 508 | 508 | ||
| 509 | (defun ibuffer--maybe-erase-shell-cmd-output () | ||
| 510 | (let ((buf (get-buffer "*Shell Command Output*"))) | ||
| 511 | (when (and (buffer-live-p buf) | ||
| 512 | (not shell-command-dont-erase-buffer) | ||
| 513 | (not (zerop (buffer-size buf)))) | ||
| 514 | (with-current-buffer buf (erase-buffer))))) | ||
| 515 | |||
| 509 | ;;;###autoload (autoload 'ibuffer-do-shell-command-pipe "ibuf-ext") | 516 | ;;;###autoload (autoload 'ibuffer-do-shell-command-pipe "ibuf-ext") |
| 510 | (define-ibuffer-op shell-command-pipe (command) | 517 | (define-ibuffer-op shell-command-pipe (command) |
| 511 | "Pipe the contents of each marked buffer to shell command COMMAND." | 518 | "Pipe the contents of each marked buffer to shell command COMMAND." |
| 512 | (:interactive "sPipe to shell command: " | 519 | (:interactive "sPipe to shell command: " |
| 513 | :opstring "Shell command executed on" | 520 | :opstring "Shell command executed on" |
| 521 | :before (ibuffer--maybe-erase-shell-cmd-output) | ||
| 514 | :modifier-p nil) | 522 | :modifier-p nil) |
| 515 | (let ((out-buf (get-buffer-create "*Shell Command Output*"))) | 523 | (let ((out-buf (get-buffer-create "*Shell Command Output*"))) |
| 516 | (with-current-buffer out-buf (goto-char (point-max))) | 524 | (with-current-buffer out-buf (goto-char (point-max))) |
| @@ -533,6 +541,7 @@ the mode if ARG is omitted or nil." | |||
| 533 | "Run shell command COMMAND separately on files of marked buffers." | 541 | "Run shell command COMMAND separately on files of marked buffers." |
| 534 | (:interactive "sShell command on buffer's file: " | 542 | (:interactive "sShell command on buffer's file: " |
| 535 | :opstring "Shell command executed on" | 543 | :opstring "Shell command executed on" |
| 544 | :before (ibuffer--maybe-erase-shell-cmd-output) | ||
| 536 | :modifier-p nil) | 545 | :modifier-p nil) |
| 537 | (let ((file (and (not (buffer-modified-p)) | 546 | (let ((file (and (not (buffer-modified-p)) |
| 538 | buffer-file-name)) | 547 | buffer-file-name)) |
| @@ -551,7 +560,6 @@ the mode if ARG is omitted or nil." | |||
| 551 | (shell-quote-argument file)) | 560 | (shell-quote-argument file)) |
| 552 | nil out-buf nil))) | 561 | nil out-buf nil))) |
| 553 | 562 | ||
| 554 | |||
| 555 | ;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext") | 563 | ;;;###autoload (autoload 'ibuffer-do-eval "ibuf-ext") |
| 556 | (define-ibuffer-op eval (form) | 564 | (define-ibuffer-op eval (form) |
| 557 | "Evaluate FORM in each of the buffers. | 565 | "Evaluate FORM in each of the buffers. |
diff --git a/lisp/ibuf-macs.el b/lisp/ibuf-macs.el index 05e568efeb2..2e751cebd6e 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'. | |||
| 169 | dangerous | 169 | dangerous |
| 170 | (opstring "operated on") | 170 | (opstring "operated on") |
| 171 | (active-opstring "Operate on") | 171 | (active-opstring "Operate on") |
| 172 | before | ||
| 173 | after | ||
| 172 | complex) | 174 | complex) |
| 173 | &rest body) | 175 | &rest body) |
| 174 | "Generate a function which operates on a buffer. | 176 | "Generate a function which operates on a buffer. |
| @@ -198,6 +200,8 @@ operation is complete, in the form: | |||
| 198 | ACTIVE-OPSTRING is a string which will be displayed to the user in a | 200 | ACTIVE-OPSTRING is a string which will be displayed to the user in a |
| 199 | confirmation message, in the form: | 201 | confirmation message, in the form: |
| 200 | \"Really ACTIVE-OPSTRING x buffers?\" | 202 | \"Really ACTIVE-OPSTRING x buffers?\" |
| 203 | BEFORE is a form to evaluate before start the operation. | ||
| 204 | AFTER is a form to evaluate once the operation is complete. | ||
| 201 | COMPLEX means this function is special; if COMPLEX is nil BODY | 205 | COMPLEX means this function is special; if COMPLEX is nil BODY |
| 202 | evaluates once for each marked buffer, MBUF, with MBUF current | 206 | evaluates once for each marked buffer, MBUF, with MBUF current |
| 203 | and saving the point. If COMPLEX is non-nil, BODY evaluates | 207 | 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 | |||
| 206 | marked buffer. BODY is evaluated with `buf' bound to the | 210 | marked buffer. BODY is evaluated with `buf' bound to the |
| 207 | buffer object. | 211 | buffer object. |
| 208 | 212 | ||
| 209 | \(fn OP ARGS DOCUMENTATION (&key INTERACTIVE MARK MODIFIER-P DANGEROUS OPSTRING ACTIVE-OPSTRING COMPLEX) &rest BODY)" | 213 | \(fn OP ARGS DOCUMENTATION (&key INTERACTIVE MARK MODIFIER-P DANGEROUS OPSTRING ACTIVE-OPSTRING BEFORE AFTER COMPLEX) &rest BODY)" |
| 210 | (declare (indent 2) (doc-string 3)) | 214 | (declare (indent 2) (doc-string 3)) |
| 211 | `(progn | 215 | `(progn |
| 212 | (defun ,(intern (concat (if (string-match "^ibuffer-do" (symbol-name op)) | 216 | (defun ,(intern (concat (if (string-match "^ibuffer-do" (symbol-name op)) |
| @@ -238,6 +242,7 @@ buffer object. | |||
| 238 | (if (eq modifier-p t) | 242 | (if (eq modifier-p t) |
| 239 | '((setq ibuffer-did-modification t)) | 243 | '((setq ibuffer-did-modification t)) |
| 240 | ()) | 244 | ()) |
| 245 | (and after `(,after)) ; post-operation form. | ||
| 241 | `((ibuffer-redisplay t) | 246 | `((ibuffer-redisplay t) |
| 242 | (message ,(concat "Operation finished; " opstring " %s buffers") count)))) | 247 | (message ,(concat "Operation finished; " opstring " %s buffers") count)))) |
| 243 | (inner-body (if complex | 248 | (inner-body (if complex |
| @@ -247,7 +252,8 @@ buffer object. | |||
| 247 | (save-excursion | 252 | (save-excursion |
| 248 | ,@body)) | 253 | ,@body)) |
| 249 | t))) | 254 | t))) |
| 250 | (body `(let ((count | 255 | (body `(let ((_ ,before) ; pre-operation form. |
| 256 | (count | ||
| 251 | (,(pcase mark | 257 | (,(pcase mark |
| 252 | (:deletion | 258 | (:deletion |
| 253 | 'ibuffer-map-deletion-lines) | 259 | 'ibuffer-map-deletion-lines) |