aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-05-23 00:11:53 +0000
committerChong Yidong2009-05-23 00:11:53 +0000
commitd4bbd646f4c76cbbcfe537d7dbc4028a72e8aa0e (patch)
tree31c70f655c83a1279d372d28d7690eb0e0879993
parent34001e4188a9b6122cfd65588fa15561af43bac4 (diff)
downloademacs-d4bbd646f4c76cbbcfe537d7dbc4028a72e8aa0e.tar.gz
emacs-d4bbd646f4c76cbbcfe537d7dbc4028a72e8aa0e.zip
* progmodes/grep.el (grep-compute-defaults): Simplify how settings
are looked up. (grep-apply-setting): New function. (grep-highlight-matches, grep-command, grep-template) (grep-use-null-device, grep-find-command, grep-find-template): Clarify role of grep-compute-defaults in docstrings. Use grep-apply-setting to apply changes (Bug#3343).
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/grep.el103
2 files changed, 65 insertions, 48 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f0a62d93681..948c7e2a868 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12009-05-23 Chong Yidong <cyd@stupidchicken.com>
2
3 * progmodes/grep.el (grep-compute-defaults): Simplify how settings
4 are looked up.
5 (grep-apply-setting): New function.
6 (grep-highlight-matches, grep-command, grep-template)
7 (grep-use-null-device, grep-find-command, grep-find-template):
8 Clarify role of grep-compute-defaults in docstrings. Use
9 grep-apply-setting to apply changes (Bug#3343).
10
12009-05-21 Glenn Morris <rgm@gnu.org> 112009-05-21 Glenn Morris <rgm@gnu.org>
2 12
3 * calendar/cal-move.el (calendar-forward-day): Fix 2008-06-21 change - 13 * calendar/cal-move.el (calendar-forward-day): Fix 2008-06-21 change -
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index fa73f7f777a..2c70c61c32a 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -38,6 +38,27 @@
38 :group 'tools 38 :group 'tools
39 :group 'processes) 39 :group 'processes)
40 40
41(defvar grep-host-defaults-alist nil
42 "Default values depending on target host.
43`grep-compute-defaults' returns default values for every local or
44remote host `grep' runs. These values can differ from host to
45host. Once computed, the default values are kept here in order
46to avoid computing them again.")
47
48(defun grep-apply-setting (symbol value)
49 "Set SYMBOL to VALUE, and update `grep-host-defaults-alist'.
50SYMBOL should be one of `grep-command', `grep-template',
51`grep-use-null-device', `grep-find-command',
52`grep-find-template', `grep-find-use-xargs', or
53`grep-highlight-matches'."
54 (when grep-host-defaults-alist
55 (let* ((host-id
56 (intern (or (file-remote-p default-directory) "localhost")))
57 (host-defaults (assq host-id grep-host-defaults-alist))
58 (defaults (assq nil grep-host-defaults-alist)))
59 (setcar (cdr (assq symbol host-defaults)) value)
60 (setcar (cdr (assq symbol defaults)) value)))
61 (set-default symbol value))
41 62
42;;;###autoload 63;;;###autoload
43(defcustom grep-window-height nil 64(defcustom grep-window-height nil
@@ -59,11 +80,13 @@ markers for highlighting and GREP_OPTIONS to add the --color
59option in front of any explicit grep options before starting 80option in front of any explicit grep options before starting
60the grep. 81the grep.
61 82
62The default value of this variable is set up by `grep-compute-defaults'; 83In interactive usage, the actual value of this variable is set up
63call that function before using this variable in your program." 84by `grep-compute-defaults'; to change the default value, use
85Customize or call the function `grep-apply-setting'."
64 :type '(choice (const :tag "Do not highlight matches with grep markers" nil) 86 :type '(choice (const :tag "Do not highlight matches with grep markers" nil)
65 (const :tag "Highlight matches with grep markers" t) 87 (const :tag "Highlight matches with grep markers" t)
66 (other :tag "Not Set" auto-detect)) 88 (other :tag "Not Set" auto-detect))
89 :set 'grep-apply-setting
67 :version "22.1" 90 :version "22.1"
68 :group 'grep) 91 :group 'grep)
69 92
@@ -84,23 +107,28 @@ If the grep program used supports an option to always include file names
84in its output (such as the `-H' option to GNU grep), it's a good idea to 107in its output (such as the `-H' option to GNU grep), it's a good idea to
85include it when specifying `grep-command'. 108include it when specifying `grep-command'.
86 109
87The default value of this variable is set up by `grep-compute-defaults'; 110In interactive usage, the actual value of this variable is set up
88call that function before using this variable in your program." 111by `grep-compute-defaults'; to change the default value, use
112Customize or call the function `grep-apply-setting'."
89 :type '(choice string 113 :type '(choice string
90 (const :tag "Not Set" nil)) 114 (const :tag "Not Set" nil))
115 :set 'grep-apply-setting
91 :group 'grep) 116 :group 'grep)
92 117
93(defcustom grep-template nil 118(defcustom grep-template nil
94 "The default command to run for \\[lgrep]. 119 "The default command to run for \\[lgrep].
95The default value of this variable is set up by `grep-compute-defaults';
96call that function before using this variable in your program.
97The following place holders should be present in the string: 120The following place holders should be present in the string:
98 <C> - place to put -i if case insensitive grep. 121 <C> - place to put -i if case insensitive grep.
99 <F> - file names and wildcards to search. 122 <F> - file names and wildcards to search.
100 <R> - the regular expression searched for. 123 <R> - the regular expression searched for.
101 <N> - place to insert null-device." 124 <N> - place to insert null-device.
125
126In interactive usage, the actual value of this variable is set up
127by `grep-compute-defaults'; to change the default value, use
128Customize or call the function `grep-apply-setting'."
102 :type '(choice string 129 :type '(choice string
103 (const :tag "Not Set" nil)) 130 (const :tag "Not Set" nil))
131 :set 'grep-apply-setting
104 :version "22.1" 132 :version "22.1"
105 :group 'grep) 133 :group 'grep)
106 134
@@ -110,34 +138,40 @@ This is done to ensure that the output of grep includes the filename of
110any match in the case where only a single file is searched, and is not 138any match in the case where only a single file is searched, and is not
111necessary if the grep program used supports the `-H' option. 139necessary if the grep program used supports the `-H' option.
112 140
113The default value of this variable is set up by `grep-compute-defaults'; 141In interactive usage, the actual value of this variable is set up
114call that function before using this variable in your program." 142by `grep-compute-defaults'; to change the default value, use
143Customize or call the function `grep-apply-setting'."
115 :type '(choice (const :tag "Do Not Append Null Device" nil) 144 :type '(choice (const :tag "Do Not Append Null Device" nil)
116 (const :tag "Append Null Device" t) 145 (const :tag "Append Null Device" t)
117 (other :tag "Not Set" auto-detect)) 146 (other :tag "Not Set" auto-detect))
147 :set 'grep-apply-setting
118 :group 'grep) 148 :group 'grep)
119 149
120;;;###autoload 150;;;###autoload
121(defcustom grep-find-command nil 151(defcustom grep-find-command nil
122 "The default find command for \\[grep-find]. 152 "The default find command for \\[grep-find].
123The default value of this variable is set up by `grep-compute-defaults'; 153In interactive usage, the actual value of this variable is set up
124call that function before using this variable in your program." 154by `grep-compute-defaults'; to change the default value, use
155Customize or call the function `grep-apply-setting'."
125 :type '(choice string 156 :type '(choice string
126 (const :tag "Not Set" nil)) 157 (const :tag "Not Set" nil))
158 :set 'grep-apply-setting
127 :group 'grep) 159 :group 'grep)
128 160
129(defcustom grep-find-template nil 161(defcustom grep-find-template nil
130 "The default command to run for \\[rgrep]. 162 "The default command to run for \\[rgrep].
131The default value of this variable is set up by `grep-compute-defaults';
132call that function before using this variable in your program.
133The following place holders should be present in the string: 163The following place holders should be present in the string:
134 <D> - base directory for find 164 <D> - base directory for find
135 <X> - find options to restrict or expand the directory list 165 <X> - find options to restrict or expand the directory list
136 <F> - find options to limit the files matched 166 <F> - find options to limit the files matched
137 <C> - place to put -i if case insensitive grep 167 <C> - place to put -i if case insensitive grep
138 <R> - the regular expression searched for." 168 <R> - the regular expression searched for.
169In interactive usage, the actual value of this variable is set up
170by `grep-compute-defaults'; to change the default value, use
171Customize or call the function `grep-apply-setting'."
139 :type '(choice string 172 :type '(choice string
140 (const :tag "Not Set" nil)) 173 (const :tag "Not Set" nil))
174 :set 'grep-apply-setting
141 :version "22.1" 175 :version "22.1"
142 :group 'grep) 176 :group 'grep)
143 177
@@ -387,13 +421,6 @@ This variable's value takes effect when `grep-compute-defaults' is called.")
387(defvar grep-regexp-history nil) 421(defvar grep-regexp-history nil)
388(defvar grep-files-history '("ch" "el")) 422(defvar grep-files-history '("ch" "el"))
389 423
390(defvar grep-host-defaults-alist nil
391 "Default values depending on target host.
392`grep-compute-defaults' returns default values for every local or
393remote host `grep' runs. These values can differ from host to
394host. Once computed, the default values are kept here in order
395to avoid computing them again.")
396
397;;;###autoload 424;;;###autoload
398(defun grep-process-setup () 425(defun grep-process-setup ()
399 "Setup compilation variables and buffer for `grep'. 426 "Setup compilation variables and buffer for `grep'.
@@ -454,33 +481,13 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
454 (defaults (assq nil grep-host-defaults-alist))) 481 (defaults (assq nil grep-host-defaults-alist)))
455 ;; There are different defaults on different hosts. They must be 482 ;; There are different defaults on different hosts. They must be
456 ;; computed for every host once. 483 ;; computed for every host once.
457 (setq grep-command 484 (dolist (setting '(grep-command grep-template
458 (or (cadr (assq 'grep-command host-defaults)) 485 grep-use-null-device grep-find-command
459 (cadr (assq 'grep-command defaults))) 486 grep-find-template grep-find-use-xargs
460 487 grep-highlight-matches))
461 grep-template 488 (set setting
462 (or (cadr (assq 'grep-template host-defaults)) 489 (or (cadr (assq setting host-defaults))
463 (cadr (assq 'grep-template defaults))) 490 (cadr (assq setting defaults)))))
464
465 grep-use-null-device
466 (or (cadr (assq 'grep-use-null-device host-defaults))
467 (cadr (assq 'grep-use-null-device defaults)))
468
469 grep-find-command
470 (or (cadr (assq 'grep-find-command host-defaults))
471 (cadr (assq 'grep-find-command defaults)))
472
473 grep-find-template
474 (or (cadr (assq 'grep-find-template host-defaults))
475 (cadr (assq 'grep-find-template defaults)))
476
477 grep-find-use-xargs
478 (or (cadr (assq 'grep-find-use-xargs host-defaults))
479 (cadr (assq 'grep-find-use-xargs defaults)))
480
481 grep-highlight-matches
482 (or (cadr (assq 'grep-highlight-matches host-defaults))
483 (cadr (assq 'grep-highlight-matches defaults))))
484 491
485 (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) 492 (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
486 (setq grep-use-null-device 493 (setq grep-use-null-device