]> code.delx.au - gnu-emacs/blobdiff - lisp/server.el
Remove finished items.
[gnu-emacs] / lisp / server.el
index 43b2dc633894e6c2d1db1f80e8568b8e504514e6..266d9d7824fa52985984fd1aa311c671ac7e1837 100644 (file)
@@ -252,8 +252,6 @@ Emacs distribution as your standard \"editor\".
 
 Prefix arg means just kill any existing server communications subprocess."
   (interactive "P")
-  ;; Make sure there is a safe directory in which to place the socket.
-  (server-ensure-safe-dir server-socket-dir)
   ;; kill it dead!
   (if server-process
       (condition-case () (delete-process server-process) (error nil)))
@@ -265,7 +263,10 @@ Prefix arg means just kill any existing server communications subprocess."
   (while server-clients
     (let ((buffer (nth 1 (car server-clients))))
       (server-buffer-done buffer)))
+  ;; Now any previous server is properly stopped.
   (unless leave-dead
+    ;; Make sure there is a safe directory in which to place the socket.
+    (server-ensure-safe-dir server-socket-dir)
     (if server-process
        (server-log (message "Restarting server")))
     (letf (((default-file-modes) ?\700))
@@ -575,11 +576,13 @@ which filenames are considered temporary.
 If invoked with a prefix argument, or if there is no server process running,
 starts server process and that is all.  Invoked by \\[server-edit]."
   (interactive "P")
-  (if (or arg
-         (not server-process)
-         (memq (process-status server-process) '(signal exit)))
-      (server-start nil)
-    (apply 'server-switch-buffer (server-done))))
+  (cond
+   ((or arg
+       (not server-process)
+       (memq (process-status server-process) '(signal exit)))
+    (server-mode 1))
+   (server-clients (apply 'server-switch-buffer (server-done)))
+   (t (message "No server editing buffers exist"))))
 
 (defun server-switch-buffer (&optional next-buffer killed-one)
   "Switch to another buffer, preferably one that has a client.
@@ -637,14 +640,15 @@ Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it."
 (define-key ctl-x-map "#" 'server-edit)
 
 (defun server-unload-hook ()
-  (server-start t)
+  (server-mode -1)
   (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
   (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function)
   (remove-hook 'kill-buffer-hook 'server-kill-buffer))
 
+(add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit.
 (add-hook 'server-unload-hook 'server-unload-hook)
 \f
 (provide 'server)
 
-;;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6
+;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6
 ;;; server.el ends here