diff options
| author | Tino Calancha | 2016-07-03 14:51:18 +0900 |
|---|---|---|
| committer | Tino Calancha | 2016-07-03 14:51:18 +0900 |
| commit | 08974112ae68aefba658a8516c8faa3374edc924 (patch) | |
| tree | 5bc0062ebb20134fed5693e06c1f1c6e12a4b6af | |
| parent | 0d06e94309fc2f296741a06394413209b45433cd (diff) | |
| download | emacs-08974112ae68aefba658a8516c8faa3374edc924.tar.gz emacs-08974112ae68aefba658a8516c8faa3374edc924.zip | |
Ibuffer: Mark buffers by content
* lisp/ibuf-ext.el (ibuffer-mark-by-content-regexp): New command.
(ibuffer-never-search-content-name): New option.
(ibuffer-never-search-content-mode): Idem.
(ibuffer-mark-by-content-regexp): Use them (Bug#23734).
* lisp/ibuffer.el (ibuffer-mode-map): Bind new command to '% c' and '% g'.
(ibuffer-mode): Update mode documentation.
; * etc/NEWS: Add NEWS entry for these changes.
| -rw-r--r-- | etc/NEWS | 11 | ||||
| -rw-r--r-- | lisp/ibuf-ext.el | 51 | ||||
| -rw-r--r-- | lisp/ibuffer.el | 7 |
3 files changed, 69 insertions, 0 deletions
| @@ -190,6 +190,17 @@ questions, with a handy way to display help texts. | |||
| 190 | 190 | ||
| 191 | * Changes in Specialized Modes and Packages in Emacs 25.2 | 191 | * Changes in Specialized Modes and Packages in Emacs 25.2 |
| 192 | 192 | ||
| 193 | ** Ibuffer | ||
| 194 | |||
| 195 | --- | ||
| 196 | *** A new command `ibuffer-mark-by-content-regexp' to mark buffers | ||
| 197 | whose content matches a regexp; bound to '% c' and '% g'. | ||
| 198 | |||
| 199 | --- | ||
| 200 | *** Two new options `ibuffer-never-search-content-name' and | ||
| 201 | `ibuffer-never-search-content-mode' used by | ||
| 202 | `ibuffer-mark-by-content-regexp'. | ||
| 203 | |||
| 193 | ** Compilation mode | 204 | ** Compilation mode |
| 194 | 205 | ||
| 195 | --- | 206 | --- |
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index d4fd09f2cce..72fa8628a1f 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el | |||
| @@ -85,6 +85,32 @@ regardless of any active filters in this buffer." | |||
| 85 | :type '(repeat (choice regexp function)) | 85 | :type '(repeat (choice regexp function)) |
| 86 | :group 'ibuffer) | 86 | :group 'ibuffer) |
| 87 | 87 | ||
| 88 | (defcustom ibuffer-never-search-content-name | ||
| 89 | (let* ((names '("Completions" "Help" "Messages" "Pp Eval Output" | ||
| 90 | "CompileLog" "Info" "Buffer List" "Ibuffer" "Apropos")) | ||
| 91 | (partial '("Customize Option: " "Async Shell Command\\*" | ||
| 92 | "Shell Command Output\\*" "ediff ")) | ||
| 93 | (beg "\\`\\*") | ||
| 94 | (end "\\*\\'") | ||
| 95 | (excluded (mapcar (lambda (x) | ||
| 96 | (format "%s%s" beg x)) partial))) | ||
| 97 | (dolist (str names (nreverse excluded)) | ||
| 98 | (push (format "%s%s%s" beg str end) excluded))) | ||
| 99 | "A list of regexps for buffers ignored by `ibuffer-mark-by-content-regexp'. | ||
| 100 | Buffers whose name matches a regexp in this list, are not searched." | ||
| 101 | :version "25.2" | ||
| 102 | :type '(repeat regexp) | ||
| 103 | :require 'ibuf-ext | ||
| 104 | :group 'ibuffer) | ||
| 105 | |||
| 106 | (defcustom ibuffer-never-search-content-mode '(dired-mode) | ||
| 107 | "A list of major modes ignored by `ibuffer-mark-by-content-regexp'. | ||
| 108 | Buffers whose major mode is in this list, are not searched." | ||
| 109 | :version "25.2" | ||
| 110 | :type '(repeat regexp) | ||
| 111 | :require 'ibuf-ext | ||
| 112 | :group 'ibuffer) | ||
| 113 | |||
| 88 | (defvar ibuffer-tmp-hide-regexps nil | 114 | (defvar ibuffer-tmp-hide-regexps nil |
| 89 | "A list of regexps which should match buffer names to not show.") | 115 | "A list of regexps which should match buffer names to not show.") |
| 90 | 116 | ||
| @@ -1483,6 +1509,31 @@ You can then feed the file name(s) to other commands with \\[yank]." | |||
| 1483 | (string-match regexp name)))))) | 1509 | (string-match regexp name)))))) |
| 1484 | 1510 | ||
| 1485 | ;;;###autoload | 1511 | ;;;###autoload |
| 1512 | (defun ibuffer-mark-by-content-regexp (regexp &optional all-buffers) | ||
| 1513 | "Mark all buffers whose content matches REGEXP. | ||
| 1514 | Optional arg ALL-BUFFERS, if non-nil, then search in all buffers. | ||
| 1515 | Otherwise buffers whose name matches an element of | ||
| 1516 | `ibuffer-never-search-content-name' or whose major mode is on | ||
| 1517 | `ibuffer-never-search-content-mode' are excluded." | ||
| 1518 | (interactive (let ((reg (read-string "Mark by content (regexp): "))) | ||
| 1519 | (list reg current-prefix-arg))) | ||
| 1520 | (ibuffer-mark-on-buffer | ||
| 1521 | #'(lambda (buf) | ||
| 1522 | (let ((mode (with-current-buffer buf major-mode)) | ||
| 1523 | res) | ||
| 1524 | (cond ((and (not all-buffers) | ||
| 1525 | (or | ||
| 1526 | (memq mode ibuffer-never-search-content-mode) | ||
| 1527 | (cl-some (lambda (x) (string-match x (buffer-name buf))) | ||
| 1528 | ibuffer-never-search-content-name))) | ||
| 1529 | (setq res nil)) | ||
| 1530 | (t | ||
| 1531 | (with-current-buffer buf | ||
| 1532 | (save-mark-and-excursion | ||
| 1533 | (goto-char (point-min)) | ||
| 1534 | (setq res (re-search-forward regexp nil t)))))) res)))) | ||
| 1535 | |||
| 1536 | ;;;###autoload | ||
| 1486 | (defun ibuffer-mark-by-mode (mode) | 1537 | (defun ibuffer-mark-by-mode (mode) |
| 1487 | "Mark all buffers whose major mode equals MODE." | 1538 | "Mark all buffers whose major mode equals MODE." |
| 1488 | (interactive | 1539 | (interactive |
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el index 609524ccd20..126b5a32b2b 100644 --- a/lisp/ibuffer.el +++ b/lisp/ibuffer.el | |||
| @@ -545,6 +545,8 @@ directory, like `default-directory'." | |||
| 545 | (define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp) | 545 | (define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp) |
| 546 | (define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp) | 546 | (define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp) |
| 547 | (define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp) | 547 | (define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp) |
| 548 | (define-key map (kbd "% c") 'ibuffer-mark-by-content-regexp) | ||
| 549 | (define-key map (kbd "% g") 'ibuffer-mark-by-content-regexp) | ||
| 548 | 550 | ||
| 549 | (define-key map (kbd "C-t") 'ibuffer-visit-tags-table) | 551 | (define-key map (kbd "C-t") 'ibuffer-visit-tags-table) |
| 550 | 552 | ||
| @@ -765,6 +767,10 @@ directory, like `default-directory'." | |||
| 765 | '(menu-item "Mark by file name (regexp)..." | 767 | '(menu-item "Mark by file name (regexp)..." |
| 766 | ibuffer-mark-by-file-name-regexp | 768 | ibuffer-mark-by-file-name-regexp |
| 767 | :help "Mark buffers whose file name matches a regexp")) | 769 | :help "Mark buffers whose file name matches a regexp")) |
| 770 | (define-key-after map [menu-bar mark ibuffer-mark-by-content-regexp] | ||
| 771 | '(menu-item "Mark by content (regexp)..." | ||
| 772 | ibuffer-mark-by-content-regexp | ||
| 773 | :help "Mark buffers whose content matches a regexp")) | ||
| 768 | 774 | ||
| 769 | map)) | 775 | map)) |
| 770 | 776 | ||
| @@ -2438,6 +2444,7 @@ Marking commands: | |||
| 2438 | `\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp. | 2444 | `\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp. |
| 2439 | `\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp. | 2445 | `\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp. |
| 2440 | `\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp. | 2446 | `\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp. |
| 2447 | `\\[ibuffer-mark-by-content-regexp]' - Mark buffers by their content, using a regexp. | ||
| 2441 | 2448 | ||
| 2442 | Filtering commands: | 2449 | Filtering commands: |
| 2443 | 2450 | ||