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

From: Eli Zaretskii <[email-masked]>
Date: Thu, 25 Jan 2024 17:12:11 +0200

> From: Nafiz Islam <[email-masked]>
> Date: Thu, 25 Jan 2024 09:58:10 -0500
> Cc: [email-masked]
> 
> 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.