From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Christoph Newsgroups: gmane.emacs.devel Subject: Weird grep.el behavior Date: Wed, 07 Apr 2010 20:35:30 -0600 Message-ID: <4BBD40F2.5020600@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1270694159 12112 80.91.229.12 (8 Apr 2010 02:35:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 8 Apr 2010 02:35:59 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 08 04:35:56 2010 Return-path: Envelope-to: ged-emacs-devel@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 1Nzhb1-00009e-R5 for ged-emacs-devel@m.gmane.org; Thu, 08 Apr 2010 04:35:56 +0200 Original-Received: from localhost ([127.0.0.1]:43378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nzhb1-0006tk-1k for ged-emacs-devel@m.gmane.org; Wed, 07 Apr 2010 22:35:55 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nzham-0006p8-FO for emacs-devel@gnu.org; Wed, 07 Apr 2010 22:35:40 -0400 Original-Received: from [140.186.70.92] (port=57128 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nzhak-0006oM-SH for emacs-devel@gnu.org; Wed, 07 Apr 2010 22:35:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nzhaj-0006gZ-RH for emacs-devel@gnu.org; Wed, 07 Apr 2010 22:35:38 -0400 Original-Received: from mail-pw0-f41.google.com ([209.85.160.41]:57033) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nzhaj-0006gN-JD for emacs-devel@gnu.org; Wed, 07 Apr 2010 22:35:37 -0400 Original-Received: by pwi2 with SMTP id 2so1984797pwi.0 for ; Wed, 07 Apr 2010 19:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=K6Z/42xfQCg7Q2iiV9KHGZk45LRTaCq7X6rV7iRkhjs=; b=dWD39wWLKrnYtYRw9bz4mlRPersxjKSfxuYayNb65w9Md6UpEb1L9YE62PQ2UG25tn X6SIneEeX98uCd6RShfInAZTvb0/wMU4b9TtD8i3o+Cq3Ke+QBbLR+J7+lKpabzzmfgt 0pNyRxYeDPtGjCXJG3vi1KlU1Mt5feSokwqY4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=oTNme3YenrTWj97n3mZ73zg1OBJEqH8iayvzZ+uRt8c2YhqT1BgDiq34i3wkNNOE+B mgtYQDflpsA9u1Y6Y54BPGmOqU/FkWuUh5sgc0/nxfSXh37xa6oTEG21PzcxDmuNUVJ+ A4yywRXThDovJrXiLaMu8b/ytTBwHF9wiR13E= Original-Received: by 10.114.87.17 with SMTP id k17mr9679577wab.215.1270694135359; Wed, 07 Apr 2010 19:35:35 -0700 (PDT) Original-Received: from [192.168.1.5] (67-41-143-56.hlrn.qwest.net [67.41.143.56]) by mx.google.com with ESMTPS id 21sm2987778pzk.12.2010.04.07.19.35.33 (version=SSLv3 cipher=RC4-MD5); Wed, 07 Apr 2010 19:35:34 -0700 (PDT) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:123344 Archived-At: Some things in grep.el that have been bugging me for a while. See the following code (dolist (setting '(grep-command grep-template grep-use-null-device grep-find-command grep-find-template grep-find-use-xargs grep-highlight-matches)) (set setting (or (cadr (assq setting host-defaults)) (cadr (assq setting defaults))))) There is a problem in the or statement, but only with the option grep-use-null-device. Using M-x grep for the fist time host-defaults are nil, so grep-use-null-device is set to default, which is autodetect. This causes the null-device test to be executed and (in my case) the result is nil, i.e. grep-use-null-device is set to nil. Now, the next time I execute M-x grep, the above code is supposed to detect that the host-defaults have been set the last time and use those. However, when it gets to grep-use-null-device the first cadr returns the value of grep-use-null-device, which is nil, and the or executes the second branch, assigning the autodetect to grep-use-null-device. All other options keep their host-default value. I assume this this is not correct. The following patch will fix this: === modified file 'lisp/progmodes/grep.el' --- lisp/progmodes/grep.el 2010-01-31 21:47:47 +0000 +++ lisp/progmodes/grep.el 2010-04-08 00:11:28 +0000 @@ -513,8 +513,8 @@ grep-find-template grep-find-use-xargs grep-highlight-matches)) (set setting - (or (cadr (assq setting host-defaults)) - (cadr (assq setting defaults))))) + (cadr (or (assq setting host-defaults) + (assq setting defaults))))) (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) (setq grep-use-null-device Only if assq returns nil, i.e. the host-defaults have never been set, the function assigns the defaults. Otherwise it uses the host-defaults. The above described leads to some funny behavior which I can't really explain. I have two Windows XP machines, which, when I execute M-x grep for the first time, present the following options: grep -nH. Running grep works fine the first time. Second time I run grep, I get an error code 2 and an error message saying NUL is not a valid file name. Looking at grep-use-null-device at this point, shows it is set to t. First time, it is tested and set to nil (I checked), second time, because the test is executed again due to the above bug, it is somehow set to t. The only difference between the two test runs is, that the second time the grep-command is actually set and the grep-probe is executing the stored command. However, the command is exactly the same: grep -nH. Note, that the -e option is missing. I stepped through the code and the test for the -e options always fails on these XP machines. I am not quite sure what exactly the test is doing (from line 541 in grep.el) but for some reason it does not work under XP. I use GnuWin32 coreutils, grep, findutils etc. which are correctly added to PATH and exec-path in Emacs. Now, I have a Windows 7 machine, which runs the exact same setup, i.e. same .emacs.d, GnuWin32 utils, path setup and on it, everything works fine and the grep options are shown as expected: grep -nH -e. The interesting part is that on this machine the above described bug has no effect. Where on my XP machines the second test for grep-use-null-device shows a different result than the first test, on Windows 7 both test results are the same and grep-use-null-device stays nil. This despite (or because of?) the fact that the first test is executed with grep -nH and the second test with grep -nH -e, since the -e option was added to grep-command. I guess I need more information on what the -e test is actually doing to debug this. Does anybody else have this problem under Windows? Thanks, Christoph