GNU bug report logs - #12640
23.3; compilation-start automatic `cd` doesn't work if path has spaces

Previous Next

Package: emacs;

Reported by: awl03 <at> doc.ic.ac.uk

Date: Sun, 14 Oct 2012 01:54:01 UTC

Severity: normal

Found in version 23.3

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12640 in the body.
You can then email your comments to 12640 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#12640; Package emacs. (Sun, 14 Oct 2012 01:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to awl03 <at> doc.ic.ac.uk:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 14 Oct 2012 01:54:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: awl03 <at> doc.ic.ac.uk
To: bug-gnu-emacs <at> gnu.org
Subject: 23.3; compilation-start automatic `cd` doesn't work if path has spaces
Date: Sun, 14 Oct 2012 00:02:19 +0100
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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12640; Package emacs. (Tue, 23 Oct 2012 19:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 12640 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: awl03 <at> doc.ic.ac.uk
Cc: 12640 <at> debbugs.gnu.org
Subject: Re: bug#12640: 23.3;
	compilation-start automatic `cd` doesn't work if path has spaces
Date: Tue, 23 Oct 2012 15:08:36 -0400
> 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  <monnier <at> iro.umontreal.ca>
 
+	* 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))





bug closed, send any further explanations to 12640 <at> debbugs.gnu.org and awl03 <at> doc.ic.ac.uk Request was from Stefan Monnier <monnier <at> iro.umontreal.ca> to control <at> debbugs.gnu.org. (Wed, 24 Oct 2012 13:57:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 22 Nov 2012 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 272 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.