{"thread":{"id":"12236","subject":"[PATCH] git.el: Add a git-grep command","startedAt":"2008-02-19T13:03:18Z","lastAt":"2008-02-24T02:00:01Z","messageCount":17,"participants":["David Kågedal","Remi Vanicat","Xavier Maillard","Karl Hasselström","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69464","messageId":"87odaa4tcl.fsf@lysator.liu.se","threadId":"12236","inReplyTo":null,"subject":"[PATCH] git.el: Add a git-grep command","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2008-02-19T13:03:18Z","receivedAt":"2008-02-19T13:03:18Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"This allows easy access to git grep from Emacs.\n\nSigned-off-by: David Kågedal <davidk@lysator.liu.se>\n---\n contrib/emacs/git.el |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 50 insertions(+), 0 deletions(-)\n\nThis works for me, but before including it someone else should try\nit. It might only work in Emacs 22, for instance.\n\nBut when it works, it is really useful.\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex f69b697..898e70a 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -49,6 +49,7 @@\n (require 'ewoc)\n (require 'log-edit)\n (require 'easymenu)\n+(require 'grep)\n \n \n ;;;; Customizations\n@@ -1584,5 +1585,54 @@ Meant to be used in `after-save-hook'.\"\n   (interactive)\n   (describe-function 'git-status-mode))\n \n+(defvar git-grep-history nil)\n+\n+(defun git-grep (regexp &optional files dir)\n+  \"Recursively grep for REGEXP in FILES in directory tree rooted at DIR.\n+The search is limited to file names matching shell pattern FILES.\n+FILES may use abbreviations defined in `grep-files-aliases', e.g.\n+entering `ch' is equivalent to `*.[ch]'.\n+\n+With \\\\[universal-argument] prefix, you can edit the constructed shell command line\n+before it is executed.\n+With two \\\\[universal-argument] prefixes, directly edit and run `git-grep-find-command'.\n+\n+Collect output in a buffer.  While find runs asynchronously, you\n+can use \\\\[next-error] (M-x next-error), or \\\\<grep-mode-map>\\\\[compile-goto-error]\n+in the grep output buffer, to go to the lines where grep found matches.\"\n+  (interactive\n+   (cond\n+    ((equal current-prefix-arg '(16))\n+     (list (read-from-minibuffer \"Run: \" \"git grep \"\n+                                 nil nil 'git-grep-history)\n+           nil))\n+    (t (let* ((regexp (grep-read-regexp))\n+              (files (grep-read-files regexp))\n+              (dir (read-directory-name \"Base directory: \"\n+                                        nil default-directory t)))\n+         (list regexp files dir)))))\n+  (when (and (stringp regexp) (> (length regexp) 0))\n+    (if (null files)\n+\t(if (not (string= regexp grep-find-command))\n+\t    (compilation-start regexp 'grep-mode))\n+      (setq dir (file-name-as-directory (expand-file-name dir)))\n+      (let ((command (concat\n+\t\t      \"git grep -n \"\n+\t\t      \"-e \" (shell-quote-argument regexp)\n+                      (if (string= files \"*\")\n+                          \"\"\n+                        (concat \" -- \" (shell-quote-argument files))))))\n+\t(when command\n+\t  (if current-prefix-arg\n+\t      (setq command\n+\t\t    (read-from-minibuffer \"Confirm: \"\n+\t\t\t\t\t  command nil nil 'git-grep-history))\n+\t    (add-to-history 'git-grep-history command))\n+\t  (let ((default-directory dir))\n+\t    (compilation-start (concat \"PAGER= \" command) 'grep-mode))\n+\t  ;; Set default-directory if we started rgrep in the *grep* buffer.\n+\t  (if (eq next-error-last-buffer (current-buffer))\n+\t      (setq default-directory dir)))))))\n+\n (provide 'git)\n ;;; git.el ends here\n-- \n1.5.4.2.148.g410dc\n\n\n-- \nDavid Kågedal\n"},{"id":"69471","messageId":"87ve4itpw0.dlv@maison.homelinux.org","threadId":"12236","inReplyTo":"87odaa4tcl.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Remi Vanicat","fromEmail":"vanicat@debian.org","sentAt":"2008-02-21T13:12:15Z","receivedAt":"2008-02-21T13:12:15Z","isPatch":true,"sender":{"key":"vanicat@debian.org","avatar":"https://gravatar.com/avatar/cd491a7f4c221349809a60f88fc21326b97cce2a705e318898aa74851db92409?d=mp&s=160"},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> This allows easy access to git grep from Emacs.\n>\n\n\nYou might want to add a menu:\n\n@@ -1497,6 +1497,7 @@ amended version of it.\"\n       [\"Diff File\" git-diff-file t]\n       [\"Interactive Diff File\" git-diff-file-idiff t]\n       [\"Log\" git-log-file t]\n+      [\"Grep\" git-grep t]\n       \"--------\"\n       [\"Mark\" git-mark-file t]\n       [\"Mark All\" git-mark-all t]\n\n-- \nRémi Vanicat\n"},{"id":"69477","messageId":"873armbbqk.fsf@lysator.liu.se","threadId":"12236","inReplyTo":"87ve4itpw0.dlv@maison.homelinux.org","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2008-02-21T14:55:15Z","receivedAt":"2008-02-21T14:55:15Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Remi Vanicat <vanicat@debian.org> writes:\n\n> David Kågedal <davidk@lysator.liu.se> writes:\n>\n>> This allows easy access to git grep from Emacs.\n>>\n>\n>\n> You might want to add a menu:\n\nNote that git-grep is completely independent of git-status. But a menu\nentry in git-status might still be a good idea.\n\n> @@ -1497,6 +1497,7 @@ amended version of it.\"\n>        [\"Diff File\" git-diff-file t]\n>        [\"Interactive Diff File\" git-diff-file-idiff t]\n>        [\"Log\" git-log-file t]\n> +      [\"Grep\" git-grep t]\n>        \"--------\"\n>        [\"Mark\" git-mark-file t]\n>        [\"Mark All\" git-mark-all t]\n\n-- \nDavid Kågedal\n"},{"id":"69546","messageId":"200802220200.m1M203f3003434@localhost.localdomain","threadId":"12236","inReplyTo":"87odaa4tcl.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-02-22T02:00:03Z","receivedAt":"2008-02-22T02:00:03Z","isPatch":true,"sender":{"key":"xma@gnu.org","avatar":null},"body":"   This allows easy access to git grep from Emacs.\n\nVery useful. Would it be possible to save the history from\nsessions to sessions ?\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"},{"id":"69555","messageId":"20080222073157.GA6630@diana.vm.bytemark.co.uk","threadId":"12236","inReplyTo":"87odaa4tcl.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-02-22T07:31:57Z","receivedAt":"2008-02-22T07:31:57Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-02-19 14:03:18 +0100, David Kågedal wrote:\n\n> This works for me, but before including it someone else should try\n> it. It might only work in Emacs 22, for instance.\n\nIt works for me (also using emacs 22).\n\nI was a bit confused about the filename pattern selection, though: the\npromt suggested \"ch\", which, when I accepted it, was converted to\n\"*.[ch]\". However, manually specifying \"*.c\" works as well. I'm not\nsure if this is specific to your patch or something affecting all grep\nstuff in emacs (though I can't recall seeing it before).\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"69562","messageId":"m3myptcqji.fsf@localhost.localdomain","threadId":"12236","inReplyTo":"87odaa4tcl.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-02-22T09:03:35Z","receivedAt":"2008-02-22T09:03:35Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> This works for me, but before including it someone else should try\n> it. It might only work in Emacs 22, for instance.\n\n1077:[emacs@git/contrib/emacs]# LC_ALL=en_EN make\nemacs -batch -f batch-byte-compile git.el\nLoading /usr/share/emacs/site-lisp/site-start.d/php-mode-init.el (source)...\n[...]\nWhile compiling toplevel forms in file /home/jnareb/git/contrib/emacs/git.el:\n  !! File error ((\"Cannot open load file\" \"grep\"))\nDone\nmake: *** [git.elc] Error 1\n\n1078:[emacs@git/contrib/emacs]# emacs --version\nGNU Emacs 21.4.1\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"69564","messageId":"87wsox9wsu.fsf@lysator.liu.se","threadId":"12236","inReplyTo":"20080222073157.GA6630@diana.vm.bytemark.co.uk","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2008-02-22T09:15:29Z","receivedAt":"2008-02-22T09:15:29Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Karl Hasselström <kha@treskal.com> writes:\n\n> On 2008-02-19 14:03:18 +0100, David Kågedal wrote:\n>\n>> This works for me, but before including it someone else should try\n>> it. It might only work in Emacs 22, for instance.\n>\n> It works for me (also using emacs 22).\n>\n> I was a bit confused about the filename pattern selection, though: the\n> promt suggested \"ch\", which, when I accepted it, was converted to\n> \"*.[ch]\". However, manually specifying \"*.c\" works as well. I'm not\n> sure if this is specific to your patch or something affecting all grep\n> stuff in emacs (though I can't recall seeing it before).\n\nThis isn't invented by me, but is \"standard\" in the grep commands in\nEmacs 22.  See the grep-files-aliases variable and the documentation\nof rgrep.\n\n-- \nDavid Kågedal\n"},{"id":"69565","messageId":"87tzk19wn5.fsf@lysator.liu.se","threadId":"12236","inReplyTo":"m3myptcqji.fsf@localhost.localdomain","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2008-02-22T09:18:54Z","receivedAt":"2008-02-22T09:18:54Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> David Kågedal <davidk@lysator.liu.se> writes:\n>\n>> This works for me, but before including it someone else should try\n>> it. It might only work in Emacs 22, for instance.\n>\n> 1077:[emacs@git/contrib/emacs]# LC_ALL=en_EN make\n> emacs -batch -f batch-byte-compile git.el\n> Loading /usr/share/emacs/site-lisp/site-start.d/php-mode-init.el (source)...\n> [...]\n> While compiling toplevel forms in file /home/jnareb/git/contrib/emacs/git.el:\n>   !! File error ((\"Cannot open load file\" \"grep\"))\n> Done\n> make: *** [git.elc] Error 1\n>\n> 1078:[emacs@git/contrib/emacs]# emacs --version\n> GNU Emacs 21.4.1\n\nAs I suspected. The problem is that the grep commands were rewritten\nfor Emacs 22, and lots of it can be reused. So to write a similar\ncommand for Emacs 21 probably requires a bit more work. And since I\nuse Emacs 22 I'm not sure I will feel motivated enough...\n\n-- \nDavid Kågedal\n"},{"id":"69569","messageId":"200802221121.35706.jnareb@gmail.com","threadId":"12236","inReplyTo":"87tzk19wn5.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-02-22T10:21:34Z","receivedAt":"2008-02-22T10:21:34Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Fri, 22 Feb 2008, David Kågedal wrote:\n> Jakub Narebski <jnareb@gmail.com> writes:\n>> David Kågedal <davidk@lysator.liu.se> writes:\n>>\n>>> This works for me, but before including it someone else should try\n>>> it. It might only work in Emacs 22, for instance.\n>>\n>> emacs -batch -f batch-byte-compile git.el\n>> [...]\n>> While compiling toplevel forms in file git/contrib/emacs/git.el:\n>>   !! File error ((\"Cannot open load file\" \"grep\"))\n>> Done\n>> make: *** [git.elc] Error 1\n>>\n>> 1078:[emacs@git/contrib/emacs]# emacs --version\n>> GNU Emacs 21.4.1\n> \n> As I suspected. The problem is that the grep commands were rewritten\n> for Emacs 22, and lots of it can be reused. So to write a similar\n> command for Emacs 21 probably requires a bit more work. And since I\n> use Emacs 22 I'm not sure I will feel motivated enough...\n\nCould you make it at least conditional on the Emacs version used,\nor even better depending on the fact if \"grep\" 'library' is available?\n\nI'd like to be able to use git.el with my Emacs, even without some\nfunctionality. TIA.\n-- \nJakub Narebski\nPoland\n"},{"id":"69572","messageId":"87ir0h9soh.fsf@lysator.liu.se","threadId":"12236","inReplyTo":"200802221121.35706.jnareb@gmail.com","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2008-02-22T10:44:30Z","receivedAt":"2008-02-22T10:44:30Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> On Fri, 22 Feb 2008, David Kågedal wrote:\n>> Jakub Narebski <jnareb@gmail.com> writes:\n>>> David Kågedal <davidk@lysator.liu.se> writes:\n>>>\n>>>> This works for me, but before including it someone else should try\n>>>> it. It might only work in Emacs 22, for instance.\n>>>\n>>> emacs -batch -f batch-byte-compile git.el\n>>> [...]\n>>> While compiling toplevel forms in file git/contrib/emacs/git.el:\n>>>   !! File error ((\"Cannot open load file\" \"grep\"))\n>>> Done\n>>> make: *** [git.elc] Error 1\n>>>\n>>> 1078:[emacs@git/contrib/emacs]# emacs --version\n>>> GNU Emacs 21.4.1\n>> \n>> As I suspected. The problem is that the grep commands were rewritten\n>> for Emacs 22, and lots of it can be reused. So to write a similar\n>> command for Emacs 21 probably requires a bit more work. And since I\n>> use Emacs 22 I'm not sure I will feel motivated enough...\n>\n> Could you make it at least conditional on the Emacs version used,\n> or even better depending on the fact if \"grep\" 'library' is available?\n\nSure. We could e.g. put it in its own file, git-grep.el.\n\n> I'd like to be able to use git.el with my Emacs, even without some\n> functionality. TIA.\n\nAbsolutely, I hope this doesn't get included until this is resolved. \n\n-- \nDavid Kågedal\n"},{"id":"69574","messageId":"87d4qpgs9y.dlv@maison.homelinux.org","threadId":"12236","inReplyTo":"87ir0h9soh.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Remi Vanicat","fromEmail":"vanicat@debian.org","sentAt":"2008-02-22T11:11:21Z","receivedAt":"2008-02-22T11:11:21Z","isPatch":true,"sender":{"key":"vanicat@debian.org","avatar":"https://gravatar.com/avatar/cd491a7f4c221349809a60f88fc21326b97cce2a705e318898aa74851db92409?d=mp&s=160"},"body":"Here is a modification with inclusion of git-grep only when the grep\nlibrary is available. \n\nTo put it in another file might be a good idea to, but in this case,\nmay be we could break this huge 1786 file in several smaller file.\n\nFrom 403143a61bf8f77d042893765b19cf7cc7062e59 Mon Sep 17 00:00:00 2001\nFrom: David Kågedal <davidk@lysator.liu.se>\nDate: Fri, 22 Feb 2008 11:57:25 +0100\nSubject: [PATCH] git.el: Add a git-grep command\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n\nThis allows easy access to git grep from Emacs.\n\nSigned-off-by: David Kågedal <davidk@lysator.liu.se>\nSigned-off-by: Rémi Vanicat <vanicat@debian.org>\n---\n contrib/emacs/git.el |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 52 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex f69b697..afaf187 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -49,6 +49,7 @@\n (require 'ewoc)\n (require 'log-edit)\n (require 'easymenu)\n+(require 'grep () t)\n \n \n ;;;; Customizations\n@@ -1496,6 +1497,7 @@ amended version of it.\"\n       [\"Diff File\" git-diff-file t]\n       [\"Interactive Diff File\" git-diff-file-idiff t]\n       [\"Log\" git-log-file t]\n+      ,@(if (featurep 'grep) (list [\"Grep\" git-grep t]) ())\n       \"--------\"\n       [\"Mark\" git-mark-file t]\n       [\"Mark All\" git-mark-all t]\n@@ -1584,5 +1586,55 @@ Meant to be used in `after-save-hook'.\"\n   (interactive)\n   (describe-function 'git-status-mode))\n \n+(when (featurep 'grep)\n+  (defvar git-grep-history nil)\n+\n+  (defun git-grep (regexp &optional files dir)\n+    \"Recursively grep for REGEXP in FILES in directory tree rooted at DIR.\n+The search is limited to file names matching shell pattern FILES.\n+FILES may use abbreviations defined in `grep-files-aliases', e.g.\n+entering `ch' is equivalent to `*.[ch]'.\n+\n+With \\\\[universal-argument] prefix, you can edit the constructed shell command line\n+before it is executed.\n+With two \\\\[universal-argument] prefixes, directly edit and run `git-grep-find-command'.\n+\n+Collect output in a buffer.  While find runs asynchronously, you\n+can use \\\\[next-error] (M-x next-error), or \\\\<grep-mode-map>\\\\[compile-goto-error]\n+in the grep output buffer, to go to the lines where grep found matches.\"\n+    (interactive\n+     (cond\n+       ((equal current-prefix-arg '(16))\n+\t(list (read-from-minibuffer \"Run: \" \"git grep \"\n+\t\t\t\t    nil nil 'git-grep-history)\n+\t      nil))\n+       (t (let* ((regexp (grep-read-regexp))\n+\t\t (files (grep-read-files regexp))\n+\t\t (dir (read-directory-name \"Base directory: \"\n+\t\t\t\t\t   nil default-directory t)))\n+\t    (list regexp files dir)))))\n+    (when (and (stringp regexp) (> (length regexp) 0))\n+      (if (null files)\n+\t  (if (not (string= regexp grep-find-command))\n+\t      (compilation-start regexp 'grep-mode))\n+\t  (setq dir (file-name-as-directory (expand-file-name dir)))\n+\t  (let ((command (concat\n+\t\t\t  \"git grep -n \"\n+\t\t\t  \"-e \" (shell-quote-argument regexp)\n+\t\t\t  (if (string= files \"*\")\n+\t\t\t      \"\"\n+\t\t\t      (concat \" -- \" (shell-quote-argument files))))))\n+\t    (when command\n+\t      (if current-prefix-arg\n+\t\t  (setq command\n+\t\t\t(read-from-minibuffer \"Confirm: \"\n+\t\t\t\t\t      command nil nil 'git-grep-history))\n+\t\t  (add-to-history 'git-grep-history command))\n+\t      (let ((default-directory dir))\n+\t\t(compilation-start (concat \"PAGER= \" command) 'grep-mode))\n+\t      ;; Set default-directory if we started rgrep in the *grep* buffer.\n+\t      (if (eq next-error-last-buffer (current-buffer))\n+\t\t  (setq default-directory dir))))))))\n+\n (provide 'git)\n ;;; git.el ends here\n-- \n1.5.4.2.191.g7b407\n\n\n\n-- \nRémi Vanicat\n"},{"id":"69576","messageId":"877igx9pxu.fsf@lysator.liu.se","threadId":"12236","inReplyTo":"87d4qpgs9y.dlv@maison.homelinux.org","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2008-02-22T11:43:41Z","receivedAt":"2008-02-22T11:43:41Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Remi Vanicat <vanicat@debian.org> writes:\n\n> Here is a modification with inclusion of git-grep only when the grep\n> library is available. \n\nNice. I didn't even know that require had more parameters. But I'd\nwrite nil instead of () in this case.\n\n> To put it in another file might be a good idea to, but in this case,\n> may be we could break this huge 1786 file in several smaller file.\n>\n> From 403143a61bf8f77d042893765b19cf7cc7062e59 Mon Sep 17 00:00:00 2001\n> From: David Kågedal <davidk@lysator.liu.se>\n> Date: Fri, 22 Feb 2008 11:57:25 +0100\n> Subject: [PATCH] git.el: Add a git-grep command\n> MIME-Version: 1.0\n> Content-Type: text/plain; charset=utf-8\n> Content-Transfer-Encoding: 8bit\n>\n> This allows easy access to git grep from Emacs.\n>\n> Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n> Signed-off-by: Rémi Vanicat <vanicat@debian.org>\n> ---\n>  contrib/emacs/git.el |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 files changed, 52 insertions(+), 0 deletions(-)\n>\n> diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\n> index f69b697..afaf187 100644\n> --- a/contrib/emacs/git.el\n> +++ b/contrib/emacs/git.el\n> @@ -49,6 +49,7 @@\n>  (require 'ewoc)\n>  (require 'log-edit)\n>  (require 'easymenu)\n> +(require 'grep () t)\n>  \n>  \n>  ;;;; Customizations\n> @@ -1496,6 +1497,7 @@ amended version of it.\"\n>        [\"Diff File\" git-diff-file t]\n>        [\"Interactive Diff File\" git-diff-file-idiff t]\n>        [\"Log\" git-log-file t]\n> +      ,@(if (featurep 'grep) (list [\"Grep\" git-grep t]) ())\n>        \"--------\"\n>        [\"Mark\" git-mark-file t]\n>        [\"Mark All\" git-mark-all t]\n> @@ -1584,5 +1586,55 @@ Meant to be used in `after-save-hook'.\"\n>    (interactive)\n>    (describe-function 'git-status-mode))\n>  \n> +(when (featurep 'grep)\n> +  (defvar git-grep-history nil)\n> +\n> +  (defun git-grep (regexp &optional files dir)\n> +    \"Recursively grep for REGEXP in FILES in directory tree rooted at DIR.\n> +The search is limited to file names matching shell pattern FILES.\n> +FILES may use abbreviations defined in `grep-files-aliases', e.g.\n> +entering `ch' is equivalent to `*.[ch]'.\n> +\n> +With \\\\[universal-argument] prefix, you can edit the constructed shell command line\n> +before it is executed.\n> +With two \\\\[universal-argument] prefixes, directly edit and run `git-grep-find-command'.\n> +\n> +Collect output in a buffer.  While find runs asynchronously, you\n> +can use \\\\[next-error] (M-x next-error), or \\\\<grep-mode-map>\\\\[compile-goto-error]\n> +in the grep output buffer, to go to the lines where grep found matches.\"\n> +    (interactive\n> +     (cond\n> +       ((equal current-prefix-arg '(16))\n> +\t(list (read-from-minibuffer \"Run: \" \"git grep \"\n> +\t\t\t\t    nil nil 'git-grep-history)\n> +\t      nil))\n> +       (t (let* ((regexp (grep-read-regexp))\n> +\t\t (files (grep-read-files regexp))\n> +\t\t (dir (read-directory-name \"Base directory: \"\n> +\t\t\t\t\t   nil default-directory t)))\n> +\t    (list regexp files dir)))))\n> +    (when (and (stringp regexp) (> (length regexp) 0))\n> +      (if (null files)\n> +\t  (if (not (string= regexp grep-find-command))\n> +\t      (compilation-start regexp 'grep-mode))\n> +\t  (setq dir (file-name-as-directory (expand-file-name dir)))\n> +\t  (let ((command (concat\n> +\t\t\t  \"git grep -n \"\n> +\t\t\t  \"-e \" (shell-quote-argument regexp)\n> +\t\t\t  (if (string= files \"*\")\n> +\t\t\t      \"\"\n> +\t\t\t      (concat \" -- \" (shell-quote-argument files))))))\n> +\t    (when command\n> +\t      (if current-prefix-arg\n> +\t\t  (setq command\n> +\t\t\t(read-from-minibuffer \"Confirm: \"\n> +\t\t\t\t\t      command nil nil 'git-grep-history))\n> +\t\t  (add-to-history 'git-grep-history command))\n> +\t      (let ((default-directory dir))\n> +\t\t(compilation-start (concat \"PAGER= \" command) 'grep-mode))\n> +\t      ;; Set default-directory if we started rgrep in the *grep* buffer.\n> +\t      (if (eq next-error-last-buffer (current-buffer))\n> +\t\t  (setq default-directory dir))))))))\n> +\n>  (provide 'git)\n>  ;;; git.el ends here\n> -- \n> 1.5.4.2.191.g7b407\n\n-- \nDavid Kågedal\n"},{"id":"69578","messageId":"20080222115532.GA14707@diana.vm.bytemark.co.uk","threadId":"12236","inReplyTo":"87wsox9wsu.fsf@lysator.liu.se","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-02-22T11:55:32Z","receivedAt":"2008-02-22T11:55:32Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-02-22 10:15:29 +0100, David Kågedal wrote:\n\n> Karl Hasselström <kha@treskal.com> writes:\n>\n> > I was a bit confused about the filename pattern selection, though:\n> > the promt suggested \"ch\", which, when I accepted it, was converted\n> > to \"*.[ch]\". However, manually specifying \"*.c\" works as well. I'm\n> > not sure if this is specific to your patch or something affecting\n> > all grep stuff in emacs (though I can't recall seeing it before).\n>\n> This isn't invented by me, but is \"standard\" in the grep commands in\n> Emacs 22. See the grep-files-aliases variable and the documentation\n> of rgrep.\n\nOh. OK. Thanks.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"69644","messageId":"200802230200.m1N202Y7007392@localhost.localdomain","threadId":"12236","inReplyTo":"87d4qpgs9y.dlv@maison.homelinux.org","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-02-23T02:00:02Z","receivedAt":"2008-02-23T02:00:02Z","isPatch":true,"sender":{"key":"xma@gnu.org","avatar":null},"body":"Hi,\n\n   Here is a modification with inclusion of git-grep only when the grep\n   library is available. \n\n   +(require 'grep () t)\n\n   +(when (featurep 'grep)\n   +  (defvar git-grep-history nil)\n   +\n   +  (defun git-grep (regexp &optional files dir)\n\nWhy not just do something like this ?\n\n(when (require 'grep () t)\n      (defvar ...)\n      (defun git-grep ...))\n\nRegards,\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"},{"id":"69701","messageId":"8763wfwjg6.dlv@maison.homelinux.org","threadId":"12236","inReplyTo":"200802230200.m1N202Y7007392@localhost.localdomain","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Remi Vanicat","fromEmail":"vanicat@debian.org","sentAt":"2008-02-23T19:39:53Z","receivedAt":"2008-02-23T19:39:53Z","isPatch":true,"sender":{"key":"vanicat@debian.org","avatar":"https://gravatar.com/avatar/cd491a7f4c221349809a60f88fc21326b97cce2a705e318898aa74851db92409?d=mp&s=160"},"body":"Xavier Maillard <xma@gnu.org> writes:\n\n> Hi,\n>\n>    Here is a modification with inclusion of git-grep only when the grep\n>    library is available. \n>\n>    +(require 'grep () t)\n>\n>    +(when (featurep 'grep)\n>    +  (defvar git-grep-history nil)\n>    +\n>    +  (defun git-grep (regexp &optional files dir)\n>\n> Why not just do something like this ?\n>\n> (when (require 'grep () t)\n>       (defvar ...)\n>       (defun git-grep ...))\n\nBecause I wanted require to stay on top of the file, but I didn't want\nto put the rest of the git-grep stuff there.\n\n(the real reason is because I did not check in the doc for the return\nvalue of require, and so I didn't knew that I could do that, but\nstill, I believe that my after the fact argument are good.)\n-- \nRémi Vanicat\n"},{"id":"69737","messageId":"200802232241.m1NMfZpg014264@localhost.localdomain","threadId":"12236","inReplyTo":"8763wfwjg6.dlv@maison.homelinux.org","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-02-23T22:41:35Z","receivedAt":"2008-02-23T22:41:35Z","isPatch":true,"sender":{"key":"xma@gnu.org","avatar":null},"body":"\n   Xavier Maillard <xma@gnu.org> writes:\n\n   > Hi,\n   >\n   >    Here is a modification with inclusion of git-grep only when the grep\n   >    library is available. \n   >\n   >    +(require 'grep () t)\n   >\n   >    +(when (featurep 'grep)\n   >    +  (defvar git-grep-history nil)\n   >    +\n   >    +  (defun git-grep (regexp &optional files dir)\n   >\n   > Why not just do something like this ?\n   >\n   > (when (require 'grep () t)\n   >       (defvar ...)\n   >       (defun git-grep ...))\n\n   Because I wanted require to stay on top of the file, but I didn't want\n   to put the rest of the git-grep stuff there.\n\nGood point. Though, you can still \"embed\" the require form\ndirectly into the defun. This is thing I have already seen in the\npast. Dunno if it is a convention or a coding style but something\nlike:\n\n(defun git-grep ()\n \"Docstring\"\n (interactive)\n (when (require 'grep nil t)\n       here the rest\n  ))\n\nis doable too. Maybe the if-else form would be better though with\nan else clause to (error \"No grep package foud.\").\n\nWell just kidding, your patch is okay ;)\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"},{"id":"69756","messageId":"200802240200.m1O201Rh015406@localhost.localdomain","threadId":"12236","inReplyTo":"8763wfwjg6.dlv@maison.homelinux.org","subject":"Re: [PATCH] git.el: Add a git-grep command","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-02-24T02:00:01Z","receivedAt":"2008-02-24T02:00:01Z","isPatch":true,"sender":{"key":"xma@gnu.org","avatar":null},"body":"\n   Xavier Maillard <xma@gnu.org> writes:\n\n   > Hi,\n   >\n   >    Here is a modification with inclusion of git-grep only when the grep\n   >    library is available. \n   >\n   >    +(require 'grep () t)\n   >\n   >    +(when (featurep 'grep)\n   >    +  (defvar git-grep-history nil)\n   >    +\n   >    +  (defun git-grep (regexp &optional files dir)\n   >\n   > Why not just do something like this ?\n   >\n   > (when (require 'grep () t)\n   >       (defvar ...)\n   >       (defun git-grep ...))\n\n   Because I wanted require to stay on top of the file, but I didn't want\n   to put the rest of the git-grep stuff there.\n\nGood point. Though, you can still \"embed\" the require form\ndirectly into the defun. This is thing I have already seen in the\npast. Dunno if it is a convention or a coding style but something\nlike:\n\n(defun git-grep ()\n \"Docstring\"\n (interactive)\n (when (require 'grep nil t)\n       here the rest\n  ))\n\nis doable too. Maybe the if-else form would be better though with\nan else clause to (error \"No grep package foud.\").\n\nWell just kidding, your patch is okay ;)\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"}]}