1 ;;; rcompile.el --- run a compilation on a remote machine
3 ;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 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 3 of the License, or
16 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
28 ;; This package is for running a remote compilation and using emacs to parse
29 ;; the error messages. It works by rsh'ing the compilation to a remote host
30 ;; and parsing the output. If the file visited at the time remote-compile was
31 ;; called was loaded remotely (ange-ftp), the host and user name are obtained
32 ;; by the calling ange-ftp-ftp-name on the current directory. In this case the
33 ;; next-error command will also ange-ftp the files over. This is achieved
34 ;; automatically because the compilation-parse-errors function uses
35 ;; default-directory to build its file names. If however the file visited was
36 ;; loaded locally, remote-compile prompts for a host and user and assumes the
37 ;; files mounted locally (otherwise, how was the visited file loaded).
39 ;; See the user defined variables section for more info.
41 ;; I was contemplating redefining "compile" to "remote-compile" automatically
42 ;; if the file visited was ange-ftp'ed but decided against it for now. If you
43 ;; feel this is a good idea, let me know and I'll consider it again.
47 ;; To use rcompile, you also need to give yourself permission to connect to
48 ;; the remote host. You do this by putting lines like:
53 ;; in a file named .rhosts in the home directory (of the remote machine).
54 ;; Be careful what you put in this file. A line like:
58 ;; Will allow anyone access to your account without a password. I suggest you
59 ;; read the rhosts(5) manual page before you edit this file (if you are not
60 ;; familiar with it already)
66 ;;; The following should not be needed.
67 ;;; (eval-when-compile (require 'ange-ftp))
69 ;;;; user defined variables
71 (defgroup remote-compile nil
72 "Run a compilation on a remote machine."
77 (defcustom remote-compile-host nil
78 "*Host for remote compilations."
79 :type
'(choice string
(const nil
))
80 :group
'remote-compile
)
82 (defcustom remote-compile-user nil
83 "User for remote compilations.
84 nil means use the value returned by \\[user-login-name]."
85 :type
'(choice string
(const nil
))
86 :group
'remote-compile
)
88 (defcustom remote-compile-run-before nil
89 "*Command to run before compilation.
90 This can be used for setting up environment variables,
91 since rsh does not invoke the shell as a login shell and files like .login
92 \(tcsh\) and .bash_profile \(bash\) are not run.
93 nil means run no commands."
94 :type
'(choice string
(const nil
))
95 :group
'remote-compile
)
97 (defcustom remote-compile-prompt-for-host nil
98 "*Non-nil means prompt for host if not available from filename."
100 :group
'remote-compile
)
102 (defcustom remote-compile-prompt-for-user nil
103 "*Non-nil means prompt for user if not available from filename."
105 :group
'remote-compile
)
107 ;;;; internal variables
109 ;; History of remote compile hosts and users
110 (defvar remote-compile-host-history nil
)
111 (defvar remote-compile-user-history nil
)
116 ;; We use the Tramp internal function`tramp-make-tramp-file-name'.
117 ;; Better would be, if there are functions to provide user, host and
118 ;; localname of a remote filename, independent of Tramp's implementation.
119 ;; The function calls are wrapped by `funcall' in order to pacify the byte
120 ;; compiler. ange-ftp check removed, because it is handled also by Tramp.
122 (defun remote-compile (host user command
)
123 "Compile the current buffer's directory on HOST. Log in as USER.
126 (let (host user command prompt l l-host l-user
)
127 (setq prompt
(if (stringp remote-compile-host
)
128 (format "Compile on host (default %s): "
131 host
(if (or remote-compile-prompt-for-host
132 (null remote-compile-host
))
133 (read-from-minibuffer prompt
135 'remote-compile-host-history
)
137 user
(if remote-compile-prompt-for-user
138 (read-from-minibuffer (format
139 "Compile by user (default %s): "
140 (or remote-compile-user
143 'remote-compile-user-history
)
144 remote-compile-user
))
145 (setq command
(read-from-minibuffer "Compile command: "
146 compile-command nil nil
147 '(compile-history .
1)))
148 (list (if (string= host
"") remote-compile-host host
)
149 (if (string= user
"") remote-compile-user user
)
151 (setq compile-command command
)
153 (setq remote-compile-user user
))
154 ((null remote-compile-user
)
155 (setq remote-compile-user
(user-login-name))))
156 (let* (localname ;; Pacify byte-compiler.
158 (format "%s %s -l %s \"(%scd %s; %s)\""
162 (if remote-compile-run-before
163 (concat remote-compile-run-before
"; ")
167 (setq remote-compile-host host
)
168 (save-some-buffers nil nil
)
169 (compilation-start compile-command
)
170 ;; Set comint-file-name-prefix in the compilation buffer so
171 ;; compilation-parse-errors will find referenced files by Tramp.
172 (with-current-buffer compilation-last-buffer
173 (when (fboundp 'tramp-make-tramp-file-name
)
174 (set (make-local-variable 'comint-file-name-prefix
)
175 (tramp-make-tramp-file-name
181 ;; arch-tag: 2866a132-ece4-4ce9-9f91-ec147f803f73
182 ;;; rcompile.el ends here