comparison lisp/progmodes/compile.el @ 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 8b57f4d6c462
children 9621341c0037 f3ec05478165
comparison
equal deleted inserted replaced
57627:c563b0f2f5ea 57628:cce8a9fe7de8
864 (or mode (setq mode 'compilation-mode)) 864 (or mode (setq mode 'compilation-mode))
865 (let* ((name-of-mode 865 (let* ((name-of-mode
866 (if (eq mode t) 866 (if (eq mode t)
867 (prog1 "compilation" (require 'comint)) 867 (prog1 "compilation" (require 'comint))
868 (replace-regexp-in-string "-mode$" "" (symbol-name mode)))) 868 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
869 cd-path ; in case process-environment contains CDPATH 869 (thisdir default-directory)
870 (thisdir (if (string-match "^\\s *cd\\s +\\(.+?\\)\\s *[;&\n]" command)
871 (substitute-in-file-name (match-string 1 command))
872 default-directory))
873 outwin outbuf) 870 outwin outbuf)
874 (with-current-buffer 871 (with-current-buffer
875 (setq outbuf 872 (setq outbuf
876 (get-buffer-create 873 (get-buffer-create
877 (compilation-buffer-name name-of-mode name-function))) 874 (compilation-buffer-name name-of-mode name-function)))
888 (delete-process comp-proc)) 885 (delete-process comp-proc))
889 (error nil)) 886 (error nil))
890 (error "Cannot have two processes in `%s' at once" 887 (error "Cannot have two processes in `%s' at once"
891 (buffer-name))))) 888 (buffer-name)))))
892 (buffer-disable-undo (current-buffer)) 889 (buffer-disable-undo (current-buffer))
890 ;; first transfer directory from where M-x compile was called
891 (setq default-directory thisdir)
893 ;; Make compilation buffer read-only. The filter can still write it. 892 ;; Make compilation buffer read-only. The filter can still write it.
894 ;; Clear out the compilation buffer. 893 ;; Clear out the compilation buffer.
895 (let ((inhibit-read-only t)) 894 (let ((inhibit-read-only t)
895 (default-directory thisdir))
896 ;; Then evaluate a cd command if any, but don't perform it yet, else start-command
897 ;; would do it again through the shell: (cd "..") AND sh -c "cd ..; make"
898 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
899 (if (match-end 1)
900 (match-string 1 command)
901 "~")
902 default-directory))
896 (erase-buffer) 903 (erase-buffer)
897 ;; Change its default-directory to the directory where the compilation
898 ;; will happen, and insert a `cd' command to indicate this.
899 (setq default-directory thisdir)
900 ;; output a mode setter, for saving and later reloading this buffer 904 ;; output a mode setter, for saving and later reloading this buffer
901 (insert "-*- mode: " name-of-mode 905 (insert "-*- mode: " name-of-mode
902 "; default-directory: " (prin1-to-string default-directory) 906 "; default-directory: " (prin1-to-string default-directory)
903 " -*-\n" command "\n")) 907 " -*-\n" command "\n")
908 (setq thisdir default-directory))
904 (set-buffer-modified-p nil)) 909 (set-buffer-modified-p nil))
905 ;; If we're already in the compilation buffer, go to the end 910 ;; If we're already in the compilation buffer, go to the end
906 ;; of the buffer, so point will track the compilation output. 911 ;; of the buffer, so point will track the compilation output.
907 (if (eq outbuf (current-buffer)) 912 (if (eq outbuf (current-buffer))
908 (goto-char (point-max))) 913 (goto-char (point-max)))
983 (compilation-handle-exit 'bizarre status status)))) 988 (compilation-handle-exit 'bizarre status status))))
984 ;; Without async subprocesses, the buffer is not yet 989 ;; Without async subprocesses, the buffer is not yet
985 ;; fontified, so fontify it now. 990 ;; fontified, so fontify it now.
986 (let ((font-lock-verbose nil)) ; shut up font-lock messages 991 (let ((font-lock-verbose nil)) ; shut up font-lock messages
987 (font-lock-fontify-buffer)) 992 (font-lock-fontify-buffer))
988 (message "Executing `%s'...done" command)))) 993 (message "Executing `%s'...done" command)))
994 ;; Now finally cd to where the shell started make/grep/...
995 (setq default-directory thisdir))
989 (if (buffer-local-value 'compilation-scroll-output outbuf) 996 (if (buffer-local-value 'compilation-scroll-output outbuf)
990 (save-selected-window 997 (save-selected-window
991 (select-window outwin) 998 (select-window outwin)
992 (goto-char (point-max)))) 999 (goto-char (point-max))))
993 ;; Make it so the next C-x ` will use this buffer. 1000 ;; Make it so the next C-x ` will use this buffer.