all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [patch] automatic multiple grep session
@ 2007-08-16 21:07 Masatake YAMATO
  2007-08-16 22:43 ` Lennart Borgman (gmail)
  2007-08-17  4:50 ` Richard Stallman
  0 siblings, 2 replies; 6+ messages in thread
From: Masatake YAMATO @ 2007-08-16 21:07 UTC (permalink / raw)
  To: emacs-devel

Hi,

Sometimes I'd like to run multiple grep without
renaming running grep buffer.

`compilation-start' has the ability to do so. However, grep, which
uses `compilation-start' doesn't use it.

I propose following patch. The patch uses given grep command line as
the name of newly created grep buffer. As the result, a user can run
different multiple grep without renaming the names. 

I'd like to install this patch if there is no objection.

There is an issue is that the command line of M-x rgrep is very
long. So the name of rgrep buffer fills the mode-line. 
Could you give me a suggestion?

Masatake YAMATO

 (defun compilation-start (command &optional mode name-function highlight-regexp)

2007-08-16  Masatake YAMATO  <jet@gyve.org>

	* progmodes/grep.el (grep-use-command-line-as-buffer-name): 
	New customizable variable.
	(grep-make-buffer-name-function): New function.
	(grep): Use `grep-make-buffer-name-function'.
	(lgrep): Ditto.
	(rgrep): Ditto.
	(rgrep): Ditto.

--- grep.el	26  7月 2007 14:27:27 +0900	1.76
+++ grep.el	17  8月 2007 05:52:36 +0900	
@@ -177,6 +177,14 @@
   :type 'hook
   :group 'grep)
 
+(defcustom grep-use-command-line-as-buffer-name nil
+  "Use the command line of grep as the name for grep buffer if non-nil.
+So you can run multiple grep sessions without renaming grep 
+buffers manually."
+  :type 'boolean
+  :version "22.2"
+  :group 'grep)
+
 (defvar grep-mode-map
   (let ((map (cons 'keymap compilation-minor-mode-map)))
     (define-key map " " 'scroll-up)
@@ -569,6 +577,12 @@
       ;; Now replace the pattern with the default tag.
       (replace-match tag-default t t grep-default 1))))
 
+(defun grep-make-buffer-name-function (seed-string)
+  "Make a function that returns a buffer name derived from SEED-STRING.
+This is used when `grep-use-command-line-as-buffer-name' is non-nil."
+  (when grep-use-command-line-as-buffer-name
+    (eval `(lambda (mode) (format "*%s*" 
+				  ,seed-string)))))
 
 ;;;###autoload
 (define-compilation-mode grep-mode "Grep"
@@ -616,8 +630,8 @@
   (compilation-start (if (and grep-use-null-device null-device)
 			 (concat command-args " " null-device)
 		       command-args)
-		     'grep-mode))
-
+		     'grep-mode
+		     (grep-make-buffer-name-function command-args)))
 
 ;;;###autoload
 (defun grep-find (command-args)
@@ -770,7 +784,8 @@
 	  ;; even when async processes aren't supported.
 	  (compilation-start (if (and grep-use-null-device null-device)
 				 (concat command " " null-device)
-			       command) 'grep-mode))
+			       command) 'grep-mode
+			       (grep-make-buffer-name-function command)))
 	(if (eq next-error-last-buffer (current-buffer))
 	    (setq default-directory dir))))))
 
@@ -811,7 +826,8 @@
   (when (and (stringp regexp) (> (length regexp) 0))
     (if (null files)
 	(if (not (string= regexp grep-find-command))
-	    (compilation-start regexp 'grep-mode))
+	    (compilation-start regexp 'grep-mode 
+			       (grep-make-buffer-name-function regexp)))
       (setq dir (file-name-as-directory (expand-file-name dir)))
       (let ((command (grep-expand-template
 		      grep-find-template
@@ -843,7 +859,8 @@
 					  command nil nil 'grep-find-history))
 	    (add-to-history 'grep-find-history command))
 	  (let ((default-directory dir))
-	    (compilation-start command 'grep-mode))
+	    (compilation-start command 'grep-mode
+			       (grep-make-buffer-name-function command)))
 	  ;; Set default-directory if we started rgrep in the *grep* buffer.
 	  (if (eq next-error-last-buffer (current-buffer))
 	      (setq default-directory dir)))))))

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

* Re: [patch] automatic multiple grep session
  2007-08-16 21:07 [patch] automatic multiple grep session Masatake YAMATO
@ 2007-08-16 22:43 ` Lennart Borgman (gmail)
  2007-08-17  3:24   ` Stefan Monnier
  2007-08-17  4:50 ` Richard Stallman
  1 sibling, 1 reply; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2007-08-16 22:43 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

Masatake YAMATO wrote:
> There is an issue is that the command line of M-x rgrep is very
> long. So the name of rgrep buffer fills the mode-line. 
> Could you give me a suggestion?

Perhaps use something like

  rgrep, ANSWER1, ANSWER2 etc

where ANSWER1 is the answer to the first rgrep prompt etc.

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

* Re: [patch] automatic multiple grep session
  2007-08-16 22:43 ` Lennart Borgman (gmail)
@ 2007-08-17  3:24   ` Stefan Monnier
  2007-08-18  1:37     ` Lennart Borgman (gmail)
  2007-08-19 23:18     ` Juri Linkov
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2007-08-17  3:24 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Masatake YAMATO, emacs-devel

>> There is an issue is that the command line of M-x rgrep is very
>> long. So the name of rgrep buffer fills the mode-line. 
>> Could you give me a suggestion?

> Perhaps use something like

>   rgrep, ANSWER1, ANSWER2 etc

> where ANSWER1 is the answer to the first rgrep prompt etc.

How 'bout tweaking uniquify to do something clever with it?
So a single grep buffer will always appear as *grep*.


        Stefan

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

* Re: [patch] automatic multiple grep session
  2007-08-16 21:07 [patch] automatic multiple grep session Masatake YAMATO
  2007-08-16 22:43 ` Lennart Borgman (gmail)
@ 2007-08-17  4:50 ` Richard Stallman
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2007-08-17  4:50 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: emacs-devel

    +(defcustom grep-use-command-line-as-buffer-name nil
    +  "Use the command line of grep as the name for grep buffer if non-nil.

I can't make sense of that sentence, or that variable name.
Can you please explain what this feature is intended to do?

    +(defun grep-make-buffer-name-function (seed-string)
    +  "Make a function that returns a buffer name derived from SEED-STRING.
    +This is used when `grep-use-command-line-as-buffer-name' is non-nil."
    +  (when grep-use-command-line-as-buffer-name
    +    (eval `(lambda (mode) (format "*%s*" 
    +				  ,seed-string)))))

What's the purpose of calling `eval' here?
It is a bad thing to do, when it is not really necessary,
and I can't see the purpose of doing so here.


Please note that some of the code you changed had its line
breaks in the wrong place; I just fixed that.

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

* Re: [patch] automatic multiple grep session
  2007-08-17  3:24   ` Stefan Monnier
@ 2007-08-18  1:37     ` Lennart Borgman (gmail)
  2007-08-19 23:18     ` Juri Linkov
  1 sibling, 0 replies; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2007-08-18  1:37 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier wrote:
>>> There is an issue is that the command line of M-x rgrep is very
>>> long. So the name of rgrep buffer fills the mode-line. 
>>> Could you give me a suggestion?
> 
>> Perhaps use something like
> 
>>   rgrep, ANSWER1, ANSWER2 etc
> 
>> where ANSWER1 is the answer to the first rgrep prompt etc.
> 
> How 'bout tweaking uniquify to do something clever with it?
> So a single grep buffer will always appear as *grep*.


Is not that more inconvinient when switching between them?

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

* Re: [patch] automatic multiple grep session
  2007-08-17  3:24   ` Stefan Monnier
  2007-08-18  1:37     ` Lennart Borgman (gmail)
@ 2007-08-19 23:18     ` Juri Linkov
  1 sibling, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2007-08-19 23:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: jet, emacs-devel

>>> There is an issue is that the command line of M-x rgrep is very
>>> long. So the name of rgrep buffer fills the mode-line. 
>>> Could you give me a suggestion?
>
>> Perhaps use something like
>
>>   rgrep, ANSWER1, ANSWER2 etc
>
>> where ANSWER1 is the answer to the first rgrep prompt etc.
>
> How 'bout tweaking uniquify to do something clever with it?
> So a single grep buffer will always appear as *grep*.

Something like (add-hook 'after-create-buffer-hook 'grep-uniquify-buffer-name)?

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

end of thread, other threads:[~2007-08-19 23:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-16 21:07 [patch] automatic multiple grep session Masatake YAMATO
2007-08-16 22:43 ` Lennart Borgman (gmail)
2007-08-17  3:24   ` Stefan Monnier
2007-08-18  1:37     ` Lennart Borgman (gmail)
2007-08-19 23:18     ` Juri Linkov
2007-08-17  4:50 ` Richard Stallman

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.