forked from vjohansen/emacs-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvj-grep.el
81 lines (64 loc) · 2.44 KB
/
vj-grep.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(require 'compile)
(require 'vj-util)
(defgroup vj-grep nil
"Extension based Grep with external script. Displays directories separately
from filenames for nicer display."
:group 'convenience
:group 'vj)
(defcustom vj-grep-source-extensions
":code,:text"
"Extensions to include in searches."
:type 'string
:group 'vj-grep)
(defvar vj-perl-program "perl")
(defvar vj-vgrep-call
(concat vj-perl-program " "
(or (locate-library "vgrep22.pl") "-S vgrep22.pl"))
"Command line for calling vgrep22.pl program.")
(defun vgrep (word &optional ext-string)
"Run grep WORD on files with vj-grep-source-extensions in current directory.
With prefix argument do a recursive grep."
(interactive
(list
(read-from-minibuffer
(if (> (length (current-word)) 0)
(format "vgrep [%s]: " (current-word))
"vgrep Expression: ")
nil nil nil 'grep-history (current-word))))
(if (string= word "")
(setq word (current-word)))
(unless (< (length word) 1)
(grep
(concat vj-vgrep-call
" -i -e " (or ext-string vj-grep-source-extensions) " "
(shell-quote-argument word) " "
(if current-prefix-arg
(concat "-r " (shell-quote-argument
(file-name-directory
(expand-file-name (read-file-name "Directory(-r): " default-directory)))))
".")
))))
(defun vj-rgrep ()
"Recursive grep (VJ June 2003)"
(interactive)
(let
((compilation-enter-directory-regexp-alist '(("Dir: \\(.*\\)" 1)))
(compilation-scroll-output nil)
(command
(concat vj-vgrep-call " -i "
" -e " vj-grep-source-extensions
" " (shell-quote-argument
(vj-read-from-minibuffer "rgrep" (current-word) 'grep-history))
" -r " (replace-regexp-in-string " " "%20"
(expand-file-name (read-file-name "Dir: " nil default-directory nil))))))
(grep (if current-prefix-arg
(read-from-minibuffer "rgrep command: " command)
command ))))
;; VJ april 2005
(defun vj-grep-includes (word)
"grep in iclude files for current buffer"
(interactive (list (read-string "include grep: " (thing-at-point 'symbol))))
(grep (concat vj-perl-program " -w "
(or (locate-library "incgrep.pl") "-S incgrep.pl")
" " (buffer-file-name) " " (shell-quote-argument word))))
(provide 'vj-grep)