849 |
|
|
850 |
(defun compilation-start (command &optional mode name-function highlight-regexp) |
(defun compilation-start (command &optional mode name-function highlight-regexp) |
851 |
"Run compilation command COMMAND (low level interface). |
"Run compilation command COMMAND (low level interface). |
852 |
|
If COMMAND starts with a cd command, that becomes the `default-directory'. |
853 |
The rest of the arguments are optional; for them, nil means use the default. |
The rest of the arguments are optional; for them, nil means use the default. |
854 |
|
|
855 |
MODE is the major mode to set in the compilation buffer. Mode |
MODE is the major mode to set in the compilation buffer. Mode |
862 |
|
|
863 |
Returns the compilation buffer created." |
Returns the compilation buffer created." |
864 |
(or mode (setq mode 'compilation-mode)) |
(or mode (setq mode 'compilation-mode)) |
865 |
(let ((name-of-mode |
(let* ((name-of-mode |
866 |
(if (eq mode t) |
(if (eq mode t) |
867 |
(prog1 "compilation" (require 'comint)) |
(prog1 "compilation" (require 'comint)) |
868 |
(replace-regexp-in-string "-mode$" "" (symbol-name mode)))) |
(replace-regexp-in-string "-mode$" "" (symbol-name mode)))) |
869 |
(process-environment |
(process-environment |
870 |
(append |
(append |
871 |
compilation-environment |
compilation-environment |
872 |
(if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning |
(if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning |
873 |
system-uses-terminfo) |
system-uses-terminfo) |
874 |
(list "TERM=dumb" "TERMCAP=" |
(list "TERM=dumb" "TERMCAP=" |
875 |
(format "COLUMNS=%d" (window-width))) |
(format "COLUMNS=%d" (window-width))) |
876 |
(list "TERM=emacs" |
(list "TERM=emacs" |
877 |
(format "TERMCAP=emacs:co#%d:tc=unknown:" |
(format "TERMCAP=emacs:co#%d:tc=unknown:" |
878 |
(window-width)))) |
(window-width)))) |
879 |
;; Set the EMACS variable, but |
;; Set the EMACS variable, but |
880 |
;; don't override users' setting of $EMACS. |
;; don't override users' setting of $EMACS. |
881 |
(unless (getenv "EMACS") '("EMACS=t")) |
(unless (getenv "EMACS") '("EMACS=t")) |
882 |
(copy-sequence process-environment))) |
(copy-sequence process-environment))) |
883 |
(thisdir default-directory) |
cd-path ; in case process-environment contains CDPATH |
884 |
outwin outbuf) |
(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) |
888 |
(with-current-buffer |
(with-current-buffer |
889 |
(setq outbuf |
(setq outbuf |
890 |
(get-buffer-create |
(get-buffer-create |
905 |
(buffer-name))))) |
(buffer-name))))) |
906 |
;; Clear out the compilation buffer and make it writable. |
;; Clear out the compilation buffer and make it writable. |
907 |
;; Change its default-directory to the directory where the compilation |
;; Change its default-directory to the directory where the compilation |
908 |
;; will happen, and insert a `cd' command to indicate this. |
;; will happen, and insert a `default-directory' to indicate this. |
909 |
(setq buffer-read-only nil) |
(setq buffer-read-only nil) |
910 |
(buffer-disable-undo (current-buffer)) |
(buffer-disable-undo (current-buffer)) |
911 |
(erase-buffer) |
(erase-buffer) |
912 |
(buffer-enable-undo (current-buffer)) |
(buffer-enable-undo (current-buffer)) |
913 |
(setq default-directory thisdir) |
(cd thisdir) |
914 |
;; output a mode setter, for saving and later reloading this buffer |
;; output a mode setter, for saving and later reloading this buffer |
915 |
(insert "cd " thisdir " # -*-" name-of-mode |
(insert "-*- mode: " name-of-mode |
916 |
"-*-\nEntering directory `" thisdir "'\n" command "\n") |
"; default-directory: " (prin1-to-string default-directory) |
917 |
|
" -*-\n" command "\n") |
918 |
(set-buffer-modified-p nil)) |
(set-buffer-modified-p nil)) |
919 |
;; If we're already in the compilation buffer, go to the end |
;; If we're already in the compilation buffer, go to the end |
920 |
;; of the buffer, so point will track the compilation output. |
;; of the buffer, so point will track the compilation output. |