From unknown Tue Aug 19 03:05:16 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces Resent-From: awl03@doc.ic.ac.uk Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Oct 2012 01:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12640 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 12640@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.135017958412714 (code B ref -1); Sun, 14 Oct 2012 01:54:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 Oct 2012 01:53:04 +0000 Received: from localhost ([127.0.0.1]:43008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TNDO3-0003Iz-Ud for submit@debbugs.gnu.org; Sat, 13 Oct 2012 21:53:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53495) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TNBxs-0001Gg-Nx for submit@debbugs.gnu.org; Sat, 13 Oct 2012 20:21:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNBwq-0000GX-HB for submit@debbugs.gnu.org; Sat, 13 Oct 2012 20:20:53 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:34752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNBwq-0000GT-E4 for submit@debbugs.gnu.org; Sat, 13 Oct 2012 20:20:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNBwp-0001Yt-FJ for bug-gnu-emacs@gnu.org; Sat, 13 Oct 2012 20:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNBwo-0000GJ-Ag for bug-gnu-emacs@gnu.org; Sat, 13 Oct 2012 20:20:51 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:57329) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNBwo-0000GA-4e for bug-gnu-emacs@gnu.org; Sat, 13 Oct 2012 20:20:50 -0400 Received: by mail-wi0-f171.google.com with SMTP id hj13so609009wib.12 for ; Sat, 13 Oct 2012 17:20:49 -0700 (PDT) Received: by 10.180.94.102 with SMTP id db6mr14541959wib.20.1350174048922; Sat, 13 Oct 2012 17:20:48 -0700 (PDT) Received: from GUNDOG7 ([87.113.201.220]) by mx.google.com with ESMTPS id b3sm5833453wie.0.2012.10.13.17.20.47 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 13 Oct 2012 17:20:48 -0700 (PDT) From: awl03@doc.ic.ac.uk Date: Sun, 14 Oct 2012 00:02:19 +0100 Message-ID: <86y5ja2cxw.fsf@doc.ic.ac.uk> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -3.4 (---) X-Mailman-Approved-At: Sat, 13 Oct 2012 21:53:03 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.4 (---) Function `compilation-start' in compile.el detects if the COMMAND starts with a `cd directory && ...` and sets the `default-directory' accordingly. But it doesn't work if the directory being `cd`ed to contains spaces, even if correctly quoted using `shell-quote-argument'. The regexp used to detect the path is too simple but I'm not sure how you would get one to detect matching quote pairs. I'm using Emacs 23.3.1 but I can see that the current git head [1] still has the problem. In GNU Emacs 23.3.1 (i386-mingw-nt6.1.7601) of 2011-03-10 on 3249CTO Windowing system distributor `Microsoft Corp.', version 6.1.7601 configured using `configure --with-gcc (4.5) --no-opt --cflags -Ic:/imagesupport/include' [1] http://repo.or.cz/w/emacs.git/blob/HEAD:/lisp/progmodes/compile.el Alex From unknown Tue Aug 19 03:05:16 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 23 Oct 2012 19:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12640 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: awl03@doc.ic.ac.uk Cc: 12640@debbugs.gnu.org Received: via spool by 12640-submit@debbugs.gnu.org id=B12640.135101943931370 (code B ref 12640); Tue, 23 Oct 2012 19:11:02 +0000 Received: (at 12640) by debbugs.gnu.org; 23 Oct 2012 19:10:39 +0000 Received: from localhost ([127.0.0.1]:58142 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TQjs6-00089v-Pn for submit@debbugs.gnu.org; Tue, 23 Oct 2012 15:10:39 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:37009) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TQjs5-00089k-1d for 12640@debbugs.gnu.org; Tue, 23 Oct 2012 15:10:37 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09MCqNj/2dsb2JhbABEDrQDgQiCFQEBBAFWIwULCzQSFBgNN4gJBboJjSaDHgOjM4FYgjBV X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="202564117" Received: from 76-10-163-99.dsl.teksavvy.com (HELO pastel.home) ([76.10.163.99]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 23 Oct 2012 15:08:37 -0400 Received: by pastel.home (Postfix, from userid 20848) id 096BC58CA3; Tue, 23 Oct 2012 15:08:36 -0400 (EDT) From: Stefan Monnier Message-ID: References: <86y5ja2cxw.fsf@doc.ic.ac.uk> Date: Tue, 23 Oct 2012 15:08:36 -0400 In-Reply-To: <86y5ja2cxw.fsf@doc.ic.ac.uk> (awl's message of "Sun, 14 Oct 2012 00:02:19 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.8 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: 0.8 (/) > Function `compilation-start' in compile.el detects if the COMMAND starts > with a `cd directory && ...` and sets the `default-directory' > accordingly. But it doesn't work if the directory being `cd`ed to > contains spaces, even if correctly quoted using > `shell-quote-argument'. > The regexp used to detect the path is too simple but I'm not sure how > you would get one to detect matching quote pairs. I've installed the patch below which should handle the simple cases of quoting. Stefan === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-23 18:40:23 +0000 +++ lisp/ChangeLog 2012-10-23 19:06:26 +0000 @@ -1,5 +1,8 @@ 2012-10-23 Stefan Monnier + * progmodes/compile.el (compilation-start): Try to handle common + quoting of `cd' argument (bug#12640). + * vc/diff-mode.el (diff-hunk): `save-excursion' while refining (bug#12671). === modified file 'lisp/progmodes/compile.el' --- lisp/progmodes/compile.el 2012-10-14 07:40:05 +0000 +++ lisp/progmodes/compile.el 2012-10-23 19:04:14 +0000 @@ -1568,12 +1568,20 @@ ;; Then evaluate a cd command if any, but don't perform it yet, else ;; start-command would do it again through the shell: (cd "..") AND ;; sh -c "cd ..; make" - (cd (if (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" - command) - (if (match-end 1) - (substitute-env-vars (match-string 1 command)) - "~") - default-directory)) + (cd (cond + ((not (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\|'[^']*'\\|\"\\(?:[^\"`$\\]\\|\\\\.\\)*\"\\)\\)?\\s *[;&\n]" + command)) + default-directory) + ((not (match-end 1)) "~") + ((eq (aref command (match-beginning 1)) ?\') + (substring command (1+ (match-beginning 1)) + (1- (match-end 1)))) + ((eq (aref command (match-beginning 1)) ?\") + (replace-regexp-in-string + "\\\\\\(.\\)" "\\1" + (substring command (1+ (match-beginning 1)) + (1- (match-end 1))))) + (t (substitute-env-vars (match-string 1 command))))) (erase-buffer) ;; Select the desired mode. (if (not (eq mode t)) From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 24 09:56:52 2012 Received: (at control) by debbugs.gnu.org; 24 Oct 2012 13:56:52 +0000 Received: from localhost ([127.0.0.1]:59663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TR1S0-0004xQ-0z for submit@debbugs.gnu.org; Wed, 24 Oct 2012 09:56:52 -0400 Received: from relais.videotron.ca ([24.201.245.36]:49897) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TR1Rx-0004xI-T2 for control@debbugs.gnu.org; Wed, 24 Oct 2012 09:56:50 -0400 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from ceviche.home ([24.201.208.110]) by VL-VM-MR001.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0MCE00A0GHBE9070@VL-VM-MR001.ip.videotron.ca> for control@debbugs.gnu.org; Wed, 24 Oct 2012 09:54:50 -0400 (EDT) Received: by ceviche.home (Postfix, from userid 20848) id 72872660E0; Wed, 24 Oct 2012 09:54:50 -0400 (EDT) From: Stefan Monnier To: control@debbugs.gnu.org Subject: Re: bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces Message-id: References: <86y5ja2cxw.fsf@doc.ic.ac.uk> Date: Wed, 24 Oct 2012 09:54:50 -0400 In-reply-to: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: close 12640 thanks [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [24.201.245.36 listed in list.dnswl.org] 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% [score: 0.5000] 0.0 T_MANY_HDRS_LCASE Odd capitalization of multiple message headers X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: close 12640 thanks [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [24.201.245.36 listed in list.dnswl.org] 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% [score: 0.5000] close 12640 thanks