[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH]: grep-default-command
From: |
Haojun Bao |
Subject: |
[PATCH]: grep-default-command |
Date: |
Sun, 15 Aug 2010 00:14:51 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
the grep-default-command has problems in the sh-arg-re, that is, when
matching a double quoted thing, it can't handle correctly when there's
embedded double quote, like this: "x\"y".
The old way to match a double quoted part is:
1) match a (beginning) double quote and go to 2)
2) do the following
2a) match anything not a double quote, go back to 2)
2b) match an escape followed by a double quote, go back to 2)
if it fails, go to 3).
3) match a (ending) double quote
To improve it, 2a) and 2b) need switched.
A second problem is when matching a non-quoted thing, the old way is:
match anything not a quote (double/single) or a space (SPC, \t, \n)
And it won't handle the following: `aa\ bb', `aa|bb'. The first should
be considered a single arg, the second should not.
A more correct way should be:
match an escape followed by anything, or
match non-special characters (not the meta-characters, like space, pipe,
redirect, etc).
=== modified file 'lisp/progmodes/grep.el'
--- lisp/progmodes/grep.el 2010-05-21 20:43:04 +0000
+++ lisp/progmodes/grep.el 2010-08-14 16:11:37 +0000
@@ -628,7 +628,16 @@
(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]\\)+\\)")
+
+ ;; Here's explanation: a shell arg can be a series of these 3 things:
+ ;;
+ ;; 1) Double quoted thing, in which double quote can occur, but must
be led by the escape ?\\
+ ;; 2) Single quoted thing, in which anything except the single quote
can occur
+ ;; 3) Non-quoted thing, in which some special chars can not occur,
unless they are led by escape.
+ ;;
+ ;; Trick is to get the correct number of escapes!
+
+ (sh-arg-re
"\\(\\(?:\"\\(?:\\\\\"\\|[^\"]\\)+\"\\|'[^']+'\\|\\(?:\\\\.\\|[^\"'
\\|><\t\n]\\)\\)+\\)")
(grep-default (or (car grep-history) grep-command)))
;; In the default command, find the arg that specifies the pattern.
(when (or (string-match
- [PATCH]: grep-default-command,
Haojun Bao <=