annotate lisp/packages/gnuserv.el @ 78:c7528f8e288d r20-0b34

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