comparison lisp/server.el @ 10281:44d98e169823

(server-process-filter): Process each line separately. (server-buffer-done): Delete dead buffers from CLIENT list. Wait a while after sending a command to emacsclient. Verify that BUFFER is a buffer.
author Richard M. Stallman <rms@gnu.org>
date Thu, 29 Dec 1994 01:43:50 +0000
parents b78b8c445f33
children 88cba63f2a9b
comparison
equal deleted inserted replaced
10280:ba09e85fa992 10281:44d98e169823
169 ;Process a request from the server to edit some files. 169 ;Process a request from the server to edit some files.
170 ;Format of STRING is "Client: CLIENTID PATH PATH PATH... \n" 170 ;Format of STRING is "Client: CLIENTID PATH PATH PATH... \n"
171 (defun server-process-filter (proc string) 171 (defun server-process-filter (proc string)
172 (server-log string) 172 (server-log string)
173 (setq string (concat server-previous-string string)) 173 (setq string (concat server-previous-string string))
174 (if (not (and (eq ?\n (aref string (1- (length string)))) 174 ;; If the input is multiple lines,
175 (eq 0 (string-match "Client: " string)))) 175 ;; process each line individually.
176 ;; If input is not complete, save it for later. 176 (while (string-match "\n" string)
177 (setq server-previous-string string) 177 (let ((request (substring string 0 (match-beginning 0)))
178 ;; If it is complete, process it now, and discard what was saved. 178 client
179 (setq string (substring string (match-end 0)))
180 (setq server-previous-string "")
181 (let ((client (list (substring string 0 (string-match " " string))))
182 (files nil) 179 (files nil)
183 (lineno 1)) 180 (lineno 1))
184 (setq string (substring string (match-end 0))) 181 ;; Remove this line from STRING.
185 (while (string-match "[^ ]+ " string) 182 (setq string (substring string (match-end 0)))
183 (if (string-match "^Client: " request)
184 (setq request (substring request (match-end 0))))
185 (setq client (list (substring request 0 (string-match " " request))))
186 (setq request (substring request (match-end 0)))
187 (while (string-match "[^ ]+ " request)
186 (let ((arg 188 (let ((arg
187 (substring string (match-beginning 0) (1- (match-end 0))))) 189 (substring request (match-beginning 0) (1- (match-end 0)))))
188 (setq string (substring string (match-end 0))) 190 (setq request (substring request (match-end 0)))
189 (if (string-match "\\`\\+[0-9]+\\'" arg) 191 (if (string-match "\\`\\+[0-9]+\\'" arg)
190 (setq lineno (read (substring arg 1))) 192 (setq lineno (read (substring arg 1)))
191 (setq files 193 (setq files
192 (cons (list arg lineno) 194 (cons (list arg lineno)
193 files)) 195 files))
196 ;; CLIENT is now a list (CLIENTNUM BUFFERS...) 198 ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
197 (setq server-clients (cons client server-clients)) 199 (setq server-clients (cons client server-clients))
198 (server-switch-buffer (nth 1 client)) 200 (server-switch-buffer (nth 1 client))
199 (run-hooks 'server-switch-hook) 201 (run-hooks 'server-switch-hook)
200 (message (substitute-command-keys 202 (message (substitute-command-keys
201 "When done with a buffer, type \\[server-edit]."))))) 203 "When done with a buffer, type \\[server-edit]."))))
204 ;; Save for later any partial line that remains.
205 (setq server-previous-string string))
202 206
203 (defun server-visit-files (files client) 207 (defun server-visit-files (files client)
204 "Finds FILES and returns the list CLIENT with the buffers nconc'd. 208 "Finds FILES and returns the list CLIENT with the buffers nconc'd.
205 FILES is an alist whose elements are (FILENAME LINENUMBER)." 209 FILES is an alist whose elements are (FILENAME LINENUMBER)."
206 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. 210 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries.
244 (while old-clients 248 (while old-clients
245 (let ((client (car old-clients))) 249 (let ((client (car old-clients)))
246 (or next-buffer 250 (or next-buffer
247 (setq next-buffer (nth 1 (memq buffer client)))) 251 (setq next-buffer (nth 1 (memq buffer client))))
248 (delq buffer client) 252 (delq buffer client)
253 ;; Delete all dead buffers from CLIENT.
254 (let ((tail client))
255 (while tail
256 (and (bufferp (car tail))
257 (null (buffer-name (car tail)))
258 (delq (car tail) client))
259 (setq tail (cdr tail))))
249 ;; If client now has no pending buffers, 260 ;; If client now has no pending buffers,
250 ;; tell it that it is done, and forget it entirely. 261 ;; tell it that it is done, and forget it entirely.
251 (if (cdr client) nil 262 (if (cdr client) nil
252 (if running 263 (if running
253 (progn 264 (progn
254 (send-string server-process 265 (send-string server-process
255 (format "Close: %s Done\n" (car client))) 266 (format "Close: %s Done\n" (car client)))
256 (server-log (format "Close: %s Done\n" (car client))))) 267 (server-log (format "Close: %s Done\n" (car client)))
268 ;; Don't send emacsserver two commands in close succession.
269 ;; It cannot handle that.
270 (sit-for 1)))
257 (setq server-clients (delq client server-clients)))) 271 (setq server-clients (delq client server-clients))))
258 (setq old-clients (cdr old-clients))) 272 (setq old-clients (cdr old-clients)))
259 (if (buffer-name buffer) 273 (if (and (bufferp buffer) (buffer-name buffer))
260 (progn 274 (progn
261 (save-excursion 275 (save-excursion
262 (set-buffer buffer) 276 (set-buffer buffer)
263 (setq server-buffer-clients nil) 277 (setq server-buffer-clients nil)
264 (run-hooks 'server-done-hook)) 278 (run-hooks 'server-done-hook))