all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: grep error because of bad previous input
Date: Thu, 27 Jul 2006 19:46:06 -0400	[thread overview]
Message-ID: <E1G6FYM-00035e-Hp@fencepost.gnu.org> (raw)
In-Reply-To: <alejw7rm1j.fsf@quant8.janestcapital.quant> (message from Sam Steingold on Thu, 27 Jul 2006 13:32:24 -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))))

  parent reply	other threads:[~2006-07-27 23:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-27 17:32 grep error because of bad previous input Sam Steingold
2006-07-27 17:51 ` Chong Yidong
2006-07-27 18:16   ` Sam Steingold
2006-07-27 23:46 ` Richard Stallman [this message]
2006-07-28  7:11   ` Stefan Monnier
2006-07-28  7:31     ` David Kastrup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1G6FYM-00035e-Hp@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.