GNU bug report logs - #23734
25.1.50; ibuffer: Search a buffer by content

Previous Next

Package: emacs;

Reported by: Tino Calancha <f92capac <at> gmail.com>

Date: Thu, 9 Jun 2016 06:17:02 UTC

Severity: wishlist

Tags: patch

Found in version 25.1.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23734 in the body.
You can then email your comments to 23734 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#23734; Package emacs. (Thu, 09 Jun 2016 06:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <f92capac <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 09 Jun 2016 06:17:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <f92capac <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.1.50; ibuffer: Search a buffer by content
Date: Thu, 9 Jun 2016 15:19:05 +0900 (JST)
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 <at> 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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23734; Package emacs. (Thu, 09 Jun 2016 17:25:02 GMT) Full text and rfc822 format available.

Message #8 received at 23734 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Tino Calancha <f92capac <at> gmail.com>
Cc: 23734 <at> debbugs.gnu.org
Subject: Re: bug#23734: 25.1.50; ibuffer: Search a buffer by content
Date: Thu, 09 Jun 2016 13:24:41 -0400
Tino Calancha wrote:

> 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.

multi-occur can do this kind of thing.

> 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).


C-u M-x multi-occur-in-matching-buffers RET . RET foo (bar) RET




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23734; Package emacs. (Thu, 09 Jun 2016 17:29:01 GMT) Full text and rfc822 format available.

Message #11 received at 23734 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Tino Calancha <f92capac <at> gmail.com>
Cc: 23734 <at> debbugs.gnu.org
Subject: Re: bug#23734: 25.1.50; ibuffer: Search a buffer by content
Date: Thu, 09 Jun 2016 13:28:06 -0400
BTW, thanks for all the patches.
If you're interested, I suggest you get write access so you can apply
things yourself.

See http://savannah.gnu.org/project/memberlist.php?group=emacs




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23734; Package emacs. (Fri, 10 Jun 2016 09:18:02 GMT) Full text and rfc822 format available.

Message #14 received at 23734 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <f92capac <at> gmail.com>
To: 23734 <at> debbugs.gnu.org, Tino Calancha <f92capac <at> gmail.com>
Subject: Re: bug#23734: 25.1.50; ibuffer: Search a buffer by content
Date: Fri, 10 Jun 2016 18:17:54 +0900
[Message part 1 (text/plain, inline)]
> multi-occur can do this kind of thing.
> C-u M-x multi-occur-in-matching-buffers RET . RET foo (bar) RET

 You are right!
  Having several ways to solve a problem, letting you to choose the one you
 like more is generally a good thing.

*) multi-occur-in-matching-buffers is certainly a more general solution
(don't require
    the user being familiar with Ibuffer).
*) The ibuffer approach it could be more suitable for people using ibuffer
or dired.

On Fri, Jun 10, 2016 at 6:16 PM, Tino Calancha <f92capac <at> gmail.com> wrote:

> > multi-occur can do this kind of thing.
> > C-u M-x multi-occur-in-matching-buffers RET . RET foo (bar) RET
>
>  You are right!
>   Having several ways to solve a problem, letting you to choose the one you
>  like more is generally a good thing.
>
> *) multi-occur-in-matching-buffers is certainly a more general solution
> (don't require
>     the user being familiar with Ibuffer).
> *) The ibuffer approach it could be more suitable for people using ibuffer
> or dired.
>
>
> On Fri, Jun 10, 2016 at 2:24 AM, Glenn Morris <rgm <at> gnu.org> wrote:
>
>> Tino Calancha wrote:
>>
>> > 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.
>>
>> multi-occur can do this kind of thing.
>>
>> > 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).
>>
>>
>> C-u M-x multi-occur-in-matching-buffers RET . RET foo (bar) RET
>>
>
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23734; Package emacs. (Fri, 10 Jun 2016 09:22:01 GMT) Full text and rfc822 format available.

Message #17 received at 23734 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <f92capac <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 23734 <at> debbugs.gnu.org
Subject: Re: bug#23734: 25.1.50; ibuffer: Search a buffer by content
Date: Fri, 10 Jun 2016 18:20:54 +0900
[Message part 1 (text/plain, inline)]
BTW, thanks for all the patches.
If you're interested, I suggest you get write access so you can apply
things yourself.

See http://savannah.gnu.org/project/memberlist.php?group=emacs
Thank you. I am very much interested.
I just sent my request and waiting to be on board 🛥

On Fri, Jun 10, 2016 at 2:28 AM, Glenn Morris <rgm <at> gnu.org> wrote:

>
> BTW, thanks for all the patches.
> If you're interested, I suggest you get write access so you can apply
> things yourself.
>
> See http://savannah.gnu.org/project/memberlist.php?group=emacs
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23734; Package emacs. (Wed, 15 Jun 2016 04:34:02 GMT) Full text and rfc822 format available.

Message #20 received at 23734 <at> debbugs.gnu.org (full text, mbox):

From: "C. Calancha" <f92capac <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Tino Calancha <f92capac <at> gmail.com>, 23734 <at> debbugs.gnu.org
Subject: Re: bug#23734: 25.1.50; ibuffer: Search a buffer by content
Date: Wed, 15 Jun 2016 13:33:40 +0900 (JST)

On Thu, 9 Jun 2016, Glenn Morris wrote:

> If you're interested, I suggest you get write access so you can apply
> things yourself.

Hi Glenn,
i got the write permissions.
If you are happy with this new feature i can commit it to the trunk.





Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Sun, 03 Jul 2016 06:14:01 GMT) Full text and rfc822 format available.

Notification sent to Tino Calancha <f92capac <at> gmail.com>:
bug acknowledged by developer. (Sun, 03 Jul 2016 06:14:02 GMT) Full text and rfc822 format available.

Message #25 received at 23734-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 23734-done <at> debbugs.gnu.org
Date: Sun, 3 Jul 2016 15:13:05 +0900 (JST)
Added the new feature into master branch




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 31 Jul 2016 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 320 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.