summaryrefslogtreecommitdiff
path: root/lisp/ibuf-ext.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2016-07-03 14:51:18 +0900
committerTino Calancha <tino.calancha@gmail.com>2016-07-03 14:51:18 +0900
commit08974112ae68aefba658a8516c8faa3374edc924 (patch)
tree5bc0062ebb20134fed5693e06c1f1c6e12a4b6af /lisp/ibuf-ext.el
parent0d06e94309fc2f296741a06394413209b45433cd (diff)
downloademacs-08974112ae68aefba658a8516c8faa3374edc924.tar.gz
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.
Diffstat (limited to 'lisp/ibuf-ext.el')
-rw-r--r--lisp/ibuf-ext.el51
1 files changed, 51 insertions, 0 deletions
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."
:type '(repeat (choice regexp function))
:group 'ibuffer)
+(defcustom ibuffer-never-search-content-name
+ (let* ((names '("Completions" "Help" "Messages" "Pp Eval Output"
+ "CompileLog" "Info" "Buffer List" "Ibuffer" "Apropos"))
+ (partial '("Customize Option: " "Async Shell Command\\*"
+ "Shell Command Output\\*" "ediff "))
+ (beg "\\`\\*")
+ (end "\\*\\'")
+ (excluded (mapcar (lambda (x)
+ (format "%s%s" beg x)) partial)))
+ (dolist (str names (nreverse excluded))
+ (push (format "%s%s%s" beg str end) excluded)))
+ "A list of regexps for buffers ignored by `ibuffer-mark-by-content-regexp'.
+Buffers whose name matches a regexp in this list, are not searched."
+ :version "25.2"
+ :type '(repeat regexp)
+ :require 'ibuf-ext
+ :group 'ibuffer)
+
+(defcustom ibuffer-never-search-content-mode '(dired-mode)
+ "A list of major modes ignored by `ibuffer-mark-by-content-regexp'.
+Buffers whose major mode is in this list, are not searched."
+ :version "25.2"
+ :type '(repeat regexp)
+ :require 'ibuf-ext
+ :group 'ibuffer)
+
(defvar ibuffer-tmp-hide-regexps nil
"A list of regexps which should match buffer names to not show.")
@@ -1483,6 +1509,31 @@ You can then feed the file name(s) to other commands with \\[yank]."
(string-match regexp name))))))
;;;###autoload
+(defun ibuffer-mark-by-content-regexp (regexp &optional all-buffers)
+ "Mark all buffers whose content matches REGEXP.
+Optional arg ALL-BUFFERS, if non-nil, then search in all buffers.
+Otherwise buffers whose name matches an element of
+`ibuffer-never-search-content-name' or whose major mode is on
+`ibuffer-never-search-content-mode' are excluded."
+ (interactive (let ((reg (read-string "Mark by content (regexp): ")))
+ (list reg current-prefix-arg)))
+ (ibuffer-mark-on-buffer
+ #'(lambda (buf)
+ (let ((mode (with-current-buffer buf major-mode))
+ res)
+ (cond ((and (not all-buffers)
+ (or
+ (memq mode ibuffer-never-search-content-mode)
+ (cl-some (lambda (x) (string-match x (buffer-name buf)))
+ ibuffer-never-search-content-name)))
+ (setq res nil))
+ (t
+ (with-current-buffer buf
+ (save-mark-and-excursion
+ (goto-char (point-min))
+ (setq res (re-search-forward regexp nil t)))))) res))))
+
+;;;###autoload
(defun ibuffer-mark-by-mode (mode)
"Mark all buffers whose major mode equals MODE."
(interactive