1 ;;; rcompile.el --- run a compilation on a remote machine
3 ;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Albert <alon@milcse.rtsg.mot.com>
9 ;; Keywords: tools, processes
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; This package is for running a remote compilation and using emacs to parse
31 ;; the error messages. It works by rsh'ing the compilation to a remote host
32 ;; and parsing the output. If the file visited at the time remote-compile was
33 ;; called was loaded remotely (ange-ftp), the host and user name are obtained
34 ;; by the calling ange-ftp-ftp-name on the current directory. In this case the
35 ;; next-error command will also ange-ftp the files over. This is achieved
36 ;; automatically because the compilation-parse-errors function uses
37 ;; default-directory to build its file names. If however the file visited was
38 ;; loaded locally, remote-compile prompts for a host and user and assumes the
39 ;; files mounted locally (otherwise, how was the visited file loaded).
41 ;; See the user defined variables section for more info.
43 ;; I was contemplating redefining "compile" to "remote-compile" automatically
44 ;; if the file visited was ange-ftp'ed but decided against it for now. If you
45 ;; feel this is a good idea, let me know and I'll consider it again.
49 ;; To use rcompile, you also need to give yourself permission to connect to
50 ;; the remote host. You do this by putting lines like:
55 ;; in a file named .rhosts in the home directory (of the remote machine).
56 ;; Be careful what you put in this file. A line like:
60 ;; Will allow anyone access to your account without a password. I suggest you
61 ;; read the rhosts(5) manual page before you edit this file (if you are not
62 ;; familiar with it already)
68 ;;; The following should not be needed.
69 ;;; (eval-when-compile (require 'ange-ftp))
71 ;;;; user defined variables
73 (defgroup remote-compile nil
74 "Run a compilation on a remote machine."
79 (defcustom remote-compile-host nil
80 "*Host for remote compilations."
81 :type
'(choice string
(const nil
))
82 :group
'remote-compile
)
84 (defcustom remote-compile-user nil
85 "User for remote compilations.
86 nil means use the value returned by \\[user-login-name]."
87 :type
'(choice string
(const nil
))
88 :group
'remote-compile
)
90 (defcustom remote-compile-run-before nil
91 "*Command to run before compilation.
92 This can be used for setting up environment variables,
93 since rsh does not invoke the shell as a login shell and files like .login
94 \(tcsh\) and .bash_profile \(bash\) are not run.
95 nil means run no commands."
96 :type
'(choice string
(const nil
))
97 :group
'remote-compile
)
99 (defcustom remote-compile-prompt-for-host nil
100 "*Non-nil means prompt for host if not available from filename."
102 :group
'remote-compile
)
104 (defcustom remote-compile-prompt-for-user nil
105 "*Non-nil means prompt for user if not available from filename."
107 :group
'remote-compile
)
109 ;;;; internal variables
111 ;; History of remote compile hosts and users
112 (defvar remote-compile-host-history nil
)
113 (defvar remote-compile-user-history nil
)
118 ;; We use the Tramp internal functions `with-parsed-tramp-file-name'
119 ;; and `tramp-make-tramp-file-name'. Better would be, if there are
120 ;; functions to provide user, host and localname of a remote filename,
121 ;; independent of Tramp's implementation. The function calls are
122 ;; wrapped by `funcall' in order to pacify the byte compiler.
123 ;; ange-ftp check removed, because it is handled also by Tramp.
125 (defun remote-compile (host user command
)
126 "Compile the current buffer's directory on HOST. Log in as USER.
129 (let ((parsed (and (featurep 'tramp
)
130 (file-remote-p default-directory
)))
131 host user command prompt l l-host l-user
)
133 (funcall (symbol-function 'with-parsed-tramp-file-name
)
137 (setq prompt
(if (stringp remote-compile-host
)
138 (format "Compile on host (default %s): "
141 host
(if (or remote-compile-prompt-for-host
142 (null remote-compile-host
))
143 (read-from-minibuffer prompt
145 'remote-compile-host-history
)
147 user
(if remote-compile-prompt-for-user
148 (read-from-minibuffer (format
149 "Compile by user (default %s): "
150 (or remote-compile-user
153 'remote-compile-user-history
)
154 remote-compile-user
)))
155 (setq command
(read-from-minibuffer "Compile command: "
156 compile-command nil nil
157 '(compile-history .
1)))
158 (list (if (string= host
"") remote-compile-host host
)
159 (if (string= user
"") remote-compile-user user
)
161 (setq compile-command command
)
163 (setq remote-compile-user user
))
164 ((null remote-compile-user
)
165 (setq remote-compile-user
(user-login-name))))
166 (let* (localname ;; Pacify byte-compiler.
167 (parsed (and (featurep 'tramp
)
168 (file-remote-p default-directory
)))
170 (format "%s %s -l %s \"(%scd %s; %s)\""
174 (if remote-compile-run-before
175 (concat remote-compile-run-before
"; ")
178 (funcall (symbol-function 'with-parsed-tramp-file-name
)
179 default-directory nil localname
)
182 (setq remote-compile-host host
)
183 (save-some-buffers nil nil
)
184 (compilation-start compile-command
)
185 ;; Set comint-file-name-prefix in the compilation buffer so
186 ;; compilation-parse-errors will find referenced files by Tramp.
187 (with-current-buffer compilation-last-buffer
188 (when (featurep 'tramp
)
189 (set (make-local-variable 'comint-file-name-prefix
)
190 (funcall (symbol-function 'tramp-make-tramp-file-name
)
191 nil
;; multi-method. To be removed with Tramp 2.1.
197 ;;; arch-tag: 2866a132-ece4-4ce9-9f91-ec147f803f73
198 ;;; rcompile.el ends here