all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Maxim Kim <habamax@gmail.com>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, 65277@debbugs.gnu.org
Subject: bug#65277: 29.1.50; emacsclient Dired: frame is closed/killed when opening another dir
Date: Mon, 14 Aug 2023 16:37:10 +0300	[thread overview]
Message-ID: <83a5utbv95.fsf@gnu.org> (raw)
In-Reply-To: <87350mpkho.fsf@gmail.com> (message from Maxim Kim on Mon, 14 Aug 2023 09:53:39 +1000)

> From: Maxim Kim <habamax@gmail.com>
> Date: Mon, 14 Aug 2023 09:53:39 +1000
> 
> 
> 1. Create one line ~/.emacs file with
> 
>    (setq dired-kill-when-opening-new-dired-buffer t)
> 
> 2. Run `emacsclient -t -a "" .` to see a dired buffer for a current
> working directory.
> 
> 3. Navigate to a directory and press RET to open it.
> 
> Emacs frame is closed. Not sure if this is known/expected behavior.

There's a more general problem here: any call to find-alternate-file
in the client frame will delete the frame:

  emacs -Q
  M-x server-start

From the shell:

  emacsclient -c SOME-FILE

In the newly-created frame:

  C-x C-v SOME-OTHER-FILE RET

Boom! the frame is deleted.

The patch below should fix that by preventing the frame from being
deleted, but it still deletes the client, so emacsclient exits, and
the client frame no longer has a server.

Does anyone see a problem with the behavior after the patch below is
installed, i.e. with the fact that emacsclient exits?

diff --git a/lisp/files.el b/lisp/files.el
index 03675a3..001a195 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1998,6 +1998,8 @@ kill-buffer-hook
 Note: Be careful with let-binding this hook considering it is
 frequently used for cleanup.")
 
+(defvar find-alternate-file-dont-kill-client nil
+  "If non-nil, `server-buffer-done' should not delete the client frame.")
 (defun find-alternate-file (filename &optional wildcards)
   "Find file FILENAME, select its buffer, kill previous buffer.
 If the current buffer now contains an empty file that you just visited
@@ -2044,7 +2046,8 @@ find-alternate-file
     ;; save a modified buffer visiting a file.  Rather, `kill-buffer'
     ;; asks that itself.  Thus, there's no need to temporarily do
     ;; `(set-buffer-modified-p nil)' before running this hook.
-    (run-hooks 'kill-buffer-hook)
+    (let ((find-alternate-file-dont-kill-client t))
+      (run-hooks 'kill-buffer-hook))
     ;; Okay, now we can end-of-life the old buffer.
     (if (get-buffer " **lose**")
 	(kill-buffer " **lose**"))
diff --git a/lisp/server.el b/lisp/server.el
index ba7e02d..c678924 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1590,7 +1590,8 @@ server-buffer-done
 		;; frames, which might change the current buffer.  We
 		;; don't want that (bug#640).
 		(save-current-buffer
-		  (server-delete-client proc))
+		  (server-delete-client proc
+                                        find-alternate-file-dont-kill-client))
 	      (server-delete-client proc))))))
     (when (and (bufferp buffer) (buffer-name buffer))
       ;; We may or may not kill this buffer;





  reply	other threads:[~2023-08-14 13:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-13 23:53 bug#65277: 29.1.50; emacsclient Dired: frame is closed/killed when opening another dir Maxim Kim
2023-08-14 13:37 ` Eli Zaretskii [this message]
2023-08-16  2:22 ` brickviking
2023-08-16  6:37 ` brickviking
2023-08-17  9:44   ` Eli Zaretskii
2023-08-17 19:02     ` Eli Zaretskii
2023-08-18  7:42       ` Eli Zaretskii
     [not found]         ` <CAHWye84OVBfhF+PX7Y9eAWPW=m46TRHHXfp40dKTe4zRGvPsRw@mail.gmail.com>
2023-08-18  8:41           ` bug#65277: Fwd: " brickviking
     [not found]           ` <CAHWye86Vmme-S60+aMgX9aDv9eOd+UX45sCrhPWfS3jiMvqvmw@mail.gmail.com>
2023-08-18  8:42             ` brickviking
2023-08-18 12:10             ` Eli Zaretskii
2023-08-19  0:51               ` brickviking
2023-08-19  7:36                 ` Eli Zaretskii
2023-08-28  1:09                   ` brickviking
2023-08-28 12:21                     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83a5utbv95.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=65277@debbugs.gnu.org \
    --cc=habamax@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.