changeset 57628:cce8a9fe7de8

(compilation-start): Rely on `cd' to get dir right and also allow argumentless cd.
author Daniel Pfeiffer <occitan@esperanto.org>
date Wed, 20 Oct 2004 22:30:34 +0000
parents c563b0f2f5ea
children 491b47c0a65b
files lisp/progmodes/compile.el
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/compile.el	Wed Oct 20 20:09:10 2004 +0000
+++ b/lisp/progmodes/compile.el	Wed Oct 20 22:30:34 2004 +0000
@@ -866,10 +866,7 @@
 	  (if (eq mode t)
 	      (prog1 "compilation" (require 'comint))
 	    (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
-	 cd-path		 ; in case process-environment contains CDPATH
-	 (thisdir (if (string-match "^\\s *cd\\s +\\(.+?\\)\\s *[;&\n]" command)
-		      (substitute-in-file-name (match-string 1 command))
-		    default-directory))
+	 (thisdir default-directory)
 	 outwin outbuf)
     (with-current-buffer
 	(setq outbuf
@@ -890,17 +887,25 @@
 	      (error "Cannot have two processes in `%s' at once"
 		     (buffer-name)))))
       (buffer-disable-undo (current-buffer))
+      ;; first transfer directory from where M-x compile was called
+      (setq default-directory thisdir)
       ;; Make compilation buffer read-only.  The filter can still write it.
       ;; Clear out the compilation buffer.
-      (let ((inhibit-read-only t))
+      (let ((inhibit-read-only t)
+	    (default-directory thisdir))
+	;; 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)
+		    (match-string 1 command)
+		  "~")
+	      default-directory))
 	(erase-buffer)
-	;; Change its default-directory to the directory where the compilation
-	;; will happen, and insert a `cd' command to indicate this.
-	(setq default-directory thisdir)
 	;; output a mode setter, for saving and later reloading this buffer
 	(insert "-*- mode: " name-of-mode
 		"; default-directory: " (prin1-to-string default-directory)
-		" -*-\n" command "\n"))
+		" -*-\n" command "\n")
+	(setq thisdir default-directory))
       (set-buffer-modified-p nil))
     ;; If we're already in the compilation buffer, go to the end
     ;; of the buffer, so point will track the compilation output.
@@ -985,7 +990,9 @@
 	  ;; fontified, so fontify it now.
 	  (let ((font-lock-verbose nil)) ; shut up font-lock messages
 	    (font-lock-fontify-buffer))
-	  (message "Executing `%s'...done" command))))
+	  (message "Executing `%s'...done" command)))
+      ;; Now finally cd to where the shell started make/grep/...
+      (setq default-directory thisdir))
     (if (buffer-local-value 'compilation-scroll-output outbuf)
 	(save-selected-window
 	  (select-window outwin)