Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / net / rcompile.el
CommitLineData
8749abea
GM
1;;; rcompile.el --- run a compilation on a remote machine
2
73b0cd50 3;; Copyright (C) 1993-1994, 2001-2011 Free Software Foundation, Inc.
8749abea
GM
4
5;; Author: 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
874a927a 12;; GNU Emacs is free software: you can redistribute it and/or modify
8749abea 13;; it under the terms of the GNU General Public License as published by
874a927a
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
8749abea
GM
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
874a927a 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
8749abea
GM
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
a1506d29 59;; familiar with it already)
8749abea
GM
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
5c4ad728 71 "Run a compilation on a remote machine."
8749abea
GM
72 :group 'processes
73 :group 'tools)
74
75
76(defcustom remote-compile-host nil
1fc7dabf 77 "Host for remote compilations."
8749abea
GM
78 :type '(choice string (const nil))
79 :group 'remote-compile)
80
81(defcustom remote-compile-user nil
82 "User for remote compilations.
83nil 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
1fc7dabf 88 "Command to run before compilation.
8749abea
GM
89This can be used for setting up environment variables,
90since rsh does not invoke the shell as a login shell and files like .login
91\(tcsh\) and .bash_profile \(bash\) are not run.
92nil means run no commands."
93 :type '(choice string (const nil))
94 :group 'remote-compile)
95
96(defcustom remote-compile-prompt-for-host nil
1fc7dabf 97 "Non-nil means prompt for host if not available from filename."
8749abea
GM
98 :type 'boolean
99 :group 'remote-compile)
100
101(defcustom remote-compile-prompt-for-user nil
1fc7dabf 102 "Non-nil means prompt for user if not available from filename."
8749abea
GM
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
ae2af0e3
SM
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.
8749abea
GM
120;;;###autoload
121(defun remote-compile (host user command)
110c171f 122 "Compile the current buffer's directory on HOST. Log in as USER.
8749abea
GM
123See \\[compile]."
124 (interactive
ae2af0e3
SM
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))
8749abea
GM
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))))
08b1eb21 155 (let* (localname ;; Pacify byte-compiler.
8749abea
GM
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 "")
ae2af0e3 164 ""
8749abea
GM
165 compile-command)))
166 (setq remote-compile-host host)
167 (save-some-buffers nil nil)
a3d41848 168 (compilation-start compile-command)
8749abea 169 ;; Set comint-file-name-prefix in the compilation buffer so
08b1eb21 170 ;; compilation-parse-errors will find referenced files by Tramp.
3432260a 171 (with-current-buffer compilation-last-buffer
ae2af0e3 172 (when (fboundp 'tramp-make-tramp-file-name)
08b1eb21 173 (set (make-local-variable 'comint-file-name-prefix)
ae2af0e3 174 (tramp-make-tramp-file-name
00d6fd04 175 nil ;; method.
08b1eb21
MA
176 remote-compile-user
177 remote-compile-host
178 ""))))))
8749abea
GM
179
180;;; rcompile.el ends here