* bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces
@ 2012-10-13 23:02 awl03
2012-10-23 19:08 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: awl03 @ 2012-10-13 23:02 UTC (permalink / raw)
To: 12640
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* bug#12640: 23.3; compilation-start automatic `cd` doesn't work if path has spaces
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
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2012-10-23 19:08 UTC (permalink / raw)
To: awl03; +Cc: 12640
> 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))
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-23 19:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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).