annotate lisp/packages/remote.el @ 82:6a378aca36af r20-0b91

Import from CVS: tag r20-0b91
author cvs
date Mon, 13 Aug 2007 09:07:36 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; remote.el version 2.6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Module to do remote editing via rcp. Assume .rhosts files are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; set up properly on both machines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Modeled after ftp.el by MLY.PREP.AI.MIT.EDU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Nick Tran
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; University of Minnesota
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Summer 87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; Almost complete rewrite. Added minor mode support, better
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; defaults, rewrote find-remote-file, wrote read-remote-file-name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; insert-remote-file, find-file, find-alternate-remote-file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; get-remote-file-or-buffer, get-remote-buffer, process-wait,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; remote-rcp-error. Also general clean up, error handling, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Eric Raible Wednesday Sept 5, 1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Automatically set major mode, added prefix arg support for most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; file operations to toggle sense of remote editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Eric Raible Thursday October 6, 1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; Manipulate buffer name more appropriately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Eric Raible Friday October 7, 1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; For write-remote-file, allow default of file part of remote name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Eric Raible Tuesday October 11, 1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defvar default-remote-host "navier:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "The host to use for remote file operations when none other is appropriate.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defvar track-default-remote-host t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 "Controls whether default-remote-host is changed after reading a remote file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 When non-nil, default-remote-host will have the value of the last remote host read.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (make-variable-buffer-local 'buffer-remote-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (set-default 'buffer-remote-file-name "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (make-variable-buffer-local 'remote-editing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvar rcp (cond ((file-exists-p "/bin/rcp") "/bin/rcp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ((file-exists-p "/usr/bsd/rcp") "/usr/bsd/rcp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (t "rcp")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (if (assoc 'remote-editing minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (setq minor-mode-alist (cons '(remote-editing " Remote") minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defun remote-editing (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "Toggle remote-editing mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 With arg, turn on remote editing mode iff arg is positive, otherwise just toggle it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 In remote editing mode, the normal bindings for find-file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 find-file-read-only, find-alternate-file, save-buffer, write-file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 and insert-file are changed to operate on a remote system by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 When remote editing, a prefix arg allows local file operations. When not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 remote editing, a prefix arg allows remote file operations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 It is assumed that .rhosts files are set up properly on both machines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (setq remote-editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if (null arg) (not remote-editing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (global-set-key "\C-xr" 'remote-editing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; Macro used as front-end to normal file operation key bindings to decide between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; local and remote modes. Automatically constructs doc string and includes prefix arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; to temporarily toggle sense of remote-editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defmacro def-local-or-remote (binding name remote local)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (let ((r (symbol-name (eval remote)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (l (symbol-name (eval local))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (list 'global-set-key binding (list 'quote name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (list 'defun name '(arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (concat "Call either " r " or " l ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 If remote-editing (which see), call " r ", else call " l ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 See also the documentation for " r " and " l ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 '(interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (list 'call-interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (list 'if '(xor remote-editing arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 remote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 local))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (def-local-or-remote "\C-x\C-f" find-local-or-remote-file 'find-remote-file 'find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (def-local-or-remote "\C-x\C-r" find-local-or-remote-file-read-only 'find-remote-file-read-only 'find-file-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (def-local-or-remote "\C-x\C-v" find-alternate-local-or-remote-file 'find-alternate-remote-file 'find-alternate-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (def-local-or-remote "\C-x\C-s" save-local-or-remote-buffer 'save-remote-buffer 'save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (def-local-or-remote "\C-x\C-w" write-local-or-remote-file 'write-remote-file 'write-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (def-local-or-remote "\C-xi" insert-local-or-remote-file 'insert-remote-file 'insert-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defun find-remote-file (host file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "Edit remote file HOST:FILE (using rcp).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 This command is similiar to find-file, but uses rcp to read the file from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 a remote machine. Also see remote-editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (interactive (read-remote-file-name "Find remote file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (let ((buffer-or-file (get-remote-file-or-buffer host file "retrieve"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 local-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (if buffer-or-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (if (bufferp buffer-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (switch-to-buffer buffer-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq local-file buffer-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let ((buf (generate-new-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (concat host (file-name-nondirectory file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (switch-to-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (not (file-exists-p local-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (message "(New remote file)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (insert-file-contents local-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (delete-file local-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; dynamic binding for normal-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (let ((buffer-file-name (concat host file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (normal-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (remote-editing 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq buffer-remote-file-name buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 buffer-offer-save t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defun find-remote-file-read-only ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "Edit remote file FILENAME, but mark buffer as read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Also see find-remote-file and remote-editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (call-interactively 'find-remote-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defun find-alternate-remote-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 "Find alternate file using rcp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 This command is similiar to find-alternate-file, but uses rcp to read the file from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 a remote machine. Also see remote-editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (and (buffer-modified-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (not buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (error "Aborted"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (let ((obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (oname (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (rename-buffer " **lose**")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (apply 'find-remote-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (read-remote-file-name "Find remote alternate file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (eq obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (rename-buffer oname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (kill-buffer obuf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun save-remote-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "Save a file using rcp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 This command is similiar to save-buffer, but uses rcp to write the file back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 to a remote machine. Also see remote-editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (buffer-modified-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (if (zerop (length buffer-remote-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (call-interactively 'write-remote-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (do-write-remote-file buffer-remote-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (message "(No changes need to be saved)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defun write-remote-file (host file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Write a file HOST:FILE using rcp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 This command is similiar to write-file, but uses rcp to write the file back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 to a remote machine. Also see remote-editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (interactive (read-remote-file-name "Write remote file" 'no-file-ok))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (do-write-remote-file (concat host file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defun insert-remote-file (host file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "Insert a remote file HOST:FILE using rcp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 This command is similiar to insert-file, but uses rcp to read the file from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 a remote machine. Also see remote-editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (interactive (read-remote-file-name "Insert remote file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (let ((f-or-b (get-remote-file-or-buffer host file "insert")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (if f-or-b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (bufferp f-or-b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (insert-buffer f-or-b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (insert-file f-or-b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (delete-file f-or-b)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;; Internal routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defun do-write-remote-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let* ((temp (concat "/tmp/" (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (output (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (prog1 (set-buffer (get-buffer-create "*Rcp Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (erase-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; write-file doesn't quite do it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (write-region (point-min) (point-max) temp nil 'no-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (message "Sending %s..." file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (if (setq time (process-wait (start-process "rcp" output rcp temp file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (if remote-editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((new-name (concat (host-part-only file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (file-name-nondirectory (file-part-only file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (or (get-buffer new-name) (rename-buffer new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (set-buffer-modified-p nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (setq buffer-remote-file-name file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (message "%d bytes in %d seconds" (buffer-size) time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (delete-file temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (remote-rcp-error output buffer-remote-file-name "update"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (defun get-remote-file-or-buffer (host file message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "Return a remote file as either a buffer or a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 If the file HOST:FILE already has been read in, return the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 that contains it; otherwise try and rcp the file to the local machine.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 If successful, return the local file name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (let ((remote (concat host file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (temp (concat "/tmp/" (file-name-nondirectory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if (string= file (file-name-directory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (message "Remote directory listing not yet implemented")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (or (get-remote-buffer remote) ;; already exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let* ((output (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (prog1 (set-buffer (get-buffer-create "*Rcp Output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (erase-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (cursor-in-echo-area t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (message "Retrieving %s..." remote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (setq time (process-wait (start-process "rcp" output rcp remote temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (message "%d bytes in %d seconds"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (nth 7 (file-attributes temp)) time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (remote-rcp-error output remote message)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (defun get-remote-buffer (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (let ((buffers (buffer-list)) found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (while (and (not found) buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (set-buffer (car buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (if (string= name buffer-remote-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq found (car buffers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq buffers (cdr buffers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 found)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun read-remote-file-name (prompt &optional no-file-ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "Read a remote file specification, and return list (host file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 Prompting with PROMPT, read a string of the form host:file. The default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 value is derived from the remote file name, or if there is none, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 from the global default (default-remote-host)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (let* ((host (or (host-part-only buffer-remote-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 default-remote-host))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (result (concat host (file-name-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (or (file-part-only buffer-remote-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (prompt (concat prompt " (host:file): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (setq result (read-no-blanks-input prompt result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (while (not (string-match (if no-file-ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ".+:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ".+:.+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq result (read-no-blanks-input prompt result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq host (host-part-only result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 file (file-part-only result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (and track-default-remote-host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (setq default-remote-host host))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (list host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if (or (null file) (string= file (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (concat file (or (if (not (string= buffer-remote-file-name ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (file-part-only buffer-remote-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (file-part-only (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (defun host-part-only (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if (string-match ".+:" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (substring name 0 (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (defun file-part-only (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (if (string-match ".+:\\(.+\\)" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (substring name (match-beginning 1) (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defun xor (a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (eq (null a) (not (null b))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defun process-wait (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (let ((time 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (while (eq (process-status proc) 'run)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (setq time (1+ time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (sleep-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (if (and (eq (process-status proc) 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (eq (process-exit-status proc) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (defun remote-rcp-error (buffer file-name message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (switch-to-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (delete-other-windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (insert (format "Unable to %s %s\n\n" message file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (message "Hit any character to continue")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (read-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (bury-buffer buffer)))