Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Override grep{-find,} with GIT version when visiting a file in GIT.

  • Loading branch information...
commit 4afc49e5708c7e96722d668ea0351d9ef7df06dc 1 parent a3a4170
@jpr5 jpr5 authored
Showing with 34 additions and 13 deletions.
  1. +34 −13 .emacs.d/vcs.el
View
47 .emacs.d/vcs.el
@@ -1,20 +1,41 @@
-;; Git stuff - load vc-git and "fix" the broken blame invocation syntax.
+;; Main VCS settings
+
+(setq vc-follow-symlinks t)
+(setq diff-switches '"-u")
+
+;; GIT
(require 'vc-git)
-(add-to-list 'vc-handled-backends 'git)
+
+;; Fix vc-git's broken blame invocation syntax (OSX Carbon Emacs 22.3.1).
(defun vc-git-annotate-command (file buf &optional rev)
(let ((name (file-relative-name file)))
(vc-git-command buf 0 name "blame" (if rev (concat rev)))))
-;; Enable this for the the ever-awesome git-blame-mode (kinda broken)
-;(require 'git)
-;(require 'format-spec)
-;(autoload 'git-blame-mode "git-blame" "Minor mode for incremental blame for Git." t)
-;(global-set-key (kbd "C-x v b") 'git-blame-mode) ;; FIXME: doesn't work
+;; Whenever we open a file, if we're in a GIT-controlled file, switch M-x grep
+;; to use a **much** faster form of grep. Assume search-from-cwd, and limit
+;; grep depth to cwd vs. M-x rgrep for unlimited depth (recursive). Nuking the
+;; "-- ." would separately accomplish a full repository-wide search.
+;;
+;; Plain version:
+(defun vc-git-override-grep ()
+ "Change buffer-local grep mechanism to use git grep (waaay faster)."
+ (when (or
+ (eq (vc-backend buffer-file-name) 'Git)
+ (eq (vc-backend buffer-file-name) 'git))
+ (set (make-local-variable 'grep-command) '("git --no-pager grep --max-depth 0 -En -- ." . 39))
+ (set (make-local-variable 'grep-find-command) '("git --no-pager grep -En -- ." . 25))))
-(setq diff-switches '"-u")
-;(setq vc-diff-switches '"-u")
-;(setq cvs-diff-flags '("-u"))
-;(setq vc-cvs-diff-switches '"-u")
-;(setenv "PATH" (concat "/usr/local/git/bin:" (getenv "PATH")))
+;; TODO: It's not possible to use search-path yet since vc-git-override-grep is
+;; called through find-file-hook. We should front-end Mx-{r,}grep
+;; buffer-locally with a function that could interactively query for a
+;; search-path override (if unspecified).
+;(defun vc-git-override-grep (&optional search-path)
+; "Change buffer-local grep mechanism to use git grep (waaay faster)."
+; (when (or
+; (eq (vc-backend buffer-file-name) 'Git)
+; (eq (vc-backend buffer-file-name) 'git))
+; (let ((path (if search-path search-path ".")))
+; (set (make-local-variable 'grep-command) '((concat "git --no-pager grep --max-depth 0 -En -- " path) . 39))
+; (set (make-local-variable 'grep-find-command) '((concat "git --no-pager grep -En -- " path) . 25)))))
-(setq vc-follow-symlinks t)
+(add-hook 'find-file-hook 'vc-git-override-grep)
Please sign in to comment.
Something went wrong with that request. Please try again.