(do_autoload): Don't output any message.
[emacs.git] / lisp / server.el
blob04da434f73713d186c3c495b616cfe60ba2792dc
1 ;;; server.el --- Lisp code for GNU Emacs running as server process
3 ;; Copyright (C) 1986, 1987, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: William Sommerfeld <wesommer@athena.mit.edu>
7 ;; Maintainer: FSF
8 ;; Keywords: processes
10 ;; Changes by peck@sun.com and by rms.
11 ;; Overhaul by Karoly Lorentey <lorentey@elte.hu> for multi-tty support.
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
30 ;;; Commentary:
32 ;; This Lisp code is run in Emacs when it is to operate as
33 ;; a server for other processes.
35 ;; Load this library and do M-x server-edit to enable Emacs as a server.
36 ;; Emacs opens up a socket for communication with clients. If there are no
37 ;; client buffers to edit, server-edit acts like (switch-to-buffer
38 ;; (other-buffer))
40 ;; When some other program runs "the editor" to edit a file,
41 ;; "the editor" can be the Emacs client program ../lib-src/emacsclient.
42 ;; This program transmits the file names to Emacs through
43 ;; the server subprocess, and Emacs visits them and lets you edit them.
45 ;; Note that any number of clients may dispatch files to Emacs to be edited.
47 ;; When you finish editing a Server buffer, again call server-edit
48 ;; to mark that buffer as done for the client and switch to the next
49 ;; Server buffer. When all the buffers for a client have been edited
50 ;; and exited with server-edit, the client "editor" will return
51 ;; to the program that invoked it.
53 ;; Your editing commands and Emacs's display output go to and from
54 ;; the terminal in the usual way. Thus, server operation is possible
55 ;; only when Emacs can talk to the terminal at the time you invoke
56 ;; the client. This is possible in four cases:
58 ;; 1. On a window system, where Emacs runs in one window and the
59 ;; program that wants to use "the editor" runs in another.
61 ;; 2. On a multi-terminal system, where Emacs runs on one terminal and the
62 ;; program that wants to use "the editor" runs on another.
64 ;; 3. When the program that wants to use "the editor" is running
65 ;; as a subprocess of Emacs.
67 ;; 4. On a system with job control, when Emacs is suspended, the program
68 ;; that wants to use "the editor" will stop and display
69 ;; "Waiting for Emacs...". It can then be suspended, and Emacs can be
70 ;; brought into the foreground for editing. When done editing, Emacs is
71 ;; suspended again, and the client program is brought into the foreground.
73 ;; The buffer local variable "server-buffer-clients" lists
74 ;; the clients who are waiting for this buffer to be edited.
75 ;; The global variable "server-clients" lists all the waiting clients,
76 ;; and which files are yet to be edited for each.
78 ;;; Code:
80 (eval-when-compile (require 'cl))
82 (defgroup server nil
83 "Emacs running as a server process."
84 :group 'external)
86 (defcustom server-use-tcp nil
87 "If non-nil, use TCP sockets instead of local sockets."
88 :set #'(lambda (sym val)
89 (unless (featurep 'make-network-process '(:family local))
90 (setq val t)
91 (unless load-in-progress
92 (message "Local sockets unsupported, using TCP sockets")))
93 (when val (random t))
94 (set-default sym val))
95 :group 'server
96 :type 'boolean
97 :version "22.1")
99 (defcustom server-host nil
100 "The name or IP address to use as host address of the server process.
101 If set, the server accepts remote connections; otherwise it is local."
102 :group 'server
103 :type '(choice
104 (string :tag "Name or IP address")
105 (const :tag "Local" nil))
106 :version "22.1")
107 (put 'server-host 'risky-local-variable t)
109 (defcustom server-auth-dir (concat user-emacs-directory "server/")
110 "Directory for server authentication files."
111 :group 'server
112 :type 'directory
113 :version "22.1")
114 (put 'server-auth-dir 'risky-local-variable t)
116 (defcustom server-raise-frame t
117 "If non-nil, raise frame when switching to a buffer."
118 :group 'server
119 :type 'boolean
120 :version "22.1")
122 (defcustom server-visit-hook nil
123 "Hook run when visiting a file for the Emacs server."
124 :group 'server
125 :type 'hook)
127 (defcustom server-switch-hook nil
128 "Hook run when switching to a buffer for the Emacs server."
129 :group 'server
130 :type 'hook)
132 (defcustom server-done-hook nil
133 "Hook run when done editing a buffer for the Emacs server."
134 :group 'server
135 :type 'hook)
137 (defvar server-process nil
138 "The current server process.")
140 (defvar server-clients nil
141 "List of current server clients.
142 Each element is a process.")
144 (defvar server-buffer-clients nil
145 "List of client processes requesting editing of current buffer.")
146 (make-variable-buffer-local 'server-buffer-clients)
147 ;; Changing major modes should not erase this local.
148 (put 'server-buffer-clients 'permanent-local t)
150 (defcustom server-window nil
151 "Specification of the window to use for selecting Emacs server buffers.
152 If nil, use the selected window.
153 If it is a function, it should take one argument (a buffer) and
154 display and select it. A common value is `pop-to-buffer'.
155 If it is a window, use that.
156 If it is a frame, use the frame's selected window.
158 It is not meaningful to set this to a specific frame or window with Custom.
159 Only programs can do so."
160 :group 'server
161 :version "22.1"
162 :type '(choice (const :tag "Use selected window"
163 :match (lambda (widget value)
164 (not (functionp value)))
165 nil)
166 (function-item :tag "Display in new frame" switch-to-buffer-other-frame)
167 (function-item :tag "Use pop-to-buffer" pop-to-buffer)
168 (function :tag "Other function")))
170 (defcustom server-temp-file-regexp "^/tmp/Re\\|/draft$"
171 "Regexp matching names of temporary files.
172 These are deleted and reused after each edit by the programs that
173 invoke the Emacs server."
174 :group 'server
175 :type 'regexp)
177 (defcustom server-kill-new-buffers t
178 "Whether to kill buffers when done with them.
179 If non-nil, kill a buffer unless it already existed before editing
180 it with Emacs server. If nil, kill only buffers as specified by
181 `server-temp-file-regexp'.
182 Please note that only buffers are killed that still have a client,
183 i.e. buffers visited which \"emacsclient --no-wait\" are never killed in
184 this way."
185 :group 'server
186 :type 'boolean
187 :version "21.1")
189 (or (assq 'server-buffer-clients minor-mode-alist)
190 (push '(server-buffer-clients " Server") minor-mode-alist))
192 (defvar server-existing-buffer nil
193 "Non-nil means the buffer existed before the server was asked to visit it.
194 This means that the server should not kill the buffer when you say you
195 are done with it in the server.")
196 (make-variable-buffer-local 'server-existing-buffer)
198 (defvar server-name "server")
200 (defvar server-socket-dir nil
201 "The directory in which to place the server socket.
202 Initialized by `server-start'.")
204 (defun server-clients-with (property value)
205 "Return a list of clients with PROPERTY set to VALUE."
206 (let (result)
207 (dolist (proc server-clients result)
208 (when (equal value (process-get proc property))
209 (push proc result)))))
211 (defun server-add-client (proc)
212 "Create a client for process PROC, if it doesn't already have one.
213 New clients have no properties."
214 (add-to-list 'server-clients proc))
216 (defmacro server-with-environment (env vars &rest body)
217 "Evaluate BODY with environment variables VARS set to those in ENV.
218 The environment variables are then restored to their previous values.
220 VARS should be a list of strings.
221 ENV should be in the same format as `process-environment'."
222 (declare (indent 2))
223 (let ((var (make-symbol "var"))
224 (value (make-symbol "value")))
225 `(let ((process-environment process-environment))
226 (dolist (,var ,vars)
227 (let ((,value (getenv-internal ,var ,env)))
228 (push (if (null ,value)
229 ,var
230 (concat ,var "=" ,value))
231 process-environment)))
232 (progn ,@body))))
234 (defun server-delete-client (proc &optional noframe)
235 "Delete CLIENT, including its buffers, terminals and frames.
236 If NOFRAME is non-nil, let the frames live. (To be used from
237 `delete-frame-functions'.)"
238 (server-log (concat "server-delete-client" (if noframe " noframe"))
239 proc)
240 ;; Force a new lookup of client (prevents infinite recursion).
241 (when (memq proc server-clients)
242 (let ((buffers (process-get proc 'buffers)))
244 ;; Kill the client's buffers.
245 (dolist (buf buffers)
246 (when (buffer-live-p buf)
247 (with-current-buffer buf
248 ;; Kill the buffer if necessary.
249 (when (and (equal server-buffer-clients
250 (list proc))
251 (or (and server-kill-new-buffers
252 (not server-existing-buffer))
253 (server-temp-file-p))
254 (not (buffer-modified-p)))
255 (let (flag)
256 (unwind-protect
257 (progn (setq server-buffer-clients nil)
258 (kill-buffer (current-buffer))
259 (setq flag t))
260 (unless flag
261 ;; Restore clients if user pressed C-g in `kill-buffer'.
262 (setq server-buffer-clients (list proc)))))))))
264 ;; Delete the client's frames.
265 (unless noframe
266 (dolist (frame (frame-list))
267 (when (and (frame-live-p frame)
268 (equal proc (frame-parameter frame 'client)))
269 ;; Prevent `server-handle-delete-frame' from calling us
270 ;; recursively.
271 (set-frame-parameter frame 'client nil)
272 (delete-frame frame))))
274 (setq server-clients (delq proc server-clients))
276 ;; Delete the client's tty.
277 (let ((terminal (process-get proc 'terminal)))
278 (when (eq (terminal-live-p terminal) t)
279 (delete-terminal terminal)))
281 ;; Delete the client's process.
282 (if (eq (process-status proc) 'open)
283 (delete-process proc))
285 (server-log "Deleted" proc))))
287 (defun server-log (string &optional client)
288 "If a *server* buffer exists, write STRING to it for logging purposes.
289 If CLIENT is non-nil, add a description of it to the logged
290 message."
291 (when (get-buffer "*server*")
292 (with-current-buffer "*server*"
293 (goto-char (point-max))
294 (insert (current-time-string)
295 (cond
296 ((null client) " ")
297 ((listp client) (format " %s: " (car client)))
298 (t (format " %s: " client)))
299 string)
300 (or (bolp) (newline)))))
302 (defun server-sentinel (proc msg)
303 "The process sentinel for Emacs server connections."
304 ;; If this is a new client process, set the query-on-exit flag to nil
305 ;; for this process (it isn't inherited from the server process).
306 (when (and (eq (process-status proc) 'open)
307 (process-query-on-exit-flag proc))
308 (set-process-query-on-exit-flag proc nil))
309 ;; Delete the associated connection file, if applicable.
310 ;; This is actually problematic: the file may have been overwritten by
311 ;; another Emacs server in the mean time, so it's not ours any more.
312 ;; (and (process-contact proc :server)
313 ;; (eq (process-status proc) 'closed)
314 ;; (ignore-errors (delete-file (process-get proc :server-file))))
315 (server-log (format "Status changed to %s: %s" (process-status proc) msg) proc)
316 (server-delete-client proc))
318 (defun server-select-display (display)
319 ;; If the current frame is on `display' we're all set.
320 (unless (equal (frame-parameter (selected-frame) 'display) display)
321 ;; Otherwise, look for an existing frame there and select it.
322 (dolist (frame (frame-list))
323 (when (equal (frame-parameter frame 'display) display)
324 (select-frame frame)))
325 ;; If there's no frame on that display yet, create and select one.
326 (unless (equal (frame-parameter (selected-frame) 'display) display)
327 (let* ((buffer (generate-new-buffer " *server-dummy*"))
328 (frame (make-frame-on-display
329 display
330 ;; Make it display (and remember) some dummy buffer, so
331 ;; we can detect later if the frame is in use or not.
332 `((server-dummmy-buffer . ,buffer)
333 ;; This frame may be deleted later (see
334 ;; server-unselect-display) so we want it to be as
335 ;; unobtrusive as possible.
336 (visibility . nil)))))
337 (select-frame frame)
338 (set-window-buffer (selected-window) buffer)
339 frame))))
341 (defun server-unselect-display (frame)
342 (when (frame-live-p frame)
343 ;; If the temporary frame is in use (displays something real), make it
344 ;; visible. If not (which can happen if the user's customizations call
345 ;; pop-to-buffer etc.), delete it to avoid preserving the connection after
346 ;; the last real frame is deleted.
347 (if (and (eq (frame-first-window frame)
348 (next-window (frame-first-window frame) 'nomini))
349 (eq (window-buffer (frame-first-window frame))
350 (frame-parameter frame 'server-dummy-buffer)))
351 ;; The temp frame still only shows one buffer, and that is the
352 ;; internal temp buffer.
353 (delete-frame frame)
354 (set-frame-parameter frame 'visibility t))
355 (kill-buffer (frame-parameter frame 'server-dummy-buffer))
356 (set-frame-parameter frame 'server-dummy-buffer nil)))
358 (defun server-handle-delete-frame (frame)
359 "Delete the client connection when the emacsclient frame is deleted."
360 (let ((proc (frame-parameter frame 'client)))
361 (when (and (frame-live-p frame)
362 proc
363 ;; See if this is the last frame for this client.
364 (>= 1 (let ((frame-num 0))
365 (dolist (f (frame-list))
366 (when (eq proc (frame-parameter f 'client))
367 (setq frame-num (1+ frame-num))))
368 frame-num)))
369 (server-log (format "server-handle-delete-frame, frame %s" frame) proc)
370 (server-delete-client proc 'noframe)))) ; Let delete-frame delete the frame later.
372 (defun server-handle-suspend-tty (terminal)
373 "Notify the emacsclient process to suspend itself when its tty device is suspended."
374 (dolist (proc (server-clients-with 'terminal terminal))
375 (server-log (format "server-handle-suspend-tty, terminal %s" terminal) proc)
376 (condition-case err
377 (server-send-string proc "-suspend \n")
378 (file-error ;The pipe/socket was closed.
379 (ignore-errors (server-delete-client proc))))))
381 (defun server-unquote-arg (arg)
382 "Remove &-quotation from ARG.
383 See `server-quote-arg' and `server-process-filter'."
384 (replace-regexp-in-string
385 "&." (lambda (s)
386 (case (aref s 1)
387 (?& "&")
388 (?- "-")
389 (?n "\n")
390 (t " ")))
391 arg t t))
393 (defun server-quote-arg (arg)
394 "In ARG, insert a & before each &, each space, each newline, and -.
395 Change spaces to underscores, too, so that the return value never
396 contains a space.
398 See `server-unquote-arg' and `server-process-filter'."
399 (replace-regexp-in-string
400 "[-&\n ]" (lambda (s)
401 (case (aref s 0)
402 (?& "&&")
403 (?- "&-")
404 (?\n "&n")
405 (?\s "&_")))
406 arg t t))
408 (defun server-send-string (proc string)
409 "A wrapper around `proc-send-string' for logging."
410 (server-log (concat "Sent " string) proc)
411 (process-send-string proc string))
413 (defun server-ensure-safe-dir (dir)
414 "Make sure DIR is a directory with no race-condition issues.
415 Creates the directory if necessary and makes sure:
416 - there's no symlink involved
417 - it's owned by us
418 - it's not readable/writable by anybody else."
419 (setq dir (directory-file-name dir))
420 (let ((attrs (file-attributes dir)))
421 (unless attrs
422 (letf (((default-file-modes) ?\700)) (make-directory dir t))
423 (setq attrs (file-attributes dir)))
424 ;; Check that it's safe for use.
425 (unless (and (eq t (car attrs)) (eql (nth 2 attrs) (user-uid))
426 (or (eq system-type 'windows-nt)
427 (zerop (logand ?\077 (file-modes dir)))))
428 (error "The directory %s is unsafe" dir))))
430 ;;;###autoload
431 (defun server-start (&optional leave-dead)
432 "Allow this Emacs process to be a server for client processes.
433 This starts a server communications subprocess through which
434 client \"editors\" can send your editing commands to this Emacs
435 job. To use the server, set up the program `emacsclient' in the
436 Emacs distribution as your standard \"editor\".
438 Optional argument LEAVE-DEAD (interactively, a prefix arg) means just
439 kill any existing server communications subprocess."
440 (interactive "P")
441 (when (or
442 (not server-clients)
443 (yes-or-no-p
444 "The current server still has clients; delete them? "))
445 ;; It is safe to get the user id now.
446 (setq server-socket-dir (or server-socket-dir
447 (format "/tmp/emacs%d" (user-uid))))
448 (when server-process
449 ;; kill it dead!
450 (ignore-errors (delete-process server-process)))
451 ;; Delete the socket files made by previous server invocations.
452 (condition-case ()
453 (delete-file (expand-file-name server-name server-socket-dir))
454 (error nil))
455 ;; If this Emacs already had a server, clear out associated status.
456 (while server-clients
457 (server-delete-client (car server-clients)))
458 ;; Now any previous server is properly stopped.
459 (if leave-dead
460 (progn
461 (server-log (message "Server stopped"))
462 (setq server-process nil))
463 (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir))
464 (server-file (expand-file-name server-name server-dir)))
465 ;; Make sure there is a safe directory in which to place the socket.
466 (server-ensure-safe-dir server-dir)
467 ;; Remove any leftover socket or authentication file.
468 (ignore-errors (delete-file server-file))
469 (when server-process
470 (server-log (message "Restarting server")))
471 (letf (((default-file-modes) ?\700))
472 (add-hook 'suspend-tty-functions 'server-handle-suspend-tty)
473 (add-hook 'delete-frame-functions 'server-handle-delete-frame)
474 (add-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
475 (add-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function)
476 (setq server-process
477 (apply #'make-network-process
478 :name server-name
479 :server t
480 :noquery t
481 :sentinel 'server-sentinel
482 :filter 'server-process-filter
483 ;; We must receive file names without being decoded.
484 ;; Those are decoded by server-process-filter according
485 ;; to file-name-coding-system.
486 :coding 'raw-text
487 ;; The rest of the args depends on the kind of socket used.
488 (if server-use-tcp
489 (list :family nil
490 :service t
491 :host (or server-host 'local)
492 :plist '(:authenticated nil))
493 (list :family 'local
494 :service server-file
495 :plist '(:authenticated t)))))
496 (unless server-process (error "Could not start server process"))
497 (when server-use-tcp
498 (let ((auth-key
499 (loop
500 ;; The auth key is a 64-byte string of random chars in the
501 ;; range `!'..`~'.
502 for i below 64
503 collect (+ 33 (random 94)) into auth
504 finally return (concat auth))))
505 (process-put server-process :auth-key auth-key)
506 (with-temp-file server-file
507 (set-buffer-multibyte nil)
508 (setq buffer-file-coding-system 'no-conversion)
509 (insert (format-network-address
510 (process-contact server-process :local))
511 " " (int-to-string (emacs-pid))
512 "\n" auth-key)))))))))
514 (defun server-running-p (&optional name)
515 "Test whether server NAME is running."
516 (interactive
517 (list (if current-prefix-arg
518 (read-string "Server name: " nil nil server-name))))
519 (unless name (setq name server-name))
520 (condition-case nil
521 (progn
522 (delete-process
523 (make-network-process
524 :name "server-client-test" :family 'local :server nil :noquery t
525 :service (expand-file-name name server-socket-dir)))
527 (file-error nil)))
529 ;;;###autoload
530 (define-minor-mode server-mode
531 "Toggle Server mode.
532 With ARG, turn Server mode on if ARG is positive, off otherwise.
533 Server mode runs a process that accepts commands from the
534 `emacsclient' program. See `server-start' and Info node `Emacs server'."
535 :global t
536 :group 'server
537 :version "22.1"
538 ;; Fixme: Should this check for an existing server socket and do
539 ;; nothing if there is one (for multiple Emacs sessions)?
540 (server-start (not server-mode)))
542 (defun server-eval-and-print (expr proc)
543 "Eval EXPR and send the result back to client PROC."
544 (let ((v (eval (car (read-from-string expr)))))
545 (when (and v proc)
546 (with-temp-buffer
547 (let ((standard-output (current-buffer)))
548 (pp v)
549 (let ((text (buffer-substring-no-properties
550 (point-min) (point-max))))
551 (server-send-string
552 proc (format "-print %s\n"
553 (server-quote-arg text)))))))))
555 (defun server-create-tty-frame (tty type proc)
556 (let ((frame
557 (server-with-environment (process-get proc 'env)
558 '("LANG" "LC_CTYPE" "LC_ALL"
559 ;; For tgetent(3); list according to ncurses(3).
560 "BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES"
561 "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING"
562 "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO"
563 "TERMINFO_DIRS" "TERMPATH"
564 ;; rxvt wants these
565 "COLORFGBG" "COLORTERM")
566 (make-frame-on-tty tty type
567 ;; Ignore nowait here; we always need to
568 ;; clean up opened ttys when the client dies.
569 `((client . ,proc)
570 (environment . ,(process-get proc 'env)))))))
572 ;; ttys don't use the `display' parameter, but callproc.c does to set
573 ;; the DISPLAY environment on subprocesses.
574 (set-frame-parameter frame 'display
575 (getenv-internal "DISPLAY" (process-get proc 'env)))
576 (select-frame frame)
577 (process-put proc 'frame frame)
578 (process-put proc 'terminal (frame-terminal frame))
580 ;; Display *scratch* by default.
581 (switch-to-buffer (get-buffer-create "*scratch*") 'norecord)
583 ;; Reply with our pid.
584 (server-send-string proc (concat "-emacs-pid "
585 (number-to-string (emacs-pid)) "\n"))
586 frame))
588 (defun server-create-window-system-frame (display nowait proc)
589 (if (not (fboundp 'make-frame-on-display))
590 (progn
591 ;; This emacs does not support X.
592 (server-log "Window system unsupported" proc)
593 (server-send-string proc "-window-system-unsupported \n")
594 nil)
595 ;; Flag frame as client-created, but use a dummy client.
596 ;; This will prevent the frame from being deleted when
597 ;; emacsclient quits while also preventing
598 ;; `server-save-buffers-kill-terminal' from unexpectedly
599 ;; killing emacs on that frame.
600 (let* ((params `((client . ,(if nowait 'nowait proc))
601 (environment . ,(process-get proc 'env))))
602 (frame (make-frame-on-display
603 (or display
604 (frame-parameter nil 'display)
605 (getenv "DISPLAY")
606 (error "Please specify display"))
607 params)))
608 (server-log (format "%s created" frame) proc)
609 ;; XXX We need to ensure the parameters are
610 ;; really set because Emacs forgets unhandled
611 ;; initialization parameters for X frames at
612 ;; the moment.
613 (modify-frame-parameters frame params)
614 (select-frame frame)
615 (process-put proc 'frame frame)
616 (process-put proc 'terminal (frame-terminal frame))
618 ;; Display *scratch* by default.
619 (switch-to-buffer (get-buffer-create "*scratch*") 'norecord)
620 frame)))
623 (defun server-goto-toplevel (proc)
624 (condition-case nil
625 ;; If we're running isearch, we must abort it to allow Emacs to
626 ;; display the buffer and switch to it.
627 (dolist (buffer (buffer-list))
628 (with-current-buffer buffer
629 (when (bound-and-true-p isearch-mode)
630 (isearch-cancel))))
631 ;; Signaled by isearch-cancel.
632 (quit (message nil)))
633 (when (> (recursion-depth) 0)
634 ;; We're inside a minibuffer already, so if the emacs-client is trying
635 ;; to open a frame on a new display, we might end up with an unusable
636 ;; frame because input from that display will be blocked (until exiting
637 ;; the minibuffer). Better exit this minibuffer right away.
638 ;; Similarly with recursive-edits such as the splash screen.
639 (run-with-timer 0 nil (lexical-let ((proc proc))
640 (lambda () (server-execute-continuation proc))))
641 (top-level)))
643 ;; We use various special properties on process objects:
644 ;; - `env' stores the info about the environment of the emacsclient process.
645 ;; - `continuation' is a no-arg function that we need to execute. It contains
646 ;; commands we wanted to execute in some earlier invocation of the process
647 ;; filter but that we somehow were unable to process at that time
648 ;; (e.g. because we first need to throw to the toplevel).
650 (defun server-execute-continuation (proc)
651 (let ((continuation (process-get proc 'continuation)))
652 (process-put proc 'continuation nil)
653 (if continuation (ignore-errors (funcall continuation)))))
655 (defun* server-process-filter (proc string)
656 "Process a request from the server to edit some files.
657 PROC is the server process. STRING consists of a sequence of
658 commands prefixed by a dash. Some commands have arguments; these
659 are &-quoted and need to be decoded by `server-unquote-arg'. The
660 filter parses and executes these commands.
662 To illustrate the protocol, here is an example command that
663 emacsclient sends to create a new X frame (note that the whole
664 sequence is sent on a single line):
666 -env HOME /home/lorentey
667 -env DISPLAY :0.0
668 ... lots of other -env commands
669 -display :0.0
670 -window-system
672 The following commands are accepted by the server:
674 `-auth AUTH-STRING'
675 Authenticate the client using the secret authentication string
676 AUTH-STRING.
678 `-env NAME=VALUE'
679 An environment variable on the client side.
681 `-dir DIRNAME'
682 The current working directory of the client process.
684 `-current-frame'
685 Forbid the creation of new frames.
687 `-nowait'
688 Request that the next frame created should not be
689 associated with this client.
691 `-display DISPLAY'
692 Set the display name to open X frames on.
694 `-position LINE[:COLUMN]'
695 Go to the given line and column number
696 in the next file opened.
698 `-file FILENAME'
699 Load the given file in the current frame.
701 `-eval EXPR'
702 Evaluate EXPR as a Lisp expression and return the
703 result in -print commands.
705 `-window-system'
706 Open a new X frame.
708 `-tty DEVICENAME TYPE'
709 Open a new tty frame at the client.
711 `-suspend'
712 Suspend this tty frame. The client sends this string in
713 response to SIGTSTP and SIGTTOU. The server must cease all I/O
714 on this tty until it gets a -resume command.
716 `-resume'
717 Resume this tty frame. The client sends this string when it
718 gets the SIGCONT signal and it is the foreground process on its
719 controlling tty.
721 `-ignore COMMENT'
722 Do nothing, but put the comment in the server
723 log. Useful for debugging.
726 The following commands are accepted by the client:
728 `-emacs-pid PID'
729 Describes the process id of the Emacs process;
730 used to forward window change signals to it.
732 `-window-system-unsupported'
733 Signals that the server does not
734 support creating X frames; the client must try again with a tty
735 frame.
737 `-print STRING'
738 Print STRING on stdout. Used to send values
739 returned by -eval.
741 `-error DESCRIPTION'
742 Signal an error (but continue processing).
744 `-suspend'
745 Suspend this terminal, i.e., stop the client process. Sent
746 when the user presses C-z."
747 (server-log (concat "Received " string) proc)
748 ;; First things first: let's check the authentication
749 (unless (process-get proc :authenticated)
750 (if (and (string-match "-auth \\(.*?\\)\n" string)
751 (equal (match-string 1 string) (process-get proc :auth-key)))
752 (progn
753 (setq string (substring string (match-end 0)))
754 (process-put proc :authenticated t)
755 (server-log "Authentication successful" proc))
756 (server-log "Authentication failed" proc)
757 (server-send-string
758 proc (concat "-error " (server-quote-arg "Authentication failed")))
759 (delete-process proc)
760 ;; We return immediately
761 (return-from server-process-filter)))
762 (let ((prev (process-get proc 'previous-string)))
763 (when prev
764 (setq string (concat prev string))
765 (process-put proc 'previous-string nil)))
766 (condition-case err
767 (progn
768 (server-add-client proc)
769 (if (not (string-match "\n" string))
770 ;; Save for later any partial line that remains.
771 (when (> (length string) 0)
772 (process-put proc 'previous-string string))
774 ;; In earlier versions of server.el (where we used an `emacsserver'
775 ;; process), there could be multiple lines. Nowadays this is not
776 ;; supported any more.
777 (assert (eq (match-end 0) (length string)))
778 (let ((request (substring string 0 (match-beginning 0)))
779 (coding-system (and default-enable-multibyte-characters
780 (or file-name-coding-system
781 default-file-name-coding-system)))
782 nowait ; t if emacsclient does not want to wait for us.
783 frame ; The frame that was opened for the client (if any).
784 display ; Open the frame on this display.
785 dontkill ; t if the client should not be killed.
786 (commands ())
788 (tty-name nil) ;nil, `window-system', or the tty name.
789 tty-type ;string.
790 (files nil)
791 (lineno 1)
792 (columnno 0))
793 ;; Remove this line from STRING.
794 (setq string (substring string (match-end 0)))
795 (while (string-match " *[^ ]* " request)
796 (let ((arg (substring request (match-beginning 0)
797 (1- (match-end 0)))))
798 (setq request (substring request (match-end 0)))
799 (cond
800 ;; -version CLIENT-VERSION: obsolete at birth.
801 ((and (equal "-version" arg) (string-match "[^ ]+ " request))
802 (setq request (substring request (match-end 0))))
804 ;; -nowait: Emacsclient won't wait for a result.
805 ((equal "-nowait" arg) (setq nowait t))
807 ;; -current-frame: Don't create frames.
808 ((equal "-current-frame" arg) (setq tty-name nil))
810 ;; -display DISPLAY:
811 ;; Open X frames on the given display instead of the default.
812 ((and (equal "-display" arg)
813 (string-match "\\([^ ]*\\) " request))
814 (setq display (match-string 1 request)
815 request (substring request (match-end 0))))
817 ;; -window-system: Open a new X frame.
818 ((equal "-window-system" arg)
819 (setq dontkill t)
820 (setq tty-name 'window-system))
822 ;; -resume: Resume a suspended tty frame.
823 ((equal "-resume" arg)
824 (lexical-let ((terminal (process-get proc 'terminal)))
825 (setq dontkill t)
826 (push (lambda ()
827 (when (eq (terminal-live-p terminal) t)
828 (resume-tty terminal)))
829 commands)))
831 ;; -suspend: Suspend the client's frame. (In case we
832 ;; get out of sync, and a C-z sends a SIGTSTP to
833 ;; emacsclient.)
834 ((equal "-suspend" arg)
835 (lexical-let ((terminal (process-get proc 'terminal)))
836 (setq dontkill t)
837 (push (lambda ()
838 (when (eq (terminal-live-p terminal) t)
839 (suspend-tty terminal)))
840 commands)))
842 ;; -ignore COMMENT: Noop; useful for debugging emacsclient.
843 ;; (The given comment appears in the server log.)
844 ((and (equal "-ignore" arg) (string-match "[^ ]* " request))
845 (setq dontkill t
846 request (substring request (match-end 0))))
848 ;; -tty DEVICE-NAME TYPE: Open a new tty frame at the client.
849 ((and (equal "-tty" arg)
850 (string-match "\\([^ ]*\\) \\([^ ]*\\) " request))
851 (setq tty-name (match-string 1 request))
852 (setq tty-type (match-string 2 request))
853 (setq dontkill t)
854 (setq request (substring request (match-end 0))))
856 ;; -position LINE[:COLUMN]: Set point to the given
857 ;; position in the next file.
858 ((and (equal "-position" arg)
859 (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)? "
860 request))
861 (setq lineno (string-to-number (match-string 1 request))
862 columnno (if (null (match-end 2)) 0
863 (string-to-number (match-string 2 request)))
864 request (substring request (match-end 0))))
866 ;; -file FILENAME: Load the given file.
867 ((and (equal "-file" arg)
868 (string-match "\\([^ ]+\\) " request))
869 (let ((file (server-unquote-arg (match-string 1 request))))
870 (setq request (substring request (match-end 0)))
871 (if coding-system
872 (setq file (decode-coding-string file coding-system)))
873 (setq file (command-line-normalize-file-name file))
874 (push (list file lineno columnno) files)
875 (server-log (format "New file: %s (%d:%d)"
876 file lineno columnno) proc))
877 (setq lineno 1
878 columnno 0))
880 ;; -eval EXPR: Evaluate a Lisp expression.
881 ((and (equal "-eval" arg)
882 (string-match "\\([^ ]+\\) " request))
883 (lexical-let ((expr (server-unquote-arg
884 (match-string 1 request))))
885 (setq request (substring request (match-end 0)))
886 (if coding-system
887 (setq expr (decode-coding-string expr coding-system)))
888 (push (lambda () (server-eval-and-print expr proc))
889 commands)
890 (setq lineno 1
891 columnno 0)))
893 ;; -env NAME=VALUE: An environment variable.
894 ((and (equal "-env" arg) (string-match "\\([^ ]+\\) " request))
895 (let ((var (server-unquote-arg (match-string 1 request))))
896 ;; XXX Variables should be encoded as in getenv/setenv.
897 (setq request (substring request (match-end 0)))
898 (process-put proc 'env
899 (cons var (process-get proc 'env)))))
901 ;; -dir DIRNAME: The cwd of the emacsclient process.
902 ((and (equal "-dir" arg) (string-match "\\([^ ]+\\) " request))
903 (setq dir (server-unquote-arg (match-string 1 request)))
904 (setq request (substring request (match-end 0)))
905 (if coding-system
906 (setq dir (decode-coding-string dir coding-system)))
907 (setq dir (command-line-normalize-file-name dir)))
909 ;; Unknown command.
910 (t (error "Unknown command: %s" arg)))))
912 (setq frame
913 (case tty-name
914 ((nil) (if display (server-select-display display)))
915 ((window-system)
916 (server-create-window-system-frame display nowait proc))
917 (t (server-create-tty-frame tty-name tty-type proc))))
919 (process-put proc 'continuation
920 (lexical-let ((proc proc)
921 (files files)
922 (nowait nowait)
923 (commands commands)
924 (dontkill dontkill)
925 (frame frame)
926 (tty-name tty-name))
927 (lambda ()
928 (server-execute proc files nowait commands
929 dontkill frame tty-name))))
931 (when (or frame files)
932 (server-goto-toplevel proc))
934 (server-execute-continuation proc))))
935 ;; condition-case
936 (error (server-return-error proc err))))
938 (defun server-execute (proc files nowait commands dontkill frame tty-name)
939 (condition-case err
940 (let* ((buffers
941 (when files
942 (run-hooks 'pre-command-hook)
943 (prog1 (server-visit-files files proc nowait)
944 (run-hooks 'post-command-hook)))))
946 (mapc 'funcall (nreverse commands))
948 ;; Delete the client if necessary.
949 (cond
950 (nowait
951 ;; Client requested nowait; return immediately.
952 (server-log "Close nowait client" proc)
953 (server-delete-client proc))
954 ((and (not dontkill) (null buffers))
955 ;; This client is empty; get rid of it immediately.
956 (server-log "Close empty client" proc)
957 (server-delete-client proc)))
958 (cond
959 ((or isearch-mode (minibufferp))
960 nil)
961 ((and frame (null buffers))
962 (message "%s" (substitute-command-keys
963 "When done with this frame, type \\[delete-frame]")))
964 ((not (null buffers))
965 (server-switch-buffer (car buffers))
966 (run-hooks 'server-switch-hook)
967 (unless nowait
968 (message "%s" (substitute-command-keys
969 "When done with a buffer, type \\[server-edit]")))))
970 (when (and frame (null tty-name))
971 (server-unselect-display frame)))
972 (error (server-return-error proc err))))
974 (defun server-return-error (proc err)
975 (ignore-errors
976 (server-send-string
977 proc (concat "-error " (server-quote-arg
978 (error-message-string err))))
979 (server-log (error-message-string err) proc)
980 (delete-process proc)))
982 (defun server-goto-line-column (file-line-col)
983 "Move point to the position indicated in FILE-LINE-COL.
984 FILE-LINE-COL should be a three-element list as described in
985 `server-visit-files'."
986 (goto-line (nth 1 file-line-col))
987 (let ((column-number (nth 2 file-line-col)))
988 (if (> column-number 0)
989 (move-to-column (1- column-number)))))
991 (defun server-visit-files (files proc &optional nowait)
992 "Find FILES and return a list of buffers created.
993 FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER).
994 PROC is the client that requested this operation.
995 NOWAIT non-nil means this client is not waiting for the results,
996 so don't mark these buffers specially, just visit them normally."
997 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries.
998 (let ((last-nonmenu-event t) client-record)
999 ;; Restore the current buffer afterward, but not using save-excursion,
1000 ;; because we don't want to save point in this buffer
1001 ;; if it happens to be one of those specified by the server.
1002 (save-current-buffer
1003 (dolist (file files)
1004 ;; If there is an existing buffer modified or the file is
1005 ;; modified, revert it. If there is an existing buffer with
1006 ;; deleted file, offer to write it.
1007 (let* ((minibuffer-auto-raise (or server-raise-frame
1008 minibuffer-auto-raise))
1009 (filen (car file))
1010 (obuf (get-file-buffer filen)))
1011 (add-to-history 'file-name-history filen)
1012 (if (and obuf (set-buffer obuf))
1013 (progn
1014 (cond ((file-exists-p filen)
1015 (when (not (verify-visited-file-modtime obuf))
1016 (revert-buffer t nil)))
1018 (when (y-or-n-p
1019 (concat "File no longer exists: " filen
1020 ", write buffer to file? "))
1021 (write-file filen))))
1022 (unless server-buffer-clients
1023 (setq server-existing-buffer t))
1024 (server-goto-line-column file))
1025 (set-buffer (find-file-noselect filen))
1026 (server-goto-line-column file)
1027 (run-hooks 'server-visit-hook)))
1028 (unless nowait
1029 ;; When the buffer is killed, inform the clients.
1030 (add-hook 'kill-buffer-hook 'server-kill-buffer nil t)
1031 (push proc server-buffer-clients))
1032 (push (current-buffer) client-record)))
1033 (unless nowait
1034 (process-put proc 'buffers
1035 (nconc (process-get proc 'buffers) client-record)))
1036 client-record))
1038 (defun server-buffer-done (buffer &optional for-killing)
1039 "Mark BUFFER as \"done\" for its client(s).
1040 This buries the buffer, then returns a list of the form (NEXT-BUFFER KILLED).
1041 NEXT-BUFFER is another server buffer, as a suggestion for what to select next,
1042 or nil. KILLED is t if we killed BUFFER (typically, because it was visiting
1043 a temp file).
1044 FOR-KILLING if non-nil indicates that we are called from `kill-buffer'."
1045 (let ((next-buffer nil)
1046 (killed nil))
1047 (dolist (proc server-clients)
1048 (let ((buffers (process-get proc 'buffers)))
1049 (or next-buffer
1050 (setq next-buffer (nth 1 (memq buffer buffers))))
1051 (when buffers ; Ignore bufferless clients.
1052 (setq buffers (delq buffer buffers))
1053 ;; Delete all dead buffers from PROC.
1054 (dolist (b buffers)
1055 (and (bufferp b)
1056 (not (buffer-live-p b))
1057 (setq buffers (delq b buffers))))
1058 (process-put proc 'buffers buffers)
1059 ;; If client now has no pending buffers,
1060 ;; tell it that it is done, and forget it entirely.
1061 (unless buffers
1062 (server-log "Close" proc)
1063 (server-delete-client proc)))))
1064 (when (and (bufferp buffer) (buffer-name buffer))
1065 ;; We may or may not kill this buffer;
1066 ;; if we do, do not call server-buffer-done recursively
1067 ;; from kill-buffer-hook.
1068 (let ((server-kill-buffer-running t))
1069 (with-current-buffer buffer
1070 (setq server-buffer-clients nil)
1071 (run-hooks 'server-done-hook))
1072 ;; Notice whether server-done-hook killed the buffer.
1073 (if (null (buffer-name buffer))
1074 (setq killed t)
1075 ;; Don't bother killing or burying the buffer
1076 ;; when we are called from kill-buffer.
1077 (unless for-killing
1078 (when (and (not killed)
1079 server-kill-new-buffers
1080 (with-current-buffer buffer
1081 (not server-existing-buffer)))
1082 (setq killed t)
1083 (bury-buffer buffer)
1084 (kill-buffer buffer))
1085 (unless killed
1086 (if (server-temp-file-p buffer)
1087 (progn
1088 (kill-buffer buffer)
1089 (setq killed t))
1090 (bury-buffer buffer)))))))
1091 (list next-buffer killed)))
1093 (defun server-temp-file-p (&optional buffer)
1094 "Return non-nil if BUFFER contains a file considered temporary.
1095 These are files whose names suggest they are repeatedly
1096 reused to pass information to another program.
1098 The variable `server-temp-file-regexp' controls which filenames
1099 are considered temporary."
1100 (and (buffer-file-name buffer)
1101 (string-match server-temp-file-regexp (buffer-file-name buffer))))
1103 (defun server-done ()
1104 "Offer to save current buffer, mark it as \"done\" for clients.
1105 This kills or buries the buffer, then returns a list
1106 of the form (NEXT-BUFFER KILLED). NEXT-BUFFER is another server buffer,
1107 as a suggestion for what to select next, or nil.
1108 KILLED is t if we killed BUFFER, which happens if it was created
1109 specifically for the clients and did not exist before their request for it."
1110 (when server-buffer-clients
1111 (if (server-temp-file-p)
1112 ;; For a temp file, save, and do make a non-numeric backup
1113 ;; (unless make-backup-files is nil).
1114 (let ((version-control nil)
1115 (buffer-backed-up nil))
1116 (save-buffer))
1117 (when (and (buffer-modified-p)
1118 buffer-file-name
1119 (y-or-n-p (concat "Save file " buffer-file-name "? ")))
1120 (save-buffer)))
1121 (server-buffer-done (current-buffer))))
1123 ;; Ask before killing a server buffer.
1124 ;; It was suggested to release its client instead,
1125 ;; but I think that is dangerous--the client would proceed
1126 ;; using whatever is on disk in that file. -- rms.
1127 (defun server-kill-buffer-query-function ()
1128 "Ask before killing a server buffer."
1129 (or (not server-buffer-clients)
1130 (let ((res t))
1131 (dolist (proc server-buffer-clients res)
1132 (when (and (memq proc server-clients)
1133 (eq (process-status proc) 'open))
1134 (setq res nil))))
1135 (yes-or-no-p (format "Buffer `%s' still has clients; kill it? "
1136 (buffer-name (current-buffer))))))
1138 (defun server-kill-emacs-query-function ()
1139 "Ask before exiting Emacs it has live clients."
1140 (or (not server-clients)
1141 (let (live-client)
1142 (dolist (proc server-clients live-client)
1143 (when (memq t (mapcar 'buffer-live-p (process-get
1144 proc 'buffers)))
1145 (setq live-client t))))
1146 (yes-or-no-p "This Emacs session has clients; exit anyway? ")))
1148 (defvar server-kill-buffer-running nil
1149 "Non-nil while `server-kill-buffer' or `server-buffer-done' is running.")
1151 (defun server-kill-buffer ()
1152 "Remove the current buffer from its clients' buffer list.
1153 Designed to be added to `kill-buffer-hook'."
1154 ;; Prevent infinite recursion if user has made server-done-hook
1155 ;; call kill-buffer.
1156 (or server-kill-buffer-running
1157 (and server-buffer-clients
1158 (let ((server-kill-buffer-running t))
1159 (when server-process
1160 (server-buffer-done (current-buffer) t))))))
1162 (defun server-edit (&optional arg)
1163 "Switch to next server editing buffer; say \"Done\" for current buffer.
1164 If a server buffer is current, it is marked \"done\" and optionally saved.
1165 The buffer is also killed if it did not exist before the clients asked for it.
1166 When all of a client's buffers are marked as \"done\", the client is notified.
1168 Temporary files such as MH <draft> files are always saved and backed up,
1169 no questions asked. (The variable `make-backup-files', if nil, still
1170 inhibits a backup; you can set it locally in a particular buffer to
1171 prevent a backup for it.) The variable `server-temp-file-regexp' controls
1172 which filenames are considered temporary.
1174 If invoked with a prefix argument, or if there is no server process running,
1175 starts server process and that is all. Invoked by \\[server-edit]."
1176 (interactive "P")
1177 (cond
1178 ((or arg
1179 (not server-process)
1180 (memq (process-status server-process) '(signal exit)))
1181 (server-mode 1))
1182 (server-clients (apply 'server-switch-buffer (server-done)))
1183 (t (message "No server editing buffers exist"))))
1185 (defun server-switch-buffer (&optional next-buffer killed-one)
1186 "Switch to another buffer, preferably one that has a client.
1187 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it.
1189 KILLED-ONE is t in a recursive call if we have already killed one
1190 temp-file server buffer. This means we should avoid the final
1191 \"switch to some other buffer\" since we've already effectively
1192 done that."
1193 (if (null next-buffer)
1194 (progn
1195 (let ((rest server-clients))
1196 (while (and rest (not next-buffer))
1197 (let ((proc (car rest)))
1198 ;; Only look at frameless clients.
1199 (when (not (process-get proc 'frame))
1200 (setq next-buffer (car (process-get proc 'buffers))))
1201 (setq rest (cdr rest)))))
1202 (and next-buffer (server-switch-buffer next-buffer killed-one))
1203 (unless (or next-buffer killed-one (window-dedicated-p (selected-window)))
1204 ;; (switch-to-buffer (other-buffer))
1205 (message "No server buffers remain to edit")))
1206 (if (not (buffer-live-p next-buffer))
1207 ;; If NEXT-BUFFER is a dead buffer, remove the server records for it
1208 ;; and try the next surviving server buffer.
1209 (apply 'server-switch-buffer (server-buffer-done next-buffer))
1210 ;; OK, we know next-buffer is live, let's display and select it.
1211 (if (functionp server-window)
1212 (funcall server-window next-buffer)
1213 (let ((win (get-buffer-window next-buffer 0)))
1214 (if (and win (not server-window))
1215 ;; The buffer is already displayed: just reuse the window.
1216 (progn
1217 (select-window win)
1218 (set-buffer next-buffer))
1219 ;; Otherwise, let's find an appropriate window.
1220 (cond ((window-live-p server-window)
1221 (select-window server-window))
1222 ((framep server-window)
1223 (unless (frame-live-p server-window)
1224 (setq server-window (make-frame)))
1225 (select-window (frame-selected-window server-window))))
1226 (when (window-minibuffer-p (selected-window))
1227 (select-window (next-window nil 'nomini 0)))
1228 ;; Move to a non-dedicated window, if we have one.
1229 (when (window-dedicated-p (selected-window))
1230 (select-window
1231 (get-window-with-predicate
1232 (lambda (w)
1233 (and (not (window-dedicated-p w))
1234 (equal (frame-terminal (window-frame w))
1235 (frame-terminal (selected-frame)))))
1236 'nomini 'visible (selected-window))))
1237 (condition-case nil
1238 (switch-to-buffer next-buffer)
1239 ;; After all the above, we might still have ended up with
1240 ;; a minibuffer/dedicated-window (if there's no other).
1241 (error (pop-to-buffer next-buffer)))))))
1242 (when server-raise-frame
1243 (select-frame-set-input-focus (window-frame (selected-window))))))
1245 ;;;###autoload
1246 (defun server-save-buffers-kill-terminal (proc &optional arg)
1247 "Offer to save each buffer, then kill PROC.
1249 With prefix arg, silently save all file-visiting buffers, then kill.
1251 If emacsclient was started with a list of filenames to edit, then
1252 only these files will be asked to be saved."
1253 (let ((buffers (process-get proc 'buffers)))
1254 ;; If client is bufferless, emulate a normal Emacs session
1255 ;; exit and offer to save all buffers. Otherwise, offer to
1256 ;; save only the buffers belonging to the client.
1257 (save-some-buffers arg
1258 (if buffers
1259 (lambda () (memq (current-buffer) buffers))
1261 (server-delete-client proc)))
1263 (define-key ctl-x-map "#" 'server-edit)
1265 (defun server-unload-hook ()
1266 "Unload the server library."
1267 (server-mode -1)
1268 (remove-hook 'suspend-tty-functions 'server-handle-suspend-tty)
1269 (remove-hook 'delete-frame-functions 'server-handle-delete-frame)
1270 (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
1271 (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function)
1272 (remove-hook 'kill-buffer-hook 'server-kill-buffer))
1274 (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit.
1275 (add-hook 'server-unload-hook 'server-unload-hook)
1277 (provide 'server)
1279 ;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6
1280 ;;; server.el ends here