all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Masatake YAMATO <jet@gyve.org>
To: emacs-devel@gnu.org
Subject: [patch] automatic multiple grep session
Date: Fri, 17 Aug 2007 06:07:14 +0900 (JST)	[thread overview]
Message-ID: <20070817.060714.149802751.jet@gyve.org> (raw)

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

             reply	other threads:[~2007-08-16 21:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 21:07 Masatake YAMATO [this message]
2007-08-16 22:43 ` [patch] automatic multiple grep session 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070817.060714.149802751.jet@gyve.org \
    --to=jet@gyve.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.