Skip to content

Instantly share code, notes, and snippets.

@paxan
Forked from offby1/git-grep.el
Created September 2, 2010 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paxan/562864 to your computer and use it in GitHub Desktop.
Save paxan/562864 to your computer and use it in GitHub Desktop.
;; There's something similar (but fancier) in vc-git.el: vc-git-grep
;; -I means don't search through binary files
(defcustom git-grep-switches "--extended-regexp -I -n --ignore-case"
"Switches to pass to `git grep'."
:type 'string)
(defcustom git-grep-default-work-tree (expand-file-name "~/Documents/src/kits")
"Top of your favorite git working tree. \\[git-grep] will search from here if it cannot figure out where else to look."
:type 'directory
)
(when (require 'vc-git nil t)
;; Uncomment this to try out the built-in-to-Emacs function.
;;(defalias 'git-grep 'vc-git-grep)
(defun git-grep (command-args)
(interactive
(let ((root (vc-git-root default-directory)))
(when (not root)
(message "git-grep: %s doesn't look like a git working tree; searching from %s instead" default-directory git-grep-default-work-tree)
(setq root git-grep-default-work-tree))
(list (read-shell-command "Run git-grep (like this): "
(format (concat
"cd %s && "
"git grep %s -e %s")
root
git-grep-switches
(shell-quote-argument (thing-at-point 'symbol)))
'git-grep-history))))
(let ((grep-use-null-device nil))
(grep command-args))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment