comparison lisp/server.el @ 111449:132f2dfd549f

Merge from emacs-23
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 09 Nov 2010 15:07:10 -0500
parents b508dbb6fb11 83594fbec156
children 3655cc4062e4
comparison
equal deleted inserted replaced
111448:321fbae3e04d 111449:132f2dfd549f
496 t))) 496 t)))
497 (unless safe 497 (unless safe
498 (error "The directory `%s' is unsafe" dir))))) 498 (error "The directory `%s' is unsafe" dir)))))
499 499
500 ;;;###autoload 500 ;;;###autoload
501 (defun server-start (&optional leave-dead) 501 (defun server-start (&optional leave-dead inhibit-prompt)
502 "Allow this Emacs process to be a server for client processes. 502 "Allow this Emacs process to be a server for client processes.
503 This starts a server communications subprocess through which 503 This starts a server communications subprocess through which
504 client \"editors\" can send your editing commands to this Emacs 504 client \"editors\" can send your editing commands to this Emacs
505 job. To use the server, set up the program `emacsclient' in the 505 job. To use the server, set up the program `emacsclient' in the
506 Emacs distribution as your standard \"editor\". 506 Emacs distribution as your standard \"editor\".
507 507
508 Optional argument LEAVE-DEAD (interactively, a prefix arg) means just 508 Optional argument LEAVE-DEAD (interactively, a prefix arg) means just
509 kill any existing server communications subprocess. 509 kill any existing server communications subprocess.
510 510
511 If a server is already running, the server is not started. 511 If a server is already running, restart it. If clients are
512 running, ask the user for confirmation first, unless optional
513 argument INHIBIT-PROMPT is non-nil.
514
512 To force-start a server, do \\[server-force-delete] and then 515 To force-start a server, do \\[server-force-delete] and then
513 \\[server-start]." 516 \\[server-start]."
514 (interactive "P") 517 (interactive "P")
515 (when (or (not server-clients) 518 (when (or (not server-clients)
516 ;; Ask the user before deleting existing clients---except 519 ;; Ask the user before deleting existing clients---except
517 ;; when we can't get user input, which may happen when 520 ;; when we can't get user input, which may happen when
518 ;; doing emacsclient --eval "(kill-emacs)" in daemon mode. 521 ;; doing emacsclient --eval "(kill-emacs)" in daemon mode.
519 (if (and (daemonp) 522 (cond
520 (null (cdr (frame-list))) 523 ((and (daemonp)
521 (eq (selected-frame) terminal-frame)) 524 (null (cdr (frame-list)))
522 leave-dead 525 (eq (selected-frame) terminal-frame))
523 (yes-or-no-p 526 leave-dead)
524 "The current server still has clients; delete them? "))) 527 (inhibit-prompt t)
528 (t (yes-or-no-p
529 "The current server still has clients; delete them? "))))
525 (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir)) 530 (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir))
526 (server-file (expand-file-name server-name server-dir))) 531 (server-file (expand-file-name server-name server-dir)))
527 (when server-process 532 (when server-process
528 ;; kill it dead! 533 ;; kill it dead!
529 (ignore-errors (delete-process server-process))) 534 (ignore-errors (delete-process server-process)))
558 (letf (((default-file-modes) ?\700)) 563 (letf (((default-file-modes) ?\700))
559 (add-hook 'suspend-tty-functions 'server-handle-suspend-tty) 564 (add-hook 'suspend-tty-functions 'server-handle-suspend-tty)
560 (add-hook 'delete-frame-functions 'server-handle-delete-frame) 565 (add-hook 'delete-frame-functions 'server-handle-delete-frame)
561 (add-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) 566 (add-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
562 (add-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) 567 (add-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function)
563 (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit. 568 (add-hook 'kill-emacs-hook 'server-force-stop) ;Cleanup upon exit.
564 (setq server-process 569 (setq server-process
565 (apply #'make-network-process 570 (apply #'make-network-process
566 :name server-name 571 :name server-name
567 :server t 572 :server t
568 :noquery t 573 :noquery t
598 (setq buffer-file-coding-system 'no-conversion) 603 (setq buffer-file-coding-system 'no-conversion)
599 (insert (format-network-address 604 (insert (format-network-address
600 (process-contact server-process :local)) 605 (process-contact server-process :local))
601 " " (number-to-string (emacs-pid)) ; Kept for compatibility 606 " " (number-to-string (emacs-pid)) ; Kept for compatibility
602 "\n" auth-key))))))))) 607 "\n" auth-key)))))))))
608
609 (defun server-force-stop ()
610 "Kill all connections to the current server.
611 This function is meant to be called from `kill-emacs-hook'."
612 (server-start nil t))
603 613
604 ;;;###autoload 614 ;;;###autoload
605 (defun server-force-delete (&optional name) 615 (defun server-force-delete (&optional name)
606 "Unconditionally delete connection file for server NAME. 616 "Unconditionally delete connection file for server NAME.
607 If server is running, it is first stopped. 617 If server is running, it is first stopped.