comparison lisp/server.el @ 88016:921eddfa6d43

(server-buffer): New const. (server-log): New var. (server-log): Use them. (server-process-filter): (Try to) run the continuation in the same cwd as the client's.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 26 Jan 2008 21:54:44 +0000
parents fdac3d75dcdb
children c17f9d425917
comparison
equal deleted inserted replaced
88015:7b54e553ca0b 88016:921eddfa6d43
292 (server-log "Deleted" proc)))) 292 (server-log "Deleted" proc))))
293 293
294 (defvar server-log-time-function 'current-time-string 294 (defvar server-log-time-function 'current-time-string
295 "Function to generate timestamps for the *server* buffer.") 295 "Function to generate timestamps for the *server* buffer.")
296 296
297 (defconst server-buffer " *server*"
298 "Buffer used internally by Emacs's server.
299 One use is to log the I/O for debugging purposes (see `server-log'),
300 the other is to provide a current buffer in which the process filter can
301 safely let-bind buffer-local variables like default-directory.")
302
303 (defvar server-log nil
304 "If non-nil, log the server's inputs and outputs in the `server-buffer'.")
305
297 (defun server-log (string &optional client) 306 (defun server-log (string &optional client)
298 "If a *server* buffer exists, write STRING to it for logging purposes. 307 "If `server-log' is non-nil, log STRING to `server-buffer'.
299 If CLIENT is non-nil, add a description of it to the logged message." 308 If CLIENT is non-nil, add a description of it to the logged message."
300 (when (get-buffer "*server*") 309 (when server-log
301 (with-current-buffer "*server*" 310 (with-current-buffer (get-buffer-create server-buffer)
302 (goto-char (point-max)) 311 (goto-char (point-max))
303 (insert (funcall server-log-time-function) 312 (insert (funcall server-log-time-function)
304 (cond 313 (cond
305 ((null client) " ") 314 ((null client) " ")
306 ((listp client) (format " %s: " (car client))) 315 ((listp client) (format " %s: " (car client)))
495 :filter 'server-process-filter 504 :filter 'server-process-filter
496 ;; We must receive file names without being decoded. 505 ;; We must receive file names without being decoded.
497 ;; Those are decoded by server-process-filter according 506 ;; Those are decoded by server-process-filter according
498 ;; to file-name-coding-system. 507 ;; to file-name-coding-system.
499 :coding 'raw-text 508 :coding 'raw-text
500 ;; The rest of the args depends on the kind of socket used. 509 ;; The other args depend on the kind of socket used.
501 (if server-use-tcp 510 (if server-use-tcp
502 (list :family nil 511 (list :family nil
503 :service t 512 :service t
504 :host (or server-host 'local) 513 :host (or server-host 'local)
505 :plist '(:authenticated nil)) 514 :plist '(:authenticated nil))
926 ((nil) (if display (server-select-display display))) 935 ((nil) (if display (server-select-display display)))
927 ((window-system) 936 ((window-system)
928 (server-create-window-system-frame display nowait proc)) 937 (server-create-window-system-frame display nowait proc))
929 (t (server-create-tty-frame tty-name tty-type proc)))) 938 (t (server-create-tty-frame tty-name tty-type proc))))
930 939
931 (process-put proc 'continuation 940 (process-put
932 (lexical-let ((proc proc) 941 proc 'continuation
933 (files files) 942 (lexical-let ((proc proc)
934 (nowait nowait) 943 (files files)
935 (commands commands) 944 (nowait nowait)
936 (dontkill dontkill) 945 (commands commands)
937 (frame frame) 946 (dontkill dontkill)
938 (tty-name tty-name)) 947 (frame frame)
939 (lambda () 948 (dir dir)
940 (server-execute proc files nowait commands 949 (tty-name tty-name))
941 dontkill frame tty-name)))) 950 (lambda ()
951 (with-current-buffer (get-buffer-create server-buffer)
952 ;; Use the same cwd as the emacsclient, if possible, so
953 ;; relative file names work correctly, even in `eval'.
954 (let ((default-directory
955 (if (file-directory-p dir) dir default-directory)))
956 (server-execute proc files nowait commands
957 dontkill frame tty-name))))))
942 958
943 (when (or frame files) 959 (when (or frame files)
944 (server-goto-toplevel proc)) 960 (server-goto-toplevel proc))
945 961
946 (server-execute-continuation proc)))) 962 (server-execute-continuation proc))))