(provide 'rcompile)
(require 'compile)
(defgroup remote-compile nil
"Run a compilation on a remote machine"
:group 'processes
:group 'tools)
(defcustom remote-compile-host nil
"*Host for remote compilations."
:type '(choice string (const nil))
:group 'remote-compile)
(defcustom remote-compile-user nil
"User for remote compilations.
nil means use the value returned by \\[user-login-name]."
:type '(choice string (const nil))
:group 'remote-compile)
(defcustom remote-compile-run-before nil
"*Command to run before compilation.
This can be used for setting up environment variables,
since rsh does not invoke the shell as a login shell and files like .login
\(tcsh\) and .bash_profile \(bash\) are not run.
nil means run no commands."
:type '(choice string (const nil))
:group 'remote-compile)
(defcustom remote-compile-prompt-for-host nil
"*Non-nil means prompt for host if not available from filename."
:type 'boolean
:group 'remote-compile)
(defcustom remote-compile-prompt-for-user nil
"*Non-nil means prompt for user if not available from filename."
:type 'boolean
:group 'remote-compile)
(defvar remote-compile-host-history nil)
(defvar remote-compile-user-history nil)
(defun remote-compile (host user command)
"Compile the the current buffer's directory on HOST. Log in as USER.
See \\[compile]."
(interactive
(let ((parsed (or (and (featurep 'ange-ftp)
(ange-ftp-ftp-name default-directory))))
host user command prompt)
(if parsed
(setq host (nth 0 parsed)
user (nth 1 parsed))
(setq prompt (if (stringp remote-compile-host)
(format "Compile on host (default %s): "
remote-compile-host)
"Compile on host: ")
host (if (or remote-compile-prompt-for-host
(null remote-compile-host))
(read-from-minibuffer prompt
"" nil nil
'remote-compile-host-history)
remote-compile-host)
user (if remote-compile-prompt-for-user
(read-from-minibuffer (format
"Compile by user (default %s)"
(or remote-compile-user
(user-login-name)))
"" nil nil
'remote-compile-user-history)
remote-compile-user)))
(setq command (read-from-minibuffer "Compile command: "
compile-command nil nil
'(compile-history . 1)))
(list (if (string= host "") remote-compile-host host)
(if (string= user "") remote-compile-user user)
command)))
(setq compile-command command)
(cond (user
(setq remote-compile-user user))
((null remote-compile-user)
(setq remote-compile-user (user-login-name))))
(let* ((parsed (and (featurep 'ange-ftp)
(ange-ftp-ftp-name default-directory)))
(compile-command
(format "%s %s -l %s \"(%scd %s; %s)\""
remote-shell-program
host
remote-compile-user
(if remote-compile-run-before
(concat remote-compile-run-before "; ")
"")
(if parsed (nth 2 parsed) default-directory)
compile-command)))
(setq remote-compile-host host)
(save-some-buffers nil nil)
(compile-internal compile-command "No more errors")
(save-excursion
(set-buffer compilation-last-buffer)
(make-variable-buffer-local 'comint-file-name-prefix)
(setq comint-file-name-prefix (concat "/" host ":")))))