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: Sun, 7 Feb 2021 20:26:58 +0000 Message-ID: References: <87wnvkixrv.fsf@miha-pc> <874kinakv2.fsf@miha-pc> 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="40869"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: jakanakaevangeli Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Feb 07 21:28:12 2021 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 1l8qfC-000AVE-Gb for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Feb 2021 21:28:10 +0100 Original-Received: from localhost ([::1]:45798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8qfB-0003cg-II for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Feb 2021 15:28:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8qe9-00035U-Fo for emacs-devel@gnu.org; Sun, 07 Feb 2021 15:27:05 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:10356 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1l8qe5-0000Ig-QY for emacs-devel@gnu.org; Sun, 07 Feb 2021 15:27:05 -0500 Original-Received: (qmail 12903 invoked by uid 3782); 7 Feb 2021 20:26:59 -0000 Original-Received: from acm.muc.de (p4fe15177.dip0.t-ipconnect.de [79.225.81.119]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 07 Feb 2021 21:26:59 +0100 Original-Received: (qmail 11707 invoked by uid 1000); 7 Feb 2021 20:26:58 -0000 Content-Disposition: inline In-Reply-To: <874kinakv2.fsf@miha-pc> X-Submission-Agent: TMDA/1.3.x (Ph3nix) 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-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:264136 Archived-At: Hello jakanakaevangeli. Thank you indeed for all the testing you are doing. It is saving me a lot of hassle in the future. On Sun, Feb 07, 2021 at 17:44:17 +0100, jakanakaevangeli wrote: [ .... ] > > Could I ask you please to try out the following patch, which should be > > applied on top of yesterday's patch: > I tried it and everything works as expected, if we use C-g. The only > minor thing I noticed is with abort-recursive-edit (C-]). When executed > from a normal buffer, it does what its doc-string suggests. But when > executed from a non-innermost minibuffer, it exits multiple recursive > edits, just like abort-minibuffers. (This isn't surprising since it > calls Fthrow (Qexit, Qt) just like abort-minibuffers, only without > asking yes_or_no_p first.) This is not good. > This might actually be intended behaviour, depending on how you > interpret "this minibuffer input" from abort-recursive-edit's > doc-string. I spent some time boring into the doc string and the description in the Elisp manual. The only conclusion I could come to was that C-] is meant to abort EXACTLY ONE level. So I have tweaked the C sources once more and come up with the following patch. It should apply to the Emacs state after yesterday's patch. Please remove the patch from earlier today before you try to apply the new patch. Thanks! --- src/eval.c~ 2021-02-06 12:44:35.798096526 +0000 +++ src/eval.c 2021-02-07 20:07:13.793787769 +0000 @@ -1163,16 +1163,17 @@ FUNC should return a Lisp_Object. This is how catches are done from within C code. */ +/* MINIBUFFER_QUIT_LEVEL is to handle quitting from nested minibuffers by + throwing t to tag `exit'. + Value -1 means there is no (throw 'exit t) in progress; + 0 means the `throw' wasn't done from an active minibuffer; + N > 0 means the `throw' was done from the minibuffer at level N. */ +EMACS_INT minibuffer_quit_level = -1; + Lisp_Object internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object arg) { - /* MINIBUFFER_QUIT_LEVEL is to handle quitting from nested minibuffers by - throwing t to tag `exit'. - Value -1 means there is no (throw 'exit t) in progress; - 0 means the `throw' wasn't done from an active minibuffer; - N > 0 means the `throw' was done from the minibuffer at level N. */ - static EMACS_INT minibuffer_quit_level = -1; /* This structure is made part of the chain `catchlist'. */ struct handler *c = push_handler (tag, CATCHER); @@ -1192,16 +1193,14 @@ Lisp_Object val = handlerlist->val; clobbered_eassert (handlerlist == c); handlerlist = handlerlist->next; - if (EQ (tag, Qexit) && EQ (val, Qt)) + if (EQ (tag, Qexit) && EQ (val, Qt) && minibuffer_quit_level > 0) /* If we've thrown t to tag `exit' from within a minibuffer, we exit all minibuffers more deeply nested than the current one. */ { - if (minibuffer_quit_level == -1) - minibuffer_quit_level = this_minibuffer_depth (Qnil); - if (minibuf_level > minibuffer_quit_level - || command_loop_level - > minibuf_c_loop_level (minibuffer_quit_level)) + /* MINIBUFFER_QUIT_LEVEL == 0 -> not in minibuffer. */ + if (minibuf_level > minibuffer_quit_level + && !NILP (Fminibuffer_innermost_command_loop_p (Qnil))) Fthrow (Qexit, Qt); else minibuffer_quit_level = -1; --- src/minibuf.c~ 2021-02-06 15:04:58.878632379 +0000 +++ src/minibuf.c 2021-02-07 20:06:34.249789948 +0000 @@ -437,12 +437,17 @@ if (!minibuf_depth) error ("Not in a minibuffer"); + if (NILP (Fminibuffer_innermost_command_loop_p (Qnil))) + error ("Not in most nested command loop"); if (minibuf_depth < minibuf_level) { array[0] = fmt; array[1] = make_fixnum (minibuf_level - minibuf_depth + 1); if (!NILP (Fyes_or_no_p (Fformat (2, array)))) - Fthrow (Qexit, Qt); + { + minibuffer_quit_level = minibuf_depth; + Fthrow (Qexit, Qt); + } } else Fthrow (Qexit, Qt); --- src/lisp.h~ 2021-02-06 12:45:15.205094355 +0000 +++ src/lisp.h 2021-02-07 20:07:45.816786005 +0000 @@ -4090,6 +4090,7 @@ } /* Defined in eval.c. */ +extern EMACS_INT minibuffer_quit_level; extern Lisp_Object Vautoload_queue; extern Lisp_Object Vrun_hooks; extern Lisp_Object Vsignaling_function; -- Alan Mackenzie (Nuremberg, Germany).