From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: grep error because of bad previous input Date: Thu, 27 Jul 2006 19:46:06 -0400 Message-ID: References: Reply-To: rms@gnu.org NNTP-Posting-Host: main.gmane.org Content-Type: text/plain; charset=ISO-8859-15 X-Trace: sea.gmane.org 1154044069 8675 80.91.229.2 (27 Jul 2006 23:47:49 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 Jul 2006 23:47:49 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 28 01:47:47 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G6FZs-0002P7-Q4 for ged-emacs-devel@m.gmane.org; Fri, 28 Jul 2006 01:47:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G6FZs-0001nW-At for ged-emacs-devel@m.gmane.org; Thu, 27 Jul 2006 19:47:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G6FYP-0001Ea-RV for emacs-devel@gnu.org; Thu, 27 Jul 2006 19:46:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G6FYO-0001Di-HE for emacs-devel@gnu.org; Thu, 27 Jul 2006 19:46:08 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G6FYO-0001DZ-8D for emacs-devel@gnu.org; Thu, 27 Jul 2006 19:46:08 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1G6FaF-00057y-L2 for emacs-devel@gnu.org; Thu, 27 Jul 2006 19:48:03 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.34) id 1G6FYM-00035e-Hp; Thu, 27 Jul 2006 19:46:06 -0400 Original-To: sds@podval.org In-reply-to: (message from Sam Steingold on Thu, 27 Jul 2006 13:32:24 -0400) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:57705 Archived-At: 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))))