forked from magnars/.emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-rgrep.el
47 lines (42 loc) · 1.64 KB
/
setup-rgrep.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(defun rgrep-fullscreen (regexp &optional files dir confirm)
"Open grep in full screen, saving windows."
(interactive
(progn
(grep-compute-defaults)
(cond
((and grep-find-command (equal current-prefix-arg '(16)))
(list (read-from-minibuffer "Run: " grep-find-command
nil nil 'grep-find-history)))
((not grep-find-template)
(error "grep.el: No `grep-find-template' available"))
(t (let* ((regexp (grep-read-regexp))
(files (grep-read-files regexp))
(dir (read-directory-name "Base directory: "
nil default-directory t))
(confirm (equal current-prefix-arg '(4))))
(list regexp files dir confirm))))))
(window-configuration-to-register ?$)
(rgrep regexp files dir confirm)
(switch-to-buffer "*grep*")
(delete-other-windows)
(beginning-of-buffer))
(defun rgrep-quit-window ()
(interactive)
(kill-buffer)
(jump-to-register ?$))
(defun rgrep-goto-file-and-close-rgrep ()
(interactive)
(compile-goto-error)
(kill-buffer "*grep*")
(delete-other-windows)
(message "Type C-x r j $ to return to pre-rgrep windows."))
(eval-after-load "grep"
'(progn
;; Don't recurse into some directories
(add-to-list 'grep-find-ignored-directories "target")
(add-to-list 'grep-find-ignored-directories "node_modules")
(add-to-list 'grep-find-ignored-directories "vendor")
;; Add custom keybindings
(define-key grep-mode-map "q" 'rgrep-quit-window)
(define-key grep-mode-map (kbd "C-<return>") 'rgrep-goto-file-and-close-rgrep)))
(provide 'setup-rgrep)