aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2023-08-19 10:34:07 +0300
committerEli Zaretskii2023-08-19 10:34:07 +0300
commite3207b13ce5acbae89441e06c19ae4df7988004e (patch)
treee78b519e499cd056ad735ed001e24797579c2612
parentb12ce748d1a6bcb84667097012eae4c2d249ba00 (diff)
downloademacs-e3207b13ce5acbae89441e06c19ae4df7988004e.tar.gz
emacs-e3207b13ce5acbae89441e06c19ae4df7988004e.zip
Fix behavior of client frames when 'find-alternate-file' is used
* lisp/files.el (find-alternate-file-dont-kill-client): New var. (find-alternate-file): Bind it to a special value when invoking kill-buffer-hook. * lisp/server.el (server-delete-client): If NOFRAME is 'dont-kill-client', don't kill the client and its terminals. (server-buffer-done): Pass 'find-alternate-file-dont-kill-client' to 'server-delete-client'. (Bug#65277)
-rw-r--r--lisp/files.el5
-rw-r--r--lisp/server.el23
2 files changed, 20 insertions, 8 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 68c0a10792d..3466a53d165 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1998,6 +1998,8 @@ INHIBIT-BUFFER-HOOKS non-nil.
1998Note: Be careful with let-binding this hook considering it is 1998Note: Be careful with let-binding this hook considering it is
1999frequently used for cleanup.") 1999frequently used for cleanup.")
2000 2000
2001(defvar find-alternate-file-dont-kill-client nil
2002 "If non-nil, `server-buffer-done' should not delete the client.")
2001(defun find-alternate-file (filename &optional wildcards) 2003(defun find-alternate-file (filename &optional wildcards)
2002 "Find file FILENAME, select its buffer, kill previous buffer. 2004 "Find file FILENAME, select its buffer, kill previous buffer.
2003If the current buffer now contains an empty file that you just visited 2005If the current buffer now contains an empty file that you just visited
@@ -2044,7 +2046,8 @@ killed."
2044 ;; save a modified buffer visiting a file. Rather, `kill-buffer' 2046 ;; save a modified buffer visiting a file. Rather, `kill-buffer'
2045 ;; asks that itself. Thus, there's no need to temporarily do 2047 ;; asks that itself. Thus, there's no need to temporarily do
2046 ;; `(set-buffer-modified-p nil)' before running this hook. 2048 ;; `(set-buffer-modified-p nil)' before running this hook.
2047 (run-hooks 'kill-buffer-hook) 2049 (let ((find-alternate-file-dont-kill-client 'dont-kill-client))
2050 (run-hooks 'kill-buffer-hook))
2048 ;; Okay, now we can end-of-life the old buffer. 2051 ;; Okay, now we can end-of-life the old buffer.
2049 (if (get-buffer " **lose**") 2052 (if (get-buffer " **lose**")
2050 (kill-buffer " **lose**")) 2053 (kill-buffer " **lose**"))
diff --git a/lisp/server.el b/lisp/server.el
index ba7e02d2555..10f15598221 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -330,6 +330,9 @@ ENV should be in the same format as `process-environment'."
330(defun server-delete-client (proc &optional noframe) 330(defun server-delete-client (proc &optional noframe)
331 "Delete PROC, including its buffers, terminals and frames. 331 "Delete PROC, including its buffers, terminals and frames.
332If NOFRAME is non-nil, let the frames live. 332If NOFRAME is non-nil, let the frames live.
333If NOFRAME is the symbol \\='dont-kill-client, also don't
334delete PROC or its terminals, just kill its buffers: this is
335for when `find-alternate-file' calls this via `kill-buffer-hook'.
333Updates `server-clients'." 336Updates `server-clients'."
334 (server-log (concat "server-delete-client" (if noframe " noframe")) proc) 337 (server-log (concat "server-delete-client" (if noframe " noframe")) proc)
335 ;; Force a new lookup of client (prevents infinite recursion). 338 ;; Force a new lookup of client (prevents infinite recursion).
@@ -366,23 +369,28 @@ Updates `server-clients'."
366 (set-frame-parameter frame 'client nil) 369 (set-frame-parameter frame 'client nil)
367 (delete-frame frame)))) 370 (delete-frame frame))))
368 371
369 (setq server-clients (delq proc server-clients)) 372 (or (eq noframe 'dont-kill-client)
373 (setq server-clients (delq proc server-clients)))
370 374
371 ;; Delete the client's tty, except on Windows (both GUI and 375 ;; Delete the client's tty, except on Windows (both GUI and
372 ;; console), where there's only one terminal and does not make 376 ;; console), where there's only one terminal and does not make
373 ;; sense to delete it, or if we are explicitly told not. 377 ;; sense to delete it, or if we are explicitly told not.
374 (unless (or (eq system-type 'windows-nt) 378 (unless (or (eq system-type 'windows-nt)
379 ;; 'find-alternate-file' caused the last client
380 ;; buffer to be killed, but we will reuse the client
381 ;; for another buffer.
382 (eq noframe 'dont-kill-client)
375 (process-get proc 'no-delete-terminal)) 383 (process-get proc 'no-delete-terminal))
376 (let ((terminal (process-get proc 'terminal))) 384 (let ((terminal (process-get proc 'terminal)))
377 ;; Only delete the terminal if it is non-nil. 385 ;; Only delete the terminal if it is non-nil.
378 (when (and terminal (eq (terminal-live-p terminal) t)) 386 (when (and terminal (eq (terminal-live-p terminal) t))
379 (delete-terminal terminal)))) 387 (delete-terminal terminal))))
380 388
381 ;; Delete the client's process. 389 ;; Delete the client's process (or don't).
382 (if (eq (process-status proc) 'open) 390 (unless (eq noframe 'dont-kill-client)
383 (delete-process proc)) 391 (if (eq (process-status proc) 'open)
384 392 (delete-process proc))
385 (server-log "Deleted" proc)))) 393 (server-log "Deleted" proc)))))
386 394
387(defvar server-log-time-function #'current-time-string 395(defvar server-log-time-function #'current-time-string
388 "Function to generate timestamps for `server-buffer'.") 396 "Function to generate timestamps for `server-buffer'.")
@@ -1590,7 +1598,8 @@ FOR-KILLING if non-nil indicates that we are called from `kill-buffer'."
1590 ;; frames, which might change the current buffer. We 1598 ;; frames, which might change the current buffer. We
1591 ;; don't want that (bug#640). 1599 ;; don't want that (bug#640).
1592 (save-current-buffer 1600 (save-current-buffer
1593 (server-delete-client proc)) 1601 (server-delete-client proc
1602 find-alternate-file-dont-kill-client))
1594 (server-delete-client proc)))))) 1603 (server-delete-client proc))))))
1595 (when (and (bufferp buffer) (buffer-name buffer)) 1604 (when (and (bufferp buffer) (buffer-name buffer))
1596 ;; We may or may not kill this buffer; 1605 ;; We may or may not kill this buffer;