git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git.el: Add a git-grep command
@ 2008-02-19 13:03 David Kågedal
  2008-02-21 13:12 ` Remi Vanicat
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: David Kågedal @ 2008-02-19 13:03 UTC (permalink / raw)
  To: Alexandre Julliard; +Cc: Git Mailing List

This allows easy access to git grep from Emacs.

Signed-off-by: David Kågedal <davidk@lysator.liu.se>
---
 contrib/emacs/git.el |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

This works for me, but before including it someone else should try
it. It might only work in Emacs 22, for instance.

But when it works, it is really useful.

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index f69b697..898e70a 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -49,6 +49,7 @@
 (require 'ewoc)
 (require 'log-edit)
 (require 'easymenu)
+(require 'grep)
 
 
 ;;;; Customizations
@@ -1584,5 +1585,54 @@ Meant to be used in `after-save-hook'."
   (interactive)
   (describe-function 'git-status-mode))
 
+(defvar git-grep-history nil)
+
+(defun git-grep (regexp &optional files dir)
+  "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
+The search is limited to file names matching shell pattern FILES.
+FILES may use abbreviations defined in `grep-files-aliases', e.g.
+entering `ch' is equivalent to `*.[ch]'.
+
+With \\[universal-argument] prefix, you can edit the constructed shell command line
+before it is executed.
+With two \\[universal-argument] prefixes, directly edit and run `git-grep-find-command'.
+
+Collect output in a buffer.  While find runs asynchronously, you
+can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
+in the grep output buffer, to go to the lines where grep found matches."
+  (interactive
+   (cond
+    ((equal current-prefix-arg '(16))
+     (list (read-from-minibuffer "Run: " "git grep "
+                                 nil nil 'git-grep-history)
+           nil))
+    (t (let* ((regexp (grep-read-regexp))
+              (files (grep-read-files regexp))
+              (dir (read-directory-name "Base directory: "
+                                        nil default-directory t)))
+         (list regexp files dir)))))
+  (when (and (stringp regexp) (> (length regexp) 0))
+    (if (null files)
+	(if (not (string= regexp grep-find-command))
+	    (compilation-start regexp 'grep-mode))
+      (setq dir (file-name-as-directory (expand-file-name dir)))
+      (let ((command (concat
+		      "git grep -n "
+		      "-e " (shell-quote-argument regexp)
+                      (if (string= files "*")
+                          ""
+                        (concat " -- " (shell-quote-argument files))))))
+	(when command
+	  (if current-prefix-arg
+	      (setq command
+		    (read-from-minibuffer "Confirm: "
+					  command nil nil 'git-grep-history))
+	    (add-to-history 'git-grep-history command))
+	  (let ((default-directory dir))
+	    (compilation-start (concat "PAGER= " command) 'grep-mode))
+	  ;; Set default-directory if we started rgrep in the *grep* buffer.
+	  (if (eq next-error-last-buffer (current-buffer))
+	      (setq default-directory dir)))))))
+
 (provide 'git)
 ;;; git.el ends here
-- 
1.5.4.2.148.g410dc


-- 
David Kågedal

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-19 13:03 [PATCH] git.el: Add a git-grep command David Kågedal
@ 2008-02-21 13:12 ` Remi Vanicat
  2008-02-21 14:55   ` David Kågedal
  2008-02-22  2:00 ` Xavier Maillard
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 17+ messages in thread
From: Remi Vanicat @ 2008-02-21 13:12 UTC (permalink / raw)
  To: David Kågedal; +Cc: Alexandre Julliard, Git Mailing List

David Kågedal <davidk@lysator.liu.se> writes:

> This allows easy access to git grep from Emacs.
>


You might want to add a menu:

@@ -1497,6 +1497,7 @@ amended version of it."
       ["Diff File" git-diff-file t]
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
+      ["Grep" git-grep t]
       "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]

-- 
Rémi Vanicat

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-21 13:12 ` Remi Vanicat
@ 2008-02-21 14:55   ` David Kågedal
  0 siblings, 0 replies; 17+ messages in thread
From: David Kågedal @ 2008-02-21 14:55 UTC (permalink / raw)
  To: Remi Vanicat; +Cc: Git Mailing List, Alexandre Julliard

Remi Vanicat <vanicat@debian.org> writes:

> David Kågedal <davidk@lysator.liu.se> writes:
>
>> This allows easy access to git grep from Emacs.
>>
>
>
> You might want to add a menu:

Note that git-grep is completely independent of git-status. But a menu
entry in git-status might still be a good idea.

> @@ -1497,6 +1497,7 @@ amended version of it."
>        ["Diff File" git-diff-file t]
>        ["Interactive Diff File" git-diff-file-idiff t]
>        ["Log" git-log-file t]
> +      ["Grep" git-grep t]
>        "--------"
>        ["Mark" git-mark-file t]
>        ["Mark All" git-mark-all t]

-- 
David Kågedal

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-19 13:03 [PATCH] git.el: Add a git-grep command David Kågedal
  2008-02-21 13:12 ` Remi Vanicat
@ 2008-02-22  2:00 ` Xavier Maillard
  2008-02-22  7:31 ` Karl Hasselström
  2008-02-22  9:03 ` Jakub Narebski
  3 siblings, 0 replies; 17+ messages in thread
From: Xavier Maillard @ 2008-02-22  2:00 UTC (permalink / raw)
  To: David Kågedal; +Cc: julliard, git

   This allows easy access to git grep from Emacs.

Very useful. Would it be possible to save the history from
sessions to sessions ?

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-19 13:03 [PATCH] git.el: Add a git-grep command David Kågedal
  2008-02-21 13:12 ` Remi Vanicat
  2008-02-22  2:00 ` Xavier Maillard
@ 2008-02-22  7:31 ` Karl Hasselström
  2008-02-22  9:15   ` David Kågedal
  2008-02-22  9:03 ` Jakub Narebski
  3 siblings, 1 reply; 17+ messages in thread
From: Karl Hasselström @ 2008-02-22  7:31 UTC (permalink / raw)
  To: David Kågedal; +Cc: Alexandre Julliard, Git Mailing List

On 2008-02-19 14:03:18 +0100, David Kågedal wrote:

> This works for me, but before including it someone else should try
> it. It might only work in Emacs 22, for instance.

It works for me (also using emacs 22).

I was a bit confused about the filename pattern selection, though: the
promt suggested "ch", which, when I accepted it, was converted to
"*.[ch]". However, manually specifying "*.c" works as well. I'm not
sure if this is specific to your patch or something affecting all grep
stuff in emacs (though I can't recall seeing it before).

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-19 13:03 [PATCH] git.el: Add a git-grep command David Kågedal
                   ` (2 preceding siblings ...)
  2008-02-22  7:31 ` Karl Hasselström
@ 2008-02-22  9:03 ` Jakub Narebski
  2008-02-22  9:18   ` David Kågedal
  3 siblings, 1 reply; 17+ messages in thread
From: Jakub Narebski @ 2008-02-22  9:03 UTC (permalink / raw)
  To: David Kågedal; +Cc: Alexandre Julliard, Git Mailing List

David Kågedal <davidk@lysator.liu.se> writes:

> This works for me, but before including it someone else should try
> it. It might only work in Emacs 22, for instance.

1077:[emacs@git/contrib/emacs]# LC_ALL=en_EN make
emacs -batch -f batch-byte-compile git.el
Loading /usr/share/emacs/site-lisp/site-start.d/php-mode-init.el (source)...
[...]
While compiling toplevel forms in file /home/jnareb/git/contrib/emacs/git.el:
  !! File error (("Cannot open load file" "grep"))
Done
make: *** [git.elc] Error 1

1078:[emacs@git/contrib/emacs]# emacs --version
GNU Emacs 21.4.1

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22  7:31 ` Karl Hasselström
@ 2008-02-22  9:15   ` David Kågedal
  2008-02-22 11:55     ` Karl Hasselström
  0 siblings, 1 reply; 17+ messages in thread
From: David Kågedal @ 2008-02-22  9:15 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: Git Mailing List, Alexandre Julliard

Karl Hasselström <kha@treskal.com> writes:

> On 2008-02-19 14:03:18 +0100, David Kågedal wrote:
>
>> This works for me, but before including it someone else should try
>> it. It might only work in Emacs 22, for instance.
>
> It works for me (also using emacs 22).
>
> I was a bit confused about the filename pattern selection, though: the
> promt suggested "ch", which, when I accepted it, was converted to
> "*.[ch]". However, manually specifying "*.c" works as well. I'm not
> sure if this is specific to your patch or something affecting all grep
> stuff in emacs (though I can't recall seeing it before).

This isn't invented by me, but is "standard" in the grep commands in
Emacs 22.  See the grep-files-aliases variable and the documentation
of rgrep.

-- 
David Kågedal

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22  9:03 ` Jakub Narebski
@ 2008-02-22  9:18   ` David Kågedal
  2008-02-22 10:21     ` Jakub Narebski
  0 siblings, 1 reply; 17+ messages in thread
From: David Kågedal @ 2008-02-22  9:18 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Git Mailing List, Alexandre Julliard

Jakub Narebski <jnareb@gmail.com> writes:

> David Kågedal <davidk@lysator.liu.se> writes:
>
>> This works for me, but before including it someone else should try
>> it. It might only work in Emacs 22, for instance.
>
> 1077:[emacs@git/contrib/emacs]# LC_ALL=en_EN make
> emacs -batch -f batch-byte-compile git.el
> Loading /usr/share/emacs/site-lisp/site-start.d/php-mode-init.el (source)...
> [...]
> While compiling toplevel forms in file /home/jnareb/git/contrib/emacs/git.el:
>   !! File error (("Cannot open load file" "grep"))
> Done
> make: *** [git.elc] Error 1
>
> 1078:[emacs@git/contrib/emacs]# emacs --version
> GNU Emacs 21.4.1

As I suspected. The problem is that the grep commands were rewritten
for Emacs 22, and lots of it can be reused. So to write a similar
command for Emacs 21 probably requires a bit more work. And since I
use Emacs 22 I'm not sure I will feel motivated enough...

-- 
David Kågedal

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22  9:18   ` David Kågedal
@ 2008-02-22 10:21     ` Jakub Narebski
  2008-02-22 10:44       ` David Kågedal
  0 siblings, 1 reply; 17+ messages in thread
From: Jakub Narebski @ 2008-02-22 10:21 UTC (permalink / raw)
  To: David Kågedal; +Cc: Git Mailing List, Alexandre Julliard

On Fri, 22 Feb 2008, David Kågedal wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
>> David Kågedal <davidk@lysator.liu.se> writes:
>>
>>> This works for me, but before including it someone else should try
>>> it. It might only work in Emacs 22, for instance.
>>
>> emacs -batch -f batch-byte-compile git.el
>> [...]
>> While compiling toplevel forms in file git/contrib/emacs/git.el:
>>   !! File error (("Cannot open load file" "grep"))
>> Done
>> make: *** [git.elc] Error 1
>>
>> 1078:[emacs@git/contrib/emacs]# emacs --version
>> GNU Emacs 21.4.1
> 
> As I suspected. The problem is that the grep commands were rewritten
> for Emacs 22, and lots of it can be reused. So to write a similar
> command for Emacs 21 probably requires a bit more work. And since I
> use Emacs 22 I'm not sure I will feel motivated enough...

Could you make it at least conditional on the Emacs version used,
or even better depending on the fact if "grep" 'library' is available?

I'd like to be able to use git.el with my Emacs, even without some
functionality. TIA.
-- 
Jakub Narebski
Poland

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22 10:21     ` Jakub Narebski
@ 2008-02-22 10:44       ` David Kågedal
  2008-02-22 11:11         ` Remi Vanicat
  0 siblings, 1 reply; 17+ messages in thread
From: David Kågedal @ 2008-02-22 10:44 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Alexandre Julliard, Git Mailing List

Jakub Narebski <jnareb@gmail.com> writes:

> On Fri, 22 Feb 2008, David Kågedal wrote:
>> Jakub Narebski <jnareb@gmail.com> writes:
>>> David Kågedal <davidk@lysator.liu.se> writes:
>>>
>>>> This works for me, but before including it someone else should try
>>>> it. It might only work in Emacs 22, for instance.
>>>
>>> emacs -batch -f batch-byte-compile git.el
>>> [...]
>>> While compiling toplevel forms in file git/contrib/emacs/git.el:
>>>   !! File error (("Cannot open load file" "grep"))
>>> Done
>>> make: *** [git.elc] Error 1
>>>
>>> 1078:[emacs@git/contrib/emacs]# emacs --version
>>> GNU Emacs 21.4.1
>> 
>> As I suspected. The problem is that the grep commands were rewritten
>> for Emacs 22, and lots of it can be reused. So to write a similar
>> command for Emacs 21 probably requires a bit more work. And since I
>> use Emacs 22 I'm not sure I will feel motivated enough...
>
> Could you make it at least conditional on the Emacs version used,
> or even better depending on the fact if "grep" 'library' is available?

Sure. We could e.g. put it in its own file, git-grep.el.

> I'd like to be able to use git.el with my Emacs, even without some
> functionality. TIA.

Absolutely, I hope this doesn't get included until this is resolved. 

-- 
David Kågedal

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22 10:44       ` David Kågedal
@ 2008-02-22 11:11         ` Remi Vanicat
  2008-02-22 11:43           ` David Kågedal
  2008-02-23  2:00           ` Xavier Maillard
  0 siblings, 2 replies; 17+ messages in thread
From: Remi Vanicat @ 2008-02-22 11:11 UTC (permalink / raw)
  To: David Kågedal; +Cc: Jakub Narebski, Alexandre Julliard, Git Mailing List

Here is a modification with inclusion of git-grep only when the grep
library is available. 

To put it in another file might be a good idea to, but in this case,
may be we could break this huge 1786 file in several smaller file.

From 403143a61bf8f77d042893765b19cf7cc7062e59 Mon Sep 17 00:00:00 2001
From: David Kågedal <davidk@lysator.liu.se>
Date: Fri, 22 Feb 2008 11:57:25 +0100
Subject: [PATCH] git.el: Add a git-grep command
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

This allows easy access to git grep from Emacs.

Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Rémi Vanicat <vanicat@debian.org>
---
 contrib/emacs/git.el |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index f69b697..afaf187 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -49,6 +49,7 @@
 (require 'ewoc)
 (require 'log-edit)
 (require 'easymenu)
+(require 'grep () t)
 
 
 ;;;; Customizations
@@ -1496,6 +1497,7 @@ amended version of it."
       ["Diff File" git-diff-file t]
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
+      ,@(if (featurep 'grep) (list ["Grep" git-grep t]) ())
       "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
@@ -1584,5 +1586,55 @@ Meant to be used in `after-save-hook'."
   (interactive)
   (describe-function 'git-status-mode))
 
+(when (featurep 'grep)
+  (defvar git-grep-history nil)
+
+  (defun git-grep (regexp &optional files dir)
+    "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
+The search is limited to file names matching shell pattern FILES.
+FILES may use abbreviations defined in `grep-files-aliases', e.g.
+entering `ch' is equivalent to `*.[ch]'.
+
+With \\[universal-argument] prefix, you can edit the constructed shell command line
+before it is executed.
+With two \\[universal-argument] prefixes, directly edit and run `git-grep-find-command'.
+
+Collect output in a buffer.  While find runs asynchronously, you
+can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
+in the grep output buffer, to go to the lines where grep found matches."
+    (interactive
+     (cond
+       ((equal current-prefix-arg '(16))
+	(list (read-from-minibuffer "Run: " "git grep "
+				    nil nil 'git-grep-history)
+	      nil))
+       (t (let* ((regexp (grep-read-regexp))
+		 (files (grep-read-files regexp))
+		 (dir (read-directory-name "Base directory: "
+					   nil default-directory t)))
+	    (list regexp files dir)))))
+    (when (and (stringp regexp) (> (length regexp) 0))
+      (if (null files)
+	  (if (not (string= regexp grep-find-command))
+	      (compilation-start regexp 'grep-mode))
+	  (setq dir (file-name-as-directory (expand-file-name dir)))
+	  (let ((command (concat
+			  "git grep -n "
+			  "-e " (shell-quote-argument regexp)
+			  (if (string= files "*")
+			      ""
+			      (concat " -- " (shell-quote-argument files))))))
+	    (when command
+	      (if current-prefix-arg
+		  (setq command
+			(read-from-minibuffer "Confirm: "
+					      command nil nil 'git-grep-history))
+		  (add-to-history 'git-grep-history command))
+	      (let ((default-directory dir))
+		(compilation-start (concat "PAGER= " command) 'grep-mode))
+	      ;; Set default-directory if we started rgrep in the *grep* buffer.
+	      (if (eq next-error-last-buffer (current-buffer))
+		  (setq default-directory dir))))))))
+
 (provide 'git)
 ;;; git.el ends here
-- 
1.5.4.2.191.g7b407



-- 
Rémi Vanicat

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22 11:11         ` Remi Vanicat
@ 2008-02-22 11:43           ` David Kågedal
  2008-02-23  2:00           ` Xavier Maillard
  1 sibling, 0 replies; 17+ messages in thread
From: David Kågedal @ 2008-02-22 11:43 UTC (permalink / raw)
  To: Remi Vanicat; +Cc: Git Mailing List, Alexandre Julliard, Jakub Narebski

Remi Vanicat <vanicat@debian.org> writes:

> Here is a modification with inclusion of git-grep only when the grep
> library is available. 

Nice. I didn't even know that require had more parameters. But I'd
write nil instead of () in this case.

> To put it in another file might be a good idea to, but in this case,
> may be we could break this huge 1786 file in several smaller file.
>
> From 403143a61bf8f77d042893765b19cf7cc7062e59 Mon Sep 17 00:00:00 2001
> From: David Kågedal <davidk@lysator.liu.se>
> Date: Fri, 22 Feb 2008 11:57:25 +0100
> Subject: [PATCH] git.el: Add a git-grep command
> MIME-Version: 1.0
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: 8bit
>
> This allows easy access to git grep from Emacs.
>
> Signed-off-by: David Kågedal <davidk@lysator.liu.se>
> Signed-off-by: Rémi Vanicat <vanicat@debian.org>
> ---
>  contrib/emacs/git.el |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 52 insertions(+), 0 deletions(-)
>
> diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
> index f69b697..afaf187 100644
> --- a/contrib/emacs/git.el
> +++ b/contrib/emacs/git.el
> @@ -49,6 +49,7 @@
>  (require 'ewoc)
>  (require 'log-edit)
>  (require 'easymenu)
> +(require 'grep () t)
>  
>  
>  ;;;; Customizations
> @@ -1496,6 +1497,7 @@ amended version of it."
>        ["Diff File" git-diff-file t]
>        ["Interactive Diff File" git-diff-file-idiff t]
>        ["Log" git-log-file t]
> +      ,@(if (featurep 'grep) (list ["Grep" git-grep t]) ())
>        "--------"
>        ["Mark" git-mark-file t]
>        ["Mark All" git-mark-all t]
> @@ -1584,5 +1586,55 @@ Meant to be used in `after-save-hook'."
>    (interactive)
>    (describe-function 'git-status-mode))
>  
> +(when (featurep 'grep)
> +  (defvar git-grep-history nil)
> +
> +  (defun git-grep (regexp &optional files dir)
> +    "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
> +The search is limited to file names matching shell pattern FILES.
> +FILES may use abbreviations defined in `grep-files-aliases', e.g.
> +entering `ch' is equivalent to `*.[ch]'.
> +
> +With \\[universal-argument] prefix, you can edit the constructed shell command line
> +before it is executed.
> +With two \\[universal-argument] prefixes, directly edit and run `git-grep-find-command'.
> +
> +Collect output in a buffer.  While find runs asynchronously, you
> +can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
> +in the grep output buffer, to go to the lines where grep found matches."
> +    (interactive
> +     (cond
> +       ((equal current-prefix-arg '(16))
> +	(list (read-from-minibuffer "Run: " "git grep "
> +				    nil nil 'git-grep-history)
> +	      nil))
> +       (t (let* ((regexp (grep-read-regexp))
> +		 (files (grep-read-files regexp))
> +		 (dir (read-directory-name "Base directory: "
> +					   nil default-directory t)))
> +	    (list regexp files dir)))))
> +    (when (and (stringp regexp) (> (length regexp) 0))
> +      (if (null files)
> +	  (if (not (string= regexp grep-find-command))
> +	      (compilation-start regexp 'grep-mode))
> +	  (setq dir (file-name-as-directory (expand-file-name dir)))
> +	  (let ((command (concat
> +			  "git grep -n "
> +			  "-e " (shell-quote-argument regexp)
> +			  (if (string= files "*")
> +			      ""
> +			      (concat " -- " (shell-quote-argument files))))))
> +	    (when command
> +	      (if current-prefix-arg
> +		  (setq command
> +			(read-from-minibuffer "Confirm: "
> +					      command nil nil 'git-grep-history))
> +		  (add-to-history 'git-grep-history command))
> +	      (let ((default-directory dir))
> +		(compilation-start (concat "PAGER= " command) 'grep-mode))
> +	      ;; Set default-directory if we started rgrep in the *grep* buffer.
> +	      (if (eq next-error-last-buffer (current-buffer))
> +		  (setq default-directory dir))))))))
> +
>  (provide 'git)
>  ;;; git.el ends here
> -- 
> 1.5.4.2.191.g7b407

-- 
David Kågedal

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22  9:15   ` David Kågedal
@ 2008-02-22 11:55     ` Karl Hasselström
  0 siblings, 0 replies; 17+ messages in thread
From: Karl Hasselström @ 2008-02-22 11:55 UTC (permalink / raw)
  To: David Kågedal; +Cc: Git Mailing List, Alexandre Julliard

On 2008-02-22 10:15:29 +0100, David Kågedal wrote:

> Karl Hasselström <kha@treskal.com> writes:
>
> > I was a bit confused about the filename pattern selection, though:
> > the promt suggested "ch", which, when I accepted it, was converted
> > to "*.[ch]". However, manually specifying "*.c" works as well. I'm
> > not sure if this is specific to your patch or something affecting
> > all grep stuff in emacs (though I can't recall seeing it before).
>
> This isn't invented by me, but is "standard" in the grep commands in
> Emacs 22. See the grep-files-aliases variable and the documentation
> of rgrep.

Oh. OK. Thanks.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-22 11:11         ` Remi Vanicat
  2008-02-22 11:43           ` David Kågedal
@ 2008-02-23  2:00           ` Xavier Maillard
  2008-02-23 19:39             ` Remi Vanicat
  1 sibling, 1 reply; 17+ messages in thread
From: Xavier Maillard @ 2008-02-23  2:00 UTC (permalink / raw)
  To: Remi Vanicat; +Cc: davidk, jnareb, julliard, git

Hi,

   Here is a modification with inclusion of git-grep only when the grep
   library is available. 

   +(require 'grep () t)

   +(when (featurep 'grep)
   +  (defvar git-grep-history nil)
   +
   +  (defun git-grep (regexp &optional files dir)

Why not just do something like this ?

(when (require 'grep () t)
      (defvar ...)
      (defun git-grep ...))

Regards,

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-23  2:00           ` Xavier Maillard
@ 2008-02-23 19:39             ` Remi Vanicat
  2008-02-23 22:41               ` Xavier Maillard
  2008-02-24  2:00               ` Xavier Maillard
  0 siblings, 2 replies; 17+ messages in thread
From: Remi Vanicat @ 2008-02-23 19:39 UTC (permalink / raw)
  To: Xavier Maillard; +Cc: Remi Vanicat, davidk, jnareb, julliard, git

Xavier Maillard <xma@gnu.org> writes:

> Hi,
>
>    Here is a modification with inclusion of git-grep only when the grep
>    library is available. 
>
>    +(require 'grep () t)
>
>    +(when (featurep 'grep)
>    +  (defvar git-grep-history nil)
>    +
>    +  (defun git-grep (regexp &optional files dir)
>
> Why not just do something like this ?
>
> (when (require 'grep () t)
>       (defvar ...)
>       (defun git-grep ...))

Because I wanted require to stay on top of the file, but I didn't want
to put the rest of the git-grep stuff there.

(the real reason is because I did not check in the doc for the return
value of require, and so I didn't knew that I could do that, but
still, I believe that my after the fact argument are good.)
-- 
Rémi Vanicat

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-23 19:39             ` Remi Vanicat
@ 2008-02-23 22:41               ` Xavier Maillard
  2008-02-24  2:00               ` Xavier Maillard
  1 sibling, 0 replies; 17+ messages in thread
From: Xavier Maillard @ 2008-02-23 22:41 UTC (permalink / raw)
  To: Remi Vanicat; +Cc: vanicat, davidk, jnareb, julliard, git


   Xavier Maillard <xma@gnu.org> writes:

   > Hi,
   >
   >    Here is a modification with inclusion of git-grep only when the grep
   >    library is available. 
   >
   >    +(require 'grep () t)
   >
   >    +(when (featurep 'grep)
   >    +  (defvar git-grep-history nil)
   >    +
   >    +  (defun git-grep (regexp &optional files dir)
   >
   > Why not just do something like this ?
   >
   > (when (require 'grep () t)
   >       (defvar ...)
   >       (defun git-grep ...))

   Because I wanted require to stay on top of the file, but I didn't want
   to put the rest of the git-grep stuff there.

Good point. Though, you can still "embed" the require form
directly into the defun. This is thing I have already seen in the
past. Dunno if it is a convention or a coding style but something
like:

(defun git-grep ()
 "Docstring"
 (interactive)
 (when (require 'grep nil t)
       here the rest
  ))

is doable too. Maybe the if-else form would be better though with
an else clause to (error "No grep package foud.").

Well just kidding, your patch is okay ;)

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org

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

* Re: [PATCH] git.el: Add a git-grep command
  2008-02-23 19:39             ` Remi Vanicat
  2008-02-23 22:41               ` Xavier Maillard
@ 2008-02-24  2:00               ` Xavier Maillard
  1 sibling, 0 replies; 17+ messages in thread
From: Xavier Maillard @ 2008-02-24  2:00 UTC (permalink / raw)
  To: Remi Vanicat; +Cc: vanicat, davidk, jnareb, julliard, git


   Xavier Maillard <xma@gnu.org> writes:

   > Hi,
   >
   >    Here is a modification with inclusion of git-grep only when the grep
   >    library is available. 
   >
   >    +(require 'grep () t)
   >
   >    +(when (featurep 'grep)
   >    +  (defvar git-grep-history nil)
   >    +
   >    +  (defun git-grep (regexp &optional files dir)
   >
   > Why not just do something like this ?
   >
   > (when (require 'grep () t)
   >       (defvar ...)
   >       (defun git-grep ...))

   Because I wanted require to stay on top of the file, but I didn't want
   to put the rest of the git-grep stuff there.

Good point. Though, you can still "embed" the require form
directly into the defun. This is thing I have already seen in the
past. Dunno if it is a convention or a coding style but something
like:

(defun git-grep ()
 "Docstring"
 (interactive)
 (when (require 'grep nil t)
       here the rest
  ))

is doable too. Maybe the if-else form would be better though with
an else clause to (error "No grep package foud.").

Well just kidding, your patch is okay ;)

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org

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

end of thread, other threads:[~2008-02-24  2:34 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-19 13:03 [PATCH] git.el: Add a git-grep command David Kågedal
2008-02-21 13:12 ` Remi Vanicat
2008-02-21 14:55   ` David Kågedal
2008-02-22  2:00 ` Xavier Maillard
2008-02-22  7:31 ` Karl Hasselström
2008-02-22  9:15   ` David Kågedal
2008-02-22 11:55     ` Karl Hasselström
2008-02-22  9:03 ` Jakub Narebski
2008-02-22  9:18   ` David Kågedal
2008-02-22 10:21     ` Jakub Narebski
2008-02-22 10:44       ` David Kågedal
2008-02-22 11:11         ` Remi Vanicat
2008-02-22 11:43           ` David Kågedal
2008-02-23  2:00           ` Xavier Maillard
2008-02-23 19:39             ` Remi Vanicat
2008-02-23 22:41               ` Xavier Maillard
2008-02-24  2:00               ` Xavier Maillard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).