emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/lisp/vc-git.el,v


From: Dan Nicolaescu
Subject: [Emacs-diffs] Changes to emacs/lisp/vc-git.el,v
Date: Wed, 26 Mar 2008 06:35:58 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Dan Nicolaescu <dann>   08/03/26 06:35:57

Index: vc-git.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/vc-git.el,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- vc-git.el   24 Mar 2008 08:21:42 -0000      1.46
+++ vc-git.el   26 Mar 2008 06:35:55 -0000      1.47
@@ -108,7 +108,7 @@
 ;; - find-file-hook ()                            NOT NEEDED
 ;; - find-file-not-found-hook ()                   NOT NEEDED
 
-(eval-when-compile (require 'cl) (require 'vc))
+(eval-when-compile (require 'cl) (require 'vc) (require 'grep))
 
 (defvar git-commits-coding-system 'utf-8
   "Default coding system for git commits.")
@@ -489,6 +489,70 @@
 (defun vc-git-rename-file (old new)
   (vc-git-command nil 0 (list old new) "mv" "-f" "--"))
 
+(defvar vc-git-extra-menu-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [git-grep]
+      '(menu-item "Git grep..." vc-git-grep
+                 :help "Run the `git grep' command"))
+    map))
+
+(defun vc-git-extra-menu () vc-git-extra-menu-map)
+
+(defun vc-git-extra-status-menu () vc-git-extra-menu-map)
+
+;; Derived from `lgrep'.
+(defun vc-git-grep (regexp &optional files dir)
+  "Run git grep, searching for REGEXP in FILES in directory 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 `grep-command'.
+
+Collect output in a buffer.  While git grep 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.
+
+This command shares argument histories with \\[rgrep] and \\[grep]."
+  (interactive
+   (progn
+     (grep-compute-defaults)
+     (cond
+      ((equal current-prefix-arg '(16))
+       (list (read-from-minibuffer "Run: " "git grep"
+                                  nil nil 'grep-history)
+            nil))
+      (t (let* ((regexp (grep-read-regexp))
+               (files (grep-read-files regexp))
+               (dir (read-directory-name "In directory: "
+                                         nil default-directory t)))
+          (list regexp files dir))))))
+  (require 'grep)
+  (when (and (stringp regexp) (> (length regexp) 0))
+    (let ((command regexp))
+      (if (null files)
+         (if (string= command "git grep")
+             (setq command nil))
+       (setq dir (file-name-as-directory (expand-file-name dir)))
+       (setq command
+             (grep-expand-template "git grep -n -e <R> -- <F>" regexp files))
+       (when command
+         (if (equal current-prefix-arg '(4))
+             (setq command
+                   (read-from-minibuffer "Confirm: "
+                                         command nil nil 'grep-history))
+           (add-to-history 'grep-history command))))
+      (when command
+       (let ((default-directory dir)
+             (compilation-environment '("PAGER=")))
+         ;; Setting process-setup-function makes exit-message-function work
+         ;; even when async processes aren't supported.
+         (compilation-start command 'grep-mode))
+       (if (eq next-error-last-buffer (current-buffer))
+           (setq default-directory dir))))))
 
 ;;; Internal commands
 




reply via email to

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