emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] automatic multiple grep session


From: Masatake YAMATO
Subject: [patch] automatic multiple grep session
Date: Fri, 17 Aug 2007 06:07:14 +0900 (JST)

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  <address@hidden>

        * 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 via email to

[Prev in Thread] Current Thread [Next in Thread]