From: Stefan Monnier <monnier@iro.umontreal.ca>
To: awl03@doc.ic.ac.uk
Cc: 12640@debbugs.gnu.org
Subject: bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces
Date: Tue, 23 Oct 2012 15:08:36 -0400 [thread overview]
Message-ID: <jwv1ugp57n9.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <86y5ja2cxw.fsf@doc.ic.ac.uk> (awl's message of "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'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@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))
prev parent reply other threads:[~2012-10-23 19:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-13 23:02 bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces awl03
2012-10-23 19:08 ` Stefan Monnier [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv1ugp57n9.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=12640@debbugs.gnu.org \
--cc=awl03@doc.ic.ac.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).