[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep error because of bad previous input
From: |
Richard Stallman |
Subject: |
Re: grep error because of bad previous input |
Date: |
Thu, 27 Jul 2006 19:46:06 -0400 |
Does this fix it?
*** grep.el 19 Jul 2006 17:19:19 -0400 1.62
--- grep.el 27 Jul 2006 19:15:01 -0400
***************
*** 456,488 ****
t)))))
(defun grep-default-command ()
(let ((tag-default
(shell-quote-argument
(or (funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default))
"")))
(sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"'
\t\n]\\)+\\)")
(grep-default (or (car grep-history) grep-command)))
! ;; Replace the thing matching for with that around cursor.
(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))))
(replace-match tag-default t t grep-default 1))))
--- 456,499 ----
t)))))
(defun grep-default-command ()
+ "Compute the default grep command for C-u M-x grep to offer."
(let ((tag-default
+ ;; Find the tag in the buffer at point.
(shell-quote-argument
(or (funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default))
"")))
+ ;; Is this a regexp to match single shell arguments?
+ ;; I guess so. Does someone know?
(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
(concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
grep-default)
;; If the string is not yet complete.
(string-match "\\(\\)\\'" grep-default))
! ;; 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))))