aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorRichard M. Stallman <[email protected]>2006-07-29 02:03:21 +0000
committerRichard M. Stallman <[email protected]>2006-07-29 02:03:21 +0000
commit13eb1bded17be81b2041fb9979f9d7a13b914742 (patch)
tree297d61aa3aa0624b41433d0ee78b727d2b62c822 /lisp
parenteb107d095c503ebe018e333bc479f24e83d8c305 (diff)
(grep-default-command): Catch errors from wildcard-to-regexp.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/grep.el36
1 files changed, 23 insertions, 13 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 1c29bfe9cc..a939d54b3c 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -465,28 +465,38 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
""))
(defun grep-default-command ()
+ "Compute the default grep command for C-u M-x grep to offer."
(let ((tag-default (shell-quote-argument (grep-tag-default)))
+ ;; This a regexp to match single shell arguments.
+ ;; Could someone please add comments explaining it?
(sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
(grep-default (or (car grep-history) grep-command)))
- ;; Replace the thing matching for with that around cursor.
+ ;; In the default command, find the arg that specifies the pattern.
(when (or (string-match
(concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
grep-default)
;; If the string is not yet complete.
(string-match "\\(\\)\\'" grep-default))
- (unless (or (not (stringp buffer-file-name))
- (when (match-beginning 2)
- (save-match-data
- (string-match
- (wildcard-to-regexp
- (file-name-nondirectory
- (match-string 3 grep-default)))
- (file-name-nondirectory buffer-file-name)))))
- (setq grep-default (concat (substring grep-default
- 0 (match-beginning 2))
- " *."
- (file-name-extension buffer-file-name))))
+ ;; Maybe we will replace the pattern with the default tag.
+ ;; But first, maybe replace the file name pattern.
+ (condition-case nil
+ (unless (or (not (stringp buffer-file-name))
+ (when (match-beginning 2)
+ (save-match-data
+ (string-match
+ (wildcard-to-regexp
+ (file-name-nondirectory
+ (match-string 3 grep-default)))
+ (file-name-nondirectory buffer-file-name)))))
+ (setq grep-default (concat (substring grep-default
+ 0 (match-beginning 2))
+ " *."
+ (file-name-extension buffer-file-name))))
+ ;; In case wildcard-to-regexp gets an error
+ ;; from invalid data.
+ (error nil))
+ ;; Now replace the pattern with the default tag.
(replace-match tag-default t t grep-default 1))))