emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] scratch/gnus-cloud 7404048 05/15: Merge branch 'master' of


From: Teodor Zlatanov
Subject: [Emacs-diffs] scratch/gnus-cloud 7404048 05/15: Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Date: Tue, 5 Jul 2016 02:22:47 +0000 (UTC)

branch: scratch/gnus-cloud
commit 740404822cfc02bb95d2f48355084e9b7805329b
Merge: c69220c 0897411
Author: Ted Zlatanov <address@hidden>
Commit: Ted Zlatanov <address@hidden>

    Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
---
 etc/NEWS         |   11 +++++++++++
 lisp/ibuf-ext.el |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lisp/ibuffer.el  |    7 +++++++
 3 files changed, 69 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index b3a044d..555d6bb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -190,6 +190,17 @@ questions, with a handy way to display help texts.
 
 * Changes in Specialized Modes and Packages in Emacs 25.2
 
+** Ibuffer
+
+---
+*** A new command `ibuffer-mark-by-content-regexp' to mark buffers
+whose content matches a regexp; bound to '% c' and '% g'.
+
+---
+*** Two new options `ibuffer-never-search-content-name' and
+`ibuffer-never-search-content-mode' used by
+`ibuffer-mark-by-content-regexp'.
+
 ** Compilation mode
 
 ---
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index d4fd09f..72fa862 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
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 609524c..126b5a3 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -545,6 +545,8 @@ directory, like `default-directory'."
     (define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp)
     (define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp)
     (define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp)
+    (define-key map (kbd "% c") 'ibuffer-mark-by-content-regexp)
+    (define-key map (kbd "% g") 'ibuffer-mark-by-content-regexp)
 
     (define-key map (kbd "C-t") 'ibuffer-visit-tags-table)
 
@@ -765,6 +767,10 @@ directory, like `default-directory'."
       '(menu-item "Mark by file name (regexp)..."
         ibuffer-mark-by-file-name-regexp
         :help "Mark buffers whose file name matches a regexp"))
+    (define-key-after map [menu-bar mark ibuffer-mark-by-content-regexp]
+      '(menu-item "Mark by content (regexp)..."
+        ibuffer-mark-by-content-regexp
+        :help "Mark buffers whose content matches a regexp"))
 
     map))
 
@@ -2438,6 +2444,7 @@ Marking commands:
   `\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a 
regexp.
   `\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using 
a regexp.
   `\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, 
using a regexp.
+  `\\[ibuffer-mark-by-content-regexp]' - Mark buffers by their content, using 
a regexp.
 
 Filtering commands:
 



reply via email to

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