Mercurial > emacs
comparison lisp/server.el @ 70672:06de67179ba1
(server-start): Only create a directory if needed.
(server-edit, server-unload-hook): server-start => server-mode.
(kill-emacs-hook): Cleanup upon exit.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 16 May 2006 06:53:01 +0000 |
parents | 718312081ce0 |
children | 59c8b05c2ce4 b6689e223e2f a5812696f7bf |
comparison
equal
deleted
inserted
replaced
70671:2dba1b0f2902 | 70672:06de67179ba1 |
---|---|
250 To use the server, set up the program `emacsclient' in the | 250 To use the server, set up the program `emacsclient' in the |
251 Emacs distribution as your standard \"editor\". | 251 Emacs distribution as your standard \"editor\". |
252 | 252 |
253 Prefix arg means just kill any existing server communications subprocess." | 253 Prefix arg means just kill any existing server communications subprocess." |
254 (interactive "P") | 254 (interactive "P") |
255 ;; Make sure there is a safe directory in which to place the socket. | |
256 (server-ensure-safe-dir server-socket-dir) | |
257 ;; kill it dead! | 255 ;; kill it dead! |
258 (if server-process | 256 (if server-process |
259 (condition-case () (delete-process server-process) (error nil))) | 257 (condition-case () (delete-process server-process) (error nil))) |
260 ;; Delete the socket files made by previous server invocations. | 258 ;; Delete the socket files made by previous server invocations. |
261 (condition-case () | 259 (condition-case () |
263 (error nil)) | 261 (error nil)) |
264 ;; If this Emacs already had a server, clear out associated status. | 262 ;; If this Emacs already had a server, clear out associated status. |
265 (while server-clients | 263 (while server-clients |
266 (let ((buffer (nth 1 (car server-clients)))) | 264 (let ((buffer (nth 1 (car server-clients)))) |
267 (server-buffer-done buffer))) | 265 (server-buffer-done buffer))) |
266 ;; Now any previous server is properly stopped. | |
268 (unless leave-dead | 267 (unless leave-dead |
268 ;; Make sure there is a safe directory in which to place the socket. | |
269 (server-ensure-safe-dir server-socket-dir) | |
269 (if server-process | 270 (if server-process |
270 (server-log (message "Restarting server"))) | 271 (server-log (message "Restarting server"))) |
271 (letf (((default-file-modes) ?\700)) | 272 (letf (((default-file-modes) ?\700)) |
272 (setq server-process | 273 (setq server-process |
273 (make-network-process | 274 (make-network-process |
576 starts server process and that is all. Invoked by \\[server-edit]." | 577 starts server process and that is all. Invoked by \\[server-edit]." |
577 (interactive "P") | 578 (interactive "P") |
578 (if (or arg | 579 (if (or arg |
579 (not server-process) | 580 (not server-process) |
580 (memq (process-status server-process) '(signal exit))) | 581 (memq (process-status server-process) '(signal exit))) |
581 (server-start nil) | 582 (server-mode 1) |
582 (apply 'server-switch-buffer (server-done)))) | 583 (apply 'server-switch-buffer (server-done)))) |
583 | 584 |
584 (defun server-switch-buffer (&optional next-buffer killed-one) | 585 (defun server-switch-buffer (&optional next-buffer killed-one) |
585 "Switch to another buffer, preferably one that has a client. | 586 "Switch to another buffer, preferably one that has a client. |
586 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it." | 587 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it." |
635 (error (pop-to-buffer next-buffer))))))))) | 636 (error (pop-to-buffer next-buffer))))))))) |
636 | 637 |
637 (define-key ctl-x-map "#" 'server-edit) | 638 (define-key ctl-x-map "#" 'server-edit) |
638 | 639 |
639 (defun server-unload-hook () | 640 (defun server-unload-hook () |
640 (server-start t) | 641 (server-mode -1) |
641 (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) | 642 (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) |
642 (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) | 643 (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) |
643 (remove-hook 'kill-buffer-hook 'server-kill-buffer)) | 644 (remove-hook 'kill-buffer-hook 'server-kill-buffer)) |
644 | 645 |
646 (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit. | |
645 (add-hook 'server-unload-hook 'server-unload-hook) | 647 (add-hook 'server-unload-hook 'server-unload-hook) |
646 | 648 |
647 (provide 'server) | 649 (provide 'server) |
648 | 650 |
649 ;;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6 | 651 ;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6 |
650 ;;; server.el ends here | 652 ;;; server.el ends here |