annotate lisp/progmodes/grep.el @ 61647:a39c60b30e5a

(resolve_face_name): Use Fsafe_get to avoid redisplay loops in case of bad face property lists. Limit number of face alias lookups to 10 (in case of face alias loops).
author Kim F. Storm <storm@cua.dk>
date Tue, 19 Apr 2005 08:34:50 +0000
parents aac0a33f5772
children e8076329ceee 3ebd9bdb4fe5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
1 ;;; grep.el --- run compiler as inferior of Emacs, parse error messages
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,
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
4 ;; 2001, 2002, 2004 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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
36 (defgroup grep nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
37 "Run compiler as inferior of Emacs, parse error messages."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
38 :group 'tools
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
39 :group 'processes)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
40
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 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
43 (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
44 "*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
45 :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
46 integer)
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 59991
diff changeset
47 :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
48 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
49
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
50 (defcustom grep-auto-highlight t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
51 "*Specify how many grep matches to highlight (and parse) initially.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
52 \(Highlighting applies to an grep match when the mouse is over it.)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
53 If this is a number N, all grep matches in the first N lines
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
54 are highlighted and parsed as soon as they arrive in Emacs.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
55 If t, highlight and parse the whole grep output as soon as it arrives.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
56 If nil, don't highlight or parse any of the grep buffer until you try to
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
57 move to the error messages.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
58
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
59 Those grep matches which are not parsed and highlighted initially
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
60 will be parsed and highlighted as soon as you try to move to them."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
61 :type '(choice (const :tag "All" t)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
62 (const :tag "None" nil)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
63 (integer :tag "First N lines"))
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 59991
diff changeset
64 :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
65 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
66
56948
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
67 (defcustom grep-highlight-matches 'auto-detect
56960
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
68 "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
69
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
70 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
71 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
72 matches in grep mode.
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
73
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
74 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
75 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
76 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
77 the grep.
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
78
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
79 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
80 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
81 :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
82 (const :tag "Highlight matches with grep markers" t)
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
83 (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
84 :version "22.1"
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
85 :group 'grep)
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
86
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
87 (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
88 "*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
89
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
90 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
91 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
92 than the begining."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
93 :type 'boolean
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 59991
diff changeset
94 :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
95 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
96
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
97 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
98 (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
99 "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
100 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
101 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
102 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
103
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
104 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
105 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
106 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
107 (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
108 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
109
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
110 (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
111 "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
112 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
113 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
114 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
115
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
116 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
117 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
118 :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
119 (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
120 (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
121 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
122
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
123 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 (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
125 "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
126 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
127 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
128 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
129 (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
130 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
131
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
132 (defcustom grep-tree-command nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
133 "The default find command for \\[grep-tree].
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
134 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
135 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
136 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
137 <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
138 <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
139 <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
140 <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
141 <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
142 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
143 (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
144 :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
145 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
146
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
147 (defcustom grep-tree-files-aliases '(
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
148 ("ch" . "*.[ch]")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
149 ("c" . "*.c")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
150 ("h" . "*.h")
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*")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
152 ("asm" . "*.[sS]")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
153 ("all" . "*")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
154 ("el" . "*.el")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
155 )
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
156 "*Alist of aliases for the FILES argument to `grep-tree'."
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
160 (defcustom grep-tree-ignore-case t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
161 "*If non-nil, `grep-tree' ignores case in matches."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
162 :type 'boolean
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
165 (defcustom grep-tree-ignore-CVS-directories t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
166 "*If non-nil, `grep-tree' does no recurse into CVS directories."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
167 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
168 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
169
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
170 (defcustom grep-error-screen-columns nil
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
171 "*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
172 See `compilation-error-screen-columns'"
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
173 :type '(choice (const :tag "Default" nil)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
174 integer)
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 59991
diff changeset
175 :version "22.1"
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
176 :group 'grep)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
177
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
178 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
179 (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
180 "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
181 :type 'hook
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
182 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
183
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
184 (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
185 (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
186 (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
187 (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
188 (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
189
53486
23376885b0f9 (grep-mode-map): Don't remap next-line, previous-line.
Richard M. Stallman <rms@gnu.org>
parents: 53154
diff changeset
190 ;; This is intolerable -- rms
23376885b0f9 (grep-mode-map): Don't remap next-line, previous-line.
Richard M. Stallman <rms@gnu.org>
parents: 53154
diff changeset
191 ;;; (define-key map [remap next-line] 'compilation-next-error)
23376885b0f9 (grep-mode-map): Don't remap next-line, previous-line.
Richard M. Stallman <rms@gnu.org>
parents: 53154
diff changeset
192 ;;; (define-key map [remap previous-line] '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
193
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
194 (define-key map "\r" 'compile-goto-error) ;; ?
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
195 (define-key map "n" 'next-error-no-select)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
196 (define-key map "p" 'previous-error-no-select)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
197 (define-key map "{" 'compilation-previous-file)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 (define-key map "}" 'compilation-next-file)
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 "\t" 'compilation-next-file)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
200
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
201 ;; 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
202 (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
203 (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
204
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
205 (define-key map [menu-bar grep compilation-kill-compilation]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
206 '("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
207 (define-key map [menu-bar grep compilation-separator2]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
208 '("----" . nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
209 (define-key map [menu-bar grep compilation-compile]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
210 '("Compile..." . compile))
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-grep]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
212 '("Another grep" . grep))
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-recompile]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
214 '("Repeat grep" . recompile))
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-separator2]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
216 '("----" . nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
217 (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
218 '("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
219 (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
220 '("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
221 (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
222 '("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
223 map)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
224 "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
225 `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
226
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
227 (defalias 'kill-grep 'kill-compilation)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
228
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
229 ;;;; TODO --- refine this!!
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
230
53145
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
231 ;;; (defcustom grep-use-compilation-buffer t
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
232 ;;; "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
233 ;;; 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
234 ;;; 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
235 ;;; 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
236 ;;; be used to navigate between grep matches."
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
237 ;;; :type 'boolean
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
238 ;;; :group 'grep)
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
239
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
240 ;; 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
241 (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
242 "The most recent grep buffer.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
243 A grep buffer becomes most recent when its process is started
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
244 or when it is used with \\[grep-next-match].
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
245 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
246 `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
247
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
248 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
249 (defvar grep-regexp-alist
58493
9acfc0fb9410 (grep-regexp-alist): Don't match parens around line numbers.
Richard M. Stallman <rms@gnu.org>
parents: 57908
diff changeset
250 ;; rms: I removed the code to match parens around the line number
9acfc0fb9410 (grep-regexp-alist): Don't match parens around line numbers.
Richard M. Stallman <rms@gnu.org>
parents: 57908
diff changeset
251 ;; because it causes confusion and so we will find out if anyone needs it.
9acfc0fb9410 (grep-regexp-alist): Don't match parens around line numbers.
Richard M. Stallman <rms@gnu.org>
parents: 57908
diff changeset
252 ;; It causes confusion with a file name that contains a number in parens.
9acfc0fb9410 (grep-regexp-alist): Don't match parens around line numbers.
Richard M. Stallman <rms@gnu.org>
parents: 57908
diff changeset
253 '(("^\\(.+?\\)[: \t]+\
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
254 \\([0-9]+\\)\\([.:]?\\)\\([0-9]+\\)?\
58493
9acfc0fb9410 (grep-regexp-alist): Don't match parens around line numbers.
Richard M. Stallman <rms@gnu.org>
parents: 57908
diff changeset
255 \\(?:-\\(?:\\([0-9]+\\)\\3\\)?\\.?\\([0-9]+\\)?\\)?[: \t]" 1 (2 . 5) (4 . 6))
59991
a518aec8f272 (grep-regexp-alist): Match an optional ^[[K
Dan Nicolaescu <dann@ics.uci.edu>
parents: 59688
diff changeset
256 ("^\\(.+?\\)[:(]+\\([0-9]+\\)\\([:)]\\).*?\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\(\033\\[K\\)?\\)"
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
257 1 2
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
258 ;; 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
259 ((lambda ()
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
260 (setq compilation-error-screen-columns nil)
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
261 (- (match-beginning 5) (match-end 3) 8))
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
262 .
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
263 (lambda () (- (match-end 5) (match-end 3) 8))))
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
264 ("^Binary file \\(.+\\) matches$" 1 nil nil 1))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
265 "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
266
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
267 (defvar grep-error "grep hit"
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
268 "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
269
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
270 ;; 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
271 ;; 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
272 (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
273 "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
274
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
275 (defvar grep-error-face compilation-error-face
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
276 "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
277
58988
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
278 (defvar grep-match-face 'match
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
279 "Face name to use for grep matches.")
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
280
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
281 (defvar grep-mode-font-lock-keywords
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
282 '(;; Command output lines.
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
283 ("^\\([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
284 (": \\(.+\\): \\(?: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
285 1 grep-error-face)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
286 ;; remove match from grep-regexp-alist before fontifying
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
287 ("^Grep finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*"
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
288 (0 '(face nil message nil help-echo nil mouse-face nil) t)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
289 (1 grep-hit-face nil t)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
290 (2 grep-error-face nil t))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
291 ("^Grep \\(exited abnormally\\) with code \\([0-9]+\\).*"
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
292 (0 '(face nil message nil help-echo nil mouse-face nil) t)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
293 (1 compilation-warning-face)
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
294 (2 compilation-line-face))
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
295 ;; Highlight grep matches and delete markers
59991
a518aec8f272 (grep-regexp-alist): Match an optional ^[[K
Dan Nicolaescu <dann@ics.uci.edu>
parents: 59688
diff changeset
296 ("\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\(\033\\[K\\)?\\)"
58988
067d5dcfe531 (grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents: 58493
diff changeset
297 (2 grep-match-face)
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
298 ((lambda (p))
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
299 (progn
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
300 ;; Delete markers with `replace-match' because it updates
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
301 ;; 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
302 (replace-match "" t t nil 3)
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
303 (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
304 "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
305 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
306
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
307 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
308 (defvar grep-program
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
309 ;; 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
310 ;; 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
311 "grep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
312 ;; (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
313 ;; (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
314 ;; "foo" null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
315 ;; (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
316 ;; 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 ;; "zgrep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
318 ;; "grep")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
319 "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
320 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
321
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
322 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
323 (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
324 "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
325 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
326
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
327 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
328 (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
329 "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
330
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
331 If nil, it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0';
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
332 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
333
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
336 ;; History of grep commands.
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
337 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
338 (defvar grep-history nil)
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
339 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
340 (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
341
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
342 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
343 (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
344 "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
345 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
346 (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
347 (grep-compute-defaults))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
348 (when (eq grep-highlight-matches t)
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
349 ;; Modify `process-environment' locally bound in `compilation-start'
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
350 (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always"))
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
351 (setenv "GREP_COLOR" "01;41"))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
352 (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
353 (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
354 (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
355 (cond ((zerop code)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
356 '("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
357 ((= code 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
358 '("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
359 (t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
360 (cons msg code)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
361 (cons msg code))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
362 (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
363
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
364 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
365 (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
366 (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
367 (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
368 (with-temp-buffer
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
369 (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
370 (not
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
371 (and (equal (condition-case nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
372 (if grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
373 ;; `grep-command' is already set, so
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
374 ;; use that for testing.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
375 (call-process-shell-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
376 grep-command nil t nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
377 "^English" hello-file)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
378 ;; otherwise use `grep-program'
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
379 (call-process grep-program nil t nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
380 "-nH" "^English" hello-file))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
381 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
382 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
384 (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
385 (looking-at
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
386 (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
387 ":[0-9]+:English")))))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
388 (unless grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
389 (setq grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
390 (let ((required-options (if grep-use-null-device "-n" "-nH")))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
391 (if (equal (condition-case nil ; in case "grep" 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
392 (call-process grep-program nil nil nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
393 "-e" "foo" null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
394 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
395 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
396 (format "%s %s -e " grep-program required-options)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
397 (format "%s %s " grep-program required-options)))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
398 (unless grep-find-use-xargs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
399 (setq grep-find-use-xargs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
400 (if (and
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
401 (equal (call-process "find" nil nil nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
402 null-device "-print0")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
403 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
404 (equal (call-process "xargs" nil nil nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
405 "-0" "-e" "echo")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
406 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
407 'gnu)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
408 (unless grep-find-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
409 (setq grep-find-command
54012
1313586e1e29 (grep-compute-defaults): Undo change from
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53953
diff changeset
410 (cond ((eq grep-find-use-xargs 'gnu)
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
411 (format "%s . -type f -print0 | xargs -0 -e %s"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
412 find-program grep-command))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
413 (grep-find-use-xargs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
414 (format "%s . -type f -print | xargs %s"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
415 find-program grep-command))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
416 (t (cons (format "%s . -type f -exec %s {} %s \\;"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
417 find-program grep-command null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
418 (+ 22 (length grep-command)))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
419 (unless grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
420 (setq grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
421 (let* ((glen (length grep-program))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
422 (gcmd (concat grep-program " <C>" (substring grep-command glen))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
423 (cond ((eq grep-find-use-xargs 'gnu)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
424 (format "%s <D> <X> -type f <F> -print0 | xargs -0 -e %s <R>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
425 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
426 (grep-find-use-xargs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
427 (format "%s <D> <X> -type f <F> -print | xargs %s <R>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
428 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
429 (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;"
56948
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
430 find-program gcmd null-device))))))
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
431 (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
432 (setq grep-highlight-matches
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
433 (with-temp-buffer
56960
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
434 (and (equal (condition-case nil
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
435 (call-process grep-program nil t nil "--help")
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
436 (error nil))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
437 0)
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
438 (progn
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
439 (goto-char (point-min))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
440 (search-forward "--color" nil t))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
441 t)))))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
442
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
443 (defun grep-default-command ()
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
444 (let ((tag-default
57908
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
445 (shell-quote-argument
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
446 (or (funcall (or find-tag-default-function
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
447 (get major-mode 'find-tag-default-function)
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
448 'find-tag-default))
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
449 "")))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
450 (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
451 (grep-default (or (car grep-history) grep-command)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
452 ;; Replace the thing matching for with that around cursor.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
453 (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
454 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
455 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
456 grep-default)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
457 ;; 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
458 (string-match "\\(\\)\\'" grep-default))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
459 (unless (or (not (stringp buffer-file-name))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
460 (when (match-beginning 2)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
461 (save-match-data
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
462 (string-match
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
463 (wildcard-to-regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
464 (file-name-nondirectory
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
465 (match-string 3 grep-default)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
466 (file-name-nondirectory buffer-file-name)))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
467 (setq grep-default (concat (substring grep-default
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
468 0 (match-beginning 2))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
469 " *."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
470 (file-name-extension buffer-file-name))))
57908
a4ed247d476f (grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 57769
diff changeset
471 (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
472
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
473 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
474 (defun grep (command-args &optional highlight-regexp)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
475 "Run grep, with user-specified args, and 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
476 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
56420
7e766b87637b (grep): Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 56333
diff changeset
477 or \\<grep-mode-map>\\[compile-goto-error] in the grep \
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
478 output buffer, to go to the lines
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
479 where grep found matches.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
480
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
481 This command uses a special history list for its COMMAND-ARGS, so you can
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
482 easily repeat a grep command.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
483
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
484 A prefix argument says to default the argument based upon the current
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
485 tag the cursor is over, substituting it into the last grep command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
486 in the grep command history (or into `grep-command'
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
487 if that history list is empty).
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
488
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
489 If specified, optional second arg HIGHLIGHT-REGEXP is the regexp to
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
490 temporarily highlight in visited source lines."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
491 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
492 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
493 (unless (and grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
494 (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
495 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
496 (let ((default (grep-default-command)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
497 (list (read-from-minibuffer "Run grep (like this): "
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
498 (if current-prefix-arg
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
499 default grep-command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
500 nil nil 'grep-history
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
501 (if current-prefix-arg nil default))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
502
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
503 ;; Setting process-setup-function makes exit-message-function work
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
504 ;; even when async processes aren't supported.
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
505 (let ((compilation-process-setup-function 'grep-process-setup))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
506 (compilation-start (if (and grep-use-null-device null-device)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
507 (concat command-args " " null-device)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
508 command-args)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
509 'grep-mode nil highlight-regexp)))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
510
55018
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
511 (define-compilation-mode grep-mode "Grep"
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
512 "Sets `grep-last-buffer' and `compilation-window-height'."
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
513 (setq grep-last-buffer (current-buffer))
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
514 (set (make-local-variable 'compilation-error-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
515 grep-hit-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
516 (set (make-local-variable 'compilation-error-regexp-alist)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
517 grep-regexp-alist))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
518
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
519 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
520 (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
521 "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
522 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
523 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
524 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
525
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
526 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
527 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
528 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
529 (progn
59605
b64dd2ff73f7 (grep-find): Copy from `grep' the condition for calling grep-compute-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 58988
diff changeset
530 (unless (and grep-command
b64dd2ff73f7 (grep-find): Copy from `grep' the condition for calling grep-compute-defaults.
Richard M. Stallman <rms@gnu.org>
parents: 58988
diff changeset
531 (or (not grep-use-null-device) (eq grep-use-null-device t)))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
532 (grep-compute-defaults))
53750
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
533 (if grep-find-command
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
534 (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
535 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
536 'grep-find-history))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
537 ;; No default was set
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
538 (read-string
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
539 "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
540 (list nil))))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
541 (when (and grep-find-command command-args)
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
542 (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
543 (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
544
59688
3761d1e2619d * NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents: 59605
diff changeset
545 ;;;###autoload
3761d1e2619d * NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents: 59605
diff changeset
546 (defalias 'find-grep 'grep-find)
3761d1e2619d * NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents: 59605
diff changeset
547
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
548 (defun grep-expand-command-macros (command &optional regexp files dir excl case-fold)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
549 "Patch grep COMMAND replacing <D>, etc."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
550 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
551 (replace-regexp-in-string "<D>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
552 (or dir ".") command t t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
553 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
554 (replace-regexp-in-string "<X>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
555 (or excl "") command t t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
556 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
557 (replace-regexp-in-string "<F>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
558 (or files "") command t t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
559 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
560 (replace-regexp-in-string "<C>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
561 (if case-fold "-i" "") command t t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
562 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
563 (replace-regexp-in-string "<R>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
564 (or regexp "") command t t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
565 command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
566
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
567 (defvar grep-tree-last-regexp "")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
568 (defvar grep-tree-last-files (car (car grep-tree-files-aliases)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
569
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
570 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
571 (defun grep-tree (regexp files dir &optional subdirs)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
572 "Grep for REGEXP in FILES in directory tree rooted at DIR.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
573 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
574 Interactively, prompt separately for each search parameter.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
575 With prefix arg, reuse previous REGEXP.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
576 The search is limited to file names matching shell pattern FILES.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
577 FILES may use abbreviations defined in `grep-tree-files-aliases', e.g.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
578 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
579
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
580 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
581 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
582
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
583 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
584 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
585
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
586 When used non-interactively, optional arg SUBDIRS limits the search to
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
587 those sub directories of DIR."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
588 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
589 (let* ((regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
590 (if current-prefix-arg
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
591 grep-tree-last-regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
592 (let* ((default (current-word))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
593 (spec (read-string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
594 (concat "Search for"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
595 (if (and default (> (length default) 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
596 (format " (default %s): " default) ": ")))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
597 (if (equal spec "") default spec))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
598 (files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
599 (read-string (concat "Search for \"" regexp "\" in files (default " grep-tree-last-files "): ")))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
600 (dir
55804
9766648e58a2 (grep-tree): Rework previous fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55747
diff changeset
601 (read-directory-name "Base directory: " nil default-directory t)))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
602 (list regexp files dir)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
603 (unless grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
604 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
605 (unless (and (stringp files) (> (length files) 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
606 (setq files grep-tree-last-files))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
607 (when files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
608 (setq grep-tree-last-files files)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
609 (let ((mf (assoc files grep-tree-files-aliases)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
610 (if mf
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
611 (setq files (cdr mf)))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
612 (let ((command-args (grep-expand-command-macros
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
613 grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
614 (setq grep-tree-last-regexp regexp)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
615 (and files (concat "-name '" files "'"))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
616 (if subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
617 (if (stringp subdirs)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
618 subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
619 (mapconcat 'identity subdirs " "))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
620 nil) ;; we change default-directory to dir
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
621 (and grep-tree-ignore-CVS-directories "-path '*/CVS' -prune -o ")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
622 grep-tree-ignore-case))
55804
9766648e58a2 (grep-tree): Rework previous fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55747
diff changeset
623 (default-directory (file-name-as-directory (expand-file-name dir)))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
624 (null-device nil)) ; see grep
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
625 (grep command-args regexp)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
626
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
627
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
628 (provide 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
629
57043
cb013e5835b8 (grep-mode): Remove unnecessary autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57022
diff changeset
630 ;; 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
631 ;;; grep.el ends here