annotate lisp/progmodes/grep.el @ 57769:e663f6b659a6

(grep-regexp-alist): Move match highlighting code to `grep-mode-font-lock-keywords'. (grep-mode-font-lock-keywords): Delete grep markers instead of making them invisible.
author Juri Linkov <juri@jurta.org>
date Thu, 28 Oct 2004 09:00:26 +0000
parents cb013e5835b8
children a4ed247d476f
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)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
47 :version "21.4"
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"))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
64 :version "21.4"
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))
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
84 :version "21.4"
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
94 :version "21.4"
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))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
144 :version "21.4"
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)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
175 :version "21.4"
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
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
250 '(("^\\(.+?\\)[:( \t]+\
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
251 \\([0-9]+\\)\\([.:]?\\)\\([0-9]+\\)?\
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
252 \\(?:-\\(?:\\([0-9]+\\)\\3\\)?\\.?\\([0-9]+\\)?\\)?[:) \t]" 1 (2 . 5) (4 . 6))
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
253 ("^\\(.+?\\)[:(]+\\([0-9]+\\)\\([:)]\\).*?\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\)"
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
254 1 2
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
255 ;; 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
256 ((lambda ()
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
257 (setq compilation-error-screen-columns nil)
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
258 (- (match-beginning 5) (match-end 3) 8))
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
259 .
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
260 (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
261 ("^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
262 "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
263
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
264 (defvar grep-error "grep hit"
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
265 "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
266
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
267 ;; 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
268 ;; 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
269 (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
270 "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
271
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
272 (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
273 "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
274
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
275 (defvar grep-mode-font-lock-keywords
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
276 '(;; Command output lines.
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
277 ("^\\([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
278 (": \\(.+\\): \\(?: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
279 1 grep-error-face)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
280 ;; 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
281 ("^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
282 (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
283 (1 grep-hit-face nil t)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
284 (2 grep-error-face nil t))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
285 ("^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
286 (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
287 (1 compilation-warning-face)
57769
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
288 (2 compilation-line-face))
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
289 ;; Highlight grep matches and delete markers
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
290 ("\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\)"
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
291 (2 compilation-column-face)
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
292 ((lambda (p))
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
293 (progn
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
294 ;; Delete markers with `replace-match' because it updates
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
295 ;; 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
296 (replace-match "" t t nil 3)
e663f6b659a6 (grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents: 57043
diff changeset
297 (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
298 "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
299 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
300
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
301 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
302 (defvar grep-program
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
303 ;; 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
304 ;; 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
305 "grep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
306 ;; (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
307 ;; (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
308 ;; "foo" null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
309 ;; (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
310 ;; 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
311 ;; "zgrep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
312 ;; "grep")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
313 "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
314 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
315
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
316 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 (defvar find-program "find"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
318 "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
319 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
320
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
321 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
322 (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
323 "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
324
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
325 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
326 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
327
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
328 This variable's value takes effect when `grep-compute-defaults' is called.")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
329
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
330 ;; History of grep commands.
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
331 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
332 (defvar grep-history nil)
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
333 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
334 (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
335
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
336 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
337 (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
338 "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
339 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
340 (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
341 (grep-compute-defaults))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
342 (when (eq grep-highlight-matches t)
56881
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
343 ;; Modify `process-environment' locally bound in `compilation-start'
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
344 (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always"))
4be25baf31b5 (grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents: 56828
diff changeset
345 (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
346 (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
347 (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
348 (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
349 (cond ((zerop code)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
350 '("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
351 ((= code 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
352 '("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
353 (t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
354 (cons msg code)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
355 (cons msg code))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
356 (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
357
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
358 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
359 (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
360 (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
361 (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
362 (with-temp-buffer
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
363 (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
364 (not
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
365 (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
366 (if grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
367 ;; `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
368 ;; 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
369 (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
370 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
371 "^English" hello-file)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
372 ;; 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
373 (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
374 "-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
375 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
376 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
377 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
378 (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
379 (looking-at
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
380 (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
381 ":[0-9]+:English")))))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
382 (unless grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 (setq grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
384 (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
385 (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
386 (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
387 "-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
388 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
389 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
390 (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
391 (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
392 (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
393 (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
394 (if (and
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
395 (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
396 null-device "-print0")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
397 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
398 (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
399 "-0" "-e" "echo")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
400 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
401 'gnu)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
402 (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
403 (setq grep-find-command
54012
1313586e1e29 (grep-compute-defaults): Undo change from
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53953
diff changeset
404 (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
405 (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
406 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
407 (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
408 (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
409 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
410 (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
411 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
412 (+ 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
413 (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
414 (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
415 (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
416 (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
417 (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
418 (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
419 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
420 (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
421 (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
422 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
423 (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
424 find-program gcmd null-device))))))
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
425 (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
426 (setq grep-highlight-matches
f6f74981c4b0 (grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents: 56921
diff changeset
427 (with-temp-buffer
56960
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
428 (and (equal (condition-case nil
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
429 (call-process grep-program nil t nil "--help")
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
430 (error nil))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
431 0)
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
432 (progn
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
433 (goto-char (point-min))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
434 (search-forward "--color" nil t))
84482ed458f2 (grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 56948
diff changeset
435 t)))))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
436
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
437 (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
438 (let ((tag-default
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
439 (funcall (or find-tag-default-function
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
440 (get major-mode 'find-tag-default-function)
56828
5ed31ed85a8e (grep-default-command): Use find-tag-default.
Richard M. Stallman <rms@gnu.org>
parents: 56420
diff changeset
441 'find-tag-default)))
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
442 (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
443 (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
444 ;; 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
445 (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
446 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
447 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
448 grep-default)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
449 ;; 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
450 (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
451 (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
452 (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
453 (save-match-data
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
454 (string-match
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
455 (wildcard-to-regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
456 (file-name-nondirectory
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
457 (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
458 (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
459 (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
460 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
461 " *."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
462 (file-name-extension buffer-file-name))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
463 (replace-match (or tag-default "") t t grep-default 1))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
464
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
465 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
466 (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
467 "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
468 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
469 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
470 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
471 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
472
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
473 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
474 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
475
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
476 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
477 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
478 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
479 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
480
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
481 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
482 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
483 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
484 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
485 (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
486 (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
487 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
488 (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
489 (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
490 (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
491 default grep-command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
492 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
493 (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
494
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
495 ;; 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
496 ;; 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
497 (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
498 (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
499 (concat command-args " " null-device)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
500 command-args)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
501 'grep-mode nil highlight-regexp)))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
502
55018
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
503 (define-compilation-mode grep-mode "Grep"
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
504 "Sets `grep-last-buffer' and `compilation-window-height'."
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
505 (setq grep-last-buffer (current-buffer))
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
506 (set (make-local-variable 'compilation-error-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
507 grep-hit-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
508 (set (make-local-variable 'compilation-error-regexp-alist)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
509 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
510
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
511 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
512 (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
513 "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
514 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
515 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
516 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
517
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
518 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
519 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
520 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
521 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
522 (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
523 (grep-compute-defaults))
53750
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
524 (if grep-find-command
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
525 (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
526 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
527 'grep-find-history))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
528 ;; No default was set
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
529 (read-string
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
530 "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
531 (list nil))))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
532 (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
533 (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
534 (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
535
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
536 (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
537 "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
538 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
539 (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
540 (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
541 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
542 (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
543 (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
544 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
545 (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
546 (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
547 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
548 (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
549 (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
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 "<R>"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
552 (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
553 command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
554
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
555 (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
556 (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
557
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
558 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
559 (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
560 "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
561 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
562 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
563 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
564 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
565 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
566 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
567
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
568 While find runs asynchronously, you can use the \\[next-error] command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
569 to find the text that grep hits refer to.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
570
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
571 This command uses a special history list for its arguments, so you can
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
572 easily repeat a find command.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
573
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
574 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
575 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
576 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
577 (let* ((regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
578 (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
579 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
580 (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
581 (spec (read-string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
582 (concat "Search for"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
583 (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
584 (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
585 (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
586 (files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
587 (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
588 (dir
55804
9766648e58a2 (grep-tree): Rework previous fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55747
diff changeset
589 (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
590 (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
591 (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
592 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
593 (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
594 (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
595 (when files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
596 (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
597 (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
598 (if mf
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
599 (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
600 (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
601 grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
602 (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
603 (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
604 (if subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
605 (if (stringp subdirs)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
606 subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
607 (mapconcat 'identity subdirs " "))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
608 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
609 (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
610 grep-tree-ignore-case))
55804
9766648e58a2 (grep-tree): Rework previous fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55747
diff changeset
611 (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
612 (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
613 (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
614
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
615
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
616 (provide 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
617
57043
cb013e5835b8 (grep-mode): Remove unnecessary autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57022
diff changeset
618 ;; 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
619 ;;; grep.el ends here