changeset 10961:88cba63f2a9b

(server-buffer-done): Return a list (NEXT-BUFFER KILLED). KILLED is t if we killed the buffer. (server-edit): Values from server-done is now list of args for server-switch-buffer. (server-switch-buffer): Likewise. (server-switch-buffer): New optional arg KILLED-ONE. Avoid the other-buffer at the end in that case.
author Richard M. Stallman <rms@gnu.org>
date Sat, 11 Mar 1995 20:32:48 +0000
parents d6d3905ec550
children 7f0bc7bcf1f3
files lisp/server.el
diffstat 1 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/server.el	Sat Mar 11 20:17:37 1995 +0000
+++ b/lisp/server.el	Sat Mar 11 20:32:48 1995 +0000
@@ -240,10 +240,12 @@
 
 (defun server-buffer-done (buffer)
   "Mark BUFFER as \"done\" for its client(s).
-Buries the buffer, and returns another server buffer
-as a suggestion for what to select next."
+This buries the buffer, then returns a list of the form (NEXT-BUFFER KILLED).
+NEXT-BUFFER is another server buffer, as a suggestion for what to select next,
+or nil.  KILLED is t if we killed BUFFER (because it was a temp file)."
   (let ((running (eq (process-status server-process) 'run))
 	(next-buffer nil)
+	(killed nil)
 	(old-clients server-clients))
     (while old-clients
       (let ((client (car old-clients)))
@@ -277,9 +279,10 @@
 	    (setq server-buffer-clients nil)
 	    (run-hooks 'server-done-hook))
 	  (if (server-temp-file-p buffer)
-	      (kill-buffer buffer)
+	      (progn (kill-buffer buffer)
+		     (setq killed t))
 	    (bury-buffer buffer))))
-    next-buffer))
+    (list next-buffer killed)))
 
 (defun server-temp-file-p (buffer)
   "Return non-nil if BUFFER contains a file considered temporary.
@@ -293,7 +296,9 @@
 
 (defun server-done ()
   "Offer to save current buffer, mark it as \"done\" for clients.
-Then bury it, and return a suggested buffer to select next."
+This buries the buffer, then returns a list of the form (NEXT-BUFFER KILLED).
+NEXT-BUFFER is another server buffer, as a suggestion for what to select next,
+or nil.  KILLED is t if we killed the BUFFER (because it was a temp file)."
   (let ((buffer (current-buffer)))
     (if server-buffer-clients
 	(progn
@@ -351,11 +356,15 @@
 	  (not server-process)
 	  (memq (process-status server-process) '(signal exit)))
       (server-start nil)
-    (server-switch-buffer (server-done))))
+    (apply 'server-switch-buffer (server-done))))
 
-(defun server-switch-buffer (next-buffer)
+(defun server-switch-buffer (next-buffer &optional killed-one)
   "Switch to another buffer, preferably one that has a client.
 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it."
+  ;; KILLED-ONE is t in a recursive call
+  ;; if we have already killed one temp-file server buffer.
+  ;; This means we should avoid the final "switch to some other buffer"
+  ;; since we've already effectively done that.
   (cond ((and (windowp server-window)
 	      (window-live-p server-window))
 	 (select-window server-window))
@@ -378,11 +387,12 @@
 	;; If NEXT-BUFFER is a dead buffer,
 	;; remove the server records for it
 	;; and try the next surviving server buffer.
-	(server-switch-buffer
-	 (server-buffer-done next-buffer)))
+	(apply 'server-switch-buffer
+	       (server-buffer-done next-buffer)))
     (if server-clients
-	(server-switch-buffer (nth 1 (car server-clients)))
-      (switch-to-buffer (other-buffer)))))
+	(server-switch-buffer (nth 1 (car server-clients)) killed-one)
+      (if (not killed-one)
+	  (switch-to-buffer (other-buffer))))))
 
 (global-set-key "\C-x#" 'server-edit)