all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#23734: 25.1.50; ibuffer: Search a buffer by content
@ 2016-06-09  6:19 Tino Calancha
  2016-06-09 17:24 ` Glenn Morris
  2016-07-03  6:13 ` bug#23734: (no subject) Tino Calancha
  0 siblings, 2 replies; 7+ messages in thread
From: Tino Calancha @ 2016-06-09  6:19 UTC (permalink / raw)
  To: 23734


It's commun one Emacs session having dozens of buffers
on memory.  On such situation, it is hard to remember
the name of one particular buffer.

It may be useful having easy way to search buffers
by content.

For example, one user is developping a funtion foo
in the buffer BUF, with name BUF-NAME:

foo-type foo (bar)

The user may not remember BUF-NAME, but s/he could be able
to write a regexp matching just the content of BUF.
For instance, something like
"foo (bar)"
likely would match just BUF content (or a few buffers more).

Following patch implements such behaviour adding a new command
`ibuffer-mark-by-content-regexp' inside ibuffer package.
This command marks on Ibuffer all buffers whose content
matches a regexp.

The new command is bound to:

I) '% c', in analogy with `ibuffer-filter-by-content';
II) '% g', in analogy with `dired-mark-files-containing-regexp'.


In GNU Emacs 25.1.50 (x86_64-pc-linux-gnu, GTK+ Version 3.20.6)
  of 2016-06-09 built on calancha-pc
Repository revision: 82f49c6a373f981a778f4d939ca2d47c031e0659

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

From ceeb3b28cb037ab94e0a3ad11f317d023a655d73 Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Thu, 9 Jun 2016 15:03:59 +0900
Subject: [PATCH] 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 menus.
; * etc/NEWS: Add NEWS entry for these changes.
---
  etc/NEWS         | 10 ++++++++++
  lisp/ibuf-ext.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
  lisp/ibuffer.el  |  7 +++++++
  3 files changed, 68 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index e2c99a1..deee0ea 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -189,6 +189,16 @@ 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 user 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 0baab6b..8e5dcc0 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -85,6 +85,32 @@ ibuffer-always-show-predicates
    :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.")

@@ -1482,6 +1508,31 @@ ibuffer-mark-by-file-name-regexp
  	   (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 @@ ibuffer-mode-map
      (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 @@ ibuffer-mode-map
        '(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 @@ ibuffer-mode
    `\\[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:

-- 
2.8.1






^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-07-03  6:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-09  6:19 bug#23734: 25.1.50; ibuffer: Search a buffer by content Tino Calancha
2016-06-09 17:24 ` Glenn Morris
2016-06-09 17:28   ` Glenn Morris
2016-06-10  9:20     ` Tino Calancha
2016-06-15  4:33     ` C. Calancha
     [not found]   ` <CAMn5WmaW1RYx=b-6_M21ko-Zwj8a_SRD82yQny-44Df49E4Yrw@mail.gmail.com>
2016-06-10  9:17     ` Tino Calancha
2016-07-03  6:13 ` bug#23734: (no subject) Tino Calancha

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.