09677a654c0dbdbe3640585f0f186e9a2d7d0067
[bpt/emacs.git] / lisp / net / rcompile.el
1 ;;; rcompile.el --- run a compilation on a remote machine
2
3 ;; Copyright (C) 1993-1994, 2001-2012 Free Software Foundation, Inc.
4
5 ;; Author: Alon Albert <alon@milcse.rtsg.mot.com>
6 ;; Maintainer: FSF
7 ;; Created: 1993 Oct 6
8 ;; Keywords: tools, processes
9
10 ;; This file is part of GNU Emacs.
11
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.
16
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.
21
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/>.
24
25 ;;; Commentary:
26
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).
37
38 ;; See the user defined variables section for more info.
39
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.
43
44 ;; Installation:
45
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:
48
49 ;; monopoly alon
50 ;; vme33
51 ;;
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:
54 ;;
55 ;; +
56 ;;
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)
60 \f
61 ;;; Code:
62
63 (provide 'rcompile)
64 (require 'compile)
65 ;;; The following should not be needed.
66 ;;; (eval-when-compile (require 'ange-ftp))
67
68 ;;;; user defined variables
69
70 (defgroup remote-compile nil
71 "Run a compilation on a remote machine."
72 :group 'processes
73 :group 'tools)
74
75
76 (defcustom remote-compile-host nil
77 "Host for remote compilations."
78 :type '(choice string (const nil))
79 :group 'remote-compile)
80
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)
86
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)
95
96 (defcustom remote-compile-prompt-for-host nil
97 "Non-nil means prompt for host if not available from filename."
98 :type 'boolean
99 :group 'remote-compile)
100
101 (defcustom remote-compile-prompt-for-user nil
102 "Non-nil means prompt for user if not available from filename."
103 :type 'boolean
104 :group 'remote-compile)
105
106 ;;;; internal variables
107
108 ;; History of remote compile hosts and users
109 (defvar remote-compile-host-history nil)
110 (defvar remote-compile-user-history nil)
111
112 \f
113 ;;;; entry point
114
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.
120 ;;;###autoload
121 (defun remote-compile (host user command)
122 "Compile the current buffer's directory on HOST. Log in as USER.
123 See \\[compile]."
124 (interactive
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): "
128 remote-compile-host)
129 "Compile on host: ")
130 host (if (or remote-compile-prompt-for-host
131 (null remote-compile-host))
132 (read-from-minibuffer prompt
133 "" nil nil
134 'remote-compile-host-history)
135 remote-compile-host)
136 user (if remote-compile-prompt-for-user
137 (read-from-minibuffer (format
138 "Compile by user (default %s): "
139 (or remote-compile-user
140 (user-login-name)))
141 "" nil nil
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)
149 command)))
150 (setq compile-command command)
151 (cond (user
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.
156 (compile-command
157 (format "%s %s -l %s \"(%scd %s; %s)\""
158 remote-shell-program
159 host
160 remote-compile-user
161 (if remote-compile-run-before
162 (concat remote-compile-run-before "; ")
163 "")
164 ""
165 compile-command)))
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
175 nil ;; method.
176 remote-compile-user
177 remote-compile-host
178 ""))))))
179
180 ;;; rcompile.el ends here