GNU bug report logs - #68697
Add option to not always use *grep* buffer when executing `grep' or `vc-git-grep' command

Previous Next

Package: emacs;

Reported by: Nafiz Islam <nafiz.islam1001 <at> gmail.com>

Date: Wed, 24 Jan 2024 20:17:02 UTC

Severity: normal

Fix blocked by 68570: 29.1; recompile might not re-use project-compile's buffer

To reply to this bug, email your comments to 68697 AT debbugs.gnu.org.

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#68697; Package emacs. (Wed, 24 Jan 2024 20:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Nafiz Islam <nafiz.islam1001 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 24 Jan 2024 20:17:02 GMT) Full text and rfc822 format available.

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

From: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Add option to not always use *grep* buffer when executing `grep' or
 `vc-git-grep' command
Date: Wed, 24 Jan 2024 15:16:12 -0500
[Message part 1 (text/plain, inline)]
The way `grep' and `vc-git-grep' works right now is that it will always
output its result to a buffer called `*grep*'. So, if I perform another
`grep' command, it will overwrite the previous grep result (unless I rename
the buffer beforehand).

I would like, at least, an option to create a new buffer each time a `grep'
command is executed. Maybe each new buffer could be given the name based on
the regexp or the grep shell command used.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68697; Package emacs. (Thu, 25 Jan 2024 07:26:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
Cc: 68697 <at> debbugs.gnu.org
Subject: Re: bug#68697: Add option to not always use *grep* buffer when
 executing `grep' or `vc-git-grep' command
Date: Thu, 25 Jan 2024 09:24:50 +0200
> From: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
> Date: Wed, 24 Jan 2024 15:16:12 -0500
> 
> The way `grep' and `vc-git-grep' works right now is that it will always output its result to a buffer called
> `*grep*'. So, if I perform another `grep' command, it will overwrite the previous grep result (unless I
> rename the buffer beforehand).
> 
> I would like, at least, an option to create a new buffer each time a `grep' command is executed.
> Maybe each new buffer could be given the name based on the regexp or the grep shell command
> used.

Did you try to define a compilation-buffer-name-function that would do
what you want?  Such a function can produce any buffer name you want.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68697; Package emacs. (Thu, 25 Jan 2024 07:49:01 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
Cc: 68697 <at> debbugs.gnu.org
Subject: Re: bug#68697: Add option to not always use *grep* buffer when
 executing `grep' or `vc-git-grep' command
Date: Thu, 25 Jan 2024 09:45:40 +0200
> The way `grep' and `vc-git-grep' works right now is that it will always
> output its result to a buffer called `*grep*'. So, if I perform another
> `grep' command, it will overwrite the previous grep result (unless I rename
> the buffer beforehand).
>
> I would like, at least, an option to create a new buffer each time a `grep'
> command is executed.

I'm using such config to create unique buffer names for
`compile' and `grep':

```
(setq compilation-buffer-name-function
      (lambda (name-of-mode)
        (generate-new-buffer-name
         (concat "*" (downcase name-of-mode) "*"))))
```

Currently in bug#68570 we are discussing about adding an option
to `project-compilation-buffer-name-function' to create unique names
for project compilation buffers.

So the same way we could turn `compilation-buffer-name-function'
into a defcustom with an option for unique compilation/grep buffers.

> Maybe each new buffer could be given the name based on
> the regexp or the grep shell command used.

A name based on a regexp could be another option indeed.
Here is what I'm using for xref buffer names with a regexp:

```
(with-eval-after-load 'project
  ;; Instead of numbers append the regexp to the xref buffer name:
  (define-advice project-find-regexp (:around (ofun &rest args) unique)
    (require 'xref)
    (let ((xref-buffer-name
           (generate-new-buffer-name
            (format "%s<%s>" xref-buffer-name (car args)))))
      (apply ofun args))))
```




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68697; Package emacs. (Thu, 25 Jan 2024 14:59:01 GMT) Full text and rfc822 format available.

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

From: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 68697 <at> debbugs.gnu.org
Subject: Re: bug#68697: Add option to not always use *grep* buffer when
 executing `grep' or `vc-git-grep' command
Date: Thu, 25 Jan 2024 09:58:10 -0500
[Message part 1 (text/plain, inline)]
Oh right, I can use compilation-buffer-name-function. My only issue is that
it doesn't have enough context to generate a meaningful buffer name; it
only takes a name-of-mode. A meaningful buffer name could consist of the
regexp or the entire grep shell command.

On Thu, Jan 25, 2024 at 2:24 AM Eli Zaretskii <eliz <at> gnu.org> wrote:

> > From: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
> > Date: Wed, 24 Jan 2024 15:16:12 -0500
> >
> > The way `grep' and `vc-git-grep' works right now is that it will always
> output its result to a buffer called
> > `*grep*'. So, if I perform another `grep' command, it will overwrite the
> previous grep result (unless I
> > rename the buffer beforehand).
> >
> > I would like, at least, an option to create a new buffer each time a
> `grep' command is executed.
> > Maybe each new buffer could be given the name based on the regexp or the
> grep shell command
> > used.
>
> Did you try to define a compilation-buffer-name-function that would do
> what you want?  Such a function can produce any buffer name you want.
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68697; Package emacs. (Thu, 25 Jan 2024 15:13:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
Cc: 68697 <at> debbugs.gnu.org
Subject: Re: bug#68697: Add option to not always use *grep* buffer when
 executing `grep' or `vc-git-grep' command
Date: Thu, 25 Jan 2024 17:12:11 +0200
> From: Nafiz Islam <nafiz.islam1001 <at> gmail.com>
> Date: Thu, 25 Jan 2024 09:58:10 -0500
> Cc: 68697 <at> debbugs.gnu.org
> 
> Oh right, I can use compilation-buffer-name-function. My only issue is that it doesn't have enough
> context to generate a meaningful buffer name; it only takes a name-of-mode. A meaningful buffer
> name could consist of the regexp or the entire grep shell command.

You could include in the buffer name the default-directory instead.

Alternatively, you could advise "M-x grep" or write a wrapper around
it, and in that advice/wrapper bind some dynamic variable to the grep
command, and your compilation-buffer-name-function could then access
that variable.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68697; Package emacs. (Fri, 14 Mar 2025 04:31:02 GMT) Full text and rfc822 format available.

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

From: Sean Whitton <spwhitton <at> spwhitton.name>
To: 68697 <at> debbugs.gnu.org
Cc: control <at> debbugs.gnu.org
Subject: Re: bug#68697: Add option to not always use *grep* buffer when
 executing `grep' or `vc-git-grep' command
Date: Fri, 14 Mar 2025 12:30:06 +0800
block 68697 by 68570
thanks

Hello,

On Thu 25 Jan 2024 at 09:45am +02, Juri Linkov wrote:

> Currently in bug#68570 we are discussing about adding an option
> to `project-compilation-buffer-name-function' to create unique names
> for project compilation buffers.
>
> So the same way we could turn `compilation-buffer-name-function'
> into a defcustom with an option for unique compilation/grep buffers.

I think that bug needs to resolve before deciding whether to do anything
more here, or just close this one, so marking as blocking.

-- 
Sean Whitton




Added blocking bug(s) 68570 Request was from Sean Whitton <spwhitton <at> spwhitton.name> to control <at> debbugs.gnu.org. (Fri, 14 Mar 2025 04:31:02 GMT) Full text and rfc822 format available.

This bug report was last modified 99 days ago.

Previous Next


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