From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Colin Fraizer" Newsgroups: gmane.emacs.bugs Subject: bug#6665: rgrep does not work on Windows Date: Wed, 17 Nov 2010 07:26:54 -0500 Message-ID: <01c701cb8652$b921a020$2b64e060$@cfraizer.com> References: <86hbjwhnc7.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1289997885 24944 80.91.229.12 (17 Nov 2010 12:44:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 17 Nov 2010 12:44:45 +0000 (UTC) To: <6665@debbugs.gnu.org> Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 17 13:44:40 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PIhNQ-0000L3-Cp for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Nov 2010 13:44:40 +0100 Original-Received: from localhost ([127.0.0.1]:41236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PIhNP-0002Fk-Qh for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Nov 2010 07:44:39 -0500 Original-Received: from [140.186.70.92] (port=42621 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PIhNB-00029u-HI for bug-gnu-emacs@gnu.org; Wed, 17 Nov 2010 07:44:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PIhN7-0005zL-7O for bug-gnu-emacs@gnu.org; Wed, 17 Nov 2010 07:44:25 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PIhN7-0005z8-33 for bug-gnu-emacs@gnu.org; Wed, 17 Nov 2010 07:44:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1PIh1V-0006vR-JX; Wed, 17 Nov 2010 07:22:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <86hbjwhnc7.fsf@gmail.com> Resent-From: "Colin Fraizer" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Nov 2010 12:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6665 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6665-submit@debbugs.gnu.org id=B6665.128999651926613 (code B ref 6665); Wed, 17 Nov 2010 12:22:01 +0000 Original-Received: (at 6665) by debbugs.gnu.org; 17 Nov 2010 12:21:59 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PIh1S-0006vC-M6 for submit@debbugs.gnu.org; Wed, 17 Nov 2010 07:21:58 -0500 Original-Received: from caibbdcaaaaf.dreamhost.com ([208.113.200.5] helo=homiemail-a40.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PIh1Q-0006v4-0A for 6665@debbugs.gnu.org; Wed, 17 Nov 2010 07:21:57 -0500 Original-Received: from homiemail-a40.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a40.g.dreamhost.com (Postfix) with ESMTP id 3FD6174C08B for <6665@debbugs.gnu.org>; Wed, 17 Nov 2010 04:26:57 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=cfraizer.com; h=from:to:subject :date:message-id:mime-version:content-type: content-transfer-encoding; q=dns; s=cfraizer.com; b=8UsuGWp8tBsk oYA/bGLQivJVBWEIm591jWKkLWi/viEIqVkx+p1RA7zR07aYDdyiwxOHTpnaEqYe 9n4fqbdZOJ1d7fVgDsGC8H1zXJoEyo8nnVgJcup+Ku/q7tEOCiGtBB6E3xlW6J6l HzLSE3VXVlDdSDcJbstiTJbWIp5C1Ek= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cfraizer.com; h=from:to :subject:date:message-id:mime-version:content-type: content-transfer-encoding; s=cfraizer.com; bh=2SwB1cwHz0cQq4l6+n 0UcSx42wA=; b=n9Fugs2lMU9FcIUvP2QL7/X/x5MLp5Iu4Jt0pitdqgr9jvnEHl tw62a7SIHm+7nWrmtR6zXIZep1spqAj2uf7zoBY9NoilTqYq4Hdtu5+gygbxro8n p/NxVKQPykS1n/OiXlw6IaKv6PL2gEWgTyjdRidm7nB2CzG0rVHrm2eB0= Original-Received: from ColinFraizerPC (stan.inter-intelli.com [209.43.1.25]) (Authenticated sender: colin@cfraizer.com) by homiemail-a40.g.dreamhost.com (Postfix) with ESMTPA id CF51374C081 for <6665@debbugs.gnu.org>; Wed, 17 Nov 2010 04:26:56 -0800 (PST) X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHQ4etXb4tfiZSN4biKqPRdt06pIQ== Content-Language: en-us X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 17 Nov 2010 07:22:01 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:41692 Archived-At: On July 19, 2010, Eli Zaretskii wrote: >I think this bug report should be closed, as it is not something Emacs can fix. I believe Mr. Zaretskii is correct that Emacs is not the cause of the problem. It appears to be a bug in the GnuWin32 and/or MSys port of "find". *However*, I would argue that rgrep constructs a bogus find command anyway and that *that* should be fixed. Specifically, it creates [NOTE: I replaced text with the string "[...]".] find . "(" -path "*/SCCS" [...] ")" -prune -o "(" -name ".#*" [...] ")" -prune -o -type f "(" -iname "*.el" ")" -exec grep -nH "mystring" {} ";" That second "-prune" is really bogus. It is supposed to mean "don't descend into the matched file as a directory", but it's not matching directories. It is matching regular filenames. I beleive a better string to generate is find . "(" -path "*/SCCS" [...] ")" -prune -o -not "(" -name ".#*" [...] ")" -and -type f "(" -iname "*.el" ")" -exec grep -nH "mystring" {} ";" That is, I would: 1. Add "-not" before the list of excluded files. 2. Remove the second "-prune". 3. Change the "-o" after the list of excluded files to "-and". I believe this should work on all systems (even with the buggy version of "find") and doesn't rely on "-prune" to mean "-noop". [I'm new here, so please excuse any breaches of rules or etiquette. I'll be happy to conform to your norms (or to leave) if you instruct me.] Best regards, --Colin Fraizer Indianapolis, Indiana, USA, Earth 8-) My (very-lightly-tested) version of rgrep follows: (defun rgrep (regexp &optional files dir confirm) "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. The search is limited to file names matching shell pattern FILES. FILES may use abbreviations defined in `grep-files-aliases', e.g. entering `ch' is equivalent to `*.[ch]'. With \\[universal-argument] prefix, you can edit the constructed shell command line before it is executed. With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'. Collect output in a buffer. While find runs asynchronously, you can use \\[next-error] (M-x next-error), or \\\\[compile-goto-error] \ in the grep output buffer, to go to the lines where grep found matches. This command shares argument histories with \\[lgrep] and \\[grep-find]." (interactive (progn (grep-compute-defaults) (cond ((and grep-find-command (equal current-prefix-arg '(16))) (list (read-from-minibuffer "Run: " grep-find-command nil nil 'grep-find-history))) ((not grep-find-template) (error "grep.el: No `grep-find-template' available")) (t (let* ((regexp (grep-read-regexp)) (files (grep-read-files regexp)) (dir (read-directory-name "Base directory: " nil default-directory t)) (confirm (equal current-prefix-arg '(4)))) (list regexp files dir confirm)))))) (when (and (stringp regexp) (> (length regexp) 0)) (unless (and dir (file-directory-p dir) (file-readable-p dir)) (setq dir default-directory)) (if (null files) (if (not (string= regexp grep-find-command)) (compilation-start regexp 'grep-mode)) (setq dir (file-name-as-directory (expand-file-name dir))) (require 'find-dired) ; for `find-name-arg' (let ((command (grep-expand-template grep-find-template regexp (concat (shell-quote-argument "(") " " find-name-arg " " (mapconcat #'shell-quote-argument (split-string files) (concat " -o " find-name-arg " ")) " " (shell-quote-argument ")")) dir (concat (and grep-find-ignored-directories (concat (shell-quote-argument "(") ;; we should use shell-quote-argument here " -path " (mapconcat #'(lambda (ignore) (cond ((stringp ignore) (shell-quote-argument (concat "*/" ignore))) ((consp ignore) (and (funcall (car ignore) dir) (shell-quote-argument (concat "*/" (cdr ignore))))))) grep-find-ignored-directories " -o -path ") " " (shell-quote-argument ")") " -prune -o ")) (and grep-find-ignored-files (concat (shell-quote-argument "-not") " " (shell-quote-argument "(") ;; we should use shell-quote-argument here " -name " (mapconcat #'(lambda (ignore) (cond ((stringp ignore) (shell-quote-argument ignore)) ((consp ignore) (and (funcall (car ignore) dir) (shell-quote-argument (cdr ignore)))))) grep-find-ignored-files " -o -name ") " " (shell-quote-argument ")") " -and ")))))) (when command (if confirm (setq command (read-from-minibuffer "Confirm: " command nil nil 'grep-find-history)) (add-to-history 'grep-find-history command)) (let ((default-directory dir)) (compilation-start command 'grep-mode)) ;; Set default-directory if we started rgrep in the *grep* buffer. (if (eq next-error-last-buffer (current-buffer)) (setq default-directory dir)))))))