From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] On the nasty "ghost key" problem on NS Date: Sat, 05 Nov 2022 08:43:02 +0800 Message-ID: <87cza2b59l.fsf@yahoo.com> References: <87leord0ei.fsf@yahoo.com> <87h6zfchpu.fsf@yahoo.com> <394D8618-AF36-44C4-BA64-7AFDFBBDC429@gmail.com> <878rkrcbkx.fsf@yahoo.com> <87sfizaria.fsf@yahoo.com> <87k04ac3s6.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40637"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Kai Ma , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 05 01:43:57 2022 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 1or7Hw-000APq-PD for ged-emacs-devel@m.gmane-mx.org; Sat, 05 Nov 2022 01:43:57 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1or7HK-0000Pu-UR; Fri, 04 Nov 2022 20:43:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1or7HJ-0000Pi-6W for emacs-devel@gnu.org; Fri, 04 Nov 2022 20:43:17 -0400 Original-Received: from sonic305-22.consmr.mail.ne1.yahoo.com ([66.163.185.148]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1or7HH-0001lO-0y for emacs-devel@gnu.org; Fri, 04 Nov 2022 20:43:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1667608990; bh=BqTmB8dop7bgh/baOZNami9XqZdlyfkMBsa2q6tCm20=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=D0lO9+wqV5oGvNHtuRfuvWvGypBl+eDi4zVVaMraYa8enJoKwH/HlXqNnMme6mRuDzKYLeuDH+Md30Kj86le7jO2wTzv7b/Q0I8s1QtwqBdL4/1cJeayLCqBJqsCmrdnMStso1BtZT8+OO6olrtxb0vBuVqEjNolIxDYFAay6xerisxFOh+rXiBFkMoXOJTSNNMy8ng1eg64XKv47Ql018FnHCziZi8gsaMB3tXP2ix8HPUzV8vpCI9XyZUi+9JzD4qteq8YFgkW7gQLcWIvIbhA//QQzXC+G78t0Ux6fJDVCWw/Q2A6Wr8F7mqTDJ5uqOCBGphN3DtglJUguTKBjg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1667608990; bh=4Qj0k4dBT7/6jKFI7rvrsaPuojcHlN+Nd9h8T542kC+=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=rpQAbFya6sDbBvYUlIKZZMWzSDpY39K7TxNMJePn/R3dXLhklqHCOYStZnTtr0CUTAafroLsU0Bah00gd5NYRk9ySEa275k80ZhT8opmeSs22SqOaxP7athq8fEIIXH4K148l3wfTchZRY0plSguxn/mChtObbQVUgBOnAdXlBu+q+jC6ocMBGh0wk42w8Vjn/l0Suj9sTklVQQS3/stk8r0E/s6uGejhunHIquZsKBbCdwLaFrTC8sEvR3zx4sj5iMxFsjbiZ1vJKOOc1tfmHJfw8T3GCrftTC6JgPDPQa8LWBuoCzBk6KQr5V+vksmKpNcXDiZHJn5OaxYBGMhKg== X-YMail-OSG: VPjkfdAVM1kQ6nZHjE1CMBHauI6BKokaVQ_Bgvyq15ggabCbEnVy6oiI9QZbptf 5B6qMBy8cwxDMatuKVUmVZn8q_mEu3RlzBGUySXp4HHynil671tdpIrxV8bgcTaOZHIQqEzXaRpt Bsbo3vQvCJryiLKSg_TGlg8g9MmcOq_pti9JQO.BOv9ogRZgHkbrSg8ksXmsZPSObcKa7h7ZcSGe KhwKxYE1NlaL54fpcrJEpU_HN_rbB.Fm.q.O_2CM4_enjWczBCh7a5chMhoSqMfNYRfRVZECqx7Z B8V.G7NEUda.lxS0KdVQuEWq.MWtX3QD0kkJFibst6uvbV1uwKIK6zJCHp1YTsTdjPJV18KRIzs9 8Zg3MC_PO1MQY_rv0fZhXDRLlTrP_zulw1SnC96hUoXGcjOHSugTk04XLKeefOLXDm7.0Ni1UfWj g6Blg8qtdfBR.Y2L6C1nPfTjbxKr70P9lpCc.sGs.rkDLW9CfCka4wVw7jvx4onPfXnhLuZ8r4xO pvJwP9vrIWQicg3CBPB0ByDJ1szVuHwMOBxVZA.uW8kWXro3FjQask3tKI9LwUHXJ.cLP98vAKVQ lviKjxK9GeiS_E5Tl7r4Np3D0jH0ipeiaZRQhr6xb6p7A6WYB3BV3pBg3gYJLgcvSkH3nqFbCGKT dP9UwLCo.WAW7NM19mYQty21MgA2jF5XvOTLz0NB1rfNccglu.wfKKmXQdNfsylj8GUu0DIejmLL qZLKqzhS3W.Kxuu0tboGcvp2oX4Xgtq.yK1GNH9ll8k7LBXoJoStuJW1QMql4A6Y37h0TYYKBI9R E8LvB7oJi.h1dFslvnspvrxIWkGaZ4.0gjtwqzGsPY X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ne1.yahoo.com with HTTP; Sat, 5 Nov 2022 00:43:10 +0000 Original-Received: by hermes--production-sg3-6c8895b545-pb7wm (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8fc1c85be188d64cd3485488208c9dcc; Sat, 05 Nov 2022 00:43:07 +0000 (UTC) In-Reply-To: (Stefan Monnier's message of "Fri, 04 Nov 2022 11:09:53 -0400") X-Mailer: WebService/1.1.20826 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.185.148; envelope-from=luangruo@yahoo.com; helo=sonic305-22.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299164 Archived-At: Stefan Monnier writes: > Just a comment from someone who's rather unfamiliar with the way input > methods work in Emacs (well, I use `TeX`, but that's about it), and even > more so for the NS code in general: > > diff --git a/src/nsterm.m b/src/nsterm.m > index 17f40dc7e3..0788442b98 100644 > --- a/src/nsterm.m > +++ b/src/nsterm.m > @@ -7063,16 +7063,23 @@ - (NSRect)firstRectForCharacterRange: (NSRange)theRange > NSRect rect; > NSPoint pt; > struct window *win; > + bool was_waiting_for_input; > + specpdl_ref count = SPECPDL_INDEX (); > > NSTRACE ("[EmacsView firstRectForCharacterRange:]"); > > if (NS_KEYLOG) > NSLog (@"firstRectForCharRange request"); > > - if (WINDOWP (echo_area_window) && ! NILP (call0 (intern ("ns-in-echo-area")))) > + was_waiting_for_input = waiting_for_input; > + waiting_for_input = false; > + specbind (Qinhibit_quit, Qt); > + if (WINDOWP (echo_area_window) && ! NILP (safe_call (true, 0, Qns_in_echo_area))) > > I'm glad we found a way to make the code work, apparently, but > Here we need a comment explaining why we do this gymnastic of > `safe_call` + `inhibit_quit` + `waiting_for_input`. That is done all over the place in the NS code. I don't really know why, you will have to ask its original authors for that, but suffice it to say calling Lisp from firstRectForCharacterRange (and also the menu bar update callbacks) will otherwise crash upon Fsignal being called. > It's very unusual to have to do that. > > win = XWINDOW (echo_area_window); > else > win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe)); > + unbind_to (count, Qnil); > + waiting_for_input = was_waiting_for_input; > > The `unbind_to` suggests that non-local exits are still possible, but if > so, we will sometimes not restore `waiting_for_input`. I think the unbind_to is just a general pattern and could easily be replaced with "Vinhibit_quit = old_inhibit_quit" (and so on and so forth.) > Now for the other part of my comment: > > (defun ns-in-echo-area () > "Whether, for purposes of inserting working composition text, the minibuffer > is currently being used." > (or isearch-mode > (and cursor-in-echo-area (current-message)) > ;; Overlay strings are not shown in some cases. > (get-char-property (point) 'invisible) > (and (not (bobp)) > (or (and (get-char-property (point) 'display) > (eq (get-char-property (1- (point)) 'display) > (get-char-property (point) 'display))) > (and (get-char-property (point) 'composition) > (eq (get-char-property (1- (point)) 'composition) > (get-char-property (point) 'composition))))))) > > In which sense does (get-char-property (point) 'invisible), or the big > (and ...) below, indicate that "the minibuffer is currently being used"? I really have no idea... > Could someone clarify this code? Maybe all it takes is to change the > docstring, I don't know, but as it stands it looks quite odd. +1