From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.devel Subject: [patch] automatic multiple grep session Date: Fri, 17 Aug 2007 06:07:14 +0900 (JST) Message-ID: <20070817.060714.149802751.jet@gyve.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1187298496 25717 80.91.229.12 (16 Aug 2007 21:08:16 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 16 Aug 2007 21:08:16 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 16 23:08:13 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1ILmZZ-0005cP-MT for ged-emacs-devel@m.gmane.org; Thu, 16 Aug 2007 23:08:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ILmZZ-0001yV-6V for ged-emacs-devel@m.gmane.org; Thu, 16 Aug 2007 17:08:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ILmZE-0001cu-RD for emacs-devel@gnu.org; Thu, 16 Aug 2007 17:07:44 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ILmZE-0001cR-4J for emacs-devel@gnu.org; Thu, 16 Aug 2007 17:07:44 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ILmZD-0001cM-Un for emacs-devel@gnu.org; Thu, 16 Aug 2007 17:07:43 -0400 Original-Received: from mo10.iij4u.or.jp ([210.138.174.78]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1ILmZD-0005QC-7K for emacs-devel@gnu.org; Thu, 16 Aug 2007 17:07:43 -0400 Original-Received: by mo.iij4u.or.jp (mo10) id l7GL7aJq000694; Fri, 17 Aug 2007 06:07:36 +0900 Original-Received: from localhost (h219-110-077-149.catv01.itscom.jp [219.110.77.149]) by mbox.iij4u.or.jp (mbox10) id l7GL7S1x013770; Fri, 17 Aug 2007 06:07:32 +0900 X-Mailer: Mew version 5.2 on Emacs 22.1.50 / Mule 5.0 (SAKAKI) X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:76644 Archived-At: 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 * 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)))))))