rcompile.el 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ;;; rcompile.el --- run a compilation on a remote machine
  2. ;; Copyright (C) 1993-1994, 2001-2015 Free Software Foundation, Inc.
  3. ;; Author: Alon Albert <alon@milcse.rtsg.mot.com>
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; Created: 1993 Oct 6
  6. ;; Keywords: tools, processes
  7. ;; Obsolete-since: 24.4
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; This package is for running a remote compilation and using emacs to parse
  21. ;; the error messages. It works by rsh'ing the compilation to a remote host
  22. ;; and parsing the output. If the file visited at the time remote-compile was
  23. ;; called was loaded remotely (ange-ftp), the host and user name are obtained
  24. ;; by the calling ange-ftp-ftp-name on the current directory. In this case the
  25. ;; next-error command will also ange-ftp the files over. This is achieved
  26. ;; automatically because the compilation-parse-errors function uses
  27. ;; default-directory to build its file names. If however the file visited was
  28. ;; loaded locally, remote-compile prompts for a host and user and assumes the
  29. ;; files mounted locally (otherwise, how was the visited file loaded).
  30. ;; See the user defined variables section for more info.
  31. ;; I was contemplating redefining "compile" to "remote-compile" automatically
  32. ;; if the file visited was ange-ftp'ed but decided against it for now. If you
  33. ;; feel this is a good idea, let me know and I'll consider it again.
  34. ;; Installation:
  35. ;; To use rcompile, you also need to give yourself permission to connect to
  36. ;; the remote host. You do this by putting lines like:
  37. ;; monopoly alon
  38. ;; vme33
  39. ;;
  40. ;; in a file named .rhosts in the home directory (of the remote machine).
  41. ;; Be careful what you put in this file. A line like:
  42. ;;
  43. ;; +
  44. ;;
  45. ;; Will allow anyone access to your account without a password. I suggest you
  46. ;; read the rhosts(5) manual page before you edit this file (if you are not
  47. ;; familiar with it already)
  48. ;;; Code:
  49. (provide 'rcompile)
  50. (require 'compile)
  51. ;;; The following should not be needed.
  52. ;;; (eval-when-compile (require 'ange-ftp))
  53. ;;;; user defined variables
  54. (defgroup remote-compile nil
  55. "Run a compilation on a remote machine."
  56. :group 'processes
  57. :group 'tools)
  58. (defcustom remote-compile-host nil
  59. "Host for remote compilations."
  60. :type '(choice string (const nil))
  61. :group 'remote-compile)
  62. (defcustom remote-compile-user nil
  63. "User for remote compilations.
  64. nil means use the value returned by \\[user-login-name]."
  65. :type '(choice string (const nil))
  66. :group 'remote-compile)
  67. (defcustom remote-compile-run-before nil
  68. "Command to run before compilation.
  69. This can be used for setting up environment variables,
  70. since rsh does not invoke the shell as a login shell and files like .login
  71. \(tcsh\) and .bash_profile \(bash\) are not run.
  72. nil means run no commands."
  73. :type '(choice string (const nil))
  74. :group 'remote-compile)
  75. (defcustom remote-compile-prompt-for-host nil
  76. "Non-nil means prompt for host if not available from filename."
  77. :type 'boolean
  78. :group 'remote-compile)
  79. (defcustom remote-compile-prompt-for-user nil
  80. "Non-nil means prompt for user if not available from filename."
  81. :type 'boolean
  82. :group 'remote-compile)
  83. ;;;; internal variables
  84. ;; History of remote compile hosts and users
  85. (defvar remote-compile-host-history nil)
  86. (defvar remote-compile-user-history nil)
  87. ;;;; entry point
  88. ;; We use the Tramp internal function`tramp-make-tramp-file-name'.
  89. ;; Better would be, if there are functions to provide user, host and
  90. ;; localname of a remote filename, independent of Tramp's implementation.
  91. ;; The function calls are wrapped by `funcall' in order to pacify the byte
  92. ;; compiler. ange-ftp check removed, because it is handled also by Tramp.
  93. ;;;###autoload
  94. (defun remote-compile (host user command)
  95. "Compile the current buffer's directory on HOST. Log in as USER.
  96. See \\[compile]."
  97. (interactive
  98. (let (host user command prompt l l-host l-user)
  99. (setq prompt (if (stringp remote-compile-host)
  100. (format "Compile on host (default %s): "
  101. remote-compile-host)
  102. "Compile on host: ")
  103. host (if (or remote-compile-prompt-for-host
  104. (null remote-compile-host))
  105. (read-from-minibuffer prompt
  106. "" nil nil
  107. 'remote-compile-host-history)
  108. remote-compile-host)
  109. user (if remote-compile-prompt-for-user
  110. (read-from-minibuffer (format
  111. "Compile by user (default %s): "
  112. (or remote-compile-user
  113. (user-login-name)))
  114. "" nil nil
  115. 'remote-compile-user-history)
  116. remote-compile-user))
  117. (setq command (read-from-minibuffer "Compile command: "
  118. compile-command nil nil
  119. '(compile-history . 1)))
  120. (list (if (string= host "") remote-compile-host host)
  121. (if (string= user "") remote-compile-user user)
  122. command)))
  123. (setq compile-command command)
  124. (cond (user
  125. (setq remote-compile-user user))
  126. ((null remote-compile-user)
  127. (setq remote-compile-user (user-login-name))))
  128. (let* (localname ;; Pacify byte-compiler.
  129. (compile-command
  130. (format "%s %s -l %s \"(%scd %s; %s)\""
  131. remote-shell-program
  132. host
  133. remote-compile-user
  134. (if remote-compile-run-before
  135. (concat remote-compile-run-before "; ")
  136. "")
  137. ""
  138. compile-command)))
  139. (setq remote-compile-host host)
  140. (save-some-buffers nil nil)
  141. (compilation-start compile-command)
  142. ;; Set comint-file-name-prefix in the compilation buffer so
  143. ;; compilation-parse-errors will find referenced files by Tramp.
  144. (with-current-buffer compilation-last-buffer
  145. (when (fboundp 'tramp-make-tramp-file-name)
  146. (set (make-local-variable 'comint-file-name-prefix)
  147. (tramp-make-tramp-file-name
  148. nil ;; method.
  149. remote-compile-user
  150. remote-compile-host
  151. ""))))))
  152. ;;; rcompile.el ends here