From c79825bd22f07399351d626fbc8060941aba36a5 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 23 Oct 2012 15:07:44 -0400 Subject: [PATCH] * lisp/progmodes/compile.el (compilation-start): Try to handle common quoting of `cd' argument. Fixes: debbugs:12640 --- lisp/ChangeLog | 3 +++ lisp/progmodes/compile.el | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 05b7cfc176e..df7420c30a3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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). diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 10fd7a75eaa..06525b354b1 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1568,12 +1568,20 @@ Returns the compilation buffer created." ;; 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)) -- 2.39.2