all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Max Mikhanosha <max@openchat.com>
To: emacs-devel@gnu.org
Subject: Buffer being killed not current in kill-buffer-hook
Date: Sat, 19 Jul 2008 16:29:25 -0400	[thread overview]
Message-ID: <8763r1obx6.wl%max@openchat.com> (raw)

When using multi-tty emacsclient, the following piece of code demostrates the problem:

DISPLAY is unset, CVS Emacs started with --no-init-file

(require 'server)
(progn (setq server-name "test")
       (server-start))
(defun print-current-buffer ()
  (message "current-buffer=%s" (current-buffer)))
(add-hook 'kill-buffer-hook 'print-current-buffer)

Now from a different screen session, connect with emacsclient like so:
"lib-src/emacsclient -c -s test foo". New tty frame will be created. 
Immeditely kill the buffer, it will ask "Buffer has existing clients"
say "yes". emacsclient will disconnect from a server.

In the *Messages* buffer on the server frame:

When done with a buffer, type C-x #
(No files need saving)
current-buffer=*scratch*

All the code that uses kill-buffer-hook rightfully assumes that the
buffer being killed will be current buffer when called, as that is
what is stated in the kill-buffer-hook documentation. For example
saveplace does not work because of this.

I had fixed this with the following patch, altho I don't know enough
about server.el logic to figure out if what it does is ok? Seems to
have fixed the bug and not broke anything else:

Index: lisp/server.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/server.el,v
retrieving revision 1.166
diff -u -b -r1.166 server.el
--- lisp/server.el	6 May 2008 07:57:49 -0000	1.166
+++ lisp/server.el	19 Jul 2008 20:28:26 -0000
@@ -1084,7 +1084,8 @@
 	  ;; tell it that it is done, and forget it entirely.
 	  (unless buffers
 	    (server-log "Close" proc)
-	    (server-delete-client proc)))))
+            (save-current-buffer 
+              (server-delete-client proc))))))
     (when (and (bufferp buffer) (buffer-name buffer))
       ;; We may or may not kill this buffer;
       ;; if we do, do not call server-buffer-done recursively





             reply	other threads:[~2008-07-19 20:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-19 20:29 Max Mikhanosha [this message]
2008-08-01 16:22 ` bug#640: Forward: Buffer being killed not current in kill-buffer-hook Max Mikhanosha
2008-09-24 20:20   ` bug#640: marked as done (Forward: Buffer being killed not current in kill-buffer-hook ) Emacs bug Tracking System

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=8763r1obx6.wl%max@openchat.com \
    --to=max@openchat.com \
    --cc=emacs-devel@gnu.org \
    /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.