comparison lisp/progmodes/compile.el @ 57067:e9dd601d101f

Parse command to see if it starts with a cd, and if so perform it for the *compilation* buffer. Change the header to reflect this.
author Daniel Pfeiffer <occitan@esperanto.org>
date Sun, 12 Sep 2004 18:08:12 +0000
parents 600db57321a8
children 7a899182458c 566253900690
comparison
equal deleted inserted replaced
57066:bb03bc287e9c 57067:e9dd601d101f
847 (compilation-start command nil name-function highlight-regexp))) 847 (compilation-start command nil name-function highlight-regexp)))
848 (make-obsolete 'compile-internal 'compilation-start) 848 (make-obsolete 'compile-internal 'compilation-start)
849 849
850 (defun compilation-start (command &optional mode name-function highlight-regexp) 850 (defun compilation-start (command &optional mode name-function highlight-regexp)
851 "Run compilation command COMMAND (low level interface). 851 "Run compilation command COMMAND (low level interface).
852 If COMMAND starts with a cd command, that becomes the `default-directory'.
852 The rest of the arguments are optional; for them, nil means use the default. 853 The rest of the arguments are optional; for them, nil means use the default.
853 854
854 MODE is the major mode to set in the compilation buffer. Mode 855 MODE is the major mode to set in the compilation buffer. Mode
855 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'. 856 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
856 NAME-FUNCTION is a function called to name the buffer. 857 NAME-FUNCTION is a function called to name the buffer.
859 the matching section of the visited source line; the default is to use the 860 the matching section of the visited source line; the default is to use the
860 global value of `compilation-highlight-regexp'. 861 global value of `compilation-highlight-regexp'.
861 862
862 Returns the compilation buffer created." 863 Returns the compilation buffer created."
863 (or mode (setq mode 'compilation-mode)) 864 (or mode (setq mode 'compilation-mode))
864 (let ((name-of-mode 865 (let* ((name-of-mode
865 (if (eq mode t) 866 (if (eq mode t)
866 (prog1 "compilation" (require 'comint)) 867 (prog1 "compilation" (require 'comint))
867 (replace-regexp-in-string "-mode$" "" (symbol-name mode)))) 868 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
868 (process-environment 869 (process-environment
869 (append 870 (append
870 compilation-environment 871 compilation-environment
871 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning 872 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
872 system-uses-terminfo) 873 system-uses-terminfo)
873 (list "TERM=dumb" "TERMCAP=" 874 (list "TERM=dumb" "TERMCAP="
874 (format "COLUMNS=%d" (window-width))) 875 (format "COLUMNS=%d" (window-width)))
875 (list "TERM=emacs" 876 (list "TERM=emacs"
876 (format "TERMCAP=emacs:co#%d:tc=unknown:" 877 (format "TERMCAP=emacs:co#%d:tc=unknown:"
877 (window-width)))) 878 (window-width))))
878 ;; Set the EMACS variable, but 879 ;; Set the EMACS variable, but
879 ;; don't override users' setting of $EMACS. 880 ;; don't override users' setting of $EMACS.
880 (unless (getenv "EMACS") '("EMACS=t")) 881 (unless (getenv "EMACS") '("EMACS=t"))
881 (copy-sequence process-environment))) 882 (copy-sequence process-environment)))
882 (thisdir default-directory) 883 cd-path ; in case process-environment contains CDPATH
883 outwin outbuf) 884 (thisdir (if (string-match "^\\s *cd\\s +\\(.+?\\)\\s *[;&\n]" command)
885 (substitute-in-file-name (match-string 1 command))
886 default-directory))
887 outwin outbuf)
884 (with-current-buffer 888 (with-current-buffer
885 (setq outbuf 889 (setq outbuf
886 (get-buffer-create 890 (get-buffer-create
887 (compilation-buffer-name name-of-mode name-function))) 891 (compilation-buffer-name name-of-mode name-function)))
888 (let ((comp-proc (get-buffer-process (current-buffer)))) 892 (let ((comp-proc (get-buffer-process (current-buffer))))
899 (error nil)) 903 (error nil))
900 (error "Cannot have two processes in `%s' at once" 904 (error "Cannot have two processes in `%s' at once"
901 (buffer-name))))) 905 (buffer-name)))))
902 ;; Clear out the compilation buffer and make it writable. 906 ;; Clear out the compilation buffer and make it writable.
903 ;; Change its default-directory to the directory where the compilation 907 ;; Change its default-directory to the directory where the compilation
904 ;; will happen, and insert a `cd' command to indicate this. 908 ;; will happen, and insert a `default-directory' to indicate this.
905 (setq buffer-read-only nil) 909 (setq buffer-read-only nil)
906 (buffer-disable-undo (current-buffer)) 910 (buffer-disable-undo (current-buffer))
907 (erase-buffer) 911 (erase-buffer)
908 (buffer-enable-undo (current-buffer)) 912 (buffer-enable-undo (current-buffer))
909 (setq default-directory thisdir) 913 (cd thisdir)
910 ;; output a mode setter, for saving and later reloading this buffer 914 ;; output a mode setter, for saving and later reloading this buffer
911 (insert "cd " thisdir " # -*-" name-of-mode 915 (insert "-*- mode: " name-of-mode
912 "-*-\nEntering directory `" thisdir "'\n" command "\n") 916 "; default-directory: " (prin1-to-string default-directory)
917 " -*-\n" command "\n")
913 (set-buffer-modified-p nil)) 918 (set-buffer-modified-p nil))
914 ;; If we're already in the compilation buffer, go to the end 919 ;; If we're already in the compilation buffer, go to the end
915 ;; of the buffer, so point will track the compilation output. 920 ;; of the buffer, so point will track the compilation output.
916 (if (eq outbuf (current-buffer)) 921 (if (eq outbuf (current-buffer))
917 (goto-char (point-max))) 922 (goto-char (point-max)))