1 ;;; rcompile.el --- run a compilation on a remote machine
3 ;; Copyright (C) 1993-1994, 2001-2013 Free Software Foundation, Inc.
5 ;; Author: Alon Albert <alon@milcse.rtsg.mot.com>
8 ;; Keywords: tools, processes
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This package is for running a remote compilation and using emacs to parse
28 ;; the error messages. It works by rsh'ing the compilation to a remote host
29 ;; and parsing the output. If the file visited at the time remote-compile was
30 ;; called was loaded remotely (ange-ftp), the host and user name are obtained
31 ;; by the calling ange-ftp-ftp-name on the current directory. In this case the
32 ;; next-error command will also ange-ftp the files over. This is achieved
33 ;; automatically because the compilation-parse-errors function uses
34 ;; default-directory to build its file names. If however the file visited was
35 ;; loaded locally, remote-compile prompts for a host and user and assumes the
36 ;; files mounted locally (otherwise, how was the visited file loaded).
38 ;; See the user defined variables section for more info.
40 ;; I was contemplating redefining "compile" to "remote-compile" automatically
41 ;; if the file visited was ange-ftp'ed but decided against it for now. If you
42 ;; feel this is a good idea, let me know and I'll consider it again.
46 ;; To use rcompile, you also need to give yourself permission to connect to
47 ;; the remote host. You do this by putting lines like:
52 ;; in a file named .rhosts in the home directory (of the remote machine).
53 ;; Be careful what you put in this file. A line like:
57 ;; Will allow anyone access to your account without a password. I suggest you
58 ;; read the rhosts(5) manual page before you edit this file (if you are not
59 ;; familiar with it already)
65 ;;; The following should not be needed.
66 ;;; (eval-when-compile (require 'ange-ftp))
68 ;;;; user defined variables
70 (defgroup remote-compile nil
71 "Run a compilation on a remote machine."
76 (defcustom remote-compile-host nil
77 "Host for remote compilations."
78 :type
'(choice string
(const nil
))
79 :group
'remote-compile
)
81 (defcustom remote-compile-user nil
82 "User for remote compilations.
83 nil means use the value returned by \\[user-login-name]."
84 :type
'(choice string
(const nil
))
85 :group
'remote-compile
)
87 (defcustom remote-compile-run-before nil
88 "Command to run before compilation.
89 This can be used for setting up environment variables,
90 since rsh does not invoke the shell as a login shell and files like .login
91 \(tcsh\) and .bash_profile \(bash\) are not run.
92 nil means run no commands."
93 :type
'(choice string
(const nil
))
94 :group
'remote-compile
)
96 (defcustom remote-compile-prompt-for-host nil
97 "Non-nil means prompt for host if not available from filename."
99 :group
'remote-compile
)
101 (defcustom remote-compile-prompt-for-user nil
102 "Non-nil means prompt for user if not available from filename."
104 :group
'remote-compile
)
106 ;;;; internal variables
108 ;; History of remote compile hosts and users
109 (defvar remote-compile-host-history nil
)
110 (defvar remote-compile-user-history nil
)
115 ;; We use the Tramp internal function`tramp-make-tramp-file-name'.
116 ;; Better would be, if there are functions to provide user, host and
117 ;; localname of a remote filename, independent of Tramp's implementation.
118 ;; The function calls are wrapped by `funcall' in order to pacify the byte
119 ;; compiler. ange-ftp check removed, because it is handled also by Tramp.
121 (defun remote-compile (host user command
)
122 "Compile the current buffer's directory on HOST. Log in as USER.
125 (let (host user command prompt l l-host l-user
)
126 (setq prompt
(if (stringp remote-compile-host
)
127 (format "Compile on host (default %s): "
130 host
(if (or remote-compile-prompt-for-host
131 (null remote-compile-host
))
132 (read-from-minibuffer prompt
134 'remote-compile-host-history
)
136 user
(if remote-compile-prompt-for-user
137 (read-from-minibuffer (format
138 "Compile by user (default %s): "
139 (or remote-compile-user
142 'remote-compile-user-history
)
143 remote-compile-user
))
144 (setq command
(read-from-minibuffer "Compile command: "
145 compile-command nil nil
146 '(compile-history .
1)))
147 (list (if (string= host
"") remote-compile-host host
)
148 (if (string= user
"") remote-compile-user user
)
150 (setq compile-command command
)
152 (setq remote-compile-user user
))
153 ((null remote-compile-user
)
154 (setq remote-compile-user
(user-login-name))))
155 (let* (localname ;; Pacify byte-compiler.
157 (format "%s %s -l %s \"(%scd %s; %s)\""
161 (if remote-compile-run-before
162 (concat remote-compile-run-before
"; ")
166 (setq remote-compile-host host
)
167 (save-some-buffers nil nil
)
168 (compilation-start compile-command
)
169 ;; Set comint-file-name-prefix in the compilation buffer so
170 ;; compilation-parse-errors will find referenced files by Tramp.
171 (with-current-buffer compilation-last-buffer
172 (when (fboundp 'tramp-make-tramp-file-name
)
173 (set (make-local-variable 'comint-file-name-prefix
)
174 (tramp-make-tramp-file-name
180 ;;; rcompile.el ends here