Mercurial > emacs
annotate lisp/progmodes/grep.el @ 112438:11f1b4757236
* image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash
when calling XpmCreatePixmapFromData.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 22 Jan 2011 20:33:12 -0800 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
62160 | 1 ;;; grep.el --- run Grep as inferior of Emacs, parse match messages |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
2 |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
107944
diff
changeset
|
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
87560
62e8690b9f1a
(find-name-arg): Declare for compiler.
Glenn Morris <rgm@gnu.org>
parents:
87523
diff
changeset
|
5 ;; Free Software Foundation, Inc. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
6 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
7 ;; 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
|
8 ;; Maintainer: FSF |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
9 ;; Keywords: tools, processes |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
10 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
11 ;; 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
|
12 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94566
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94566
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94566
diff
changeset
|
16 ;; (at your option) any later version. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
17 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
18 ;; 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
|
19 ;; 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
|
20 ;; 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
|
21 ;; 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
|
22 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94566
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
25 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
26 ;;; Commentary: |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
27 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
28 ;; 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
|
29 ;; user's manual. |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
30 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
31 ;;; Code: |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
32 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
33 (require 'compile) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
34 |
65232
6b7109ed93a0
(font-lock-lines-before): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
65126
diff
changeset
|
35 |
53139
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 |
70258 | 37 "Run grep as inferior of Emacs, parse error messages." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
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 |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
41 (defvar grep-host-defaults-alist nil |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
42 "Default values depending on target host. |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
43 `grep-compute-defaults' returns default values for every local or |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
44 remote host `grep' runs. These values can differ from host to |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
45 host. Once computed, the default values are kept here in order |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
46 to avoid computing them again.") |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
47 |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
48 (defun grep-apply-setting (symbol value) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
49 "Set SYMBOL to VALUE, and update `grep-host-defaults-alist'. |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
50 SYMBOL should be one of `grep-command', `grep-template', |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
51 `grep-use-null-device', `grep-find-command', |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
52 `grep-find-template', `grep-find-use-xargs', or |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
53 `grep-highlight-matches'." |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
54 (when grep-host-defaults-alist |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
55 (let* ((host-id |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
56 (intern (or (file-remote-p default-directory) "localhost"))) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
57 (host-defaults (assq host-id grep-host-defaults-alist)) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
58 (defaults (assq nil grep-host-defaults-alist))) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
59 (setcar (cdr (assq symbol host-defaults)) value) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
60 (setcar (cdr (assq symbol defaults)) value))) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
61 (set-default symbol value)) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
62 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
63 ;;;###autoload |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
64 (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
|
65 "*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
|
66 :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
|
67 integer) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
68 :version "22.1" |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
69 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
70 |
56948
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
71 (defcustom grep-highlight-matches 'auto-detect |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
72 "Use special markers to highlight grep matches. |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
73 |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
74 Some grep programs are able to surround matches with special |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
75 markers in grep output. Such markers can be used to highlight |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
76 matches in grep mode. |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
77 |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
78 This option sets the environment variable GREP_COLORS to specify |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
79 markers for highlighting and GREP_OPTIONS to add the --color |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
80 option in front of any explicit grep options before starting |
56960
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
81 the grep. |
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
82 |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
83 When this option is `auto', grep uses `--color=auto' to highlight |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
84 matches only when it outputs to a terminal (when `grep' is the last |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
85 command in the pipe), thus avoiding the use of any potentially-harmful |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
86 escape sequences when standard output goes to a file or pipe. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
87 |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
88 To make grep highlight matches even into a pipe, you need the option |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
89 `always' that forces grep to use `--color=always' to unconditionally |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
90 output escape sequences. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
91 |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
92 In interactive usage, the actual value of this variable is set up |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
93 by `grep-compute-defaults' when the default value is `auto-detect'. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
94 To change the default value, use Customize or call the function |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
95 `grep-apply-setting'." |
56948
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
96 :type '(choice (const :tag "Do not highlight matches with grep markers" nil) |
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
97 (const :tag "Highlight matches with grep markers" t) |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
98 (const :tag "Use --color=always" always) |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
99 (const :tag "Use --color=auto" auto) |
56948
f6f74981c4b0
(grep-highlight-matches): Change default from
Juri Linkov <juri@jurta.org>
parents:
56921
diff
changeset
|
100 (other :tag "Not Set" auto-detect)) |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
101 :set 'grep-apply-setting |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
102 :version "22.1" |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
103 :group 'grep) |
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
104 |
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-scroll-output nil |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
106 "*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
|
107 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
108 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
|
109 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
|
110 than the begining." |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
111 :type 'boolean |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
112 :version "22.1" |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
113 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
114 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
115 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
116 (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
|
117 "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
|
118 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
|
119 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
|
120 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
|
121 |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
122 In interactive usage, the actual value of this variable is set up |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
123 by `grep-compute-defaults'; to change the default value, use |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
124 Customize or call the function `grep-apply-setting'." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
125 :type '(choice string |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
126 (const :tag "Not Set" nil)) |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
127 :set 'grep-apply-setting |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
128 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
129 |
70258 | 130 (defcustom grep-template nil |
131 "The default command to run for \\[lgrep]. | |
132 The following place holders should be present in the string: | |
133 <C> - place to put -i if case insensitive grep. | |
134 <F> - file names and wildcards to search. | |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
135 <X> - file names and wildcards to exclude. |
70258 | 136 <R> - the regular expression searched for. |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
137 <N> - place to insert null-device. |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
138 |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
139 In interactive usage, the actual value of this variable is set up |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
140 by `grep-compute-defaults'; to change the default value, use |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
141 Customize or call the function `grep-apply-setting'." |
70258 | 142 :type '(choice string |
143 (const :tag "Not Set" nil)) | |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
144 :set 'grep-apply-setting |
70258 | 145 :version "22.1" |
146 :group 'grep) | |
147 | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
148 (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
|
149 "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
|
150 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
|
151 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
|
152 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
|
153 |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
154 In interactive usage, the actual value of this variable is set up |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
155 by `grep-compute-defaults'; to change the default value, use |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
156 Customize or call the function `grep-apply-setting'." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
157 :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
|
158 (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
|
159 (other :tag "Not Set" auto-detect)) |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
160 :set 'grep-apply-setting |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
161 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
162 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
163 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
164 (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
|
165 "The default find command for \\[grep-find]. |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
166 In interactive usage, the actual value of this variable is set up |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
167 by `grep-compute-defaults'; to change the default value, use |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
168 Customize or call the function `grep-apply-setting'." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
169 :type '(choice string |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
170 (const :tag "Not Set" nil)) |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
171 :set 'grep-apply-setting |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
172 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
173 |
70258 | 174 (defcustom grep-find-template nil |
175 "The default command to run for \\[rgrep]. | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
176 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
|
177 <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
|
178 <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
|
179 <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
|
180 <C> - place to put -i if case insensitive grep |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
181 <R> - the regular expression searched for. |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
182 In interactive usage, the actual value of this variable is set up |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
183 by `grep-compute-defaults'; to change the default value, use |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
184 Customize or call the function `grep-apply-setting'." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
185 :type '(choice string |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
186 (const :tag "Not Set" nil)) |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
187 :set 'grep-apply-setting |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
188 :version "22.1" |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
189 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
190 |
83780
d1d369daf8dd
(grep-files-aliases): Add cc alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
83778
diff
changeset
|
191 (defcustom grep-files-aliases |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
192 '(("all" . "* .*") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
193 ("el" . "*.el") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
194 ("ch" . "*.[ch]") |
83780
d1d369daf8dd
(grep-files-aliases): Add cc alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
83778
diff
changeset
|
195 ("c" . "*.c") |
96604
8e43e1211ac1
(grep-files-aliases): Improve the C++ source
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94775
diff
changeset
|
196 ("cc" . "*.cc *.cxx *.cpp *.C *.CC *.c++") |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
197 ("cchh" . "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++") |
96604
8e43e1211ac1
(grep-files-aliases): Improve the C++ source
Dan Nicolaescu <dann@ics.uci.edu>
parents:
94775
diff
changeset
|
198 ("hh" . "*.hxx *.hpp *.[Hh] *.HH *.h++") |
83780
d1d369daf8dd
(grep-files-aliases): Add cc alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
83778
diff
changeset
|
199 ("h" . "*.h") |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
200 ("l" . "[Cc]hange[Ll]og*") |
83780
d1d369daf8dd
(grep-files-aliases): Add cc alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
83778
diff
changeset
|
201 ("m" . "[Mm]akefile*") |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
202 ("tex" . "*.tex") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
203 ("texi" . "*.texi") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
204 ("asm" . "*.[sS]")) |
70258 | 205 "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
206 :type 'alist |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
207 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
208 |
83778
309cf30d46f5
(grep-find-ignored-directories): Add
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82421
diff
changeset
|
209 (defcustom grep-find-ignored-directories |
87523
fe5c2c0f8dcf
* progmodes/grep.el (grep-find-ignored-directories): Initialize
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
87453
diff
changeset
|
210 vc-directory-exclusion-list |
103787
fb68f473a020
(rgrep): Allow grep-find-ignored-directories
Sam Steingold <sds@gnu.org>
parents:
103276
diff
changeset
|
211 "*List of names of sub-directories which `rgrep' shall not recurse into. |
fb68f473a020
(rgrep): Allow grep-find-ignored-directories
Sam Steingold <sds@gnu.org>
parents:
103276
diff
changeset
|
212 If an element is a cons cell, the car is called on the search directory |
fb68f473a020
(rgrep): Allow grep-find-ignored-directories
Sam Steingold <sds@gnu.org>
parents:
103276
diff
changeset
|
213 to determine whether cdr should not be recursed into." |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
214 :type '(choice (repeat :tag "Ignored directories" string) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
215 (const :tag "No ignored directories" nil)) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
216 :group 'grep) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
217 |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
218 (defcustom grep-find-ignored-files |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
219 (cons ".#*" (delq nil (mapcar (lambda (s) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
220 (unless (string-match-p "/\\'" s) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
221 (concat "*" s))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
222 completion-ignored-extensions))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
223 "*List of file names which `rgrep' and `lgrep' shall exclude. |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
224 If an element is a cons cell, the car is called on the search directory |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
225 to determine whether cdr should not be excluded." |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
226 :type '(choice (repeat :tag "Ignored file" string) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
227 (const :tag "No ignored files" nil)) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
228 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
229 |
56226
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
230 (defcustom grep-error-screen-columns nil |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
231 "*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
|
232 See `compilation-error-screen-columns'" |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
233 :type '(choice (const :tag "Default" nil) |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
234 integer) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59991
diff
changeset
|
235 :version "22.1" |
56226
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
236 :group 'grep) |
bfe817c8d413
(grep-error-screen-columns): New variable.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
56155
diff
changeset
|
237 |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
238 ;;;###autoload |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
239 (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
|
240 "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
|
241 :type 'hook |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
242 :group 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
243 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
244 (defvar grep-mode-map |
94775
b51bb57e843b
(compilation-minor-mode-map, compilation-mode-map):
Sam Steingold <sds@gnu.org>
parents:
94673
diff
changeset
|
245 (let ((map (make-sparse-keymap))) |
b51bb57e843b
(compilation-minor-mode-map, compilation-mode-map):
Sam Steingold <sds@gnu.org>
parents:
94673
diff
changeset
|
246 (set-keymap-parent map compilation-minor-mode-map) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
247 (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
|
248 (define-key map "\^?" 'scroll-down) |
57022
463edf7390ca
(grep-mode-map): Rename `next-error-follow-mode' to `next-error-follow-minor-mode'.
Juri Linkov <juri@jurta.org>
parents:
56998
diff
changeset
|
249 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
250 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
251 (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
|
252 (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
|
253 (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
|
254 (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
|
255 (define-key map "}" 'compilation-next-file) |
64728
c1b77e79c51a
(grep-mode-map): Bind TAB to `compilation-next-error'
Juri Linkov <juri@jurta.org>
parents:
64725
diff
changeset
|
256 (define-key map "\t" 'compilation-next-error) |
c1b77e79c51a
(grep-mode-map): Bind TAB to `compilation-next-error'
Juri Linkov <juri@jurta.org>
parents:
64725
diff
changeset
|
257 (define-key map [backtab] 'compilation-previous-error) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
258 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
259 ;; 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
|
260 (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
|
261 (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
|
262 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
263 (define-key map [menu-bar grep compilation-kill-compilation] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
264 '(menu-item "Kill Grep" kill-compilation |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
265 :help "Kill the currently running grep process")) |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
266 (define-key map [menu-bar grep compilation-separator2] '("----")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
267 (define-key map [menu-bar grep compilation-compile] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
268 '(menu-item "Compile..." compile |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
269 :help "Compile the program including the current buffer. Default: run `make'")) |
101450
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
270 (define-key map [menu-bar grep compilation-rgrep] |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
271 '(menu-item "Recursive grep..." rgrep |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
272 :help "User-friendly recursive grep in directory tree")) |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
273 (define-key map [menu-bar grep compilation-lgrep] |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
274 '(menu-item "Local grep..." lgrep |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
275 :help "User-friendly grep in a directory")) |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
276 (define-key map [menu-bar grep compilation-grep-find] |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
277 '(menu-item "Grep via Find..." grep-find |
2bdde6d84336
(grep-mode-map): Put grep-find before grep and
Juri Linkov <juri@jurta.org>
parents:
100908
diff
changeset
|
278 :help "Run grep via find, with user-specified args")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
279 (define-key map [menu-bar grep compilation-grep] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
280 '(menu-item "Another grep..." grep |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
281 :help "Run grep, with user-specified args, and collect output in a buffer.")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
282 (define-key map [menu-bar grep compilation-recompile] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
283 '(menu-item "Repeat grep" recompile |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
284 :help "Run grep again")) |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
285 (define-key map [menu-bar grep compilation-separator2] '("----")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
286 (define-key map [menu-bar grep compilation-first-error] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
287 '(menu-item "First Match" first-error |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
288 :help "Restart at the first match, visit corresponding location")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
289 (define-key map [menu-bar grep compilation-previous-error] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
290 '(menu-item "Previous Match" previous-error |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
291 :help "Visit the previous match and corresponding location")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
292 (define-key map [menu-bar grep compilation-next-error] |
92493
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
293 '(menu-item "Next Match" next-error |
402ee2cfca27
* bindings.el (mode-line-remote): Add mouse-face. Improve tooltip.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92230
diff
changeset
|
294 :help "Visit the next match and corresponding location")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
295 map) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
296 "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
|
297 `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
|
298 |
92204
ab425a596ec9
(grep-mode-tool-bar-map): New variable.
Jan Djärv <jan.h.d@swipnet.se>
parents:
88102
diff
changeset
|
299 (defvar grep-mode-tool-bar-map |
98660
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
300 ;; When bootstrapping, tool-bar-map is not properly initialized yet, |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
301 ;; so don't do anything. |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
302 (when (keymapp (butlast tool-bar-map)) |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
303 (let ((map (butlast (copy-keymap tool-bar-map))) |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
304 (help (last tool-bar-map))) ;; Keep Help last in tool bar |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
305 (tool-bar-local-item |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
306 "left-arrow" 'previous-error-no-select 'previous-error-no-select map |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
307 :rtl "right-arrow" |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
308 :help "Goto previous match") |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
309 (tool-bar-local-item |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
310 "right-arrow" 'next-error-no-select 'next-error-no-select map |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
311 :rtl "left-arrow" |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
312 :help "Goto next match") |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
313 (tool-bar-local-item |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
314 "cancel" 'kill-compilation 'kill-compilation map |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
315 :enable '(let ((buffer (compilation-find-buffer))) |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
316 (get-buffer-process buffer)) |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
317 :help "Stop grep") |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
318 (tool-bar-local-item |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
319 "refresh" 'recompile 'recompile map |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
320 :help "Restart grep") |
90b078ed2dc4
(grep-mode-tool-bar-map): Check if tool-bar-map has been initialized
Chong Yidong <cyd@stupidchicken.com>
parents:
98629
diff
changeset
|
321 (append map help)))) |
92204
ab425a596ec9
(grep-mode-tool-bar-map): New variable.
Jan Djärv <jan.h.d@swipnet.se>
parents:
88102
diff
changeset
|
322 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
323 (defalias 'kill-grep 'kill-compilation) |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
324 |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
325 ;;;; TODO --- refine this!! |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
326 |
94141
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
327 ;; (defcustom grep-use-compilation-buffer t |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
328 ;; "When non-nil, grep specific commands update `compilation-last-buffer'. |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
329 ;; This means that standard compile commands like \\[next-error] and \\[compile-goto-error] |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
330 ;; can be used to navigate between grep matches (the default). |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
331 ;; Otherwise, the grep specific commands like \\[grep-next-match] must |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
332 ;; be used to navigate between grep matches." |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
333 ;; :type 'boolean |
e93898d6903e
Fix up comment convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93335
diff
changeset
|
334 ;; :group 'grep) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
335 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
336 ;; 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
|
337 (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
|
338 "The most recent grep buffer. |
71854
a4944423be59
(grep-last-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
71422
diff
changeset
|
339 A grep buffer becomes most recent when you select Grep mode in it. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
340 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
|
341 `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
|
342 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
343 ;;;###autoload |
105950
e411fa8e0abf
* progmodes/grep.el (grep-regexp-alist):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105939
diff
changeset
|
344 (defconst grep-regexp-alist |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
345 '(("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2" |
64725
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
346 1 3) |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
347 ;; Rule to match column numbers is commented out since no known grep |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
348 ;; produces them |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
349 ;; ("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2\\(?:\\([0-9]+\\)\\(?:-\\([0-9]+\\)\\)?\\2\\)?" |
64725
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
350 ;; 1 3 (4 . 5)) |
111579
4433803ef920
* lisp/progmodes/grep.el (grep-regexp-alist): Tighten the regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108743
diff
changeset
|
351 ;; Note that we want to use as tight a regexp as we can to try and |
4433803ef920
* lisp/progmodes/grep.el (grep-regexp-alist): Tighten the regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108743
diff
changeset
|
352 ;; handle weird file names (with colons in them) as well as possible. |
4433803ef920
* lisp/progmodes/grep.el (grep-regexp-alist): Tighten the regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108743
diff
changeset
|
353 ;; E.g. we use [1-9][0-9]* rather than [0-9]+ so as to accept ":034:" in |
4433803ef920
* lisp/progmodes/grep.el (grep-regexp-alist): Tighten the regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108743
diff
changeset
|
354 ;; file names. |
4433803ef920
* lisp/progmodes/grep.el (grep-regexp-alist): Tighten the regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108743
diff
changeset
|
355 ("^\\(\\(.+?\\):\\([1-9][0-9]*\\):\\).*?\ |
64509 | 356 \\(\033\\[01;31m\\(?:\033\\[K\\)?\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)" |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
357 2 3 |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
358 ;; Calculate column positions (beg . end) of first grep match on a line |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
359 ((lambda () |
64509 | 360 (setq compilation-error-screen-columns nil) |
361 (- (match-beginning 4) (match-end 1))) | |
56881
4be25baf31b5
(grep-highlight-matches): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
56828
diff
changeset
|
362 . |
64509 | 363 (lambda () (- (match-end 5) (match-end 1) |
111579
4433803ef920
* lisp/progmodes/grep.el (grep-regexp-alist): Tighten the regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108743
diff
changeset
|
364 (- (match-end 4) (match-beginning 4))))) |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
365 nil 1) |
64740
eeed7a7c1afa
(grep-regexp-alist): Set 5th arg `TYPE' to
Juri Linkov <juri@jurta.org>
parents:
64728
diff
changeset
|
366 ("^Binary file \\(.+\\) matches$" 1 nil nil 0 1)) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
367 "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
|
368 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
369 (defvar grep-error "grep hit" |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
370 "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
|
371 |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
372 ;; 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
|
373 ;; 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
|
374 (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
|
375 "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
|
376 |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
377 (defvar grep-error-face 'compilation-error |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
378 "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
|
379 |
58988
067d5dcfe531
(grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents:
58493
diff
changeset
|
380 (defvar grep-match-face 'match |
067d5dcfe531
(grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents:
58493
diff
changeset
|
381 "Face name to use for grep matches.") |
067d5dcfe531
(grep-match-face): New defvar.
Juri Linkov <juri@jurta.org>
parents:
58493
diff
changeset
|
382 |
64725
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
383 (defvar grep-context-face 'shadow |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
384 "Face name to use for grep context lines.") |
0344b299e9e6
(grep-regexp-alist): Replace complex regexp
Juri Linkov <juri@jurta.org>
parents:
64699
diff
changeset
|
385 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
386 (defvar grep-mode-font-lock-keywords |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
387 '(;; Command output lines. |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
388 ("^\\([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
|
389 (": \\(.+\\): \\(?: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
|
390 1 grep-error-face) |
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
391 ;; remove match from grep-regexp-alist before fontifying |
71422
2611669abf9e
(grep-mode-font-lock-keywords): Correct regexps
Kim F. Storm <storm@cua.dk>
parents:
70712
diff
changeset
|
392 ("^Grep[/a-zA-z]* started.*" |
65126
559a37c2f306
(grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents:
65056
diff
changeset
|
393 (0 '(face nil message nil help-echo nil mouse-face nil) t)) |
71422
2611669abf9e
(grep-mode-font-lock-keywords): Correct regexps
Kim F. Storm <storm@cua.dk>
parents:
70712
diff
changeset
|
394 ("^Grep[/a-zA-z]* finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*" |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
395 (0 '(face nil message nil help-echo nil mouse-face nil) t) |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
396 (1 compilation-info-face nil t) |
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
397 (2 compilation-warning-face nil t)) |
71422
2611669abf9e
(grep-mode-font-lock-keywords): Correct regexps
Kim F. Storm <storm@cua.dk>
parents:
70712
diff
changeset
|
398 ("^Grep[/a-zA-z]* \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?.*" |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
399 (0 '(face nil message nil help-echo nil mouse-face nil) t) |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
400 (1 grep-error-face) |
64944
c845f6151d83
(grep-mode-map): Add ellipsis to "Another grep".
Juri Linkov <juri@jurta.org>
parents:
64864
diff
changeset
|
401 (2 grep-error-face nil t)) |
64864
c474b6f22449
(grep-regexp-alist): Use `.+?' instead of `[^:\n]+'.
Juri Linkov <juri@jurta.org>
parents:
64740
diff
changeset
|
402 ("^.+?-[0-9]+-.*\n" (0 grep-context-face)) |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
403 ;; Highlight grep matches and delete markers |
64509 | 404 ("\\(\033\\[01;31m\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)" |
61902
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
405 ;; Refontification does not work after the markers have been |
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
406 ;; deleted. So we use the font-lock-face property here as Font |
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
407 ;; Lock does not clear that. |
e8076329ceee
(grep-mode-font-lock-keywords): Use the font-lock-face property to
Lute Kamstra <lute@gnu.org>
parents:
59996
diff
changeset
|
408 (2 (list 'face nil 'font-lock-face grep-match-face)) |
64509 | 409 ((lambda (bound)) |
57769
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
410 (progn |
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
411 ;; Delete markers with `replace-match' because it updates |
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
412 ;; the match-data, whereas `delete-region' would render it obsolete. |
e663f6b659a6
(grep-regexp-alist): Move match highlighting
Juri Linkov <juri@jurta.org>
parents:
57043
diff
changeset
|
413 (replace-match "" t t nil 3) |
64509 | 414 (replace-match "" t t nil 1)))) |
415 ("\\(\033\\[[0-9;]*[mK]\\)" | |
416 ;; Delete all remaining escape sequences | |
417 ((lambda (bound)) | |
418 (replace-match "" t t nil 1)))) | |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
419 "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
|
420 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
|
421 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
422 ;;;###autoload |
105939
a0f778f4a995
* term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105170
diff
changeset
|
423 (defvar grep-program (purecopy "grep") |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
424 "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
|
425 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
|
426 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
427 ;;;###autoload |
105939
a0f778f4a995
* term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105170
diff
changeset
|
428 (defvar find-program (purecopy "find") |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
429 "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
|
430 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
|
431 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
432 ;;;###autoload |
105939
a0f778f4a995
* term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105170
diff
changeset
|
433 (defvar xargs-program (purecopy "xargs") |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
434 "The default xargs program for `grep-find-command'. |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
435 See `grep-find-use-xargs'. |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
436 This variable's value takes effect when `grep-compute-defaults' is called.") |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
437 |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
438 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
439 (defvar grep-find-use-xargs nil |
77033
25b4502cd0b4
(grep-find-use-xargs): Rewrite docstring.
Chong Yidong <cyd@stupidchicken.com>
parents:
76966
diff
changeset
|
440 "Non-nil means that `grep-find' uses the `xargs' utility by default. |
25b4502cd0b4
(grep-find-use-xargs): Rewrite docstring.
Chong Yidong <cyd@stupidchicken.com>
parents:
76966
diff
changeset
|
441 If `exec', use `find -exec'. |
25b4502cd0b4
(grep-find-use-xargs): Rewrite docstring.
Chong Yidong <cyd@stupidchicken.com>
parents:
76966
diff
changeset
|
442 If `gnu', use `find -print0' and `xargs -0'. |
25b4502cd0b4
(grep-find-use-xargs): Rewrite docstring.
Chong Yidong <cyd@stupidchicken.com>
parents:
76966
diff
changeset
|
443 Any other non-nil value means to use `find -print' and `xargs'. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
444 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
445 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
|
446 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
447 ;; History of grep commands. |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
448 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
449 (defvar grep-history nil) |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
450 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
451 (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
|
452 |
70258 | 453 ;; History of lgrep and rgrep regexp and files args. |
454 (defvar grep-regexp-history nil) | |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
455 (defvar grep-files-history nil) |
70258 | 456 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
457 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
458 (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
|
459 "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
|
460 Set up `compilation-exit-message-function' and run `grep-setup-hook'." |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
461 (when (eq grep-highlight-matches 'auto-detect) |
56960
84482ed458f2
(grep-highlight-matches): Doc fix.
Juri Linkov <juri@jurta.org>
parents:
56948
diff
changeset
|
462 (grep-compute-defaults)) |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
463 (unless (or (eq grep-highlight-matches 'auto-detect) |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
464 (null grep-highlight-matches)) |
86354
29047758dd89
(grep-process-setup): Set envvar "TERM" to "emacs-grep".
Juri Linkov <juri@jurta.org>
parents:
86249
diff
changeset
|
465 ;; `setenv' modifies `process-environment' let-bound in `compilation-start' |
29047758dd89
(grep-process-setup): Set envvar "TERM" to "emacs-grep".
Juri Linkov <juri@jurta.org>
parents:
86249
diff
changeset
|
466 ;; Any TERM except "dumb" allows GNU grep to use `--color=auto' |
29047758dd89
(grep-process-setup): Set envvar "TERM" to "emacs-grep".
Juri Linkov <juri@jurta.org>
parents:
86249
diff
changeset
|
467 (setenv "TERM" "emacs-grep") |
102336
83645050eee3
(grep-process-setup) [windows-nt msdos]: Use "--color=always".
Eli Zaretskii <eliz@gnu.org>
parents:
101450
diff
changeset
|
468 (setenv "GREP_OPTIONS" |
83645050eee3
(grep-process-setup) [windows-nt msdos]: Use "--color=always".
Eli Zaretskii <eliz@gnu.org>
parents:
101450
diff
changeset
|
469 (concat (getenv "GREP_OPTIONS") |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
470 " --color=" (if (eq grep-highlight-matches 'always) |
102336
83645050eee3
(grep-process-setup) [windows-nt msdos]: Use "--color=always".
Eli Zaretskii <eliz@gnu.org>
parents:
101450
diff
changeset
|
471 "always" "auto"))) |
86354
29047758dd89
(grep-process-setup): Set envvar "TERM" to "emacs-grep".
Juri Linkov <juri@jurta.org>
parents:
86249
diff
changeset
|
472 ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions |
64509 | 473 (setenv "GREP_COLOR" "01;31") |
86354
29047758dd89
(grep-process-setup): Set envvar "TERM" to "emacs-grep".
Juri Linkov <juri@jurta.org>
parents:
86249
diff
changeset
|
474 ;; GREP_COLORS is used in GNU grep 2.5.2 and later versions |
64509 | 475 (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:ml=:cx=:ne")) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
476 (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
|
477 (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
|
478 (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
|
479 (cond ((zerop code) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
480 '("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
|
481 ((= code 1) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
482 '("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
|
483 (t |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
484 (cons msg code))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
485 (cons msg code)))) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
486 (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
|
487 |
70258 | 488 (defun grep-probe (command args &optional func result) |
104601
3f203311bcc1
* progmodes/grep.el (grep-probe): Let-bind `process-file-side-effects' with nil.
Michael Albinus <michael.albinus@gmx.de>
parents:
104525
diff
changeset
|
489 (let (process-file-side-effects) |
3f203311bcc1
* progmodes/grep.el (grep-probe): Let-bind `process-file-side-effects' with nil.
Michael Albinus <michael.albinus@gmx.de>
parents:
104525
diff
changeset
|
490 (equal (condition-case nil |
3f203311bcc1
* progmodes/grep.el (grep-probe): Let-bind `process-file-side-effects' with nil.
Michael Albinus <michael.albinus@gmx.de>
parents:
104525
diff
changeset
|
491 (apply (or func 'process-file) command args) |
3f203311bcc1
* progmodes/grep.el (grep-probe): Let-bind `process-file-side-effects' with nil.
Michael Albinus <michael.albinus@gmx.de>
parents:
104525
diff
changeset
|
492 (error nil)) |
3f203311bcc1
* progmodes/grep.el (grep-probe): Let-bind `process-file-side-effects' with nil.
Michael Albinus <michael.albinus@gmx.de>
parents:
104525
diff
changeset
|
493 (or result 0)))) |
70258 | 494 |
56333
eb4bc9a65835
(grep-compute-defaults, grep-command)
Eli Zaretskii <eliz@gnu.org>
parents:
56226
diff
changeset
|
495 ;;;###autoload |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
496 (defun grep-compute-defaults () |
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
497 ;; Keep default values. |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
498 (unless grep-host-defaults-alist |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
499 (add-to-list |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
500 'grep-host-defaults-alist |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
501 (cons nil |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
502 `((grep-command ,grep-command) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
503 (grep-template ,grep-template) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
504 (grep-use-null-device ,grep-use-null-device) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
505 (grep-find-command ,grep-find-command) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
506 (grep-find-template ,grep-find-template) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
507 (grep-find-use-xargs ,grep-find-use-xargs) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
508 (grep-highlight-matches ,grep-highlight-matches))))) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
509 (let* ((host-id |
88102
0fa30755c209
(grep-compute-defaults):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87560
diff
changeset
|
510 (intern (or (file-remote-p default-directory) "localhost"))) |
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
511 (host-defaults (assq host-id grep-host-defaults-alist)) |
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
512 (defaults (assq nil grep-host-defaults-alist))) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
513 ;; There are different defaults on different hosts. They must be |
82031
73ba7647c960
* progmodes/grep.el (grep-compute-defaults): Keep default values.
Michael Albinus <michael.albinus@gmx.de>
parents:
81972
diff
changeset
|
514 ;; computed for every host once. |
103276
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
515 (dolist (setting '(grep-command grep-template |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
516 grep-use-null-device grep-find-command |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
517 grep-find-template grep-find-use-xargs |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
518 grep-highlight-matches)) |
a53bb8ffd3ae
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
Chong Yidong <cyd@stupidchicken.com>
parents:
102336
diff
changeset
|
519 (set setting |
107944
f3e910318160
* progmodes/grep.el (grep-compute-defaults): Fix handling of host
Chong Yidong <cyd@stupidchicken.com>
parents:
107067
diff
changeset
|
520 (cadr (or (assq setting host-defaults) |
f3e910318160
* progmodes/grep.el (grep-compute-defaults): Fix handling of host
Chong Yidong <cyd@stupidchicken.com>
parents:
107067
diff
changeset
|
521 (assq setting defaults))))) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
522 |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
523 (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
524 (setq grep-use-null-device |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
525 (with-temp-buffer |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
526 (let ((hello-file (expand-file-name "HELLO" data-directory))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
527 (not |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
528 (and (if grep-command |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
529 ;; `grep-command' is already set, so |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
530 ;; use that for testing. |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
531 (grep-probe grep-command |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
532 `(nil t nil "^English" ,hello-file) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
533 #'call-process-shell-command) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
534 ;; otherwise use `grep-program' |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
535 (grep-probe grep-program |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
536 `(nil t nil "-nH" "^English" ,hello-file))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
537 (progn |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
538 (goto-char (point-min)) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
539 (looking-at |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
540 (concat (regexp-quote hello-file) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
541 ":[0-9]+:English"))))))))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
542 (unless (and grep-command grep-find-command |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
543 grep-template grep-find-template) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
544 (let ((grep-options |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
545 (concat (if grep-use-null-device "-n" "-nH") |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
546 (if (grep-probe grep-program |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
547 `(nil nil nil "-e" "foo" ,null-device) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
548 nil 1) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
549 " -e")))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
550 (unless grep-command |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
551 (setq grep-command |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
552 (format "%s %s " grep-program grep-options))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
553 (unless grep-template |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
554 (setq grep-template |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
555 (format "%s <X> <C> %s <R> <F>" grep-program grep-options))) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
556 (unless grep-find-use-xargs |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
557 (setq grep-find-use-xargs |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
558 (cond |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
559 ((and |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
560 (grep-probe find-program `(nil nil nil ,null-device "-print0")) |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
561 (grep-probe xargs-program `(nil nil nil "-0" "-e" "echo"))) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
562 'gnu) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
563 (t |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
564 'exec)))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
565 (unless grep-find-command |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
566 (setq grep-find-command |
70258 | 567 (cond ((eq grep-find-use-xargs 'gnu) |
112238 | 568 ;; Windows shells need the program file name |
569 ;; after the pipe symbol be quoted if they use | |
570 ;; forward slashes as directory separators. | |
571 (format "%s . -type f -print0 | \"%s\" -0 -e %s" | |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
572 find-program xargs-program grep-command)) |
72500
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
573 ((eq grep-find-use-xargs 'exec) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
574 (let ((cmd0 (format "%s . -type f -exec %s" |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
575 find-program grep-command))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
576 (cons |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
577 (format "%s {} %s %s" |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
578 cmd0 null-device |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
579 (shell-quote-argument ";")) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
580 (1+ (length cmd0))))) |
72500
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
581 (t |
112238 | 582 (format "%s . -type f -print | \"%s\" %s" |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
583 find-program xargs-program grep-command))))) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
584 (unless grep-find-template |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
585 (setq grep-find-template |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
586 (let ((gcmd (format "%s <C> %s <R>" |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
587 grep-program grep-options))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
588 (cond ((eq grep-find-use-xargs 'gnu) |
112238 | 589 (format "%s . <X> -type f <F> -print0 | \"%s\" -0 -e %s" |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
590 find-program xargs-program gcmd)) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
591 ((eq grep-find-use-xargs 'exec) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
592 (format "%s . <X> -type f <F> -exec %s {} %s %s" |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
593 find-program gcmd null-device |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
594 (shell-quote-argument ";"))) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
595 (t |
112238 | 596 (format "%s . <X> -type f <F> -print | \"%s\" %s" |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
597 find-program xargs-program gcmd)))))))) |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
598 (when (eq grep-highlight-matches 'auto-detect) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
599 (setq grep-highlight-matches |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
600 (with-temp-buffer |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
601 (and (grep-probe grep-program '(nil t nil "--help")) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
602 (progn |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
603 (goto-char (point-min)) |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
604 (search-forward "--color" nil t)) |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
605 ;; Windows and DOS pipes fail `isatty' detection in Grep. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
606 (if (memq system-type '(windows-nt ms-dos)) |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
607 'always 'auto))))) |
81936
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
608 |
64c6efb87c40
* progmodes/grep.el (grep-probe): Use `process-file'.
Michael Albinus <michael.albinus@gmx.de>
parents:
77033
diff
changeset
|
609 ;; Save defaults for this host. |
81972
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
610 (setq grep-host-defaults-alist |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
611 (delete (assq host-id grep-host-defaults-alist) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
612 grep-host-defaults-alist)) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
613 (add-to-list |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
614 'grep-host-defaults-alist |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
615 (cons host-id |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
616 `((grep-command ,grep-command) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
617 (grep-template ,grep-template) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
618 (grep-use-null-device ,grep-use-null-device) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
619 (grep-find-command ,grep-find-command) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
620 (grep-find-template ,grep-find-template) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
621 (grep-find-use-xargs ,grep-find-use-xargs) |
7447c9b7efeb
* progmodes/grep.el (grep-host-defaults-alist): New defvar.
Michael Albinus <michael.albinus@gmx.de>
parents:
81936
diff
changeset
|
622 (grep-highlight-matches ,grep-highlight-matches)))))) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
623 |
72163
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
624 (defun grep-tag-default () |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
625 (or (and transient-mark-mode mark-active |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
626 (/= (point) (mark)) |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
627 (buffer-substring-no-properties (point) (mark))) |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
628 (funcall (or find-tag-default-function |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
629 (get major-mode 'find-tag-default-function) |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
630 'find-tag-default)) |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
631 "")) |
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
632 |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
633 (defun grep-default-command () |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
634 "Compute the default grep command for \\[universal-argument] \\[grep] to offer." |
72163
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
635 (let ((tag-default (shell-quote-argument (grep-tag-default))) |
72173
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
636 ;; This a regexp to match single shell arguments. |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
637 ;; Could someone please add comments explaining it? |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
638 (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
|
639 (grep-default (or (car grep-history) grep-command))) |
72173
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
640 ;; In the default command, find the arg that specifies the pattern. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
641 (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
|
642 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*" |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
643 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
|
644 grep-default) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
645 ;; 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
|
646 (string-match "\\(\\)\\'" grep-default)) |
72173
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
647 ;; Maybe we will replace the pattern with the default tag. |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
648 ;; But first, maybe replace the file name pattern. |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
649 (condition-case nil |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
650 (unless (or (not (stringp buffer-file-name)) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
651 (when (match-beginning 2) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
652 (save-match-data |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
653 (string-match |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
654 (wildcard-to-regexp |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
655 (file-name-nondirectory |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
656 (match-string 3 grep-default))) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
657 (file-name-nondirectory buffer-file-name))))) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
658 (setq grep-default (concat (substring grep-default |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
659 0 (match-beginning 2)) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
660 " *." |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
661 (file-name-extension buffer-file-name)))) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
662 ;; In case wildcard-to-regexp gets an error |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
663 ;; from invalid data. |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
664 (error nil)) |
691a901b4418
(grep-default-command): Catch errors from wildcard-to-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
72165
diff
changeset
|
665 ;; Now replace the pattern with the default tag. |
57908
a4ed247d476f
(grep-default-command): Take empty string
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
57769
diff
changeset
|
666 (replace-match tag-default t t grep-default 1)))) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
667 |
54372
a4d3c17f991f
(kill-grep): Move here from compile.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54012
diff
changeset
|
668 |
64509 | 669 ;;;###autoload |
55018 | 670 (define-compilation-mode grep-mode "Grep" |
671 "Sets `grep-last-buffer' and `compilation-window-height'." | |
672 (setq grep-last-buffer (current-buffer)) | |
92204
ab425a596ec9
(grep-mode-tool-bar-map): New variable.
Jan Djärv <jan.h.d@swipnet.se>
parents:
88102
diff
changeset
|
673 (set (make-local-variable 'tool-bar-map) grep-mode-tool-bar-map) |
55018 | 674 (set (make-local-variable 'compilation-error-face) |
675 grep-hit-face) | |
676 (set (make-local-variable 'compilation-error-regexp-alist) | |
63576
7c3d537469b0
(grep-regexp-alist): Use backreference at the
Juri Linkov <juri@jurta.org>
parents:
62160
diff
changeset
|
677 grep-regexp-alist) |
65126
559a37c2f306
(grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents:
65056
diff
changeset
|
678 (set (make-local-variable 'compilation-process-setup-function) |
559a37c2f306
(grep, grep-mode): Make buffer-local variables
Juri Linkov <juri@jurta.org>
parents:
65056
diff
changeset
|
679 'grep-process-setup) |
69499
caf8f09897bc
* font-lock.el (font-lock-lines-before): Delete variable, subsumed by
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
680 (set (make-local-variable 'compilation-disable-input) t)) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
681 |
70258 | 682 |
683 ;;;###autoload | |
684 (defun grep (command-args) | |
685 "Run grep, with user-specified args, and collect output in a buffer. | |
686 While grep runs asynchronously, you can use \\[next-error] (M-x next-error), | |
687 or \\<grep-mode-map>\\[compile-goto-error] in the grep \ | |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
688 output buffer, to go to the lines where grep |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
689 found matches. |
70258 | 690 |
75803
81c369551691
(grep): Mention lgrep and rgrep in the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
75347
diff
changeset
|
691 For doing a recursive `grep', see the `rgrep' command. For running |
75877
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
692 `grep' in a specific directory, see `lgrep'. |
75803
81c369551691
(grep): Mention lgrep and rgrep in the
Dan Nicolaescu <dann@ics.uci.edu>
parents:
75347
diff
changeset
|
693 |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
694 This command uses a special history list for its COMMAND-ARGS, so you |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
695 can easily repeat a grep command. |
70258 | 696 |
697 A prefix argument says to default the argument based upon the current | |
698 tag the cursor is over, substituting it into the last grep command | |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
699 in the grep command history (or into `grep-command' if that history |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
700 list is empty)." |
70258 | 701 (interactive |
702 (progn | |
703 (grep-compute-defaults) | |
704 (let ((default (grep-default-command))) | |
93114
57fa8ebfd227
* progmodes/compile.el (compile):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92493
diff
changeset
|
705 (list (read-shell-command "Run grep (like this): " |
57fa8ebfd227
* progmodes/compile.el (compile):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92493
diff
changeset
|
706 (if current-prefix-arg default grep-command) |
57fa8ebfd227
* progmodes/compile.el (compile):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92493
diff
changeset
|
707 'grep-history |
57fa8ebfd227
* progmodes/compile.el (compile):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92493
diff
changeset
|
708 (if current-prefix-arg nil default)))))) |
70258 | 709 |
710 ;; Setting process-setup-function makes exit-message-function work | |
711 ;; even when async processes aren't supported. | |
712 (compilation-start (if (and grep-use-null-device null-device) | |
713 (concat command-args " " null-device) | |
714 command-args) | |
715 'grep-mode)) | |
716 | |
717 | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
718 ;;;###autoload |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
719 (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
|
720 "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
|
721 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
|
722 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
|
723 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
|
724 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
725 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
|
726 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
|
727 (interactive |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
728 (progn |
70258 | 729 (grep-compute-defaults) |
53750
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
730 (if grep-find-command |
93114
57fa8ebfd227
* progmodes/compile.el (compile):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92493
diff
changeset
|
731 (list (read-shell-command "Run find (like this): " |
57fa8ebfd227
* progmodes/compile.el (compile):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92493
diff
changeset
|
732 grep-find-command 'grep-find-history)) |
53750
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
733 ;; No default was set |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
734 (read-string |
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
735 "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
|
736 (list nil)))) |
70712
070ab453b31f
(grep-find): Don't check grep-find-command
Kim F. Storm <storm@cua.dk>
parents:
70534
diff
changeset
|
737 (when command-args |
53750
4deb14fde58c
(grep-compute-defaults): Use executable-command-find-posix-p.
Richard M. Stallman <rms@gnu.org>
parents:
53486
diff
changeset
|
738 (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
|
739 (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
|
740 |
59688
3761d1e2619d
* NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents:
59605
diff
changeset
|
741 ;;;###autoload |
3761d1e2619d
* NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents:
59605
diff
changeset
|
742 (defalias 'find-grep 'grep-find) |
3761d1e2619d
* NEWS: Mention alias `find-grep' for `grep-find'.
David Kastrup <dak@gnu.org>
parents:
59605
diff
changeset
|
743 |
70258 | 744 |
745 ;; User-friendly interactive API. | |
746 | |
747 (defconst grep-expand-keywords | |
748 '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i")) | |
749 ("<D>" . dir) | |
750 ("<F>" . files) | |
751 ("<N>" . null-device) | |
752 ("<X>" . excl) | |
753 ("<R>" . (shell-quote-argument (or regexp "")))) | |
754 "List of substitutions performed by `grep-expand-template'. | |
755 If car of an element matches, the cdr is evalled in to get the | |
756 substitution string. Note dynamic scoping of variables.") | |
757 | |
758 (defun grep-expand-template (template &optional regexp files dir excl) | |
759 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>." | |
760 (let ((command template) | |
761 (cf case-fold-search) | |
762 (case-fold-search nil)) | |
763 (dolist (kw grep-expand-keywords command) | |
764 (if (string-match (car kw) command) | |
70315
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
765 (setq command |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
766 (replace-match |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
767 (or (if (symbolp (cdr kw)) |
70340
3146cc3b9e56
(grep-expand-template): Use symbol-value instead of eval on symbols.
Kim F. Storm <storm@cua.dk>
parents:
70315
diff
changeset
|
768 (symbol-value (cdr kw)) |
70315
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
769 (save-match-data (eval (cdr kw)))) |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
770 "") |
cf0d76a2f0c7
(grep-expand-template): Use save-match-data.
Kim F. Storm <storm@cua.dk>
parents:
70259
diff
changeset
|
771 t t command)))))) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
772 |
70258 | 773 (defun grep-read-regexp () |
774 "Read regexp arg for interactive grep." | |
72163
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
775 (let ((default (grep-tag-default))) |
70258 | 776 (read-string |
777 (concat "Search for" | |
778 (if (and default (> (length default) 0)) | |
72163
bca9d3121eef
(grep-tag-default): New function.
Kim F. Storm <storm@cua.dk>
parents:
72024
diff
changeset
|
779 (format " (default \"%s\"): " default) ": ")) |
70258 | 780 nil 'grep-regexp-history default))) |
781 | |
782 (defun grep-read-files (regexp) | |
783 "Read files arg for interactive grep." | |
104745
60a123e396f8
(grep-read-files): Strip trailing <N> from buffer names
Juri Linkov <juri@jurta.org>
parents:
104601
diff
changeset
|
784 (let* ((bn (or (buffer-file-name) |
60a123e396f8
(grep-read-files): Strip trailing <N> from buffer names
Juri Linkov <juri@jurta.org>
parents:
104601
diff
changeset
|
785 (replace-regexp-in-string "<[0-9]+>\\'" "" (buffer-name)))) |
70259
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
786 (fn (and bn |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
787 (stringp bn) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
788 (file-name-nondirectory bn))) |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
789 (default-alias |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
790 (and fn |
108743
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
791 (let ((aliases (remove (assoc "all" grep-files-aliases) |
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
792 grep-files-aliases)) |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
793 alias) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
794 (while aliases |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
795 (setq alias (car aliases) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
796 aliases (cdr aliases)) |
108743
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
797 (if (string-match (mapconcat |
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
798 'wildcard-to-regexp |
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
799 (split-string (cdr alias) nil t) |
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
800 "\\|") |
4b1caf0bded6
* progmodes/grep.el (grep-read-files): Fix multi-pattern aliases.
Juri Linkov <juri@jurta.org>
parents:
107944
diff
changeset
|
801 fn) |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
802 (setq aliases nil) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
803 (setq alias nil))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
804 (cdr alias)))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
805 (default-extension |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
806 (and fn |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
807 (let ((ext (file-name-extension fn))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
808 (and ext (concat "*." ext))))) |
70259
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
809 (default |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
810 (or default-alias |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
811 default-extension |
72165
301cc56a3482
(grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
parents:
72163
diff
changeset
|
812 (car grep-files-history) |
301cc56a3482
(grep-read-files): Use car of grep-files-history or grep-files-aliases
Kim F. Storm <storm@cua.dk>
parents:
72163
diff
changeset
|
813 (car (car grep-files-aliases)))) |
106479
67d8bc783433
(grep-read-files): Use `completing-read'
Juri Linkov <juri@jurta.org>
parents:
106243
diff
changeset
|
814 (files (completing-read |
70258 | 815 (concat "Search for \"" regexp |
70259
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
816 "\" in files" |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
817 (if default (concat " (default " default ")")) |
58edc69a1813
(grep-read-files): Use buffer-name if no buffer-file-name.
Kim F. Storm <storm@cua.dk>
parents:
70258
diff
changeset
|
818 ": ") |
106479
67d8bc783433
(grep-read-files): Use `completing-read'
Juri Linkov <juri@jurta.org>
parents:
106243
diff
changeset
|
819 'read-file-name-internal |
67d8bc783433
(grep-read-files): Use `completing-read'
Juri Linkov <juri@jurta.org>
parents:
106243
diff
changeset
|
820 nil nil nil 'grep-files-history |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
821 (delete-dups |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
822 (delq nil (append (list default default-alias default-extension) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
823 (mapcar 'car grep-files-aliases))))))) |
70258 | 824 (and files |
825 (or (cdr (assoc files grep-files-aliases)) | |
826 files)))) | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
827 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
828 ;;;###autoload |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
829 (defun lgrep (regexp &optional files dir confirm) |
75877
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
830 "Run grep, searching for REGEXP in FILES in directory DIR. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
831 The search is limited to file names matching shell pattern FILES. |
70258 | 832 FILES may use abbreviations defined in `grep-files-aliases', e.g. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
833 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
|
834 |
70526 | 835 With \\[universal-argument] prefix, you can edit the constructed shell command line |
836 before it is executed. | |
837 With two \\[universal-argument] prefixes, directly edit and run `grep-command'. | |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
838 |
70258 | 839 Collect output in a buffer. While grep runs asynchronously, you |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
840 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \ |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
841 in the grep output buffer, |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
842 to go to the lines where grep found matches. |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
843 |
70258 | 844 This command shares argument histories with \\[rgrep] and \\[grep]." |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
845 (interactive |
70258 | 846 (progn |
847 (grep-compute-defaults) | |
848 (cond | |
849 ((and grep-command (equal current-prefix-arg '(16))) | |
850 (list (read-from-minibuffer "Run: " grep-command | |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
851 nil nil 'grep-history))) |
70258 | 852 ((not grep-template) |
105170 | 853 (error "grep.el: No `grep-template' available")) |
70258 | 854 (t (let* ((regexp (grep-read-regexp)) |
75877
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
855 (files (grep-read-files regexp)) |
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
856 (dir (read-directory-name "In directory: " |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
857 nil default-directory t)) |
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
858 (confirm (equal current-prefix-arg '(4)))) |
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
859 (list regexp files dir confirm)))))) |
70258 | 860 (when (and (stringp regexp) (> (length regexp) 0)) |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
861 (unless (and dir (file-directory-p dir) (file-readable-p dir)) |
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
862 (setq dir default-directory)) |
70258 | 863 (let ((command regexp)) |
864 (if (null files) | |
865 (if (string= command grep-command) | |
866 (setq command nil)) | |
75877
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
867 (setq dir (file-name-as-directory (expand-file-name dir))) |
70258 | 868 (setq command (grep-expand-template |
869 grep-template | |
870 regexp | |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
871 files |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
872 nil |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
873 (and grep-find-ignored-files |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
874 (concat " --exclude=" |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
875 (mapconcat |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
876 #'(lambda (ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
877 (cond ((stringp ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
878 (shell-quote-argument ignore)) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
879 ((consp ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
880 (and (funcall (car ignore) dir) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
881 (shell-quote-argument |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
882 (cdr ignore)))))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
883 grep-find-ignored-files |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
884 " --exclude="))))) |
70258 | 885 (when command |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
886 (if confirm |
70258 | 887 (setq command |
888 (read-from-minibuffer "Confirm: " | |
889 command nil nil 'grep-history)) | |
70421
47fe68ac1971
(lgrep, rgrep): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents:
70340
diff
changeset
|
890 (add-to-history 'grep-history command)))) |
70258 | 891 (when command |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
892 (let ((default-directory dir)) |
75877
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
893 ;; Setting process-setup-function makes exit-message-function work |
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
894 ;; even when async processes aren't supported. |
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
895 (compilation-start (if (and grep-use-null-device null-device) |
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
896 (concat command " " null-device) |
82421 | 897 command) |
898 'grep-mode)) | |
75877
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
899 (if (eq next-error-last-buffer (current-buffer)) |
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
900 (setq default-directory dir)))))) |
9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
Kim F. Storm <storm@cua.dk>
parents:
75803
diff
changeset
|
901 |
70258 | 902 |
106121
f58be5f9ad87
* find-dired.el (find-name-arg): Remove autoload. (Bug#4387)
Juri Linkov <juri@jurta.org>
parents:
105950
diff
changeset
|
903 (defvar find-name-arg) ; not autoloaded but defined in find-dired |
70258 | 904 |
905 ;;;###autoload | |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
906 (defun rgrep (regexp &optional files dir confirm) |
70526 | 907 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. |
70258 | 908 The search is limited to file names matching shell pattern FILES. |
909 FILES may use abbreviations defined in `grep-files-aliases', e.g. | |
910 entering `ch' is equivalent to `*.[ch]'. | |
911 | |
70526 | 912 With \\[universal-argument] prefix, you can edit the constructed shell command line |
913 before it is executed. | |
914 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'. | |
70258 | 915 |
916 Collect output in a buffer. While find runs asynchronously, you | |
86249
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
917 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \ |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
918 in the grep output buffer, |
ef17406635fe
(xargs-program): New variable.
Juanma Barranquero <lekktu@gmail.com>
parents:
83780
diff
changeset
|
919 to go to the lines where grep found matches. |
70258 | 920 |
921 This command shares argument histories with \\[lgrep] and \\[grep-find]." | |
922 (interactive | |
923 (progn | |
924 (grep-compute-defaults) | |
925 (cond | |
926 ((and grep-find-command (equal current-prefix-arg '(16))) | |
927 (list (read-from-minibuffer "Run: " grep-find-command | |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
928 nil nil 'grep-find-history))) |
70258 | 929 ((not grep-find-template) |
105170 | 930 (error "grep.el: No `grep-find-template' available")) |
70258 | 931 (t (let* ((regexp (grep-read-regexp)) |
932 (files (grep-read-files regexp)) | |
933 (dir (read-directory-name "Base directory: " | |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
934 nil default-directory t)) |
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
935 (confirm (equal current-prefix-arg '(4)))) |
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
936 (list regexp files dir confirm)))))) |
70258 | 937 (when (and (stringp regexp) (> (length regexp) 0)) |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
938 (unless (and dir (file-directory-p dir) (file-readable-p dir)) |
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
939 (setq dir default-directory)) |
70258 | 940 (if (null files) |
941 (if (not (string= regexp grep-find-command)) | |
942 (compilation-start regexp 'grep-mode)) | |
70534
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
943 (setq dir (file-name-as-directory (expand-file-name dir))) |
106121
f58be5f9ad87
* find-dired.el (find-name-arg): Remove autoload. (Bug#4387)
Juri Linkov <juri@jurta.org>
parents:
105950
diff
changeset
|
944 (require 'find-dired) ; for `find-name-arg' |
70534
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
945 (let ((command (grep-expand-template |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
946 grep-find-template |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
947 regexp |
72500
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
948 (concat (shell-quote-argument "(") |
79589
05774558f6e1
(rgrep): Use find-name-arg.
Jason Rumney <jasonr@gnu.org>
parents:
78234
diff
changeset
|
949 " " find-name-arg " " |
70534
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
950 (mapconcat #'shell-quote-argument |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
951 (split-string files) |
79643
078fe4baaf42
(rgrep): Fix last change.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
79589
diff
changeset
|
952 (concat " -o " find-name-arg " ")) |
72500
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
953 " " |
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
954 (shell-quote-argument ")")) |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
955 dir |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
956 (concat |
70258 | 957 (and grep-find-ignored-directories |
72500
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
958 (concat (shell-quote-argument "(") |
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
959 ;; we should use shell-quote-argument here |
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
960 " -path " |
103787
fb68f473a020
(rgrep): Allow grep-find-ignored-directories
Sam Steingold <sds@gnu.org>
parents:
103276
diff
changeset
|
961 (mapconcat |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
962 #'(lambda (ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
963 (cond ((stringp ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
964 (shell-quote-argument |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
965 (concat "*/" ignore))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
966 ((consp ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
967 (and (funcall (car ignore) dir) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
968 (shell-quote-argument |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
969 (concat "*/" |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
970 (cdr ignore))))))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
971 grep-find-ignored-directories |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
972 " -o -path ") |
72500
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
973 " " |
35e43fe3d8ef
(grep-find-use-xargs): Use explicit value `exec'
Kim F. Storm <storm@cua.dk>
parents:
72173
diff
changeset
|
974 (shell-quote-argument ")") |
104898
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
975 " -prune -o ")) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
976 (and grep-find-ignored-files |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
977 (concat (shell-quote-argument "(") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
978 ;; we should use shell-quote-argument here |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
979 " -name " |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
980 (mapconcat |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
981 #'(lambda (ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
982 (cond ((stringp ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
983 (shell-quote-argument ignore)) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
984 ((consp ignore) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
985 (and (funcall (car ignore) dir) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
986 (shell-quote-argument |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
987 (cdr ignore)))))) |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
988 grep-find-ignored-files |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
989 " -o -name ") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
990 " " |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
991 (shell-quote-argument ")") |
5c11b1241dc1
(grep-template): Add "<X>" to docstring.
Juri Linkov <juri@jurta.org>
parents:
104745
diff
changeset
|
992 " -prune -o ")))))) |
70258 | 993 (when command |
104525
b8afce0dc654
(lgrep, rgrep): At the beginning
Juri Linkov <juri@jurta.org>
parents:
104243
diff
changeset
|
994 (if confirm |
70258 | 995 (setq command |
996 (read-from-minibuffer "Confirm: " | |
997 command nil nil 'grep-find-history)) | |
70421
47fe68ac1971
(lgrep, rgrep): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents:
70340
diff
changeset
|
998 (add-to-history 'grep-find-history command)) |
70534
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
999 (let ((default-directory dir)) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
1000 (compilation-start command 'grep-mode)) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
1001 ;; Set default-directory if we started rgrep in the *grep* buffer. |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
1002 (if (eq next-error-last-buffer (current-buffer)) |
afe3317800c2
(rgrep): Set default directory of *grep*
Kim F. Storm <storm@cua.dk>
parents:
70526
diff
changeset
|
1003 (setq default-directory dir))))))) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
1004 |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1005 ;;;###autoload |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1006 (defun zrgrep (regexp &optional files dir confirm grep-find-template) |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1007 "Recursively grep for REGEXP in gzipped FILES in tree rooted at DIR. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1008 Like `rgrep' but uses `zgrep' for `grep-program', sets the default |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1009 file name to `*.gz', and sets `grep-highlight-matches' to `always'." |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1010 (interactive |
107067
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1011 (progn |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1012 ;; Compute standard default values. |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1013 (grep-compute-defaults) |
107067
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1014 ;; Compute the default zrgrep command by running `grep-compute-defaults' |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1015 ;; for grep program "zgrep", but not changing global values. |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1016 (let ((grep-program "zgrep") |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1017 ;; Don't change global values for variables computed |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1018 ;; by `grep-compute-defaults'. |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1019 (grep-find-template nil) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1020 (grep-find-command nil) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1021 (grep-host-defaults-alist nil) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1022 ;; Use for `grep-read-files' |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1023 (grep-files-aliases '(("all" . "* .*") |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1024 ("gz" . "*.gz")))) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1025 ;; Recompute defaults using let-bound values above. |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1026 (grep-compute-defaults) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1027 (cond |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1028 ((and grep-find-command (equal current-prefix-arg '(16))) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1029 (list (read-from-minibuffer "Run: " grep-find-command |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1030 nil nil 'grep-find-history))) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1031 ((not grep-find-template) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1032 (error "grep.el: No `grep-find-template' available")) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1033 (t (let* ((regexp (grep-read-regexp)) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1034 (files (grep-read-files regexp)) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1035 (dir (read-directory-name "Base directory: " |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1036 nil default-directory t)) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1037 (confirm (equal current-prefix-arg '(4)))) |
5f67deabc08b
* progmodes/grep.el (zrgrep): Call `grep-compute-defaults' at the
Juri Linkov <juri@jurta.org>
parents:
106815
diff
changeset
|
1038 (list regexp files dir confirm grep-find-template))))))) |
106243
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1039 ;; Set `grep-highlight-matches' to `always' |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1040 ;; since `zgrep' puts filters in the grep output. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1041 (let ((grep-highlight-matches 'always)) |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1042 ;; `rgrep' uses the dynamically bound value `grep-find-template' |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1043 ;; from the argument `grep-find-template' whose value is computed |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1044 ;; in the `interactive' spec. |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1045 (rgrep regexp files dir confirm))) |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1046 |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1047 ;;;###autoload |
20e6e5b85a34
Search recursively in gzipped files. (Bug#4982)
Juri Linkov <juri@jurta.org>
parents:
106121
diff
changeset
|
1048 (defalias 'rzgrep 'zrgrep) |
53139
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
1049 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
1050 (provide 'grep) |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
1051 |
df3033332097
* progmodes/grep.el: New file with grep code from compile.el.
Kim F. Storm <storm@cua.dk>
parents:
diff
changeset
|
1052 ;;; grep.el ends here |