Initial Commit
[packages] / xemacs-packages / net-utils / rcompile.el
1 ;;; rcompile.el --- run a compilation on a remote machine
2
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4
5 ;; Author: Albert    <alon@milcse.rtsg.mot.com>
6 ;; Maintainer: FSF
7 ;; Created: 1993 Oct 6
8 ;; Version: 1.1
9 ;; Keywords: tools, processes
10
11 ;; This file is part of XEmacs.
12
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ;; 02111-1307, USA.
27
28 ;;; Synched up with: FSF 19.34.
29
30 ;;; Commentary:
31
32 ;; This package is for running a remote compilation and using emacs to parse
33 ;; the error messages. It works by rsh'ing the compilation to a remote host
34 ;; and parsing the output. If the file visited at the time remote-compile was
35 ;; called was loaded remotely (ange-ftp), the host and user name are obtained
36 ;; by the calling ange-ftp-ftp-name on the current directory. In this case the
37 ;; next-error command will also ange-ftp the files over. This is achieved
38 ;; automatically because the compilation-parse-errors function uses
39 ;; default-directory to build it's file names. If however the file visited was
40 ;; loaded locally, remote-compile prompts for a host and user and assumes the
41 ;; files mounted locally (otherwise, how was the visited file loaded).
42
43 ;; See the user defined variables section for more info.
44
45 ;; I was contemplating redefining "compile" to "remote-compile" automatically
46 ;; if the file visited was ange-ftp'ed but decided against it for now. If you
47 ;; feel this is a good idea, let me know and I'll consider it again.
48
49 ;;; Installation:
50
51 ;; To use rcompile, you also need to give yourself permission to connect to
52 ;; the remote host.  You do this by putting lines like:
53
54 ;; monopoly alon
55 ;; vme33
56 ;;
57 ;; in a file named .rhosts in the home directory (of the remote machine).
58 ;; Be careful what you put in this file. A line like:
59 ;;
60 ;; +
61 ;;
62 ;; Will allow anyone access to your account without a password. I suggest you
63 ;; read the rhosts(5) manual page before you edit this file (if you are not
64 ;; familiar with it already) 
65 \f
66 ;;; Code:
67
68 (provide 'rcompile)
69 (require 'compile)
70 ;;; The following should not be needed.
71 ;;; (eval-when-compile (require 'ange-ftp))
72
73 ;; But this is if you want a clean build on XEmacs. --SY.
74 (eval-when-compile
75   (when (featurep 'xemacs)
76     (defalias 'ange-ftp-ftp-name 'ignore)
77     (defalias 'ange-ftp-ftp-path 'ignore)))
78
79 ;;;; user defined variables
80
81 (defgroup remote-compile nil
82   "Run a compilation on a remote machine"
83   :group 'processes
84   :group 'tools)
85
86
87 (defcustom remote-compile-host nil
88   "*Host for remote compilations."
89   :type '(choice string (const nil))
90   :group 'remote-compile)
91
92 (defcustom remote-compile-user nil
93   "User for remote compilations.
94 nil means use the value returned by \\[user-login-name]."
95   :type '(choice string (const nil))
96   :group 'remote-compile)
97
98 (defcustom remote-compile-run-before nil
99   "*Command to run before compilation.
100 This can be used for setting up environment variables,
101 since rsh does not invoke the shell as a login shell and files like .login
102 \(tcsh\) and .bash_profile \(bash\) are not run.
103 nil means run no commands."
104   :type '(choice string (const nil))
105   :group 'remote-compile)
106
107 (defcustom remote-compile-prompt-for-host nil
108   "*Non-nil means prompt for host if not available from filename."
109   :type 'boolean
110   :group 'remote-compile)
111
112 (defcustom remote-compile-prompt-for-user nil
113   "*Non-nil means prompt for user if not available from filename."
114   :type 'boolean
115   :group 'remote-compile)
116
117 ;;;; internal variables
118
119 ;; History of remote compile hosts and users
120 (defvar remote-compile-host-history nil)
121 (defvar remote-compile-user-history nil)
122
123 \f
124 ;;;; entry point
125
126 ;;;###autoload
127 (defun remote-compile (host user command)
128   "Compile the current buffer's directory on HOST.  Log in as USER.
129 See \\[compile]."
130   (interactive
131    (let ((parsed 
132           ;; XEmacs change
133           (cond
134            ((featurep 'efs)
135             (efs-ftp-path default-directory))
136            ((featurep 'ange-ftp)
137             (if (fboundp 'ange-ftp-ftp-name)
138                 (ange-ftp-ftp-name default-directory)
139               (ange-ftp-ftp-path default-directory)))
140            (t nil)))
141          host user command prompt)
142      (if parsed
143          (setq host (nth 0 parsed)
144                user (nth 1 parsed))
145        (setq prompt (if (stringp remote-compile-host)
146                         (format "Compile on host (default %s): "
147                                 remote-compile-host)
148                       "Compile on host: ")
149              host (if (or remote-compile-prompt-for-host
150                           (null remote-compile-host))
151                       (read-from-minibuffer prompt
152                                             "" nil nil
153                                             'remote-compile-host-history)
154                     remote-compile-host)
155              user (if remote-compile-prompt-for-user
156                       (read-from-minibuffer (format
157                                              "Compile by user (default %s)"
158                                              (or remote-compile-user
159                                                  (user-login-name)))
160                                             "" nil nil
161                                             'remote-compile-user-history)
162                     remote-compile-user)))
163      (setq command (read-from-minibuffer "Compile command: "
164                                          compile-command nil nil
165                                          '(compile-history . 1)))
166      (list (if (string= host "") remote-compile-host host)
167            (if (string= user "") remote-compile-user user)
168            command)))
169   (setq compile-command command)
170   (cond (user
171          (setq remote-compile-user user))
172         ((null remote-compile-user)
173          (setq remote-compile-user (user-login-name))))
174   (let* ((parsed
175           ;; XEmacs change
176           (cond
177            ((featurep 'efs)
178             (efs-ftp-path default-directory))
179            ((featurep 'ange-ftp)
180             (if (fboundp 'ange-ftp-ftp-name)
181                 (ange-ftp-ftp-name default-directory)
182               (ange-ftp-ftp-path default-directory)))
183            (t nil)))
184          (compile-command
185           (format "%s %s -l %s \"(%scd %s; %s)\""
186                   remote-shell-program
187                   host
188                   remote-compile-user
189                   (if remote-compile-run-before
190                       (concat remote-compile-run-before "; ")
191                     "")
192                   (if parsed (nth 2 parsed) default-directory)
193                   compile-command)))
194     (setq remote-compile-host host)
195     (save-some-buffers nil nil)
196     (compile-internal compile-command "No more errors")
197     ;; Set comint-file-name-prefix in the compilation buffer so
198     ;; compilation-parse-errors will find referenced files by ange-ftp.
199     (save-excursion
200       (set-buffer compilation-last-buffer)
201       (setq comint-file-name-prefix (concat "/" user "@" host ":")))))
202
203 ;;; rcompile.el ends here