annotate lisp/progmodes/grep.el @ 76414:439b3ff34422

** md5i@cs.cmu.edu, Feb 20: move-end-of-line in comint buffers Postphoned to post Emacs 22.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 09 Mar 2007 14:57:38 +0000
parents 9ba96fd63815
children dac34bd10d88 dd7c098af727
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
62160
37249e74aa98 Fix file's header line.
Eli Zaretskii <eliz@gnu.org>
parents: 61902
diff changeset
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,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72500
diff changeset
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
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
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63576
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63576
diff changeset
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
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
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
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
94 (defcustom grep-template nil
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
95 "The default command to run for \\[lgrep].
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
96 The default value of this variable is set up by `grep-compute-defaults';
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
97 call that function before using this variable in your program.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
98 The following place holders should be present in the string:
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
99 <C> - place to put -i if case insensitive grep.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
100 <F> - file names and wildcards to search.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
101 <R> - the regular expression searched for.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
102 <N> - place to insert null-device."
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
103 :type '(choice string
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
104 (const :tag "Not Set" nil))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
105 :version "22.1"
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
106 :group 'grep)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
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
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
130 (defcustom grep-find-template nil
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
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
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
145 (defcustom grep-files-aliases '(
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
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
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
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
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
152 ("l" . "[Cc]hange[Ll]og*")
75877
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
153 ("tex" . "*.tex")
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
154 ("texi" . "*.texi")
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
155 )
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
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
72024
ee140bf82264 (grep-find-ignored-directories): Add .svn and _darcs to list.
Kim F. Storm <storm@cua.dk>
parents: 71854
diff changeset
160 (defcustom grep-find-ignored-directories '("CVS" ".svn" "{arch}" ".hg" "_darcs")
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
161 "*List of names of sub-directories which `rgrep' shall not recurse into."
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
162 :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
163 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
164
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
165 (defcustom grep-error-screen-columns nil
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
166 "*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
167 See `compilation-error-screen-columns'"
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
168 :type '(choice (const :tag "Default" nil)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
169 integer)
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 59991
diff changeset
170 :version "22.1"
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
171 :group 'grep)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
172
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
173 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
174 (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
175 "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
176 :type 'hook
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
177 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
178
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
179 (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
180 (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
181 (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
182 (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
183 (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
184
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 "\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
186 (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
187 (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
188 (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
189 (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
190 (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
191 (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
192
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
193 ;; 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
194 (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
195 (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
196
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-kill-compilation]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 '("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
199 (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
200 '("----" . nil))
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-compile]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
202 '("Compile..." . compile))
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 compilation-grep]
64944
c845f6151d83 (grep-mode-map): Add ellipsis to "Another grep".
Juri Linkov <juri@jurta.org>
parents: 64864
diff changeset
204 '("Another grep..." . grep))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
205 (define-key map [menu-bar grep compilation-grep-find]
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
206 '("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
207 (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
208 '("Repeat grep" . recompile))
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-separator2]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
210 '("----" . nil))
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-first-error]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
212 '("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
213 (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
214 '("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
215 (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
216 '("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
217 map)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
218 "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
219 `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
220
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
221 (defalias 'kill-grep 'kill-compilation)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
222
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
223 ;;;; TODO --- refine this!!
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
224
53145
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
225 ;;; (defcustom grep-use-compilation-buffer t
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
226 ;;; "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
227 ;;; 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
228 ;;; 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
229 ;;; 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
230 ;;; be used to navigate between grep matches."
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
231 ;;; :type 'boolean
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
232 ;;; :group 'grep)
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
233
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
234 ;; 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
235 (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
236 "The most recent grep buffer.
71854
a4944423be59 (grep-last-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 71422
diff changeset
237 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
238 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
239 `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
240
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
241 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
242 (defvar grep-regexp-alist
64864
c474b6f22449 (grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents: 64740
diff changeset
243 '(("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2"
64725
0344b299e9e6 (grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents: 64699
diff changeset
244 1 3)
0344b299e9e6 (grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents: 64699
diff changeset
245 ;; 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
246 ;; produces them
64864
c474b6f22449 (grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents: 64740
diff changeset
247 ;; ("^\\(.+?\\)\\(:[ \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
248 ;; 1 3 (4 . 5))
63576
7c3d537469b0 (grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents: 62160
diff changeset
249 ("^\\(\\(.+?\\):\\([0-9]+\\):\\).*?\
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
250 \\(\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
251 2 3
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
252 ;; 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
253 ((lambda ()
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
254 (setq compilation-error-screen-columns nil)
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
255 (- (match-beginning 4) (match-end 1)))
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
256 .
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
257 (lambda () (- (match-end 5) (match-end 1)
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
258 (- (match-end 4) (match-beginning 4)))))
63576
7c3d537469b0 (grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents: 62160
diff changeset
259 nil 1)
64740
eeed7a7c1afa (grep-regexp-alist): Set 5th arg `TYPE' to
Juri Linkov <juri@jurta.org>
parents: 64728
diff changeset
260 ("^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
261 "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
262
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
263 (defvar grep-error "grep hit"
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
264 "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
265
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
266 ;; 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
267 ;; 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
268 (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
269 "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
270
64864
c474b6f22449 (grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents: 64740
diff changeset
271 (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
272 "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
273
58988
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
274 (defvar grep-match-face 'match
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
275 "Face name to use for grep matches.")
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
276
64725
0344b299e9e6 (grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents: 64699
diff changeset
277 (defvar grep-context-face 'shadow
0344b299e9e6 (grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents: 64699
diff changeset
278 "Face name to use for grep context lines.")
0344b299e9e6 (grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents: 64699
diff changeset
279
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
280 (defvar grep-mode-font-lock-keywords
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
281 '(;; Command output lines.
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
282 ("^\\([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
283 (": \\(.+\\): \\(?: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
284 1 grep-error-face)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
285 ;; 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
286 ("^Grep[/a-zA-z]* started.*"
65126
559a37c2f306 (grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents: 65056
diff changeset
287 (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
288 ("^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
289 (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
290 (1 compilation-info-face nil t)
c474b6f22449 (grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents: 64740
diff changeset
291 (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
292 ("^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
293 (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
294 (1 grep-error-face)
64944
c845f6151d83 (grep-mode-map): Add ellipsis to "Another grep".
Juri Linkov <juri@jurta.org>
parents: 64864
diff changeset
295 (2 grep-error-face nil t))
64864
c474b6f22449 (grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents: 64740
diff changeset
296 ("^.+?-[0-9]+-.*\n" (0 grep-context-face))
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
297 ;; Highlight grep matches and delete markers
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
298 ("\\(\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
299 ;; 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
300 ;; 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
301 ;; 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
302 (2 (list 'face nil 'font-lock-face grep-match-face))
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
303 ((lambda (bound))
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
304 (progn
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
305 ;; Delete markers with `replace-match' because it updates
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
306 ;; 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
307 (replace-match "" t t nil 3)
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
308 (replace-match "" t t nil 1))))
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
309 ("\\(\033\\[[0-9;]*[mK]\\)"
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
310 ;; Delete all remaining escape sequences
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
311 ((lambda (bound))
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
312 (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
313 "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
314 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
315
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
316 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 (defvar grep-program
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
318 ;; 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
319 ;; 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
320 "grep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
321 ;; (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
322 ;; (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
323 ;; "foo" null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
324 ;; (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
325 ;; 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
326 ;; "zgrep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
327 ;; "grep")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
328 "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
329 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
330
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
331 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
332 (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
333 "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
334 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
335
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
336 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
337 (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
338 "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
339
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
340 If `exec', it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0';
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
341 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
342
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
343 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
344
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
345 ;; History of grep commands.
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
346 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
347 (defvar grep-history nil)
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
348 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
349 (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
350
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
351 ;; History of lgrep and rgrep regexp and files args.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
352 (defvar grep-regexp-history nil)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
353 (defvar grep-files-history '("ch" "el"))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
354
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
355
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
356 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
357 (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
358 "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
359 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
360 (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
361 (grep-compute-defaults))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
362 (when (eq grep-highlight-matches t)
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
363 ;; Modify `process-environment' locally bound in `compilation-start'
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
364 (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always"))
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
365 ;; for GNU grep 2.5.1
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
366 (setenv "GREP_COLOR" "01;31")
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
367 ;; for GNU grep 2.5.1-cvs
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
368 (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
369 (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
370 (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
371 (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
372 (cond ((zerop code)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
373 '("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
374 ((= code 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
375 '("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
376 (t
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 (cons msg code))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
379 (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
380
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
381 (defun grep-probe (command args &optional func result)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
382 (equal (condition-case nil
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
383 (apply (or func 'call-process) command args)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
384 (error nil))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
385 (or result 0)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
386
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
387 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
388 (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
389 (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
390 (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
391 (with-temp-buffer
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
392 (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
393 (not
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
394 (and (if grep-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
395 ;; `grep-command' is already set, so
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
396 ;; use that for testing.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
397 (grep-probe grep-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
398 `(nil t nil "^English" ,hello-file)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
399 #'call-process-shell-command)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
400 ;; otherwise use `grep-program'
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
401 (grep-probe grep-program
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
402 `(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
403 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
404 (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
405 (looking-at
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
406 (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
407 ":[0-9]+:English")))))))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
408 (unless (and grep-command grep-find-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
409 grep-template grep-find-template)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
410 (let ((grep-options
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
411 (concat (if grep-use-null-device "-n" "-nH")
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
412 (if (grep-probe grep-program
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
413 `(nil nil nil "-e" "foo" ,null-device)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
414 nil 1)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
415 " -e"))))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
416 (unless grep-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
417 (setq grep-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
418 (format "%s %s " grep-program grep-options)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
419 (unless grep-template
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
420 (setq grep-template
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
421 (format "%s <C> %s <R> <F>" grep-program grep-options)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
422 (unless grep-find-use-xargs
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
423 (setq grep-find-use-xargs
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
424 (cond
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
425 ((and
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
426 (grep-probe find-program `(nil nil nil ,null-device "-print0"))
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
427 (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo")))
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
428 'gnu)
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
429 (t
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
430 'exec))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
431 (unless grep-find-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
432 (setq grep-find-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
433 (cond ((eq grep-find-use-xargs 'gnu)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
434 (format "%s . -type f -print0 | xargs -0 -e %s"
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
435 find-program grep-command))
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
436 ((eq grep-find-use-xargs 'exec)
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
437 (let ((cmd0 (format "%s . -type f -exec %s"
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
438 find-program grep-command)))
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
439 (cons
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
440 (format "%s {} %s %s"
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
441 cmd0 null-device
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
442 (shell-quote-argument ";"))
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
443 (1+ (length cmd0)))))
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
444 (t
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
445 (format "%s . -type f -print | xargs %s"
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
446 find-program grep-command)))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
447 (unless grep-find-template
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
448 (setq grep-find-template
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
449 (let ((gcmd (format "%s <C> %s <R>"
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
450 grep-program grep-options)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
451 (cond ((eq grep-find-use-xargs 'gnu)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
452 (format "%s . <X> -type f <F> -print0 | xargs -0 -e %s"
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
453 find-program gcmd))
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
454 ((eq grep-find-use-xargs 'exec)
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
455 (format "%s . <X> -type f <F> -exec %s {} %s %s"
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
456 find-program gcmd null-device
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
457 (shell-quote-argument ";")))
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
458 (t
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
459 (format "%s . <X> -type f <F> -print | xargs %s"
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
460 find-program gcmd))))))))
56948
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
461 (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
462 (setq grep-highlight-matches
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
463 (with-temp-buffer
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
464 (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
465 (progn
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
466 (goto-char (point-min))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
467 (search-forward "--color" nil t))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
468 t)))))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
469
72163
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
470 (defun grep-tag-default ()
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
471 (or (and transient-mark-mode mark-active
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
472 (/= (point) (mark))
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
473 (buffer-substring-no-properties (point) (mark)))
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
474 (funcall (or find-tag-default-function
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
475 (get major-mode 'find-tag-default-function)
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
476 'find-tag-default))
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
477 ""))
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
478
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
479 (defun grep-default-command ()
72173
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
480 "Compute the default grep command for C-u M-x grep to offer."
72163
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
481 (let ((tag-default (shell-quote-argument (grep-tag-default)))
72173
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
482 ;; This a regexp to match single shell arguments.
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
483 ;; 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
484 (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
485 (grep-default (or (car grep-history) grep-command)))
72173
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
486 ;; 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
487 (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
488 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
489 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
490 grep-default)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
491 ;; 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
492 (string-match "\\(\\)\\'" grep-default))
72173
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
493 ;; Maybe we will replace the pattern with the default tag.
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
494 ;; But first, maybe replace the file name pattern.
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
495 (condition-case nil
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
496 (unless (or (not (stringp buffer-file-name))
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
497 (when (match-beginning 2)
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
498 (save-match-data
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
499 (string-match
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
500 (wildcard-to-regexp
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
501 (file-name-nondirectory
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
502 (match-string 3 grep-default)))
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
503 (file-name-nondirectory buffer-file-name)))))
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
504 (setq grep-default (concat (substring grep-default
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
505 0 (match-beginning 2))
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
506 " *."
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
507 (file-name-extension buffer-file-name))))
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
508 ;; In case wildcard-to-regexp gets an error
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
509 ;; from invalid data.
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
510 (error nil))
691a901b4418 (grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 72165
diff changeset
511 ;; Now replace the pattern with the default tag.
57908
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
512 (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
513
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
514
64509
9a66028f1658 (grep-regexp-alist)
Juri Linkov <juri@jurta.org>
parents: 64085
diff changeset
515 ;;;###autoload
55018
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
516 (define-compilation-mode grep-mode "Grep"
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
517 "Sets `grep-last-buffer' and `compilation-window-height'."
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
518 (setq grep-last-buffer (current-buffer))
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
519 (set (make-local-variable 'compilation-error-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
520 grep-hit-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
521 (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
522 grep-regexp-alist)
65126
559a37c2f306 (grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents: 65056
diff changeset
523 (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
524 '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
525 (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
526
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
527
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
528 ;;;###autoload
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
529 (defun grep (command-args)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
530 "Run grep, with user-specified args, and collect output in a buffer.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
531 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
532 or \\<grep-mode-map>\\[compile-goto-error] in the grep \
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
533 output buffer, to go to the lines
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
534 where grep found matches.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
535
75803
81c369551691 (grep): Mention lgrep and rgrep in the
Dan Nicolaescu <dann@ics.uci.edu>
parents: 75347
diff changeset
536 For doing a recursive `grep', see the `rgrep' command. For running
75877
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
537 `grep' in a specific directory, see `lgrep'.
75803
81c369551691 (grep): Mention lgrep and rgrep in the
Dan Nicolaescu <dann@ics.uci.edu>
parents: 75347
diff changeset
538
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
539 This command uses a special history list for its COMMAND-ARGS, so you can
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
540 easily repeat a grep command.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
541
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
542 A prefix argument says to default the argument based upon the current
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
543 tag the cursor is over, substituting it into the last grep command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
544 in the grep command history (or into `grep-command'
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
545 if that history list is empty)."
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
546 (interactive
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
547 (progn
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
548 (grep-compute-defaults)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
549 (let ((default (grep-default-command)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
550 (list (read-from-minibuffer "Run grep (like this): "
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
551 (if current-prefix-arg
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
552 default grep-command)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
553 nil nil 'grep-history
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
554 (if current-prefix-arg nil default))))))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
555
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
556 ;; Setting process-setup-function makes exit-message-function work
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
557 ;; even when async processes aren't supported.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
558 (compilation-start (if (and grep-use-null-device null-device)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
559 (concat command-args " " null-device)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
560 command-args)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
561 'grep-mode))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
562
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
563
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
564 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
565 (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
566 "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
567 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
568 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
569 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
570
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
571 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
572 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
573 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
574 (progn
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
575 (grep-compute-defaults)
53750
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
576 (if grep-find-command
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
577 (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
578 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
579 'grep-find-history))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
580 ;; No default was set
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
581 (read-string
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
582 "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
583 (list nil))))
70712
070ab453b31f (grep-find): Don't check grep-find-command
Kim F. Storm <storm@cua.dk>
parents: 70534
diff changeset
584 (when command-args
53750
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
585 (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
586 (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
587
59688
3761d1e2619d * NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents: 59605
diff changeset
588 ;;;###autoload
3761d1e2619d * NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents: 59605
diff changeset
589 (defalias 'find-grep 'grep-find)
3761d1e2619d * NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents: 59605
diff changeset
590
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
591
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
592 ;; User-friendly interactive API.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
593
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
594 (defconst grep-expand-keywords
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
595 '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i"))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
596 ("<D>" . dir)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
597 ("<F>" . files)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
598 ("<N>" . null-device)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
599 ("<X>" . excl)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
600 ("<R>" . (shell-quote-argument (or regexp ""))))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
601 "List of substitutions performed by `grep-expand-template'.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
602 If car of an element matches, the cdr is evalled in to get the
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
603 substitution string. Note dynamic scoping of variables.")
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
604
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
605 (defun grep-expand-template (template &optional regexp files dir excl)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
606 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
607 (let ((command template)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
608 (cf case-fold-search)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
609 (case-fold-search nil))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
610 (dolist (kw grep-expand-keywords command)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
611 (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
612 (setq command
cf0d76a2f0c7 (grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents: 70259
diff changeset
613 (replace-match
cf0d76a2f0c7 (grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents: 70259
diff changeset
614 (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
615 (symbol-value (cdr kw))
70315
cf0d76a2f0c7 (grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents: 70259
diff changeset
616 (save-match-data (eval (cdr kw))))
cf0d76a2f0c7 (grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents: 70259
diff changeset
617 "")
cf0d76a2f0c7 (grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents: 70259
diff changeset
618 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
619
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
620 (defun grep-read-regexp ()
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
621 "Read regexp arg for interactive grep."
72163
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
622 (let ((default (grep-tag-default)))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
623 (read-string
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
624 (concat "Search for"
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
625 (if (and default (> (length default) 0))
72163
bca9d3121eef (grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents: 72024
diff changeset
626 (format " (default \"%s\"): " default) ": "))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
627 nil 'grep-regexp-history default)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
628
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
629 (defun grep-read-files (regexp)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
630 "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
631 (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
632 (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
633 (stringp bn)
58edc69a1813 (grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents: 70258
diff changeset
634 (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
635 (default
58edc69a1813 (grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents: 70258
diff changeset
636 (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
637 (let ((aliases grep-files-aliases)
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
638 alias)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
639 (while aliases
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
640 (setq alias (car aliases)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
641 aliases (cdr aliases))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
642 (if (string-match (wildcard-to-regexp (cdr alias)) fn)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
643 (setq aliases nil)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
644 (setq alias nil)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
645 (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
646 (and fn
58edc69a1813 (grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents: 70258
diff changeset
647 (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>
parents: 72163
diff changeset
648 (and ext (concat "*." ext))))
301cc56a3482 (grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
parents: 72163
diff changeset
649 (car grep-files-history)
301cc56a3482 (grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
parents: 72163
diff changeset
650 (car (car grep-files-aliases))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
651 (files (read-string
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
652 (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
653 "\" in files"
58edc69a1813 (grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents: 70258
diff changeset
654 (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
655 ": ")
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
656 nil 'grep-files-history default)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
657 (and files
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
658 (or (cdr (assoc files grep-files-aliases))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
659 files))))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
660
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
661 ;;;###autoload
75877
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
662 (defun lgrep (regexp &optional files dir)
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
663 "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
664 The search is limited to file names matching shell pattern FILES.
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
665 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
666 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
667
70526
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
668 With \\[universal-argument] prefix, you can edit the constructed shell command line
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
669 before it is executed.
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
670 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
671
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
672 Collect output in a buffer. While grep runs asynchronously, you
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
673 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
674 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
675
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
676 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
677 (interactive
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
678 (progn
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
679 (grep-compute-defaults)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
680 (cond
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
681 ((and grep-command (equal current-prefix-arg '(16)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
682 (list (read-from-minibuffer "Run: " grep-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
683 nil nil 'grep-history)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
684 nil))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
685 ((not grep-template)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
686 (list nil
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
687 (read-string "grep.el: No `grep-template' available. Press RET.")))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
688 (t (let* ((regexp (grep-read-regexp))
75877
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
689 (files (grep-read-files regexp))
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
690 (dir (read-directory-name "In directory: "
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
691 nil default-directory t)))
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
692 (list regexp files dir))))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
693 (when (and (stringp regexp) (> (length regexp) 0))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
694 (let ((command regexp))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
695 (if (null files)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
696 (if (string= command grep-command)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
697 (setq command nil))
75877
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
698 (setq dir (file-name-as-directory (expand-file-name dir)))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
699 (setq command (grep-expand-template
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
700 grep-template
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
701 regexp
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
702 files))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
703 (when command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
704 (if (equal current-prefix-arg '(4))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
705 (setq command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
706 (read-from-minibuffer "Confirm: "
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
707 command nil nil 'grep-history))
70421
47fe68ac1971 (lgrep, rgrep): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents: 70340
diff changeset
708 (add-to-history 'grep-history command))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
709 (when command
75877
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
710 (let ((default-directory dir))
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
711 ;; Setting process-setup-function makes exit-message-function work
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
712 ;; even when async processes aren't supported.
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
713 (compilation-start (if (and grep-use-null-device null-device)
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
714 (concat command " " null-device)
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
715 command) 'grep-mode))
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
716 (if (eq next-error-last-buffer (current-buffer))
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
717 (setq default-directory dir))))))
9ba96fd63815 (grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents: 75803
diff changeset
718
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
719
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
720
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
721 ;;;###autoload
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
722 (defun rgrep (regexp &optional files dir)
70526
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
723 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
724 The search is limited to file names matching shell pattern FILES.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
725 FILES may use abbreviations defined in `grep-files-aliases', e.g.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
726 entering `ch' is equivalent to `*.[ch]'.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
727
70526
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
728 With \\[universal-argument] prefix, you can edit the constructed shell command line
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
729 before it is executed.
0c5d2102f71a (lgrep, rgrep): Doc fixes.
Kim F. Storm <storm@cua.dk>
parents: 70421
diff changeset
730 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'.
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
731
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
732 Collect output in a buffer. While find runs asynchronously, you
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
733 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
734 in the grep output buffer, to go to the lines where grep found matches.
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
735
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
736 This command shares argument histories with \\[lgrep] and \\[grep-find]."
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
737 (interactive
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
738 (progn
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
739 (grep-compute-defaults)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
740 (cond
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
741 ((and grep-find-command (equal current-prefix-arg '(16)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
742 (list (read-from-minibuffer "Run: " grep-find-command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
743 nil nil 'grep-find-history)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
744 nil))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
745 ((not grep-find-template)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
746 (list nil nil
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
747 (read-string "grep.el: No `grep-find-template' available. Press RET.")))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
748 (t (let* ((regexp (grep-read-regexp))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
749 (files (grep-read-files regexp))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
750 (dir (read-directory-name "Base directory: "
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
751 nil default-directory t)))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
752 (list regexp files dir))))))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
753 (when (and (stringp regexp) (> (length regexp) 0))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
754 (if (null files)
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
755 (if (not (string= regexp grep-find-command))
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
756 (compilation-start regexp 'grep-mode))
70534
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
757 (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
758 (let ((command (grep-expand-template
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
759 grep-find-template
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
760 regexp
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
761 (concat (shell-quote-argument "(")
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
762 " -name "
70534
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
763 (mapconcat #'shell-quote-argument
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
764 (split-string files)
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
765 " -o -name ")
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
766 " "
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
767 (shell-quote-argument ")"))
70534
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
768 dir
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
769 (and grep-find-ignored-directories
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
770 (concat (shell-quote-argument "(")
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
771 ;; we should use shell-quote-argument here
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
772 " -path "
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
773 (mapconcat #'(lambda (dir)
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
774 (shell-quote-argument
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
775 (concat "*/" dir)))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
776 grep-find-ignored-directories
72500
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
777 " -o -path ")
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
778 " "
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
779 (shell-quote-argument ")")
35e43fe3d8ef (grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents: 72173
diff changeset
780 " -prune -o ")))))
70258
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
781 (when command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
782 (if current-prefix-arg
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
783 (setq command
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
784 (read-from-minibuffer "Confirm: "
5dfde453f39e (defgroup grep): Doc fix.
Kim F. Storm <storm@cua.dk>
parents: 69499
diff changeset
785 command nil nil 'grep-find-history))
70421
47fe68ac1971 (lgrep, rgrep): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents: 70340
diff changeset
786 (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
787 (let ((default-directory dir))
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
788 (compilation-start command 'grep-mode))
afe3317800c2 (rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents: 70526
diff changeset
789 ;; 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
790 (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
791 (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
792
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
793
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
794 (provide 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
795
57043
cb013e5835b8 (grep-mode): Remove unnecessary autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57022
diff changeset
796 ;; 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
797 ;;; grep.el ends here