0
|
1 ; Lisp Interface code between GNU Emacs and gnuserv.
|
|
2 ;
|
|
3 ; This file is part of GNU Emacs.
|
|
4 ;
|
|
5 ; Copying is permitted under those conditions described by the GNU
|
|
6 ; General Public License.
|
|
7 ;
|
70
|
8 ; Copyright (C) 1989-1994 Free Software Foundation, Inc.
|
0
|
9 ;
|
|
10 ; Author: Andy Norman (ange@hplb.hpl.hp.com) based on
|
|
11 ; 'lisp/server.el' from the 18.52 GNU Emacs distribution.
|
|
12 ;
|
|
13 ; Please mail bugs and suggestions to the author at the above address.
|
|
14 ;
|
|
15 ;;; Synched up with: Not in FSF.
|
|
16
|
|
17 ; Updated for XEmacs, GNU Emacs 19 and Epoch V4 to use multiple frames
|
|
18 ; by Bob Weiner, <weiner@mot.com>, 1/20/94. (Still works with Emacs V18, too.)
|
|
19 ; Modified 'server-process-filter' to use \^D as end of request terminator
|
|
20 ; as gnuclient and gnudoit have been modified to send. This permits
|
|
21 ; multi-line requests.
|
|
22 ; Modified 'server-make-window-visible' to work with multiple frames.
|
|
23 ; Modified 'server-find-file' to display in a separate frame when possible.
|
|
24 ; Modified 'server-edit' to delete newly created frame when used to
|
|
25 ; terminate an edit and to signal an error if called within a
|
|
26 ; non-server-edit buffer.
|
|
27 ; Bob Weiner, <weiner@mot.com>, 5/9/94.
|
|
28 ; Added 'server-done-function' variable. Made default value 'kill-buffer'
|
|
29 ; instead of 'bury-buffer' as in original gnuserv.el.
|
|
30 ;
|
|
31 ; Darrell Kindred <dkindred+@cmu.edu> May/1994
|
|
32 ; Updated to allow multi-line return values:
|
|
33 ; - output to gnuserv is "m/n:xxx" where m is the client number,
|
|
34 ; n is the length of the data, and xxx is the data itself, followed
|
|
35 ; by newline
|
|
36 ;
|
|
37 ; Arup Mukherjee <arup+@cmu.edu> May/1994
|
|
38 ; Updated for XEmacs 19.10, and others:
|
|
39 ; - use find-file-other-screen if present
|
2
|
40 ; - new variable gnuserv-frame can be set to a frame or screen which
|
0
|
41 ; is used for all edited files.
|
|
42 ; - check to see if server.el is already loaded and complain if it is, since
|
|
43 ; gnuserv.el can't coexist with server.el
|
|
44 ; - rename server-start to gnuserv-start, although server-start remains as
|
|
45 ; an alias. This allows gnuserv-start to be autoloaded from gnuserv.el
|
|
46 ; - changed server-get-buffer to take into account that in newer emacsen,
|
|
47 ; get buffer returns nil on deleted buffers.
|
|
48 ; - only try to create/delete frames or screens if window-system is non-nil
|
|
49 ; (otherwise things don't work w/ emacs19 on a dumb terminal)
|
|
50 ;
|
|
51 ; Ben Wing <wing@666.com> sometime in 1995
|
|
52 ; Updated to allow `gnuattach'-type connections to the existing TTY
|
|
53 ;
|
|
54 ; Ben Wing <wing@666.com> May/1996
|
|
55 ; patch to get TTY terminal type correct.
|
|
56
|
|
57
|
|
58
|
|
59 (defconst gnuserv-rcs-header-id "!Header: gnuserv.el,v 2.1 95/02/16 12:00:16 arup alpha !")
|
|
60
|
|
61
|
|
62 ;; server.el and gnuserv.el can't coexist because of conflicting defvar's and
|
|
63 ;; function names.
|
|
64
|
|
65 (if (and (boundp 'server-buffer-clients)
|
|
66 (not (featurep 'gnuserv)))
|
|
67 (error "Can't run gnuserv because server.el appears to be loaded already"))
|
|
68
|
|
69 (defvar gnuserv-frame nil
|
|
70 "*If non-nil, the frame to be used to display all edited files.
|
|
71 If nil, then a new frame is created for each file edited.
|
|
72 This variable has no effect in XEmacs versions older than 19.9.")
|
|
73
|
|
74 (defvar server-done-function 'kill-buffer
|
|
75 "*A function of one argument, a buffer, which removes the buffer after editing.
|
70
|
76 Functions such as 'kill-buffer' and 'bury-buffer' are good values.")
|
0
|
77
|
|
78 (defvar server-program "gnuserv"
|
|
79 "*The program to use as the edit server")
|
|
80
|
|
81 (defvar server-process nil
|
|
82 "The current server process")
|
|
83
|
|
84 (defvar server-string ""
|
|
85 "The last input string from the server")
|
|
86
|
|
87 (defvar current-client nil
|
|
88 "The client we are currently talking to")
|
|
89
|
|
90 (defvar server-clients nil
|
|
91 "List of current server clients.
|
|
92 Each element is (CLIENTID BUFFER...) where CLIENTID is an integer
|
|
93 that can be given to the server process to identify a client.
|
|
94 When a buffer is killed, it is removed from this list.")
|
|
95
|
|
96 (defvar server-buffer-clients nil
|
|
97 "List of client ids for clients requesting editing of the current buffer.")
|
|
98
|
|
99 (make-variable-buffer-local 'server-buffer-clients)
|
|
100 (setq-default server-buffer-clients nil)
|
|
101 (or (assq 'server-buffer-clients minor-mode-alist)
|
|
102 (setq minor-mode-alist (cons '(server-buffer-clients " Server")
|
|
103 minor-mode-alist)))
|
|
104
|
|
105 (defun server-log (string)
|
|
106 "If a *server* buffer exists, write STRING to it for logging purposes."
|
|
107 (if (get-buffer "*server*")
|
|
108 (save-excursion
|
|
109 (set-buffer "*server*")
|
|
110 (goto-char (point-max))
|
|
111 (insert string)
|
|
112 (or (bolp) (newline)))))
|
|
113
|
|
114
|
|
115 (defun server-sentinel (proc msg)
|
|
116 (cond ((eq (process-status proc) 'exit)
|
|
117 (server-log (message "Server subprocess exited")))
|
|
118 ((eq (process-status proc) 'signal)
|
|
119 (server-log (message "Server subprocess killed")))))
|
|
120
|
|
121
|
|
122 (defun server-process-display-error (string)
|
|
123 "Whenever a gnuserv error is reported, display it in a pop-up window."
|
|
124 (let ((cur (selected-window))
|
|
125 (pop-up-windows t))
|
|
126 (pop-to-buffer (get-buffer-create "*server*"))
|
|
127 (set-window-start (selected-window) (point))
|
|
128 (server-log string)
|
|
129 (select-window cur)))
|
|
130
|
|
131
|
|
132 (defun server-process-filter (proc string)
|
|
133 "Process client gnuserv requests to execute Emacs commands."
|
|
134 (setq server-string (concat server-string string))
|
|
135 (if (string-match "\^D$" server-string) ; requests end with ctrl-D
|
|
136 (if (string-match "^[0-9]+" server-string) ; client request id
|
|
137 (progn
|
|
138 (server-log server-string)
|
|
139 (let ((header (read-from-string server-string)))
|
|
140 (setq current-client (car header))
|
|
141 (condition-case oops
|
|
142 (eval (car (read-from-string server-string
|
|
143 (cdr header))))
|
|
144 (error (setq server-string "")
|
|
145 (server-write-to-client current-client oops)
|
|
146 (setq current-client nil)
|
|
147 (signal (car oops) (cdr oops)))
|
|
148 (quit (setq server-string "")
|
|
149 (server-write-to-client current-client oops)
|
|
150 (setq current-client nil)
|
|
151 (signal 'quit nil)))
|
|
152 (setq server-string "")))
|
|
153 (progn ;error string from server
|
|
154 (server-process-display-error server-string)
|
|
155 (setq server-string "")))))
|
|
156
|
|
157
|
|
158 (defun server-release-outstanding-buffers ()
|
|
159 "Release all buffers that have clients waiting for them to be finished."
|
|
160 (interactive)
|
|
161 (while server-clients
|
|
162 (let ((buffer (nth 1 (car server-clients)))) ; for all buffers...
|
|
163 (server-buffer-done buffer)))) ; destructively modifies server-clients
|
|
164
|
|
165 ;;;###autoload
|
|
166 (defun gnuserv-start (&optional leave-dead)
|
|
167 "Allow this Emacs process to be a server for client processes.
|
|
168 This starts a server communications subprocess through which
|
|
169 client \"editors\" (gnuclient and gnudoit) can send editing commands to
|
|
170 this Emacs job. See the gnuserv(1) manual page for more details.
|
|
171
|
|
172 Prefix arg means just kill any existing server communications subprocess."
|
|
173 (interactive "P")
|
|
174 ;; kill it dead!
|
|
175 (if server-process
|
|
176 (progn
|
|
177 (server-release-outstanding-buffers)
|
|
178 (set-process-sentinel server-process nil)
|
|
179 (condition-case ()
|
|
180 (delete-process server-process)
|
|
181 (error nil))))
|
|
182 ;; If we already had a server, clear out associated status.
|
|
183 (if leave-dead
|
|
184 nil
|
|
185 (if server-process
|
|
186 (server-log (message "Restarting server")))
|
|
187 (setq server-string "")
|
|
188 (setq current-client nil)
|
|
189 (let ((process-connection-type t))
|
|
190 (setq server-process
|
|
191 (start-process "server" nil server-program)))
|
|
192 (set-process-sentinel server-process 'server-sentinel)
|
|
193 (set-process-filter server-process 'server-process-filter)
|
|
194 (process-kill-without-query server-process)))
|
|
195
|
|
196 ;; make gnuserv-start an alias to server-start, for backward compatibility
|
|
197 (fset 'server-start (function gnuserv-start))
|
|
198
|
70
|
199
|
0
|
200 (defun server-write-to-client (client form)
|
|
201 "Write the given form to the given client via the server process."
|
|
202 (if (and client
|
|
203 (eq (process-status server-process) 'run))
|
|
204 (let* ((result (format "%s" form))
|
|
205 (s (format "%s/%d:%s\n" client (length result) result)))
|
|
206 (process-send-string server-process s)
|
|
207 (server-log s))))
|
|
208
|
|
209 (defun server-eval (form)
|
|
210 "Evaluate form and return result to client."
|
|
211 (server-write-to-client current-client (eval form))
|
|
212 (setq current-client nil))
|
|
213
|
|
214
|
|
215 (defun server-eval-quickly (form)
|
|
216 "Let client know that we've received the request, but eval the form
|
|
217 afterwards in order to not keep the client waiting."
|
|
218 (server-write-to-client current-client nil)
|
|
219 (setq current-client nil)
|
|
220 (eval form))
|
|
221
|
|
222 (defun server-make-window-visible ()
|
|
223 "Try to make this window even more visible."
|
70
|
224 (cond
|
|
225 ;; XEmacs can (in theory) raise any kind of frame
|
|
226 ((fboundp 'raise-frame)
|
|
227 (raise-frame (selected-frame)))
|
|
228 ((not (and (boundp 'window-system) window-system))
|
|
229 nil)
|
|
230 ((fboundp 'deiconify-screen)
|
|
231 (deiconify-screen (selected-screen))
|
|
232 (raise-screen (selected-screen)))
|
|
233 ((fboundp 'mapraised-screen)
|
|
234 (mapraised-screen))
|
|
235 ((fboundp 'x-remap-window)
|
|
236 (x-remap-window)
|
|
237 ;; give window chance to re-display text
|
|
238 (accept-process-output))))
|
0
|
239
|
70
|
240 (defun server-tty-find-file (tty termtype file)
|
|
241 (let ((device (make-tty-device tty termtype)))
|
0
|
242 (select-frame (make-frame nil device))
|
|
243 (if (not file)
|
|
244 (switch-to-buffer (get-buffer-create "*scratch*"))
|
70
|
245 (find-file file))))
|
0
|
246
|
|
247 (defun server-find-file (file)
|
|
248 "Edit file FILENAME.
|
|
249 Switch to a buffer visiting file FILENAME,
|
|
250 creating one if none already exists."
|
|
251 (let ((obuf (get-file-buffer file))
|
|
252 ;; XEmacs addition.
|
|
253 (force-dialog-box-use t))
|
|
254 (if (and obuf (set-buffer obuf))
|
|
255 (if (file-exists-p file)
|
|
256 (if (or (not (verify-visited-file-modtime obuf))
|
|
257 (buffer-modified-p obuf))
|
|
258 (revert-buffer t nil))
|
|
259 (if (y-or-n-p
|
|
260 (concat "File no longer exists: "
|
|
261 file
|
|
262 ", write buffer to file? "))
|
|
263 (write-file file))))
|
|
264 (cond ((and window-system
|
|
265 gnuserv-frame (fboundp 'frame-live-p) ;; v19 & XEmacs 19.12+
|
|
266 (frame-live-p gnuserv-frame))
|
|
267 (select-frame gnuserv-frame)
|
|
268 (find-file file))
|
|
269
|
|
270 ((and window-system
|
|
271 gnuserv-frame (fboundp 'live-screen-p) ;; XEmacs 19.9+
|
|
272 (live-screen-p gnuserv-frame))
|
|
273 (select-screen gnuserv-frame)
|
|
274 (find-file file))
|
|
275
|
|
276 ((and window-system
|
|
277 (fboundp 'select-frame)) ;; v19 & XEmacs 19.12+
|
|
278 (select-frame (make-frame))
|
|
279 (find-file file))
|
|
280
|
|
281 ((and window-system
|
|
282 (fboundp 'select-screen) ;; XEmacs 19.10+
|
|
283 (fboundp 'make-screen))
|
|
284 (select-screen (make-screen))
|
|
285 (find-file file))
|
|
286
|
|
287 ((and (eq window-system 'x) ;; XEmacs 19.9-
|
|
288 (fboundp 'select-screen)
|
|
289 (fboundp 'x-create-screen))
|
|
290 (select-screen (x-create-screen nil))
|
|
291 (find-file file))
|
|
292
|
|
293 ((and window-system
|
|
294 (fboundp 'create-screen)) ;; epoch
|
|
295 (if (screenp gnuserv-frame)
|
|
296 (progn (select-screen gnuserv-frame)
|
|
297 (find-file file))
|
|
298 (select-screen (create-screen (find-file-noselect file)))))
|
|
299
|
70
|
300 (t (find-file file))))) ;; emacs18+
|
0
|
301
|
|
302
|
|
303 (defun server-edit-files-quickly (list)
|
|
304 "For each (line-number . file) pair in LIST, edit the file at line-number.
|
|
305 Unlike (server-edit-files), no information is saved about clients waiting on
|
|
306 edits to this buffer."
|
|
307 (server-write-to-client current-client nil)
|
|
308 (setq current-client nil)
|
|
309 (while list
|
|
310 (let ((line (car (car list)))
|
|
311 (path (cdr (car list))))
|
|
312 (server-find-file path)
|
|
313 (server-make-window-visible)
|
|
314 (goto-line line))
|
|
315 (setq list (cdr list))))
|
|
316
|
|
317
|
|
318 (defun server-edit-files (list)
|
|
319 "For each (line-number . file) pair in LIST, edit the file at line-number.
|
|
320 Save enough information for (server-kill-buffer) to inform the client when
|
|
321 the edit is finished."
|
|
322 (while list
|
|
323 (let ((line (car (car list)))
|
|
324 (path (cdr (car list))))
|
|
325 (server-find-file path)
|
|
326 (server-make-window-visible)
|
|
327 (let ((old-clients (assq current-client server-clients))
|
|
328 (buffer (current-buffer)))
|
|
329 (goto-line line)
|
|
330 (setq server-buffer-clients
|
|
331 (cons current-client server-buffer-clients))
|
|
332 (if old-clients ;client already waiting for buffers?
|
|
333 (nconc old-clients (list buffer)) ;yes -- append this one as well
|
|
334 (setq server-clients ;nope -- make a new record
|
|
335 (cons (list current-client buffer)
|
|
336 server-clients)))))
|
|
337 (setq list (cdr list)))
|
|
338 (message (substitute-command-keys
|
|
339 (if (and (boundp 'infodock-version) window-system)
|
|
340 "Type {\\[server-edit]} or select Frame/Delete to finish edit."
|
|
341 "When done with a buffer, type \\[server-edit]."))))
|
|
342
|
70
|
343 (defun server-tty-edit-files (tty termtype list)
|
0
|
344 "For each (line-number . file) pair in LIST, edit the file at line-number.
|
|
345 Save enough information for (server-kill-buffer) to inform the client when
|
|
346 the edit is finished."
|
|
347 (or list (setq list '((1 . nil))))
|
|
348 (while list
|
|
349 (let ((line (car (car list)))
|
|
350 (path (cdr (car list))))
|
70
|
351 (server-tty-find-file tty termtype path)
|
0
|
352 (server-make-window-visible)
|
|
353 (let ((old-clients (assq current-client server-clients))
|
|
354 (buffer (current-buffer)))
|
|
355 (goto-line line)
|
|
356 (setq server-buffer-clients
|
|
357 (cons current-client server-buffer-clients))
|
|
358 (if old-clients ;client already waiting for buffers?
|
|
359 (nconc old-clients (list buffer)) ;yes -- append this one as well
|
|
360 (setq server-clients ;nope -- make a new record
|
|
361 (cons (list current-client buffer)
|
|
362 server-clients)))))
|
|
363 (setq list (cdr list)))
|
|
364 (message (substitute-command-keys
|
|
365 (if (and (boundp 'infodock-version) window-system)
|
|
366 "Type {\\[server-edit]} or select Frame/Delete to finish edit."
|
|
367 "When done with a buffer, type \\[server-edit]."))))
|
|
368
|
|
369 (defun server-get-buffer (buffer)
|
|
370 "One arg, a BUFFER or a buffer name. Return the buffer object even if killed.
|
|
371 Signal an error if there is no record of BUFFER."
|
|
372 (if (null buffer)
|
|
373 (current-buffer)
|
|
374 (let ((buf (get-buffer buffer)))
|
|
375 (if (null buf)
|
|
376 (if (bufferp buffer)
|
|
377 buffer
|
|
378 (if (stringp buffer)
|
|
379 (error "No buffer named %s" buffer)
|
|
380 (error "Invalid buffer argument")))
|
|
381 buf))))
|
|
382
|
|
383 (defun server-kill-buffer (buffer)
|
|
384 "Kill the BUFFER. The argument may be a buffer object or buffer name.
|
|
385 NOTE: This function has been enhanced to allow for remote editing
|
|
386 in the following way:
|
|
387
|
|
388 If the buffer is waited upon by one or more clients, and a client is
|
|
389 not waiting for other buffers to be killed, then the client is told
|
|
390 that the buffer has been killed."
|
|
391 (interactive "bKill buffer ")
|
|
392 (setq buffer (server-get-buffer buffer))
|
|
393 (if (buffer-name buffer)
|
|
394 (save-excursion
|
|
395 (set-buffer buffer)
|
|
396 (let ((old-clients server-clients))
|
|
397 (server-real-kill-buffer buffer) ;try to kill it
|
|
398 (if (buffer-name buffer) ;succeeded in killing?
|
|
399 nil ;nope
|
|
400 (while old-clients
|
|
401 (let ((client (car old-clients)))
|
|
402 (delq buffer client)
|
|
403 (if (cdr client) ;pending buffers?
|
|
404 nil ;yep
|
|
405 (server-write-to-client (car client) nil) ;nope, tell client
|
|
406 (setq server-clients (delq client server-clients))))
|
70
|
407 (setq old-clients (cdr old-clients))))))))
|
36
|
408
|
|
409
|
0
|
410 (defun server-kill-all-local-variables ()
|
|
411 "Eliminate all the buffer-local variable values of the current buffer.
|
|
412 This buffer will then see the default values of all variables.
|
|
413 NOTE: This function has been modified to ignore the variable
|
|
414 server-buffer-clients."
|
|
415 (let ((clients server-buffer-clients))
|
|
416 (server-real-kill-all-local-variables)
|
|
417 (if clients
|
|
418 (setq server-buffer-clients clients))))
|
|
419
|
|
420
|
|
421 (or (fboundp 'server-real-kill-buffer)
|
|
422 (fset 'server-real-kill-buffer (symbol-function 'kill-buffer)))
|
|
423
|
|
424 (fset 'kill-buffer 'server-kill-buffer)
|
|
425
|
|
426 (or (fboundp 'server-real-kill-all-local-variables)
|
|
427 (fset 'server-real-kill-all-local-variables
|
|
428 (symbol-function 'kill-all-local-variables)))
|
|
429
|
|
430 (fset 'kill-all-local-variables 'server-kill-all-local-variables)
|
|
431
|
|
432
|
|
433 (defun server-buffer-done (buffer)
|
|
434 "Mark BUFFER as \"done\" for its client(s).
|
|
435 Buries the buffer, and returns another server buffer as a suggestion for the
|
|
436 new current buffer."
|
|
437 (let ((next-buffer nil)
|
|
438 (old-clients server-clients))
|
|
439 (while old-clients
|
|
440 (let ((client (car old-clients)))
|
|
441 (or next-buffer
|
|
442 (setq next-buffer (nth 1 (memq buffer client))))
|
|
443 (delq buffer client)
|
|
444 ;; If client now has no pending buffers,
|
|
445 ;; tell it that it is done, and forget it entirely.
|
|
446 (if (cdr client)
|
|
447 nil
|
70
|
448 (server-write-to-client (car client) nil)
|
|
449 (setq server-clients (delq client server-clients))))
|
0
|
450 (setq old-clients (cdr old-clients)))
|
70
|
451 (if (buffer-name buffer)
|
|
452 (save-excursion
|
|
453 (set-buffer buffer)
|
|
454 (setq server-buffer-clients nil)))
|
|
455 (funcall server-done-function buffer)
|
0
|
456 next-buffer))
|
|
457
|
|
458
|
|
459 (defun mh-draft-p (buffer)
|
|
460 "Return non-nil if this BUFFER is an mh <draft> file. Since MH deletes
|
|
461 draft *BEFORE* it is edited, the server treats them specially."
|
|
462 ;; This may not be appropriately robust for all cases.
|
|
463 (string= (buffer-name buffer) "draft"))
|
|
464
|
|
465
|
|
466 (defun server-done ()
|
|
467 "Offer to save current buffer and mark it as \"done\" for clients.
|
|
468 Also bury it, and return a suggested new current buffer."
|
|
469 (let ((buffer (current-buffer)))
|
|
470 (if server-buffer-clients
|
|
471 (progn
|
70
|
472 (if (mh-draft-p buffer)
|
0
|
473 (progn (save-buffer)
|
|
474 (write-region (point-min) (point-max)
|
|
475 (concat buffer-file-name "~"))
|
|
476 (kill-buffer buffer))
|
70
|
477 (if (and (buffer-modified-p)
|
|
478 (y-or-n-p (concat "Save file " buffer-file-name "? ")))
|
|
479 (save-buffer buffer)))
|
0
|
480 (server-buffer-done buffer)))))
|
|
481
|
|
482
|
|
483 (defun server-edit (&optional arg)
|
70
|
484 "Switch to next server editing buffer and mark current one as \"done\".
|
|
485 If a server buffer is current, it is marked \"done\" and optionally saved.
|
|
486 MH <draft> files are always saved and backed up, no questions asked.
|
|
487 When all of a client's buffers are marked as \"done\", the client is notified.
|
0
|
488
|
|
489 If invoked with a prefix argument, or if there is no server process running,
|
70
|
490 starts server process and that is all. Invoked by \\[server-edit]."
|
0
|
491 (interactive "P")
|
|
492 (if (or arg
|
|
493 (not server-process)
|
|
494 (memq (process-status server-process) '(signal exit)))
|
|
495 (server-start nil)
|
|
496 (if server-buffer-clients
|
70
|
497 (progn (server-switch-buffer (server-done))
|
2
|
498 (cond ((fboundp 'console-type) ;; XEmacs 19.14+
|
|
499 (or (and (equal (console-type) 'x)
|
|
500 gnuserv-frame
|
|
501 (frame-live-p gnuserv-frame))
|
|
502 (condition-case ()
|
70
|
503 (delete-frame (selected-frame) nil)
|
2
|
504 (error
|
|
505 (message "Not deleting last visible frame...")))))
|
|
506 ((or (not window-system)
|
0
|
507 (and gnuserv-frame
|
|
508 (or (and (fboundp 'frame-live-p)
|
|
509 (frame-live-p gnuserv-frame))
|
|
510 (and (fboundp 'live-screen-p)
|
|
511 (live-screen-p gnuserv-frame))
|
|
512 (and (fboundp 'create-screen)
|
|
513 (screenp gnuserv-frame)))))
|
|
514 ()) ;; do nothing
|
|
515 ((fboundp 'delete-frame)
|
|
516 (delete-frame (selected-frame) t))
|
|
517 ((fboundp 'delete-screen)
|
|
518 (delete-screen))))
|
|
519 (error
|
|
520 "(server-edit): Use only on buffers created by external programs.")
|
|
521 )))
|
|
522
|
70
|
523 (defun server-switch-buffer (next-buffer)
|
0
|
524 "Switch to NEXT-BUFFER if a live buffer, otherwise switch to another buffer
|
70
|
525 with gnuserv clients. If no such buffer is available, simply choose another
|
|
526 one."
|
0
|
527 (if next-buffer
|
|
528 (if (and (bufferp next-buffer)
|
|
529 (buffer-name next-buffer))
|
|
530 (switch-to-buffer next-buffer)
|
|
531 ;; If NEXT-BUFFER is a dead buffer,
|
|
532 ;; remove the server records for it
|
|
533 ;; and try the next surviving server buffer.
|
70
|
534 (server-switch-buffer
|
|
535 (server-buffer-done next-buffer)))
|
|
536 (if server-clients
|
|
537 (server-switch-buffer (nth 1 (car server-clients)))
|
|
538 (switch-to-buffer (other-buffer)))))
|
0
|
539
|
|
540 (global-set-key "\C-x#" 'server-edit)
|
|
541
|
|
542 (provide 'gnuserv)
|
|
543
|