Commit | Line | Data |
---|---|---|
8749abea GM |
1 | ;;; rcompile.el --- run a compilation on a remote machine |
2 | ||
e9bffc61 GM |
3 | ;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4 | ;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc. | |
8749abea GM |
5 | |
6 | ;; Author: Albert <alon@milcse.rtsg.mot.com> | |
7 | ;; Maintainer: FSF | |
8 | ;; Created: 1993 Oct 6 | |
9 | ;; Keywords: tools, processes | |
10 | ||
11 | ;; This file is part of GNU Emacs. | |
12 | ||
874a927a | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
8749abea | 14 | ;; it under the terms of the GNU General Public License as published by |
874a927a GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
8749abea GM |
17 | |
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. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
874a927a | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8749abea GM |
25 | |
26 | ;;; Commentary: | |
27 | ||
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). | |
38 | ||
39 | ;; See the user defined variables section for more info. | |
40 | ||
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. | |
44 | ||
45 | ;; Installation: | |
46 | ||
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: | |
49 | ||
50 | ;; monopoly alon | |
51 | ;; vme33 | |
52 | ;; | |
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: | |
55 | ;; | |
56 | ;; + | |
57 | ;; | |
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 | |
a1506d29 | 60 | ;; familiar with it already) |
8749abea GM |
61 | \f |
62 | ;;; Code: | |
63 | ||
64 | (provide 'rcompile) | |
65 | (require 'compile) | |
66 | ;;; The following should not be needed. | |
67 | ;;; (eval-when-compile (require 'ange-ftp)) | |
68 | ||
69 | ;;;; user defined variables | |
70 | ||
71 | (defgroup remote-compile nil | |
5c4ad728 | 72 | "Run a compilation on a remote machine." |
8749abea GM |
73 | :group 'processes |
74 | :group 'tools) | |
75 | ||
76 | ||
77 | (defcustom remote-compile-host nil | |
1fc7dabf | 78 | "Host for remote compilations." |
8749abea GM |
79 | :type '(choice string (const nil)) |
80 | :group 'remote-compile) | |
81 | ||
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) | |
87 | ||
88 | (defcustom remote-compile-run-before nil | |
1fc7dabf | 89 | "Command to run before compilation. |
8749abea GM |
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) | |
96 | ||
97 | (defcustom remote-compile-prompt-for-host nil | |
1fc7dabf | 98 | "Non-nil means prompt for host if not available from filename." |
8749abea GM |
99 | :type 'boolean |
100 | :group 'remote-compile) | |
101 | ||
102 | (defcustom remote-compile-prompt-for-user nil | |
1fc7dabf | 103 | "Non-nil means prompt for user if not available from filename." |
8749abea GM |
104 | :type 'boolean |
105 | :group 'remote-compile) | |
106 | ||
107 | ;;;; internal variables | |
108 | ||
109 | ;; History of remote compile hosts and users | |
110 | (defvar remote-compile-host-history nil) | |
111 | (defvar remote-compile-user-history nil) | |
112 | ||
113 | \f | |
114 | ;;;; entry point | |
115 | ||
ae2af0e3 SM |
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. | |
8749abea GM |
121 | ;;;###autoload |
122 | (defun remote-compile (host user command) | |
110c171f | 123 | "Compile the current buffer's directory on HOST. Log in as USER. |
8749abea GM |
124 | See \\[compile]." |
125 | (interactive | |
ae2af0e3 SM |
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): " | |
129 | remote-compile-host) | |
130 | "Compile on host: ") | |
131 | host (if (or remote-compile-prompt-for-host | |
132 | (null remote-compile-host)) | |
133 | (read-from-minibuffer prompt | |
134 | "" nil nil | |
135 | 'remote-compile-host-history) | |
136 | remote-compile-host) | |
137 | user (if remote-compile-prompt-for-user | |
138 | (read-from-minibuffer (format | |
139 | "Compile by user (default %s): " | |
140 | (or remote-compile-user | |
141 | (user-login-name))) | |
142 | "" nil nil | |
143 | 'remote-compile-user-history) | |
144 | remote-compile-user)) | |
8749abea GM |
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) | |
150 | command))) | |
151 | (setq compile-command command) | |
152 | (cond (user | |
153 | (setq remote-compile-user user)) | |
154 | ((null remote-compile-user) | |
155 | (setq remote-compile-user (user-login-name)))) | |
08b1eb21 | 156 | (let* (localname ;; Pacify byte-compiler. |
8749abea GM |
157 | (compile-command |
158 | (format "%s %s -l %s \"(%scd %s; %s)\"" | |
159 | remote-shell-program | |
160 | host | |
161 | remote-compile-user | |
162 | (if remote-compile-run-before | |
163 | (concat remote-compile-run-before "; ") | |
164 | "") | |
ae2af0e3 | 165 | "" |
8749abea GM |
166 | compile-command))) |
167 | (setq remote-compile-host host) | |
168 | (save-some-buffers nil nil) | |
a3d41848 | 169 | (compilation-start compile-command) |
8749abea | 170 | ;; Set comint-file-name-prefix in the compilation buffer so |
08b1eb21 | 171 | ;; compilation-parse-errors will find referenced files by Tramp. |
3432260a | 172 | (with-current-buffer compilation-last-buffer |
ae2af0e3 | 173 | (when (fboundp 'tramp-make-tramp-file-name) |
08b1eb21 | 174 | (set (make-local-variable 'comint-file-name-prefix) |
ae2af0e3 | 175 | (tramp-make-tramp-file-name |
00d6fd04 | 176 | nil ;; method. |
08b1eb21 MA |
177 | remote-compile-user |
178 | remote-compile-host | |
179 | "")))))) | |
8749abea GM |
180 | |
181 | ;;; rcompile.el ends here |