From 60b2d047f0392a706f3fc371e5636a519786499d Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Thu, 6 Jun 2013 14:51:31 +0900 Subject: [PATCH] rm my-grep and add my-rgrep --- emacs.el | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/emacs.el b/emacs.el index 939ed69..5872899 100644 --- a/emacs.el +++ b/emacs.el @@ -1830,26 +1830,25 @@ if arg given, use that eshell buffer, otherwise make new eshell buffer." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; misc funcs -(defun my-grep () - "Use git-grep if avaliable. Only called interactively." - (interactive) +(defun my-rgrep (word) + "My recursive grep." + (interactive "sWord to search: ") (require 'grep) - (let ((--grep-command-bak grep-command) - (--grep-use-null-device-bak grep-use-null-device)) - (if (called-interactively-p 'any) - (progn - (when (eq 0 - (shell-command "git rev-parse --git-dir")) - (grep-apply-setting 'grep-command - "git --no-pager grep -nH -e ") - (grep-apply-setting 'grep-use-null-device - nil)) - (call-interactively 'grep) - (grep-apply-setting 'grep-command - --grep-command-bak) - (grep-apply-setting 'grep-use-null-device - --grep-use-null-device-bak)) - (message "my-grep only allow interactive call.")))) + (compilation-start (if (eq 0 + (shell-command "git rev-parse --git-dir")) + (format "git --no-pager grep -nH -e '%s'" + word) + (if (executable-find "ag") + (format "ag --nocolor --nogroup --nopager '%s'" + word) + (if (executable-find "ack") + (format "ack --nocolor --nogroup --nopager '%s'" + word) + (format "find . -type f -exec grep '%s' {} +" + word)))) + 'grep-mode)) + +(define-key ctl-x-map "s" 'my-rgrep) (defun make () "Run \"make -k\" in current directory."