annotate lisp/progmodes/grep.el @ 53139:df3033332097

* progmodes/grep.el: New file with grep code from compile.el. (grep): New defcustom group. (grep-window-height): New defcustom, like compilation-window-height. (grep-auto-highlight): New defcustom, like compile-auto-highlight. (grep-scroll-output): New defcustom, like compilation-scroll-output. (grep-command, grep-use-null-device, grep-find-command) (grep-tree-files-aliases, grep-tree-ignore-case) (grep-tree-ignore-CVS-directories): Move to grep custom group. (grep-setup-hook): New hook variable. (grep-mode-map): New keymap for grep commands. Add Grep menu. (grep-use-compilation-buffer): New defcustom. (grep-last-buffer): New defvar, override compilation-last-buffer. (grep): Add optional arg HIGHLIGHT-REGEXP. Doc fix. Call compile-internal with args highlight-regexp and grep-mode-map.
author Kim F. Storm <storm@cua.dk>
date Sun, 23 Nov 2003 20:56:10 +0000
parents
children a0151f86f01e
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 1999, 2001, 2002
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
77 (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
78 "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
79 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
80 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
81 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
82
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
83 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
84 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
85 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
86 (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
87 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
88
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
89 (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
90 "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
91 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
92 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
93 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
94
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
95 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
96 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
97 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
98 :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
99 (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
100 (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
101 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
102
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
103 (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
104 "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
105 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
106 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
107 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
108 (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
109 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
110
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
111 (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
112 "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
113 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
114 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
115 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
116 <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
117 <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
118 <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
119 <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
120 <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
121 :type '(choice string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
122 (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
123 :version "21.4"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
124 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
125
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
126 (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
127 ("ch" . "*.[ch]")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
128 ("c" . "*.c")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
129 ("h" . "*.h")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
130 ("m" . "[Mm]akefile*")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
131 ("asm" . "*.[sS]")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
132 ("all" . "*")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
133 ("el" . "*.el")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
134 )
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
135 "*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
136 :type 'alist
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
137 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
138
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
139 (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
140 "*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
141 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
142 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
143
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
144 (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
145 "*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
146 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
147 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
148
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
149 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
150 (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
151 "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
152 :type 'hook
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
153 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
154
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
155 (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
156 (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
157 (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
158 (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
159
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
160 (define-key map [remap next-line] 'compilation-next-error)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
161 (define-key map [remap previous-line] 'compilation-previous-error)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
162
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
163 (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
164 (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
165 (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
166 (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
167 (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
168 (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
169
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
170 ;; 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
171 (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
172 (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
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 [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
175 '("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
176 (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
177 '("----" . nil))
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 [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
179 '("Compile..." . compile))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
180 (define-key map [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
181 '("Another grep" . grep))
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 compilation-recompile]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
183 '("Repeat grep" . recompile))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
184 (define-key map [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
185 '("----" . nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
186 (define-key map [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
187 '("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
188 (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
189 '("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
190 (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
191 '("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
192 map)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
193 "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
194 `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
195
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
196 ;;;; TODO --- refine this!!
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
197
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
198 (defcustom grep-use-compilation-buffer t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
199 "When non-nil, grep specific commands update `compilation-last-buffer'.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
200 This means that standard compile commands like \\[next-error] and \\[compile-goto-error]
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
201 can be used to navigate between grep matches (the default).
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
202 Otherwise, the grep specific commands like \\[grep-next-match] must
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
203 be used to navigate between grep matches."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
204 :type 'boolean
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
205 :group 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
206
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
207 ;; 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
208 (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
209 "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
210 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
211 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
212 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
213 `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
214
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
215 ;; Note: the character class after the optional drive letter does not
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
216 ;; include a space to support file names with blanks.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
217 (defvar grep-regexp-alist
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
218 '(("\\([a-zA-Z]?:?[^:(\t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
219 "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
220
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
221 (defvar grep-program
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
222 ;; 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
223 ;; 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
224 "grep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
225 ;; (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
226 ;; (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
227 ;; "foo" null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
228 ;; (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
229 ;; 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
230 ;; "zgrep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
231 ;; "grep")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
232 "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
233 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
234
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
235 (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
236 "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
237 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
238
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
239 (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
240 "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
241
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
242 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
243 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
244
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
245 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
246
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
247 ;; History of grep commands.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
248 (defvar grep-history nil)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
249 (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
250
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
251 (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
252 "Setup compilation variables and buffer for `grep'.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
253 Set up `compilation-exit-message-function' and `compilation-window-height'.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
254 Sets `grep-last-buffer' and runs `grep-setup-hook'."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
255 (setq grep-last-buffer (current-buffer))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
256 (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
257 (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
258 (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
259 (cond ((zerop code)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
260 '("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
261 ((= code 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
262 '("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
263 (t
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
264 (cons msg code)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
265 (cons msg code))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
266 (if grep-window-height
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
267 (set (make-local-variable 'compilation-window-height)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
268 grep-window-height))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
269 (set (make-local-variable 'compile-auto-highlight)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
270 grep-auto-highlight)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
271 (set (make-local-variable 'compilation-scroll-output)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
272 grep-scroll-output)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
273 (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
274
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
275 (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
276 (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
277 (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
278 (with-temp-buffer
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
279 (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
280 (not
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
281 (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
282 (if grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
283 ;; `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
284 ;; 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
285 (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
286 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
287 "^English" hello-file)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
288 ;; 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
289 (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
290 "-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
291 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
292 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
293 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
294 (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
295 (looking-at
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
296 (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
297 ":[0-9]+:English")))))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
298 (unless grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
299 (setq grep-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
300 (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
301 (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
302 (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
303 "-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
304 (error nil))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
305 1)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
306 (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
307 (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
308 (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
309 (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
310 (if (and
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
311 (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
312 null-device "-print0")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
313 0)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
314 (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
315 "-0" "-e" "echo")
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
316 0))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
317 'gnu)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
318 (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
319 (setq grep-find-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
320 (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
321 (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
322 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
323 (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
324 (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
325 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
326 (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
327 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
328 (+ 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
329 (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
330 (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
331 (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
332 (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
333 (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
334 (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
335 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
336 (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
337 (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
338 find-program gcmd))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
339 (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
340 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
341
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
342 (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
343 (let ((tag-default
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
344 (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
345 (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
346 ;; 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
347 ;; 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
348 'grep-tag-default)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
349 (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
350 (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
351 ;; 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
352 (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
353 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
354 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
355 grep-default)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
356 ;; 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
357 (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
358 (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
359 (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
360 (save-match-data
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
361 (string-match
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
362 (wildcard-to-regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
363 (file-name-nondirectory
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
364 (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
365 (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
366 (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
367 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
368 " *."
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
369 (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
370 (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
371
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
372 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
373 (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
374 "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
375 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
376 or \\<grep-minor-mode-map>\\[compile-goto-error] in the grep \
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
377 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
378 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
379
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
380 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
381 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
382
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
383 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
384 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
385 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
386 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
387
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
388 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
389 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
390 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
391 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
392 (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
393 (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
394 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
395 (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
396 (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
397 (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
398 default grep-command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
399 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
400 (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
401
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
402 ;; 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
403 ;; even when async processes aren't supported.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
404 (let* ((compilation-process-setup-function 'grep-process-setup)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
405 (buf (compile-internal (if (and grep-use-null-device null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
406 (concat command-args " " null-device)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
407 command-args)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
408 "No more grep hits" "grep"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
409 ;; Give it a simpler regexp to match.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
410 nil grep-regexp-alist
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
411 nil nil nil nil nil nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
412 highlight-regexp grep-mode-map)))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
413
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
414 ;; This is a copy of find-tag-default from etags.el.
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
415 (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
416 (save-excursion
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
417 (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
418 (forward-char 1))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
419 (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
420 (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
421 t)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
422 (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
423 (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
424 t))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
425 (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
426 (buffer-substring (point)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
427 (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
428 (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
429 (forward-char 1))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
430 (point))))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
431
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
432 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
433 (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
434 "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
435 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
436 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
437 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
438
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
439 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
440 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
441 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
442 (progn
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
443 (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
444 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
445 (list (read-from-minibuffer "Run find (like this): "
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
446 grep-find-command nil nil
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
447 'grep-find-history))))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
448 (let ((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
449 (grep command-args)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
450
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
451 (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
452 "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
453 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
454 (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
455 (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
456 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
457 (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
458 (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
459 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
460 (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
461 (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
462 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
463 (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
464 (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
465 (setq command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
466 (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
467 (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
468 command)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
469
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
470 (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
471 (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
472
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
473 ;;;###autoload
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
474 (defun grep-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
475 "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
476 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
477 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
478 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
479 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
480 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
481 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
482
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
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
489 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
490 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
491 (interactive
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
492 (let* ((regexp
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
493 (if current-prefix-arg
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
494 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
495 (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
496 (spec (read-string
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
497 (concat "Search for"
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
498 (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
499 (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
500 (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
501 (files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
502 (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
503 (dir
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
504 (read-directory-name "Base directory: " nil default-directory t)))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
505 (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
506 (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
507 (grep-compute-defaults))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
508 (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
509 (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
510 (when files
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
511 (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
512 (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
513 (if mf
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
514 (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
515 (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
516 grep-tree-command
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
517 (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
518 (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
519 (if subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
520 (if (stringp subdirs)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
521 subdirs
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
522 (mapconcat 'identity subdirs " "))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
523 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
524 (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
525 grep-tree-ignore-case))
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
526 (default-directory dir)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
527 (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
528 (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
529
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
530
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
531 (provide 'grep)
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
532
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
533 ;;; grep.el ends here
df3033332097 * progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff changeset
534