From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Stop frames stealing eachothers' minibuffers! Date: Tue, 3 Nov 2020 21:08:53 +0000 Message-ID: <20201103210853.GA21923@ACM> References: <20201031161422.GA5887@ACM> <83d00ygx9c.fsf@gnu.org> <20201031194419.GC5887@ACM> <834kmago8m.fsf@gnu.org> <20201031203914.GD5887@ACM> <835z6ogc1h.fsf@gnu.org> <20201101195313.GA6190@ACM> <83sg9rd6cp.fsf@gnu.org> <20201102185147.GC7297@ACM> <83mtzzd0s3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22863"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 03 22:10:40 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ka3Zg-0005qN-6l for ged-emacs-devel@m.gmane-mx.org; Tue, 03 Nov 2020 22:10:40 +0100 Original-Received: from localhost ([::1]:33676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka3Zf-0007gs-6J for ged-emacs-devel@m.gmane-mx.org; Tue, 03 Nov 2020 16:10:39 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka3Y6-0006Eo-B2 for emacs-devel@gnu.org; Tue, 03 Nov 2020 16:09:02 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:63125 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1ka3Y3-0003l5-Or for emacs-devel@gnu.org; Tue, 03 Nov 2020 16:09:01 -0500 Original-Received: (qmail 7366 invoked by uid 3782); 3 Nov 2020 21:08:55 -0000 Original-Received: from acm.muc.de (p4fe159c8.dip0.t-ipconnect.de [79.225.89.200]) by localhost.muc.de (tmda-ofmipd) with ESMTP; Tue, 03 Nov 2020 22:08:55 +0100 Original-Received: (qmail 23148 invoked by uid 1000); 3 Nov 2020 21:08:53 -0000 Content-Disposition: inline In-Reply-To: <83mtzzd0s3.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 16:08:56 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:258663 Archived-At: Hello, Eli. On Mon, Nov 02, 2020 at 21:19:40 +0200, Eli Zaretskii wrote: > > Date: Mon, 2 Nov 2020 18:51:47 +0000 > > Cc: emacs-devel@gnu.org > > From: Alan Mackenzie > > Please just use the guts of Fminibufferp; the tests it does on its > > > argument are not needed here. > > Sorry, I can't follow you, here. What do you mean by "the guts" of > > Fminibufferp? What things do you mean that the word "just" should > > exclude? > I meant to exclude these tests that Fminibufferp does: > if (NILP (buffer)) > buffer = Fcurrent_buffer (); > else if (STRINGP (buffer)) > buffer = Fget_buffer (buffer); > else > CHECK_BUFFER (buffer); OK, I've extracted a new function `live_minibuffer_p' from Fminibufferp, and call that directly from the mini-window emptying code. (The new second parameter in Fminibufferp is still needed, since it is used in minibuffer.el.) Here's a patch of the subset of changes to minibuf.c which are relevant to our discussions of the last two or three days. Perhaps we are close to the stage when this could be committed to master. diff --git a/src/minibuf.c b/src/minibuf.c index f957b2ae17..ebc00ae4e4 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -261,15 +302,31 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag, return val; } +/* Return true when BUFFER is an active minibuffer. */ +static bool +live_minibuffer_p (Lisp_Object buffer) +{ + Lisp_Object tem; + EMACS_INT i; + + if (EQ (buffer, Fcar (Vminibuffer_list))) + /* *Minibuf-0* is never active. */ + return false; + tem = Fcdr (Vminibuffer_list); + for (i = 1; i <= minibuf_level; i++, tem = Fcdr (tem)) + if (EQ (Fcar (tem), buffer)) + return true; + return false; +} + DEFUN ("minibufferp", Fminibufferp, - Sminibufferp, 0, 1, 0, + Sminibufferp, 0, 2, 0, doc: /* Return t if BUFFER is a minibuffer. No argument or nil as argument means use current buffer as BUFFER. -BUFFER can be a buffer or a buffer name. */) - (Lisp_Object buffer) +BUFFER can be a buffer or a buffer name. If LIVE is non-nil, then +return t only if BUFFER is an active minibuffer. */) + (Lisp_Object buffer, Lisp_Object live) { - Lisp_Object tem; - if (NILP (buffer)) buffer = Fcurrent_buffer (); else if (STRINGP (buffer)) @@ -277,8 +334,10 @@ BUFFER can be a buffer or a buffer name. */) else CHECK_BUFFER (buffer); - tem = Fmemq (buffer, Vminibuffer_list); - return ! NILP (tem) ? Qt : Qnil; + return (NILP (live) + ? !NILP (Fmemq (buffer, Vminibuffer_list)) + : live_minibuffer_p (buffer)) + ? Qt : Qnil; } DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end, @@ -566,8 +626,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, if (minibuf_level == 1 || !EQ (minibuf_window, selected_window)) minibuf_selected_window = selected_window; - /* Empty out the minibuffers of all frames other than the one - where we are going to display one now. + /* Empty out the minibuffers of all frames, except those frames + where there is an active minibuffer. Set them to point to ` *Minibuf-0*', which is always empty. */ empty_minibuf = get_minibuffer (0); @@ -575,12 +635,17 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, { Lisp_Object root_window = Fframe_root_window (frame); Lisp_Object mini_window = XWINDOW (root_window)->next; + Lisp_Object buffer; - if (! NILP (mini_window) && ! EQ (mini_window, minibuf_window) - && !NILP (Fwindow_minibuffer_p (mini_window))) - /* Use set_window_buffer instead of Fset_window_buffer (see - discussion of bug#11984, bug#12025, bug#12026). */ - set_window_buffer (mini_window, empty_minibuf, 0, 0); + if (!NILP (mini_window) && !EQ (mini_window, minibuf_window) + && !NILP (Fwindow_minibuffer_p (mini_window))) + { + buffer = XWINDOW (mini_window)->contents; + if (!live_minibuffer_p (buffer)) + /* Use set_window_buffer instead of Fset_window_buffer (see + discussion of bug#11984, bug#12025, bug#12026). */ + set_window_buffer (mini_window, empty_minibuf, 0, 0); + } } /* Display this minibuffer in the proper window. */ -- Alan Mackenzie (Nuremberg, Germany).