Function: ibuffer-mark-by-content-regexp

ibuffer-mark-by-content-regexp is an autoloaded, interactive and byte-compiled function defined in ibuf-ext.el.gz.

Signature

(ibuffer-mark-by-content-regexp REGEXP &optional ALL-BUFFERS)

Documentation

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.

Probably introduced at or before Emacs version 26.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/ibuf-ext.el.gz
;;;###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-dolist (x ibuffer-never-search-content-name nil)
                      (when-let* ((found (string-match x (buffer-name buf))))
                        (cl-return found)))))
              (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))))