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.

Full log


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))





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.