62160
|
1 ;;; grep.el --- run Grep as inferior of Emacs, parse match messages
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
2
|
57769
|
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
75347
|
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
5
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
6 ;; Author: Roland McGrath <roland@gnu.org>
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
7 ;; Maintainer: FSF
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
8 ;; Keywords: tools, processes
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
9
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
11
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by
|
78234
|
14 ;; the Free Software Foundation; either version 3, or (at your option)
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
15 ;; any later version.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
16
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
21
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
64085
|
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
25 ;; Boston, MA 02110-1301, USA.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
26
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
27 ;;; Commentary:
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
28
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
29 ;; This package provides the grep facilities documented in the Emacs
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
30 ;; user's manual.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
31
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
32 ;;; Code:
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
33
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
34 (require 'compile)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
35
|
65232
|
36
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
37 (defgroup grep nil
|
70258
|
38 "Run grep as inferior of Emacs, parse error messages."
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
39 :group 'tools
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
40 :group 'processes)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
41
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
42
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
43 ;;;###autoload
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
44 (defcustom grep-window-height nil
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
45 "*Number of lines in a grep window. If nil, use `compilation-window-height'."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
46 :type '(choice (const :tag "Default" nil)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
47 integer)
|
59996
|
48 :version "22.1"
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
49 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
50
|
56948
|
51 (defcustom grep-highlight-matches 'auto-detect
|
56960
|
52 "If t, use special markers to highlight grep matches.
|
56881
|
53
|
|
54 Some grep programs are able to surround matches with special
|
|
55 markers in grep output. Such markers can be used to highlight
|
|
56 matches in grep mode.
|
|
57
|
|
58 This option sets the environment variable GREP_COLOR to specify
|
|
59 markers for highlighting and GREP_OPTIONS to add the --color
|
|
60 option in front of any explicit grep options before starting
|
56960
|
61 the grep.
|
|
62
|
|
63 The default value of this variable is set up by `grep-compute-defaults';
|
|
64 call that function before using this variable in your program."
|
56948
|
65 :type '(choice (const :tag "Do not highlight matches with grep markers" nil)
|
|
66 (const :tag "Highlight matches with grep markers" t)
|
|
67 (other :tag "Not Set" auto-detect))
|
59996
|
68 :version "22.1"
|
56881
|
69 :group 'grep)
|
|
70
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
71 (defcustom grep-scroll-output nil
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
72 "*Non-nil to scroll the *grep* buffer window as output appears.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
73
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
74 Setting it causes the grep commands to put point at the end of their
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
75 output window so that the end of the output is always visible rather
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
76 than the begining."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
77 :type 'boolean
|
59996
|
78 :version "22.1"
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
79 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
80
|
56333
|
81 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
82 (defcustom grep-command nil
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
83 "The default grep command for \\[grep].
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
84 If the grep program used supports an option to always include file names
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
85 in its output (such as the `-H' option to GNU grep), it's a good idea to
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
86 include it when specifying `grep-command'.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
87
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
88 The default value of this variable is set up by `grep-compute-defaults';
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
89 call that function before using this variable in your program."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
90 :type '(choice string
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
91 (const :tag "Not Set" nil))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
92 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
93
|
70258
|
94 (defcustom grep-template nil
|
|
95 "The default command to run for \\[lgrep].
|
|
96 The default value of this variable is set up by `grep-compute-defaults';
|
|
97 call that function before using this variable in your program.
|
|
98 The following place holders should be present in the string:
|
|
99 <C> - place to put -i if case insensitive grep.
|
|
100 <F> - file names and wildcards to search.
|
|
101 <R> - the regular expression searched for.
|
|
102 <N> - place to insert null-device."
|
|
103 :type '(choice string
|
|
104 (const :tag "Not Set" nil))
|
|
105 :version "22.1"
|
|
106 :group 'grep)
|
|
107
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
108 (defcustom grep-use-null-device 'auto-detect
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
109 "If t, append the value of `null-device' to `grep' commands.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
110 This is done to ensure that the output of grep includes the filename of
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
111 any match in the case where only a single file is searched, and is not
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
112 necessary if the grep program used supports the `-H' option.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
113
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
114 The default value of this variable is set up by `grep-compute-defaults';
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
115 call that function before using this variable in your program."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
116 :type '(choice (const :tag "Do Not Append Null Device" nil)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
117 (const :tag "Append Null Device" t)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
118 (other :tag "Not Set" auto-detect))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
119 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
120
|
56333
|
121 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
122 (defcustom grep-find-command nil
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
123 "The default find command for \\[grep-find].
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
124 The default value of this variable is set up by `grep-compute-defaults';
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
125 call that function before using this variable in your program."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
126 :type '(choice string
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
127 (const :tag "Not Set" nil))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
128 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
129
|
70258
|
130 (defcustom grep-find-template nil
|
|
131 "The default command to run for \\[rgrep].
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
132 The default value of this variable is set up by `grep-compute-defaults';
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
133 call that function before using this variable in your program.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
134 The following place holders should be present in the string:
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
135 <D> - base directory for find
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
136 <X> - find options to restrict or expand the directory list
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
137 <F> - find options to limit the files matched
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
138 <C> - place to put -i if case insensitive grep
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
139 <R> - the regular expression searched for."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
140 :type '(choice string
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
141 (const :tag "Not Set" nil))
|
59996
|
142 :version "22.1"
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
143 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
144
|
83780
|
145 (defcustom grep-files-aliases
|
|
146 '(("asm" . "*.[sS]")
|
|
147 ("c" . "*.c")
|
|
148 ("cc" . "*.cc")
|
|
149 ("ch" . "*.[ch]")
|
|
150 ("el" . "*.el")
|
|
151 ("h" . "*.h")
|
|
152 ("l" . "[Cc]hange[Ll]og*")
|
|
153 ("m" . "[Mm]akefile*")
|
|
154 ("tex" . "*.tex")
|
|
155 ("texi" . "*.texi"))
|
70258
|
156 "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'."
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
157 :type 'alist
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
158 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
159
|
83778
|
160 (defcustom grep-find-ignored-directories
|
|
161 '(".bzr"
|
|
162 ".git"
|
|
163 ".hg"
|
|
164 ".svn"
|
|
165 "CVS"
|
|
166 "RCS"
|
|
167 "_MTN"
|
|
168 "_darcs"
|
|
169 "{arch}")
|
70258
|
170 "*List of names of sub-directories which `rgrep' shall not recurse into."
|
|
171 :type '(repeat string)
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
172 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
173
|
56226
|
174 (defcustom grep-error-screen-columns nil
|
|
175 "*If non-nil, column numbers in grep hits are screen columns.
|
|
176 See `compilation-error-screen-columns'"
|
|
177 :type '(choice (const :tag "Default" nil)
|
|
178 integer)
|
59996
|
179 :version "22.1"
|
56226
|
180 :group 'grep)
|
|
181
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
182 ;;;###autoload
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
183 (defcustom grep-setup-hook nil
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
184 "List of hook functions run by `grep-process-setup' (see `run-hooks')."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
185 :type 'hook
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
186 :group 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
187
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
188 (defvar grep-mode-map
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
189 (let ((map (cons 'keymap compilation-minor-mode-map)))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
190 (define-key map " " 'scroll-up)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
191 (define-key map "\^?" 'scroll-down)
|
57022
463edf7390ca
(grep-mode-map): Rename `next-error-follow-mode' to `next-error-follow-minor-mode'.
Juri Linkov <juri@jurta.org>
diff
changeset
|
192 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
193
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
194 (define-key map "\r" 'compile-goto-error) ;; ?
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
195 (define-key map "n" 'next-error-no-select)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
196 (define-key map "p" 'previous-error-no-select)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
197 (define-key map "{" 'compilation-previous-file)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
198 (define-key map "}" 'compilation-next-file)
|
64728
|
199 (define-key map "\t" 'compilation-next-error)
|
|
200 (define-key map [backtab] 'compilation-previous-error)
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
201
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
202 ;; Set up the menu-bar
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
203 (define-key map [menu-bar grep]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
204 (cons "Grep" (make-sparse-keymap "Grep")))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
205
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
206 (define-key map [menu-bar grep compilation-kill-compilation]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
207 '("Kill Grep" . kill-compilation))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
208 (define-key map [menu-bar grep compilation-separator2]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
209 '("----" . nil))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
210 (define-key map [menu-bar grep compilation-compile]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
211 '("Compile..." . compile))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
212 (define-key map [menu-bar grep compilation-grep]
|
64944
|
213 '("Another grep..." . grep))
|
70258
|
214 (define-key map [menu-bar grep compilation-grep-find]
|
|
215 '("Recursive grep..." . grep-find))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
216 (define-key map [menu-bar grep compilation-recompile]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
217 '("Repeat grep" . recompile))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
218 (define-key map [menu-bar grep compilation-separator2]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
219 '("----" . nil))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
220 (define-key map [menu-bar grep compilation-first-error]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
221 '("First Match" . first-error))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
222 (define-key map [menu-bar grep compilation-previous-error]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
223 '("Previous Match" . previous-error))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
224 (define-key map [menu-bar grep compilation-next-error]
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
225 '("Next Match" . next-error))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
226 map)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
227 "Keymap for grep buffers.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
228 `compilation-minor-mode-map' is a cdr of this.")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
229
|
54372
|
230 (defalias 'kill-grep 'kill-compilation)
|
|
231
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
232 ;;;; TODO --- refine this!!
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
233
|
53145
|
234 ;;; (defcustom grep-use-compilation-buffer t
|
|
235 ;;; "When non-nil, grep specific commands update `compilation-last-buffer'.
|
|
236 ;;; This means that standard compile commands like \\[next-error] and \\[compile-goto-error]
|
|
237 ;;; can be used to navigate between grep matches (the default).
|
|
238 ;;; Otherwise, the grep specific commands like \\[grep-next-match] must
|
|
239 ;;; be used to navigate between grep matches."
|
|
240 ;;; :type 'boolean
|
|
241 ;;; :group 'grep)
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
242
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
243 ;; override compilation-last-buffer
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
244 (defvar grep-last-buffer nil
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
245 "The most recent grep buffer.
|
71854
|
246 A grep buffer becomes most recent when you select Grep mode in it.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
247 Notice that using \\[next-error] or \\[compile-goto-error] modifies
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
248 `complation-last-buffer' rather than `grep-last-buffer'.")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
249
|
56333
|
250 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
251 (defvar grep-regexp-alist
|
64864
|
252 '(("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2"
|
64725
|
253 1 3)
|
|
254 ;; Rule to match column numbers is commented out since no known grep
|
|
255 ;; produces them
|
64864
|
256 ;; ("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2\\(?:\\([0-9]+\\)\\(?:-\\([0-9]+\\)\\)?\\2\\)?"
|
64725
|
257 ;; 1 3 (4 . 5))
|
63576
|
258 ("^\\(\\(.+?\\):\\([0-9]+\\):\\).*?\
|
64509
|
259 \\(\033\\[01;31m\\(?:\033\\[K\\)?\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)"
|
63576
|
260 2 3
|
57769
|
261 ;; Calculate column positions (beg . end) of first grep match on a line
|
56881
|
262 ((lambda ()
|
64509
|
263 (setq compilation-error-screen-columns nil)
|
|
264 (- (match-beginning 4) (match-end 1)))
|
56881
|
265 .
|
64509
|
266 (lambda () (- (match-end 5) (match-end 1)
|
|
267 (- (match-end 4) (match-beginning 4)))))
|
63576
|
268 nil 1)
|
64740
|
269 ("^Binary file \\(.+\\) matches$" 1 nil nil 0 1))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
270 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
271
|
54372
|
272 (defvar grep-error "grep hit"
|
|
273 "Message to print when no matches are found.")
|
|
274
|
|
275 ;; Reverse the colors because grep hits are not errors (though we jump there
|
|
276 ;; with `next-error'), and unreadable files can't be gone to.
|
|
277 (defvar grep-hit-face compilation-info-face
|
|
278 "Face name to use for grep hits.")
|
|
279
|
64864
|
280 (defvar grep-error-face 'compilation-error
|
54372
|
281 "Face name to use for grep error messages.")
|
|
282
|
58988
|
283 (defvar grep-match-face 'match
|
|
284 "Face name to use for grep matches.")
|
|
285
|
64725
|
286 (defvar grep-context-face 'shadow
|
|
287 "Face name to use for grep context lines.")
|
|
288
|
54372
|
289 (defvar grep-mode-font-lock-keywords
|
|
290 '(;; Command output lines.
|
|
291 ("^\\([A-Za-z_0-9/\.+-]+\\)[ \t]*:" 1 font-lock-function-name-face)
|
|
292 (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$"
|
|
293 1 grep-error-face)
|
|
294 ;; remove match from grep-regexp-alist before fontifying
|
71422
|
295 ("^Grep[/a-zA-z]* started.*"
|
65126
|
296 (0 '(face nil message nil help-echo nil mouse-face nil) t))
|
71422
|
297 ("^Grep[/a-zA-z]* finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*"
|
54372
|
298 (0 '(face nil message nil help-echo nil mouse-face nil) t)
|
64864
|
299 (1 compilation-info-face nil t)
|
|
300 (2 compilation-warning-face nil t))
|
71422
|
301 ("^Grep[/a-zA-z]* \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
|
54372
|
302 (0 '(face nil message nil help-echo nil mouse-face nil) t)
|
64864
|
303 (1 grep-error-face)
|
64944
|
304 (2 grep-error-face nil t))
|
64864
|
305 ("^.+?-[0-9]+-.*\n" (0 grep-context-face))
|
57769
|
306 ;; Highlight grep matches and delete markers
|
64509
|
307 ("\\(\033\\[01;31m\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)"
|
61902
|
308 ;; Refontification does not work after the markers have been
|
|
309 ;; deleted. So we use the font-lock-face property here as Font
|
|
310 ;; Lock does not clear that.
|
|
311 (2 (list 'face nil 'font-lock-face grep-match-face))
|
64509
|
312 ((lambda (bound))
|
57769
|
313 (progn
|
|
314 ;; Delete markers with `replace-match' because it updates
|
|
315 ;; the match-data, whereas `delete-region' would render it obsolete.
|
|
316 (replace-match "" t t nil 3)
|
64509
|
317 (replace-match "" t t nil 1))))
|
|
318 ("\\(\033\\[[0-9;]*[mK]\\)"
|
|
319 ;; Delete all remaining escape sequences
|
|
320 ((lambda (bound))
|
|
321 (replace-match "" t t nil 1))))
|
54372
|
322 "Additional things to highlight in grep output.
|
|
323 This gets tacked on the end of the generated expressions.")
|
|
324
|
56333
|
325 ;;;###autoload
|
76966
|
326 (defvar grep-program "grep"
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
327 "The default grep program for `grep-command' and `grep-find-command'.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
328 This variable's value takes effect when `grep-compute-defaults' is called.")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
329
|
56333
|
330 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
331 (defvar find-program "find"
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
332 "The default find program for `grep-find-command'.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
333 This variable's value takes effect when `grep-compute-defaults' is called.")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
334
|
56333
|
335 ;;;###autoload
|
86249
|
336 (defvar xargs-program "xargs"
|
|
337 "The default xargs program for `grep-find-command'.
|
|
338 See `grep-find-use-xargs'.
|
|
339 This variable's value takes effect when `grep-compute-defaults' is called.")
|
|
340
|
|
341 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
342 (defvar grep-find-use-xargs nil
|
77033
|
343 "Non-nil means that `grep-find' uses the `xargs' utility by default.
|
|
344 If `exec', use `find -exec'.
|
|
345 If `gnu', use `find -print0' and `xargs -0'.
|
|
346 Any other non-nil value means to use `find -print' and `xargs'.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
347
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
348 This variable's value takes effect when `grep-compute-defaults' is called.")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
349
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
350 ;; History of grep commands.
|
56333
|
351 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
352 (defvar grep-history nil)
|
56333
|
353 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
354 (defvar grep-find-history nil)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
355
|
70258
|
356 ;; History of lgrep and rgrep regexp and files args.
|
|
357 (defvar grep-regexp-history nil)
|
|
358 (defvar grep-files-history '("ch" "el"))
|
|
359
|
81972
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
360 (defvar grep-host-defaults-alist nil
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
361 "Default values depending on target host.
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
362 `grep-compute-defaults' returns default values for every local or
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
363 remote host `grep' runs. These values can differ from host to
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
364 host. Once computed, the default values are kept here in order
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
365 to avoid computing them again.")
|
70258
|
366
|
56333
|
367 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
368 (defun grep-process-setup ()
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
369 "Setup compilation variables and buffer for `grep'.
|
54372
|
370 Set up `compilation-exit-message-function' and run `grep-setup-hook'."
|
56960
|
371 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
|
|
372 (grep-compute-defaults))
|
|
373 (when (eq grep-highlight-matches t)
|
86354
|
374 ;; `setenv' modifies `process-environment' let-bound in `compilation-start'
|
|
375 ;; Any TERM except "dumb" allows GNU grep to use `--color=auto'
|
|
376 (setenv "TERM" "emacs-grep")
|
|
377 ;; `--color=auto' emits escape sequences on a tty rather than on a pipe,
|
|
378 ;; thus allowing to use multiple grep filters on the command line
|
|
379 ;; and to output escape sequences only on the final grep output
|
|
380 (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=auto"))
|
|
381 ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions
|
64509
|
382 (setenv "GREP_COLOR" "01;31")
|
86354
|
383 ;; GREP_COLORS is used in GNU grep 2.5.2 and later versions
|
64509
|
384 (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:ml=:cx=:ne"))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
385 (set (make-local-variable 'compilation-exit-message-function)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
386 (lambda (status code msg)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
387 (if (eq status 'exit)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
388 (cond ((zerop code)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
389 '("finished (matches found)\n" . "matched"))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
390 ((= code 1)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
391 '("finished with no matches found\n" . "no match"))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
392 (t
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
393 (cons msg code)))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
394 (cons msg code))))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
395 (run-hooks 'grep-setup-hook))
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
396
|
70258
|
397 (defun grep-probe (command args &optional func result)
|
|
398 (equal (condition-case nil
|
81936
|
399 (apply (or func 'process-file) command args)
|
70258
|
400 (error nil))
|
|
401 (or result 0)))
|
|
402
|
56333
|
403 ;;;###autoload
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
404 (defun grep-compute-defaults ()
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
405 ;; Keep default values.
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
406 (unless grep-host-defaults-alist
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
407 (add-to-list
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
408 'grep-host-defaults-alist
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
409 (cons nil
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
410 `((grep-command ,grep-command)
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
411 (grep-template ,grep-template)
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
412 (grep-use-null-device ,grep-use-null-device)
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
413 (grep-find-command ,grep-find-command)
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
414 (grep-find-template ,grep-find-template)
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
415 (grep-find-use-xargs ,grep-find-use-xargs)
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
416 (grep-highlight-matches ,grep-highlight-matches)))))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
417 (let* ((host-id
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
418 (intern (or (file-remote-p default-directory 'host) "localhost")))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
419 (host-defaults (assq host-id grep-host-defaults-alist))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
420 (defaults (assq nil grep-host-defaults-alist)))
|
81936
|
421 ;; There are different defaults on different hosts. They must be
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
422 ;; computed for every host once.
|
81936
|
423 (setq grep-command
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
424 (or (cadr (assq 'grep-command host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
425 (cadr (assq 'grep-command defaults)))
|
81936
|
426
|
|
427 grep-template
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
428 (or (cadr (assq 'grep-template host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
429 (cadr (assq 'grep-template defaults)))
|
81936
|
430
|
|
431 grep-use-null-device
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
432 (or (cadr (assq 'grep-use-null-device host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
433 (cadr (assq 'grep-use-null-device defaults)))
|
81936
|
434
|
|
435 grep-find-command
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
436 (or (cadr (assq 'grep-find-command host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
437 (cadr (assq 'grep-find-command defaults)))
|
81936
|
438
|
|
439 grep-find-template
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
440 (or (cadr (assq 'grep-find-template host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
441 (cadr (assq 'grep-find-template defaults)))
|
81936
|
442
|
|
443 grep-find-use-xargs
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
444 (or (cadr (assq 'grep-find-use-xargs host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
445 (cadr (assq 'grep-find-use-xargs defaults)))
|
81936
|
446
|
|
447 grep-highlight-matches
|
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
448 (or (cadr (assq 'grep-highlight-matches host-defaults))
|
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
449 (cadr (assq 'grep-highlight-matches defaults))))
|
81936
|
450
|
|
451 (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
|
|
452 (setq grep-use-null-device
|
|
453 (with-temp-buffer
|
|
454 (let ((hello-file (expand-file-name "HELLO" data-directory)))
|
|
455 (not
|
|
456 (and (if grep-command
|
|
457 ;; `grep-command' is already set, so
|
|
458 ;; use that for testing.
|
|
459 (grep-probe grep-command
|
|
460 `(nil t nil "^English" ,hello-file)
|
|
461 #'call-process-shell-command)
|
|
462 ;; otherwise use `grep-program'
|
|
463 (grep-probe grep-program
|
|
464 `(nil t nil "-nH" "^English" ,hello-file)))
|
|
465 (progn
|
|
466 (goto-char (point-min))
|
|
467 (looking-at
|
|
468 (concat (regexp-quote hello-file)
|
|
469 ":[0-9]+:English")))))))))
|
|
470 (unless (and grep-command grep-find-command
|
|
471 grep-template grep-find-template)
|
|
472 (let ((grep-options
|
|
473 (concat (if grep-use-null-device "-n" "-nH")
|
|
474 (if (grep-probe grep-program
|
|
475 `(nil nil nil "-e" "foo" ,null-device)
|
|
476 nil 1)
|
|
477 " -e"))))
|
|
478 (unless grep-command
|
|
479 (setq grep-command
|
|
480 (format "%s %s " grep-program grep-options)))
|
|
481 (unless grep-template
|
|
482 (setq grep-template
|
|
483 (format "%s <C> %s <R> <F>" grep-program grep-options)))
|
|
484 (unless grep-find-use-xargs
|
|
485 (setq grep-find-use-xargs
|
|
486 (cond
|
|
487 ((and
|
|
488 (grep-probe find-program `(nil nil nil ,null-device "-print0"))
|
86249
|
489 (grep-probe xargs-program `(nil nil nil "-0" "-e" "echo")))
|
81936
|
490 'gnu)
|
|
491 (t
|
|
492 'exec))))
|
|
493 (unless grep-find-command
|
|
494 (setq grep-find-command
|
70258
|
495 (cond ((eq grep-find-use-xargs 'gnu)
|
86249
|
496 (format "%s . -type f -print0 | %s -0 -e %s"
|
|
497 find-program xargs-program grep-command))
|
72500
|
498 ((eq grep-find-use-xargs 'exec)
|
81936
|
499 (let ((cmd0 (format "%s . -type f -exec %s"
|
|
500 find-program grep-command)))
|
|
501 (cons
|
|
502 (format "%s {} %s %s"
|
|
503 cmd0 null-device
|
|
504 (shell-quote-argument ";"))
|
|
505 (1+ (length cmd0)))))
|
72500
|
506 (t
|
86249
|
507 (format "%s . -type f -print | %s %s"
|
|
508 find-program xargs-program grep-command)))))
|
81936
|
509 (unless grep-find-template
|
|
510 (setq grep-find-template
|
|
511 (let ((gcmd (format "%s <C> %s <R>"
|
|
512 grep-program grep-options)))
|
|
513 (cond ((eq grep-find-use-xargs 'gnu)
|
86249
|
514 (format "%s . <X> -type f <F> -print0 | %s -0 -e %s"
|
|
515 find-program xargs-program gcmd))
|
81936
|
516 ((eq grep-find-use-xargs 'exec)
|
|
517 (format "%s . <X> -type f <F> -exec %s {} %s %s"
|
|
518 find-program gcmd null-device
|
|
519 (shell-quote-argument ";")))
|
|
520 (t
|
86249
|
521 (format "%s . <X> -type f <F> -print | %s %s"
|
|
522 find-program xargs-program gcmd))))))))
|
81936
|
523 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
|
|
524 (setq grep-highlight-matches
|
|
525 (with-temp-buffer
|
|
526 (and (grep-probe grep-program '(nil t nil "--help"))
|
|
527 (progn
|
|
528 (goto-char (point-min))
|
|
529 (search-forward "--color" nil t))
|
|
530 t))))
|
|
531
|
|
532 ;; Save defaults for this host.
|
81972
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
533 (setq grep-host-defaults-alist
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
534 (delete (assq host-id grep-host-defaults-alist)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
535 grep-host-defaults-alist))
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
536 (add-to-list
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
537 'grep-host-defaults-alist
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
538 (cons host-id
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
539 `((grep-command ,grep-command)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
540 (grep-template ,grep-template)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
541 (grep-use-null-device ,grep-use-null-device)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
542 (grep-find-command ,grep-find-command)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
543 (grep-find-template ,grep-find-template)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
544 (grep-find-use-xargs ,grep-find-use-xargs)
|
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
diff
changeset
|
545 (grep-highlight-matches ,grep-highlight-matches))))))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
546
|
72163
|
547 (defun grep-tag-default ()
|
|
548 (or (and transient-mark-mode mark-active
|
|
549 (/= (point) (mark))
|
|
550 (buffer-substring-no-properties (point) (mark)))
|
|
551 (funcall (or find-tag-default-function
|
|
552 (get major-mode 'find-tag-default-function)
|
|
553 'find-tag-default))
|
|
554 ""))
|
|
555
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
556 (defun grep-default-command ()
|
86249
|
557 "Compute the default grep command for \\[universal-argument] \\[grep] to offer."
|
72163
|
558 (let ((tag-default (shell-quote-argument (grep-tag-default)))
|
72173
|
559 ;; This a regexp to match single shell arguments.
|
|
560 ;; Could someone please add comments explaining it?
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
561 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
562 (grep-default (or (car grep-history) grep-command)))
|
72173
|
563 ;; In the default command, find the arg that specifies the pattern.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
564 (when (or (string-match
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
565 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
566 sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
567 grep-default)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
568 ;; If the string is not yet complete.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
569 (string-match "\\(\\)\\'" grep-default))
|
72173
|
570 ;; Maybe we will replace the pattern with the default tag.
|
|
571 ;; But first, maybe replace the file name pattern.
|
|
572 (condition-case nil
|
|
573 (unless (or (not (stringp buffer-file-name))
|
|
574 (when (match-beginning 2)
|
|
575 (save-match-data
|
|
576 (string-match
|
|
577 (wildcard-to-regexp
|
|
578 (file-name-nondirectory
|
|
579 (match-string 3 grep-default)))
|
|
580 (file-name-nondirectory buffer-file-name)))))
|
|
581 (setq grep-default (concat (substring grep-default
|
|
582 0 (match-beginning 2))
|
|
583 " *."
|
|
584 (file-name-extension buffer-file-name))))
|
|
585 ;; In case wildcard-to-regexp gets an error
|
|
586 ;; from invalid data.
|
|
587 (error nil))
|
|
588 ;; Now replace the pattern with the default tag.
|
57908
|
589 (replace-match tag-default t t grep-default 1))))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
590
|
54372
|
591
|
64509
|
592 ;;;###autoload
|
55018
|
593 (define-compilation-mode grep-mode "Grep"
|
|
594 "Sets `grep-last-buffer' and `compilation-window-height'."
|
|
595 (setq grep-last-buffer (current-buffer))
|
|
596 (set (make-local-variable 'compilation-error-face)
|
|
597 grep-hit-face)
|
|
598 (set (make-local-variable 'compilation-error-regexp-alist)
|
63576
|
599 grep-regexp-alist)
|
65126
|
600 (set (make-local-variable 'compilation-process-setup-function)
|
|
601 'grep-process-setup)
|
69499
caf8f09897bc
* font-lock.el (font-lock-lines-before): Delete variable, subsumed by
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
602 (set (make-local-variable 'compilation-disable-input) t))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
603
|
70258
|
604
|
|
605 ;;;###autoload
|
|
606 (defun grep (command-args)
|
|
607 "Run grep, with user-specified args, and collect output in a buffer.
|
|
608 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
|
|
609 or \\<grep-mode-map>\\[compile-goto-error] in the grep \
|
86249
|
610 output buffer, to go to the lines where grep
|
|
611 found matches.
|
70258
|
612
|
75803
|
613 For doing a recursive `grep', see the `rgrep' command. For running
|
75877
|
614 `grep' in a specific directory, see `lgrep'.
|
75803
|
615
|
86249
|
616 This command uses a special history list for its COMMAND-ARGS, so you
|
|
617 can easily repeat a grep command.
|
70258
|
618
|
|
619 A prefix argument says to default the argument based upon the current
|
|
620 tag the cursor is over, substituting it into the last grep command
|
86249
|
621 in the grep command history (or into `grep-command' if that history
|
|
622 list is empty)."
|
70258
|
623 (interactive
|
|
624 (progn
|
|
625 (grep-compute-defaults)
|
|
626 (let ((default (grep-default-command)))
|
|
627 (list (read-from-minibuffer "Run grep (like this): "
|
|
628 (if current-prefix-arg
|
|
629 default grep-command)
|
|
630 nil nil 'grep-history
|
|
631 (if current-prefix-arg nil default))))))
|
|
632
|
|
633 ;; Setting process-setup-function makes exit-message-function work
|
|
634 ;; even when async processes aren't supported.
|
|
635 (compilation-start (if (and grep-use-null-device null-device)
|
|
636 (concat command-args " " null-device)
|
|
637 command-args)
|
|
638 'grep-mode))
|
|
639
|
|
640
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
641 ;;;###autoload
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
642 (defun grep-find (command-args)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
643 "Run grep via find, with user-specified args COMMAND-ARGS.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
644 Collect output in a buffer.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
645 While find runs asynchronously, you can use the \\[next-error] command
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
646 to find the text that grep hits refer to.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
647
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
648 This command uses a special history list for its arguments, so you can
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
649 easily repeat a find command."
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
650 (interactive
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
651 (progn
|
70258
|
652 (grep-compute-defaults)
|
53750
|
653 (if grep-find-command
|
|
654 (list (read-from-minibuffer "Run find (like this): "
|
|
655 grep-find-command nil nil
|
|
656 'grep-find-history))
|
|
657 ;; No default was set
|
|
658 (read-string
|
|
659 "compile.el: No `grep-find-command' command available. Press RET.")
|
|
660 (list nil))))
|
70712
|
661 (when command-args
|
53750
|
662 (let ((null-device nil)) ; see grep
|
|
663 (grep command-args))))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
664
|
59688
|
665 ;;;###autoload
|
|
666 (defalias 'find-grep 'grep-find)
|
|
667
|
70258
|
668
|
|
669 ;; User-friendly interactive API.
|
|
670
|
|
671 (defconst grep-expand-keywords
|
|
672 '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i"))
|
|
673 ("<D>" . dir)
|
|
674 ("<F>" . files)
|
|
675 ("<N>" . null-device)
|
|
676 ("<X>" . excl)
|
|
677 ("<R>" . (shell-quote-argument (or regexp ""))))
|
|
678 "List of substitutions performed by `grep-expand-template'.
|
|
679 If car of an element matches, the cdr is evalled in to get the
|
|
680 substitution string. Note dynamic scoping of variables.")
|
|
681
|
|
682 (defun grep-expand-template (template &optional regexp files dir excl)
|
|
683 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
|
|
684 (let ((command template)
|
|
685 (cf case-fold-search)
|
|
686 (case-fold-search nil))
|
|
687 (dolist (kw grep-expand-keywords command)
|
|
688 (if (string-match (car kw) command)
|
70315
|
689 (setq command
|
|
690 (replace-match
|
|
691 (or (if (symbolp (cdr kw))
|
70340
|
692 (symbol-value (cdr kw))
|
70315
|
693 (save-match-data (eval (cdr kw))))
|
|
694 "")
|
|
695 t t command))))))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
696
|
70258
|
697 (defun grep-read-regexp ()
|
|
698 "Read regexp arg for interactive grep."
|
72163
|
699 (let ((default (grep-tag-default)))
|
70258
|
700 (read-string
|
|
701 (concat "Search for"
|
|
702 (if (and default (> (length default) 0))
|
72163
|
703 (format " (default \"%s\"): " default) ": "))
|
70258
|
704 nil 'grep-regexp-history default)))
|
|
705
|
|
706 (defun grep-read-files (regexp)
|
|
707 "Read files arg for interactive grep."
|
70259
|
708 (let* ((bn (or (buffer-file-name) (buffer-name)))
|
|
709 (fn (and bn
|
|
710 (stringp bn)
|
|
711 (file-name-nondirectory bn)))
|
|
712 (default
|
|
713 (or (and fn
|
|
714 (let ((aliases grep-files-aliases)
|
70258
|
715 alias)
|
|
716 (while aliases
|
|
717 (setq alias (car aliases)
|
|
718 aliases (cdr aliases))
|
|
719 (if (string-match (wildcard-to-regexp (cdr alias)) fn)
|
|
720 (setq aliases nil)
|
|
721 (setq alias nil)))
|
|
722 (cdr alias)))
|
70259
|
723 (and fn
|
|
724 (let ((ext (file-name-extension fn)))
|
72165
301cc56a3482
(grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
diff
changeset
|
725 (and ext (concat "*." ext))))
|
301cc56a3482
(grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
diff
changeset
|
726 (car grep-files-history)
|
301cc56a3482
(grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
diff
changeset
|
727 (car (car grep-files-aliases))))
|
70258
|
728 (files (read-string
|
|
729 (concat "Search for \"" regexp
|
70259
|
730 "\" in files"
|
|
731 (if default (concat " (default " default ")"))
|
|
732 ": ")
|
70258
|
733 nil 'grep-files-history default)))
|
|
734 (and files
|
|
735 (or (cdr (assoc files grep-files-aliases))
|
|
736 files))))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
737
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
738 ;;;###autoload
|
75877
|
739 (defun lgrep (regexp &optional files dir)
|
|
740 "Run grep, searching for REGEXP in FILES in directory DIR.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
741 The search is limited to file names matching shell pattern FILES.
|
70258
|
742 FILES may use abbreviations defined in `grep-files-aliases', e.g.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
743 entering `ch' is equivalent to `*.[ch]'.
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
744
|
70526
|
745 With \\[universal-argument] prefix, you can edit the constructed shell command line
|
|
746 before it is executed.
|
|
747 With two \\[universal-argument] prefixes, directly edit and run `grep-command'.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
748
|
70258
|
749 Collect output in a buffer. While grep runs asynchronously, you
|
86249
|
750 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \
|
|
751 in the grep output buffer,
|
|
752 to go to the lines where grep found matches.
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
753
|
70258
|
754 This command shares argument histories with \\[rgrep] and \\[grep]."
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
755 (interactive
|
70258
|
756 (progn
|
|
757 (grep-compute-defaults)
|
|
758 (cond
|
|
759 ((and grep-command (equal current-prefix-arg '(16)))
|
|
760 (list (read-from-minibuffer "Run: " grep-command
|
|
761 nil nil 'grep-history)
|
|
762 nil))
|
|
763 ((not grep-template)
|
|
764 (list nil
|
|
765 (read-string "grep.el: No `grep-template' available. Press RET.")))
|
|
766 (t (let* ((regexp (grep-read-regexp))
|
75877
|
767 (files (grep-read-files regexp))
|
|
768 (dir (read-directory-name "In directory: "
|
|
769 nil default-directory t)))
|
|
770 (list regexp files dir))))))
|
70258
|
771 (when (and (stringp regexp) (> (length regexp) 0))
|
|
772 (let ((command regexp))
|
|
773 (if (null files)
|
|
774 (if (string= command grep-command)
|
|
775 (setq command nil))
|
75877
|
776 (setq dir (file-name-as-directory (expand-file-name dir)))
|
70258
|
777 (setq command (grep-expand-template
|
|
778 grep-template
|
|
779 regexp
|
|
780 files))
|
|
781 (when command
|
|
782 (if (equal current-prefix-arg '(4))
|
|
783 (setq command
|
|
784 (read-from-minibuffer "Confirm: "
|
|
785 command nil nil 'grep-history))
|
70421
|
786 (add-to-history 'grep-history command))))
|
70258
|
787 (when command
|
75877
|
788 (let ((default-directory dir))
|
|
789 ;; Setting process-setup-function makes exit-message-function work
|
|
790 ;; even when async processes aren't supported.
|
|
791 (compilation-start (if (and grep-use-null-device null-device)
|
|
792 (concat command " " null-device)
|
82421
|
793 command)
|
|
794 'grep-mode))
|
75877
|
795 (if (eq next-error-last-buffer (current-buffer))
|
|
796 (setq default-directory dir))))))
|
|
797
|
70258
|
798
|
|
799
|
|
800 ;;;###autoload
|
|
801 (defun rgrep (regexp &optional files dir)
|
70526
|
802 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
|
70258
|
803 The search is limited to file names matching shell pattern FILES.
|
|
804 FILES may use abbreviations defined in `grep-files-aliases', e.g.
|
|
805 entering `ch' is equivalent to `*.[ch]'.
|
|
806
|
70526
|
807 With \\[universal-argument] prefix, you can edit the constructed shell command line
|
|
808 before it is executed.
|
|
809 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'.
|
70258
|
810
|
|
811 Collect output in a buffer. While find runs asynchronously, you
|
86249
|
812 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \
|
|
813 in the grep output buffer,
|
|
814 to go to the lines where grep found matches.
|
70258
|
815
|
|
816 This command shares argument histories with \\[lgrep] and \\[grep-find]."
|
|
817 (interactive
|
|
818 (progn
|
|
819 (grep-compute-defaults)
|
|
820 (cond
|
|
821 ((and grep-find-command (equal current-prefix-arg '(16)))
|
|
822 (list (read-from-minibuffer "Run: " grep-find-command
|
|
823 nil nil 'grep-find-history)
|
|
824 nil))
|
|
825 ((not grep-find-template)
|
|
826 (list nil nil
|
|
827 (read-string "grep.el: No `grep-find-template' available. Press RET.")))
|
|
828 (t (let* ((regexp (grep-read-regexp))
|
|
829 (files (grep-read-files regexp))
|
|
830 (dir (read-directory-name "Base directory: "
|
|
831 nil default-directory t)))
|
|
832 (list regexp files dir))))))
|
|
833 (when (and (stringp regexp) (> (length regexp) 0))
|
|
834 (if (null files)
|
|
835 (if (not (string= regexp grep-find-command))
|
|
836 (compilation-start regexp 'grep-mode))
|
70534
|
837 (setq dir (file-name-as-directory (expand-file-name dir)))
|
|
838 (let ((command (grep-expand-template
|
|
839 grep-find-template
|
|
840 regexp
|
72500
|
841 (concat (shell-quote-argument "(")
|
|
842 " -name "
|
70534
|
843 (mapconcat #'shell-quote-argument
|
|
844 (split-string files)
|
|
845 " -o -name ")
|
72500
|
846 " "
|
|
847 (shell-quote-argument ")"))
|
70534
|
848 dir
|
70258
|
849 (and grep-find-ignored-directories
|
72500
|
850 (concat (shell-quote-argument "(")
|
|
851 ;; we should use shell-quote-argument here
|
|
852 " -path "
|
|
853 (mapconcat #'(lambda (dir)
|
|
854 (shell-quote-argument
|
|
855 (concat "*/" dir)))
|
70258
|
856 grep-find-ignored-directories
|
72500
|
857 " -o -path ")
|
|
858 " "
|
|
859 (shell-quote-argument ")")
|
|
860 " -prune -o ")))))
|
70258
|
861 (when command
|
|
862 (if current-prefix-arg
|
|
863 (setq command
|
|
864 (read-from-minibuffer "Confirm: "
|
|
865 command nil nil 'grep-find-history))
|
70421
|
866 (add-to-history 'grep-find-history command))
|
70534
|
867 (let ((default-directory dir))
|
|
868 (compilation-start command 'grep-mode))
|
|
869 ;; Set default-directory if we started rgrep in the *grep* buffer.
|
|
870 (if (eq next-error-last-buffer (current-buffer))
|
|
871 (setq default-directory dir)))))))
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
872
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
873
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
874 (provide 'grep)
|
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
875
|
57043
|
876 ;; arch-tag: 5a5b9169-a79d-4f38-9c38-f69615f39c4d
|
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
877 ;;; grep.el ends here
|