From e0cec396b528f8c64aeb6189483eaf851afc245e Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 8 Oct 2009 22:30:44 +0200 Subject: [PATCH] Notify threads when a buffer is killed. --- src/buffer.c | 8 +------- src/thread.c | 31 +++++++++++++++++++++++++++++++ src/thread.h | 2 ++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 939d28e6210..7be468f4b90 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1516,13 +1516,7 @@ with SIGHUP. */) /* Make this buffer not be current. In the process, notice if this is the sole visible buffer and give up if so. */ - if (b == current_buffer) - { - tem = Fother_buffer (buffer, Qnil, Qnil); - Fset_buffer (tem); - if (b == current_buffer) - return Qnil; - } + thread_notify_kill_buffer (b); /* Notice if the buffer to kill is the sole visible buffer when we're currently in the mini-buffer, and give up if so. */ diff --git a/src/thread.c b/src/thread.c index 9cfa19fbbaa..6663c369d1f 100644 --- a/src/thread.c +++ b/src/thread.c @@ -460,6 +460,37 @@ other_threads_p (void) return avail > 1; } +Lisp_Object +thread_notify_kill_buffer (register struct buffer *b) +{ + register Lisp_Object tem; + struct thread_state *it = all_threads; + for (; it; it = it->next_thread) + { + if (b == it->desired_buffer) + { + register Lisp_Object buf; + XSETBUFFER (buf, it->desired_buffer); + tem = Fother_buffer (buf, Qnil, Qnil); + it->desired_buffer = XBUFFER (tem); + if (b == it->desired_buffer) + return Qnil; + } + + if (b == it->m_current_buffer) + { + register Lisp_Object buf; + XSETBUFFER (buf, it->m_current_buffer); + tem = Fother_buffer (buf, Qnil, Qnil); + it->m_current_buffer = XBUFFER (tem); + if (b == it->m_current_buffer) + return Qnil; + } + } + + return Qt; +} + void init_threads_once (void) { diff --git a/src/thread.h b/src/thread.h index 423944fe653..f9495893d5f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -147,3 +147,5 @@ EXFUN (Finhibit_yield, 1); extern int thread_inhibit_yield_p P_ ((void)); extern void thread_acquire_buffer (char *, void *); + +extern Lisp_Object thread_notify_kill_buffer (register struct buffer *b); -- 2.39.5