Mercurial > emacs
annotate lisp/progmodes/grep.el @ 71474:14d585ea5e05
(Top): Update the detailed menu according to changes in msdog.texi.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 24 Jun 2006 17:23:14 +0000 |
parents | 2611669abf9e |
children | a4944423be59 138ce2701550 |
rev | line source |
---|---|
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
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
68773
dc49655f57ae
Update copyright for 2006.
Nick Roberts <nickrob@snap.net.nz>
parents:
65232
diff
changeset
|
4 ;; 2001, 2002, 2003, 2004, 2005, 2006 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 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
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
6b7109ed93a0
(font-lock-lines-before): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
65126
diff
changeset
|
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
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
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
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
51 (defcustom grep-highlight-matches 'auto-detect |
56960
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
52 "If t, use special markers to highlight grep matches. |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
53 |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
54 Some grep programs are able to surround matches with special |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
55 markers in grep output. Such markers can be used to highlight |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
56 matches in grep mode. |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
57 |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
58 This option sets the environment variable GREP_COLOR to specify |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
59 markers for highlighting and GREP_OPTIONS to add the --color |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
60 option in front of any explicit grep options before starting |
56960
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
61 the grep. |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
62 |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
63 The default value of this variable is set up by `grep-compute-defaults'; |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
64 call that function before using this variable in your program." |
56948
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
65 :type '(choice (const :tag "Do not highlight matches with grep markers" nil) |
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
66 (const :tag "Highlight matches with grep markers" t) |
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
67 (other :tag "Not Set" auto-detect)) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
68 :version "22.1" |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
69 :group 'grep) |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
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
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
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
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
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
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
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
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
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 |
70258 | 145 (defcustom grep-files-aliases '( |
146 ("el" . "*.el") | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
147 ("ch" . "*.[ch]") |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
148 ("c" . "*.c") |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
149 ("h" . "*.h") |
70258 | 150 ("asm" . "*.[sS]") |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
151 ("m" . "[Mm]akefile*") |
70258 | 152 ("l" . "[Cc]hange[Ll]og*") |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
153 ) |
70258 | 154 "*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
|
155 :type 'alist |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
156 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
157 |
70258 | 158 (defcustom grep-find-ignored-directories '("CVS" ".hg" "{arch}") |
159 "*List of names of sub-directories which `rgrep' shall not recurse into." | |
160 :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
|
161 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
162 |
56226
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
163 (defcustom grep-error-screen-columns nil |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
164 "*If non-nil, column numbers in grep hits are screen columns. |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
165 See `compilation-error-screen-columns'" |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
166 :type '(choice (const :tag "Default" nil) |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
167 integer) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
168 :version "22.1" |
56226
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
169 :group 'grep) |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
170 |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
171 ;;;###autoload |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
172 (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
|
173 "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
|
174 :type 'hook |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
175 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
176 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
177 (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
|
178 (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
|
179 (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
|
180 (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>
parents:
56998
diff
changeset
|
181 (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
|
182 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
183 (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
|
184 (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
|
185 (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
|
186 (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
|
187 (define-key map "}" 'compilation-next-file) |
64728
c1b77e79c51a
(grep-mode-map): Bind TAB to `compilation-next-error'
Juri Linkov <juri@jurta.org>
parents:
64725
diff
changeset
|
188 (define-key map "\t" 'compilation-next-error) |
c1b77e79c51a
(grep-mode-map): Bind TAB to `compilation-next-error'
Juri Linkov <juri@jurta.org>
parents:
64725
diff
changeset
|
189 (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
|
190 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
191 ;; 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
|
192 (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
|
193 (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
|
194 |
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 [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
|
196 '("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
|
197 (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
|
198 '("----" . nil)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
199 (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
|
200 '("Compile..." . compile)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
201 (define-key map [menu-bar grep compilation-grep] |
64944
c845f6151d83
(grep-mode-map): Add ellipsis to "Another grep".
Juri Linkov <juri@jurta.org>
parents:
64864
diff
changeset
|
202 '("Another grep..." . grep)) |
70258 | 203 (define-key map [menu-bar grep compilation-grep-find] |
204 '("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
|
205 (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
|
206 '("Repeat grep" . recompile)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
207 (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
|
208 '("----" . nil)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
209 (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
|
210 '("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
|
211 (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
|
212 '("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
|
213 (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
|
214 '("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
|
215 map) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
216 "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
|
217 `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
|
218 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
219 (defalias 'kill-grep 'kill-compilation) |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
220 |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
221 ;;;; TODO --- refine this!! |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
222 |
53145
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
223 ;;; (defcustom grep-use-compilation-buffer t |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
224 ;;; "When non-nil, grep specific commands update `compilation-last-buffer'. |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
225 ;;; This means that standard compile commands like \\[next-error] and \\[compile-goto-error] |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
226 ;;; can be used to navigate between grep matches (the default). |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
227 ;;; Otherwise, the grep specific commands like \\[grep-next-match] must |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
228 ;;; be used to navigate between grep matches." |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
229 ;;; :type 'boolean |
a0151f86f01e
Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents:
53139
diff
changeset
|
230 ;;; :group 'grep) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
231 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
232 ;; 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
|
233 (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
|
234 "The most recent grep buffer. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
235 A grep buffer becomes most recent when its process is started |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
236 or when it is used with \\[grep-next-match]. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
237 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
|
238 `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
|
239 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
240 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
241 (defvar grep-regexp-alist |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
242 '(("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2" |
64725
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
243 1 3) |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
244 ;; Rule to match column numbers is commented out since no known grep |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
245 ;; produces them |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
246 ;; ("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2\\(?:\\([0-9]+\\)\\(?:-\\([0-9]+\\)\\)?\\2\\)?" |
64725
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
247 ;; 1 3 (4 . 5)) |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
248 ("^\\(\\(.+?\\):\\([0-9]+\\):\\).*?\ |
64509 | 249 \\(\033\\[01;31m\\(?:\033\\[K\\)?\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)" |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
250 2 3 |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
251 ;; Calculate column positions (beg . end) of first grep match on a line |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
252 ((lambda () |
64509 | 253 (setq compilation-error-screen-columns nil) |
254 (- (match-beginning 4) (match-end 1))) | |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
255 . |
64509 | 256 (lambda () (- (match-end 5) (match-end 1) |
257 (- (match-end 4) (match-beginning 4))))) | |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
258 nil 1) |
64740
eeed7a7c1afa
(grep-regexp-alist): Set 5th arg `TYPE' to
Juri Linkov <juri@jurta.org>
parents:
64728
diff
changeset
|
259 ("^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
|
260 "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
|
261 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
262 (defvar grep-error "grep hit" |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
263 "Message to print when no matches are found.") |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
264 |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
265 ;; Reverse the colors because grep hits are not errors (though we jump there |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
266 ;; with `next-error'), and unreadable files can't be gone to. |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
267 (defvar grep-hit-face compilation-info-face |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
268 "Face name to use for grep hits.") |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
269 |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
270 (defvar grep-error-face 'compilation-error |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
271 "Face name to use for grep error messages.") |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
272 |
58988
067d5dcfe531
(grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents:
58493
diff
changeset
|
273 (defvar grep-match-face 'match |
067d5dcfe531
(grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents:
58493
diff
changeset
|
274 "Face name to use for grep matches.") |
067d5dcfe531
(grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents:
58493
diff
changeset
|
275 |
64725
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
276 (defvar grep-context-face 'shadow |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
277 "Face name to use for grep context lines.") |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
278 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
279 (defvar grep-mode-font-lock-keywords |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
280 '(;; Command output lines. |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
281 ("^\\([A-Za-z_0-9/\.+-]+\\)[ \t]*:" 1 font-lock-function-name-face) |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
282 (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$" |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
283 1 grep-error-face) |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
284 ;; remove match from grep-regexp-alist before fontifying |
71422
2611669abf9e
(grep-mode-font-lock-keywords): Correct regexps
Kim F. Storm <storm@cua.dk>
parents:
70712
diff
changeset
|
285 ("^Grep[/a-zA-z]* started.*" |
65126
559a37c2f306
(grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents:
65056
diff
changeset
|
286 (0 '(face nil message nil help-echo nil mouse-face nil) t)) |
71422
2611669abf9e
(grep-mode-font-lock-keywords): Correct regexps
Kim F. Storm <storm@cua.dk>
parents:
70712
diff
changeset
|
287 ("^Grep[/a-zA-z]* finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*" |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
288 (0 '(face nil message nil help-echo nil mouse-face nil) t) |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
289 (1 compilation-info-face nil t) |
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
290 (2 compilation-warning-face nil t)) |
71422
2611669abf9e
(grep-mode-font-lock-keywords): Correct regexps
Kim F. Storm <storm@cua.dk>
parents:
70712
diff
changeset
|
291 ("^Grep[/a-zA-z]* \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?.*" |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
292 (0 '(face nil message nil help-echo nil mouse-face nil) t) |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
293 (1 grep-error-face) |
64944
c845f6151d83
(grep-mode-map): Add ellipsis to "Another grep".
Juri Linkov <juri@jurta.org>
parents:
64864
diff
changeset
|
294 (2 grep-error-face nil t)) |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
295 ("^.+?-[0-9]+-.*\n" (0 grep-context-face)) |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
296 ;; Highlight grep matches and delete markers |
64509 | 297 ("\\(\033\\[01;31m\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)" |
61902
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
298 ;; Refontification does not work after the markers have been |
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
299 ;; deleted. So we use the font-lock-face property here as Font |
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
300 ;; Lock does not clear that. |
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
301 (2 (list 'face nil 'font-lock-face grep-match-face)) |
64509 | 302 ((lambda (bound)) |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
303 (progn |
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
304 ;; Delete markers with `replace-match' because it updates |
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
305 ;; the match-data, whereas `delete-region' would render it obsolete. |
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
306 (replace-match "" t t nil 3) |
64509 | 307 (replace-match "" t t nil 1)))) |
308 ("\\(\033\\[[0-9;]*[mK]\\)" | |
309 ;; Delete all remaining escape sequences | |
310 ((lambda (bound)) | |
311 (replace-match "" t t nil 1)))) | |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
312 "Additional things to highlight in grep output. |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
313 This gets tacked on the end of the generated expressions.") |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
314 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
315 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
316 (defvar grep-program |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
317 ;; Currently zgrep has trouble. It runs egrep instead of grep, |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
318 ;; and it doesn't pass along long options right. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
319 "grep" |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
320 ;; (if (equal (condition-case nil ; in case "zgrep" isn't in exec-path |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
321 ;; (call-process "zgrep" nil nil nil |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
322 ;; "foo" null-device) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
323 ;; (error nil)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
324 ;; 1) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
325 ;; "zgrep" |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
326 ;; "grep") |
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
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
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
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
335 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
336 (defvar grep-find-use-xargs nil |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
337 "Whether \\[grep-find] uses the `xargs' utility by default. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
338 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
339 If nil, it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0'; |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
340 if not nil and not `gnu', it uses `find -print' and `xargs'. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
341 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
342 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
|
343 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
344 ;; History of grep commands. |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
345 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
346 (defvar grep-history nil) |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
347 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
348 (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
|
349 |
70258 | 350 ;; History of lgrep and rgrep regexp and files args. |
351 (defvar grep-regexp-history nil) | |
352 (defvar grep-files-history '("ch" "el")) | |
353 | |
354 | |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
355 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
356 (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
|
357 "Setup compilation variables and buffer for `grep'. |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
358 Set up `compilation-exit-message-function' and run `grep-setup-hook'." |
56960
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
359 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
360 (grep-compute-defaults)) |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
361 (when (eq grep-highlight-matches t) |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
362 ;; Modify `process-environment' locally bound in `compilation-start' |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
363 (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always")) |
64509 | 364 ;; for GNU grep 2.5.1 |
365 (setenv "GREP_COLOR" "01;31") | |
366 ;; for GNU grep 2.5.1-cvs | |
367 (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
|
368 (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
|
369 (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
|
370 (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
|
371 (cond ((zerop code) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
372 '("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
|
373 ((= code 1) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
374 '("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
|
375 (t |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
376 (cons msg code))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
377 (cons msg code)))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
378 (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
|
379 |
70258 | 380 (defun grep-probe (command args &optional func result) |
381 (equal (condition-case nil | |
382 (apply (or func 'call-process) command args) | |
383 (error nil)) | |
384 (or result 0))) | |
385 | |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
386 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
387 (defun grep-compute-defaults () |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
388 (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
389 (setq grep-use-null-device |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
390 (with-temp-buffer |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
391 (let ((hello-file (expand-file-name "HELLO" data-directory))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
392 (not |
70258 | 393 (and (if grep-command |
394 ;; `grep-command' is already set, so | |
395 ;; use that for testing. | |
396 (grep-probe grep-command | |
397 `(nil t nil "^English" ,hello-file) | |
398 #'call-process-shell-command) | |
399 ;; otherwise use `grep-program' | |
400 (grep-probe grep-program | |
401 `(nil t nil "-nH" "^English" ,hello-file))) | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
402 (progn |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
403 (goto-char (point-min)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
404 (looking-at |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
405 (concat (regexp-quote hello-file) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
406 ":[0-9]+:English"))))))))) |
70258 | 407 (unless (and grep-command grep-find-command |
408 grep-template grep-find-template) | |
409 (let ((grep-options | |
410 (concat (if grep-use-null-device "-n" "-nH") | |
411 (if (grep-probe grep-program | |
412 `(nil nil nil "-e" "foo" ,null-device) | |
413 nil 1) | |
414 " -e")))) | |
415 (unless grep-command | |
416 (setq grep-command | |
417 (format "%s %s " grep-program grep-options))) | |
418 (unless grep-template | |
419 (setq grep-template | |
420 (format "%s <C> %s <R> <F>" grep-program grep-options))) | |
421 (unless grep-find-use-xargs | |
422 (setq grep-find-use-xargs | |
423 (if (and | |
424 (grep-probe find-program `(nil nil nil ,null-device "-print0")) | |
425 (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo"))) | |
426 'gnu))) | |
427 (unless grep-find-command | |
428 (setq grep-find-command | |
429 (cond ((eq grep-find-use-xargs 'gnu) | |
430 (format "%s . -type f -print0 | xargs -0 -e %s" | |
431 find-program grep-command)) | |
432 (grep-find-use-xargs | |
433 (format "%s . -type f -print | xargs %s" | |
434 find-program grep-command)) | |
435 (t (cons (format "%s . -type f -exec %s {} %s \\;" | |
436 find-program grep-command null-device) | |
437 (+ 22 (length grep-command))))))) | |
438 (unless grep-find-template | |
439 (setq grep-find-template | |
440 (let ((gcmd (format "%s <C> %s <R>" | |
441 grep-program grep-options))) | |
442 (cond ((eq grep-find-use-xargs 'gnu) | |
443 (format "%s . <X> -type f <F> -print0 | xargs -0 -e %s" | |
444 find-program gcmd)) | |
445 (grep-find-use-xargs | |
446 (format "%s . <X> -type f <F> -print | xargs %s" | |
447 find-program gcmd)) | |
448 (t (format "%s . <X> -type f <F> -exec %s {} %s \\;" | |
449 find-program gcmd null-device)))))))) | |
56948
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
450 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) |
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
451 (setq grep-highlight-matches |
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
452 (with-temp-buffer |
70258 | 453 (and (grep-probe grep-program '(nil t nil "--help")) |
56960
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
454 (progn |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
455 (goto-char (point-min)) |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
456 (search-forward "--color" nil t)) |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
457 t))))) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
458 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
459 (defun grep-default-command () |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
460 (let ((tag-default |
57908
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
461 (shell-quote-argument |
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
462 (or (funcall (or find-tag-default-function |
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
463 (get major-mode 'find-tag-default-function) |
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
464 'find-tag-default)) |
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
465 ""))) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
466 (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
|
467 (grep-default (or (car grep-history) grep-command))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
468 ;; Replace the thing matching for with that around cursor. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
469 (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
|
470 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*" |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
471 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
|
472 grep-default) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
473 ;; 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
|
474 (string-match "\\(\\)\\'" grep-default)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
475 (unless (or (not (stringp buffer-file-name)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
476 (when (match-beginning 2) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
477 (save-match-data |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
478 (string-match |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
479 (wildcard-to-regexp |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
480 (file-name-nondirectory |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
481 (match-string 3 grep-default))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
482 (file-name-nondirectory buffer-file-name))))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
483 (setq grep-default (concat (substring grep-default |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
484 0 (match-beginning 2)) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
485 " *." |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
486 (file-name-extension buffer-file-name)))) |
57908
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
487 (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
|
488 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
489 |
64509 | 490 ;;;###autoload |
55018 | 491 (define-compilation-mode grep-mode "Grep" |
492 "Sets `grep-last-buffer' and `compilation-window-height'." | |
493 (setq grep-last-buffer (current-buffer)) | |
494 (set (make-local-variable 'compilation-error-face) | |
495 grep-hit-face) | |
496 (set (make-local-variable 'compilation-error-regexp-alist) | |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
497 grep-regexp-alist) |
65126
559a37c2f306
(grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents:
65056
diff
changeset
|
498 (set (make-local-variable 'compilation-process-setup-function) |
559a37c2f306
(grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents:
65056
diff
changeset
|
499 'grep-process-setup) |
69499
caf8f09897bc
* font-lock.el (font-lock-lines-before): Delete variable, subsumed by
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
500 (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
|
501 |
70258 | 502 |
503 ;;;###autoload | |
504 (defun grep (command-args) | |
505 "Run grep, with user-specified args, and collect output in a buffer. | |
506 While grep runs asynchronously, you can use \\[next-error] (M-x next-error), | |
507 or \\<grep-mode-map>\\[compile-goto-error] in the grep \ | |
508 output buffer, to go to the lines | |
509 where grep found matches. | |
510 | |
511 This command uses a special history list for its COMMAND-ARGS, so you can | |
512 easily repeat a grep command. | |
513 | |
514 A prefix argument says to default the argument based upon the current | |
515 tag the cursor is over, substituting it into the last grep command | |
516 in the grep command history (or into `grep-command' | |
517 if that history list is empty)." | |
518 (interactive | |
519 (progn | |
520 (grep-compute-defaults) | |
521 (let ((default (grep-default-command))) | |
522 (list (read-from-minibuffer "Run grep (like this): " | |
523 (if current-prefix-arg | |
524 default grep-command) | |
525 nil nil 'grep-history | |
526 (if current-prefix-arg nil default)))))) | |
527 | |
528 ;; Setting process-setup-function makes exit-message-function work | |
529 ;; even when async processes aren't supported. | |
530 (compilation-start (if (and grep-use-null-device null-device) | |
531 (concat command-args " " null-device) | |
532 command-args) | |
533 'grep-mode)) | |
534 | |
535 | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
536 ;;;###autoload |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
537 (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
|
538 "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
|
539 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
|
540 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
|
541 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
|
542 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
543 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
|
544 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
|
545 (interactive |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
546 (progn |
70258 | 547 (grep-compute-defaults) |
53750
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
548 (if grep-find-command |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
549 (list (read-from-minibuffer "Run find (like this): " |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
550 grep-find-command nil nil |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
551 'grep-find-history)) |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
552 ;; No default was set |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
553 (read-string |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
554 "compile.el: No `grep-find-command' command available. Press RET.") |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
555 (list nil)))) |
70712
070ab453b31f
(grep-find): Don't check grep-find-command
Kim F. Storm <storm@cua.dk>
parents:
70534
diff
changeset
|
556 (when command-args |
53750
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
557 (let ((null-device nil)) ; see grep |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
558 (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
|
559 |
59688
3761d1e2619d
* NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents:
59605
diff
changeset
|
560 ;;;###autoload |
3761d1e2619d
* NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents:
59605
diff
changeset
|
561 (defalias 'find-grep 'grep-find) |
3761d1e2619d
* NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents:
59605
diff
changeset
|
562 |
70258 | 563 |
564 ;; User-friendly interactive API. | |
565 | |
566 (defconst grep-expand-keywords | |
567 '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i")) | |
568 ("<D>" . dir) | |
569 ("<F>" . files) | |
570 ("<N>" . null-device) | |
571 ("<X>" . excl) | |
572 ("<R>" . (shell-quote-argument (or regexp "")))) | |
573 "List of substitutions performed by `grep-expand-template'. | |
574 If car of an element matches, the cdr is evalled in to get the | |
575 substitution string. Note dynamic scoping of variables.") | |
576 | |
577 (defun grep-expand-template (template &optional regexp files dir excl) | |
578 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>." | |
579 (let ((command template) | |
580 (cf case-fold-search) | |
581 (case-fold-search nil)) | |
582 (dolist (kw grep-expand-keywords command) | |
583 (if (string-match (car kw) command) | |
70315
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
584 (setq command |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
585 (replace-match |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
586 (or (if (symbolp (cdr kw)) |
70340
3146cc3b9e56
(grep-expand-template): Use symbol-value instead of eval on symbols.
Kim F. Storm <storm@cua.dk>
parents:
70315
diff
changeset
|
587 (symbol-value (cdr kw)) |
70315
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
588 (save-match-data (eval (cdr kw)))) |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
589 "") |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
590 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
|
591 |
70258 | 592 (defun grep-read-regexp () |
593 "Read regexp arg for interactive grep." | |
594 (let ((default | |
595 (or (funcall (or find-tag-default-function | |
596 (get major-mode 'find-tag-default-function) | |
597 'find-tag-default)) | |
598 ""))) | |
599 (read-string | |
600 (concat "Search for" | |
601 (if (and default (> (length default) 0)) | |
602 (format " (default %s): " default) ": ")) | |
603 nil 'grep-regexp-history default))) | |
604 | |
605 (defun grep-read-files (regexp) | |
606 "Read files arg for interactive grep." | |
70259
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
607 (let* ((bn (or (buffer-file-name) (buffer-name))) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
608 (fn (and bn |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
609 (stringp bn) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
610 (file-name-nondirectory bn))) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
611 (default |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
612 (or (and fn |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
613 (let ((aliases grep-files-aliases) |
70258 | 614 alias) |
615 (while aliases | |
616 (setq alias (car aliases) | |
617 aliases (cdr aliases)) | |
618 (if (string-match (wildcard-to-regexp (cdr alias)) fn) | |
619 (setq aliases nil) | |
620 (setq alias nil))) | |
621 (cdr alias))) | |
70259
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
622 (and fn |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
623 (let ((ext (file-name-extension fn))) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
624 (and ext (concat "*." ext)))))) |
70258 | 625 (files (read-string |
626 (concat "Search for \"" regexp | |
70259
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
627 "\" in files" |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
628 (if default (concat " (default " default ")")) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
629 ": ") |
70258 | 630 nil 'grep-files-history default))) |
631 (and files | |
632 (or (cdr (assoc files grep-files-aliases)) | |
633 files)))) | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
634 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
635 ;;;###autoload |
70258 | 636 (defun lgrep (regexp &optional files) |
637 "Run grep, searching for REGEXP in FILES in current directory. | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
638 The search is limited to file names matching shell pattern FILES. |
70258 | 639 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
|
640 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
|
641 |
70526 | 642 With \\[universal-argument] prefix, you can edit the constructed shell command line |
643 before it is executed. | |
644 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
|
645 |
70258 | 646 Collect output in a buffer. While grep runs asynchronously, you |
647 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] | |
648 in the grep output buffer, 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
|
649 |
70258 | 650 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
|
651 (interactive |
70258 | 652 (progn |
653 (grep-compute-defaults) | |
654 (cond | |
655 ((and grep-command (equal current-prefix-arg '(16))) | |
656 (list (read-from-minibuffer "Run: " grep-command | |
657 nil nil 'grep-history) | |
658 nil)) | |
659 ((not grep-template) | |
660 (list nil | |
661 (read-string "grep.el: No `grep-template' available. Press RET."))) | |
662 (t (let* ((regexp (grep-read-regexp)) | |
663 (files (grep-read-files regexp))) | |
664 (list regexp files)))))) | |
665 (when (and (stringp regexp) (> (length regexp) 0)) | |
666 (let ((command regexp)) | |
667 (if (null files) | |
668 (if (string= command grep-command) | |
669 (setq command nil)) | |
670 (setq command (grep-expand-template | |
671 grep-template | |
672 regexp | |
673 files)) | |
674 (when command | |
675 (if (equal current-prefix-arg '(4)) | |
676 (setq command | |
677 (read-from-minibuffer "Confirm: " | |
678 command nil nil 'grep-history)) | |
70421
47fe68ac1971
(lgrep, rgrep): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents:
70340
diff
changeset
|
679 (add-to-history 'grep-history command)))) |
70258 | 680 (when command |
681 ;; Setting process-setup-function makes exit-message-function work | |
682 ;; even when async processes aren't supported. | |
683 (compilation-start (if (and grep-use-null-device null-device) | |
684 (concat command " " null-device) | |
685 command) 'grep-mode))))) | |
686 | |
687 | |
688 ;;;###autoload | |
689 (defun rgrep (regexp &optional files dir) | |
70526 | 690 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. |
70258 | 691 The search is limited to file names matching shell pattern FILES. |
692 FILES may use abbreviations defined in `grep-files-aliases', e.g. | |
693 entering `ch' is equivalent to `*.[ch]'. | |
694 | |
70526 | 695 With \\[universal-argument] prefix, you can edit the constructed shell command line |
696 before it is executed. | |
697 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'. | |
70258 | 698 |
699 Collect output in a buffer. While find runs asynchronously, you | |
700 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] | |
701 in the grep output buffer, to go to the lines where grep found matches. | |
702 | |
703 This command shares argument histories with \\[lgrep] and \\[grep-find]." | |
704 (interactive | |
705 (progn | |
706 (grep-compute-defaults) | |
707 (cond | |
708 ((and grep-find-command (equal current-prefix-arg '(16))) | |
709 (list (read-from-minibuffer "Run: " grep-find-command | |
710 nil nil 'grep-find-history) | |
711 nil)) | |
712 ((not grep-find-template) | |
713 (list nil nil | |
714 (read-string "grep.el: No `grep-find-template' available. Press RET."))) | |
715 (t (let* ((regexp (grep-read-regexp)) | |
716 (files (grep-read-files regexp)) | |
717 (dir (read-directory-name "Base directory: " | |
718 nil default-directory t))) | |
719 (list regexp files dir)))))) | |
720 (when (and (stringp regexp) (> (length regexp) 0)) | |
721 (if (null files) | |
722 (if (not (string= regexp grep-find-command)) | |
723 (compilation-start regexp 'grep-mode)) | |
70534
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
724 (setq dir (file-name-as-directory (expand-file-name dir))) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
725 (let ((command (grep-expand-template |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
726 grep-find-template |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
727 regexp |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
728 (concat "\\( -name " |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
729 (mapconcat #'shell-quote-argument |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
730 (split-string files) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
731 " -o -name ") |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
732 " \\)") |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
733 dir |
70258 | 734 (and grep-find-ignored-directories |
735 (concat "\\( -path '*/" | |
736 (mapconcat #'identity | |
737 grep-find-ignored-directories | |
738 "' -o -path '*/") | |
739 "' \\) -prune -o "))))) | |
740 (when command | |
741 (if current-prefix-arg | |
742 (setq command | |
743 (read-from-minibuffer "Confirm: " | |
744 command nil nil 'grep-find-history)) | |
70421
47fe68ac1971
(lgrep, rgrep): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents:
70340
diff
changeset
|
745 (add-to-history 'grep-find-history command)) |
70534
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
746 (let ((default-directory dir)) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
747 (compilation-start command 'grep-mode)) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
748 ;; Set default-directory if we started rgrep in the *grep* buffer. |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
749 (if (eq next-error-last-buffer (current-buffer)) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
750 (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
|
751 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
752 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
753 (provide 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
754 |
57043
cb013e5835b8
(grep-mode): Remove unnecessary autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57022
diff
changeset
|
755 ;; 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
|
756 ;;; grep.el ends here |