Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created March 16, 2023 21:47
Show Gist options
  • Save twopoint718/1845c1e246ce4050d3303d3b61384b2e to your computer and use it in GitHub Desktop.
Save twopoint718/1845c1e246ce4050d3303d3b61384b2e to your computer and use it in GitHub Desktop.
Wrapper for Emacs' default grep. It uses `git grep`, passes in the git project directory, and also uses the current symbol under cursor as a default.
(defun cjw-git-grep (my-word)
"Use git-grep for search in current project (vc-root-dir). Default
search term uses symbol under cursor"
(interactive
(list
(read-string
(format "Search (%s): " (thing-at-point 'symbol)) ; prompt
nil ; initial input
nil ; history list
(thing-at-point 'symbol) ; evaluated. will be default
)))
(let ((default-directory (vc-root-dir)))
(message "=====> git grep '%s' in %s" my-word (vc-root-dir))
(grep (format "git --no-pager grep --line-number -e '%s'" my-word))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment