annotate lisp/progmodes/grep.el @ 56648:5defa47ef9da

*** empty log message ***
author Daniel Pfeiffer <occitan@esperanto.org>
date Wed, 11 Aug 2004 20:00:11 +0000
parents 7e766b87637b
children 5ed31ed85a8e 97905c4f1a42
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
53851
823980f7d612 (grep-regexp-alist): Allow :, \t and ( in file names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53750
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 1999, 2001, 02, 2004
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
67 (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
68 "*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
69
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
70 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
71 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
72 than the begining."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
73 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
74 :version "21.4"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
75 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
76
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
77 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
78 (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
79 "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
80 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
81 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
82 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
83
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
84 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
85 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
86 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
87 (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
88 :group 'grep)
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 (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
91 "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
92 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
93 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
94 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
95
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
96 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
97 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
98 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
99 :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
100 (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
101 (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
102 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
103
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
104 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
105 (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
106 "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
107 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
108 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
109 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
110 (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
111 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
112
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
113 (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
114 "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
115 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
116 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
117 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
118 <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
119 <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
120 <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
121 <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
122 <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
123 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 (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
125 :version "21.4"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
126 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
127
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
128 (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
129 ("ch" . "*.[ch]")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
130 ("c" . "*.c")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
131 ("h" . "*.h")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
132 ("m" . "[Mm]akefile*")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
133 ("asm" . "*.[sS]")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
134 ("all" . "*")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
135 ("el" . "*.el")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
136 )
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
137 "*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
138 :type 'alist
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
139 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
140
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
141 (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
142 "*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
143 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
144 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
145
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
146 (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
147 "*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
148 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
149 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
150
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
151 (defcustom grep-error-screen-columns nil
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
152 "*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
153 See `compilation-error-screen-columns'"
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
154 :type '(choice (const :tag "Default" nil)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
155 integer)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
156 :version "21.4"
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
157 :group 'grep)
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
158
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
159 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
160 (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
161 "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
162 :type 'hook
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 (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
166 (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
167 (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
168 (define-key map "\^?" 'scroll-down)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
169
53486
23376885b0f9 (grep-mode-map): Don't remap next-line, previous-line.
Richard M. Stallman <rms@gnu.org>
parents: 53154
diff changeset
170 ;; 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
171 ;;; (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
172 ;;; (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
173
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
174 (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
175 (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
176 (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
177 (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
178 (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
179 (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
180
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
181 ;; 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
182 (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
183 (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
184
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
185 (define-key map [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
186 '("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
187 (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
188 '("----" . nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
189 (define-key map [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
190 '("Compile..." . compile))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
191 (define-key map [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
192 '("Another grep" . grep))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
193 (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
194 '("Repeat grep" . recompile))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
195 (define-key map [menu-bar grep compilation-separator2]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
196 '("----" . nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
197 (define-key map [menu-bar grep compilation-first-error]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 '("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
199 (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
200 '("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
201 (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
202 '("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
203 map)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
204 "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
205 `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
206
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
207 (defalias 'kill-grep 'kill-compilation)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
208
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
209 ;;;; TODO --- refine this!!
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
210
53145
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
211 ;;; (defcustom grep-use-compilation-buffer t
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
212 ;;; "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
213 ;;; 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
214 ;;; 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
215 ;;; 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
216 ;;; be used to navigate between grep matches."
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
217 ;;; :type 'boolean
a0151f86f01e Remove grep-use-compilation-buffer defcustom.
Kim F. Storm <storm@cua.dk>
parents: 53139
diff changeset
218 ;;; :group 'grep)
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
219
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
220 ;; 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
221 (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
222 "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
223 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
224 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
225 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
226 `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
227
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
228 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
229 (defvar grep-regexp-alist
56226
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
230 '(("^\\(.+?\\)[:( \t]+\
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
231 \\([0-9]+\\)\\([.:]?\\)\\([0-9]+\\)?\
bfe817c8d413 (grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents: 56155
diff changeset
232 \\(?:-\\(?:\\([0-9]+\\)\\3\\)?\\.?\\([0-9]+\\)?\\)?[:) \t]" 1 (2 . 5) (4 . 6))
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
233 ("^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
234 "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
235
54372
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
236 (defvar grep-error "grep hit"
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
237 "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
238
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
239 ;; 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
240 ;; 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
241 (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
242 "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
243
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
244 (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
245 "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
246
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
247 (defvar grep-mode-font-lock-keywords
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
248 '(;; Command output lines.
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
249 ("^\\([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
250 (": \\(.+\\): \\(?: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
251 1 grep-error-face)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
252 ;; 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
253 ("^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
254 (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
255 (1 grep-hit-face nil t)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
256 (2 grep-error-face nil t))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
257 ("^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
258 (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
259 (1 compilation-warning-face)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
260 (2 compilation-line-face)))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
261 "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
262 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
263
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
264 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
265 (defvar grep-program
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
266 ;; 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
267 ;; 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
268 "grep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
269 ;; (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
270 ;; (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
271 ;; "foo" null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
272 ;; (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
273 ;; 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
274 ;; "zgrep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
275 ;; "grep")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
276 "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
277 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
278
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
279 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
280 (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
281 "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
282 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
283
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
284 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
285 (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
286 "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
287
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
288 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
289 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
290
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
291 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
292
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
293 ;; History of grep commands.
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
294 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
295 (defvar grep-history nil)
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
296 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
297 (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
298
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
299 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
300 (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
301 "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
302 Set up `compilation-exit-message-function' and run `grep-setup-hook'."
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
303 (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
304 (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
305 (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
306 (cond ((zerop code)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
307 '("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
308 ((= code 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
309 '("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
310 (t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
311 (cons msg code)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
312 (cons msg code))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
313 (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
314
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
315 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
316 (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
317 (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
318 (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
319 (with-temp-buffer
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
320 (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
321 (not
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
322 (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
323 (if grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
324 ;; `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
325 ;; 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
326 (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
327 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
328 "^English" hello-file)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
329 ;; 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
330 (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
331 "-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
332 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
333 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
334 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
335 (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
336 (looking-at
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
337 (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
338 ":[0-9]+:English")))))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
339 (unless grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
340 (setq grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
341 (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
342 (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
343 (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
344 "-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
345 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
346 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
347 (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
348 (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
349 (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
350 (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
351 (if (and
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
352 (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
353 null-device "-print0")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
354 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
355 (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
356 "-0" "-e" "echo")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
357 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
358 'gnu)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
359 (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
360 (setq grep-find-command
54012
1313586e1e29 (grep-compute-defaults): Undo change from
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53953
diff changeset
361 (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
362 (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
363 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
364 (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
365 (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
366 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
367 (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
368 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
369 (+ 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
370 (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
371 (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
372 (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
373 (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
374 (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
375 (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
376 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
377 (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
378 (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
379 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
380 (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
381 find-program gcmd null-device)))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
382
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 (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
384 (let ((tag-default
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
385 (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
386 (get major-mode '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
387 ;; We use grep-tag-default instead of
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
388 ;; find-tag-default, to avoid loading etags.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
389 'grep-tag-default)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
390 (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
391 (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
392 ;; 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
393 (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
394 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
395 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
396 grep-default)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
397 ;; 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
398 (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
399 (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
400 (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
401 (save-match-data
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
402 (string-match
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
403 (wildcard-to-regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
404 (file-name-nondirectory
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
405 (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
406 (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
407 (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
408 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
409 " *."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
410 (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
411 (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
412
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
413 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
414 (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
415 "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
416 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
417 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
418 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
419 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
420
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
421 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
422 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
423
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
424 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
425 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
426 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
427 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
428
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
429 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
430 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
431 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
432 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
433 (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
434 (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
435 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
436 (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
437 (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
438 (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
439 default grep-command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
440 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
441 (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
442
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
443 ;; 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
444 ;; 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
445 (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
446 (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
447 (concat command-args " " null-device)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
448 command-args)
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
449 'grep-mode nil highlight-regexp)))
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
450
a4d3c17f991f (kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54012
diff changeset
451 ;;;###autoload (autoload 'grep-mode "grep" nil t)
55018
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
452 (define-compilation-mode grep-mode "Grep"
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
453 "Sets `grep-last-buffer' and `compilation-window-height'."
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
454 (setq grep-last-buffer (current-buffer))
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
455 (set (make-local-variable 'compilation-error-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
456 grep-hit-face)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
457 (set (make-local-variable 'compilation-error-regexp-alist)
4f12dee543dc Undo previous change
Jan Djärv <jan.h.d@swipnet.se>
parents: 55017
diff changeset
458 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
459
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
460 ;; This is a copy of find-tag-default from etags.el.
56333
eb4bc9a65835 (grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents: 56226
diff changeset
461 ;;;###autoload
53139
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
462 (defun grep-tag-default ()
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
463 (save-excursion
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
464 (while (looking-at "\\sw\\|\\s_")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
465 (forward-char 1))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
466 (when (or (re-search-backward "\\sw\\|\\s_"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
467 (save-excursion (beginning-of-line) (point))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
468 t)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
469 (re-search-forward "\\(\\sw\\|\\s_\\)+"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
470 (save-excursion (end-of-line) (point))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
471 t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
472 (goto-char (match-end 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
473 (buffer-substring (point)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
474 (progn (forward-sexp -1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
475 (while (looking-at "\\s'")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
476 (forward-char 1))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
477 (point))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
478
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
479 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
480 (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
481 "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
482 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
483 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
484 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
485
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
486 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
487 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
488 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
489 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
490 (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
491 (grep-compute-defaults))
53750
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
492 (if grep-find-command
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
493 (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
494 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
495 'grep-find-history))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
496 ;; No default was set
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
497 (read-string
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
498 "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
499 (list nil))))
4deb14fde58c (grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents: 53486
diff changeset
500 (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
501 (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
502 (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
503
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
504 (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
505 "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
506 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
507 (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
508 (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
509 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
510 (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
511 (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
512 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
513 (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
514 (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
515 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
516 (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
517 (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
518 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
519 (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
520 (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
521 command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
522
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
523 (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
524 (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
525
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
526 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
527 (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
528 "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
529 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
530 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
531 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
532 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
533 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
534 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
535
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
536 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
537 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
538
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
539 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
540 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
541
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
542 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
543 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
544 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
545 (let* ((regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
546 (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
547 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
548 (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
549 (spec (read-string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
550 (concat "Search for"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
551 (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
552 (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
553 (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
554 (files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
555 (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
556 (dir
55804
9766648e58a2 (grep-tree): Rework previous fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55747
diff changeset
557 (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
558 (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
559 (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
560 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
561 (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
562 (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
563 (when files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
564 (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
565 (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
566 (if mf
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
567 (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
568 (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
569 grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
570 (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
571 (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
572 (if subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
573 (if (stringp subdirs)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
574 subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
575 (mapconcat 'identity subdirs " "))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
576 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
577 (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
578 grep-tree-ignore-case))
55804
9766648e58a2 (grep-tree): Rework previous fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55747
diff changeset
579 (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
580 (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
581 (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
582
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
583
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
584 (provide 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
585
53953
68ce0c560d06 Move "ends here" comment to end; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53951
diff changeset
586 ;;; 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
587 ;;; grep.el ends here