From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#42915: 27.1; Setting ns-function-modifier to control breaks control for certain keys Date: Wed, 19 Aug 2020 00:50:44 +0200 (CEST) Message-ID: <20200818225041.GB6536@breton.holly.idiocy.org> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26961"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 42915@debbugs.gnu.org To: "Ryan C. Thompson" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 19 00:51:15 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1k8ARk-0006qj-RY for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Aug 2020 00:51:13 +0200 Original-Received: from localhost ([::1]:53562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8ARj-0001o0-Da for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Aug 2020 18:51:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8ARa-0001nb-K8 for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2020 18:51:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k8ARa-0006bK-AX for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2020 18:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k8ARa-0001ee-7i for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2020 18:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Aug 2020 22:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42915 X-GNU-PR-Package: emacs Original-Received: via spool by 42915-submit@debbugs.gnu.org id=B42915.15977910596352 (code B ref 42915); Tue, 18 Aug 2020 22:51:02 +0000 Original-Received: (at 42915) by debbugs.gnu.org; 18 Aug 2020 22:50:59 +0000 Original-Received: from localhost ([127.0.0.1]:37294 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k8ARX-0001eO-FL for submit@debbugs.gnu.org; Tue, 18 Aug 2020 18:50:59 -0400 Original-Received: from mailout-l3b-97.contactoffice.com ([212.3.242.97]:40156) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k8ARS-0001e6-8Q for 42915@debbugs.gnu.org; Tue, 18 Aug 2020 18:50:57 -0400 Original-Received: from smtpauth1.co-bxl (smtpauth1.co-bxl [10.2.0.15]) by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id 6F258558; Wed, 19 Aug 2020 00:50:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1597791047; s=20200222-6h9o; d=idiocy.org; i=alan@idiocy.org; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To; l=4604; bh=aXqXzXGLqkrPFAz9okYNotffw6YjNRMON0HcP9r9OZI=; b=scK/WDYhTtV1DpxhugJPWxJjcydQWgYZt5WQlLty9zUGlkddLZV3qWpYA9cu4lpZ HgIhkZdKltzPHydMwCDxVYXsRflCULwG/u+6qq5RFCVfTeKQQogUfWsWnLjppoOPtv0 UsiGx45+APliRROmluEZsvG08Q6hSk/toCdB8Hdjc3wRXGEQV0XvG2PNYv4AKujqMUB jT2g1AP3BA6ljgdjenKaXYTOqMZhWbxLhksfXXW5R8jAvWSP1KcudUNJW6ENTIv6ko3 ROenJFLWJWslcrTupdp64eYNhjkCAvgrfCDZKIqintqAQBS8bMh0cme+UUYe1qDfQrs cQ13lab2kg== Original-Received: by smtp.mailfence.com with ESMTPA ; Wed, 19 Aug 2020 00:50:42 +0200 (CEST) Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 741CE2024A73F2; Tue, 18 Aug 2020 23:50:41 +0100 (BST) Mail-Followup-To: Alan Third , "Ryan C. Thompson" , 42915@debbugs.gnu.org Content-Disposition: inline In-Reply-To: X-ContactOffice-Account: com:241649512 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:185547 Archived-At: --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Aug 18, 2020 at 10:22:18AM -0400, Ryan C. Thompson wrote: > On a mac, run: > > emacs -Q --eval "(setq ns-function-modifier 'control)" > > Then try C-right, C-home, and similar key combinations. Emacs will act as if > control is not being held down, i.e. C-right will run right-char instead of > right-word. Indeed, C-h k C-right shows the key binding for right, not > C-right. However, other key combinations, such as C-f, work as expected. > > As far as I can tell, this only started happening after I updated to Emacs > 27. I was previously using this config with Emacs 26.3 and never saw this > issue. So I believe this is a new bug in Emacs 27. Can you please try the attached patch? Note that there may be some change to how "function" keys, like return and the arrow keys, are handled when using the fn key. I can't remember exactly how they worked with Emacs 26, but I believe the new behaviour should be more consistent across the board. -- Alan Third --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-Handle-fn-functions-keys-better-on-NS-bug-42915.patch" Content-Transfer-Encoding: 8bit >From 6460cec4412a0f8bc5a16b91743423bef6c09e14 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Tue, 18 Aug 2020 23:41:08 +0100 Subject: [PATCH] Handle fn + functions keys better on NS (bug#42915) * doc/emacs/macos.texi (Mac / GNUstep Customization): Document the caveat regarding fn and function keys. * src/nsterm.m (EV_MODIFIERS2): Ignore ns_function_modifier if this is a function key. ([EmacsView keyDown:]): Get rid of the code that unsets the ns_function_modifier value in modifiers. --- doc/emacs/macos.texi | 4 ++++ src/nsterm.m | 23 ++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi index 00daa8b35d..3fb625b417 100644 --- a/doc/emacs/macos.texi +++ b/doc/emacs/macos.texi @@ -143,6 +143,10 @@ Mac / GNUstep Customization may also be set to @code{left}, which means to use the same behavior as the corresponding left-hand key. +Emacs is unable to detect when the @key{function} key is being used as +a modifier with function keys. As a result Emacs will ignore the +modifier set in @code{ns-function-modifier} with these keys. + @subsection Frame Variables @table @code diff --git a/src/nsterm.m b/src/nsterm.m index 98c5b69d68..1c306c1b8e 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -402,7 +402,7 @@ - (NSColor *)colorUsingDefaultColorSpace hyper_modifier : 0) \ | ((flags & NSEventModifierFlagShift) ? \ shift_modifier : 0) \ - | ((flags & NS_FUNCTION_KEY_MASK) \ + | (((flags & NS_FUNCTION_KEY_MASK) && kind == QCordinary) \ ? parse_solitary_modifier (mod_of_kind (ns_function_modifier, \ kind)) \ : 0) \ @@ -6505,25 +6505,22 @@ untranslated characters (returned by the we have both shift-like and control-like modifiers because the NSEvent API doesn’t let us ignore only some modifiers. In that case we use UCKeyTranslate (ns_get_shifted_character) - to look up the correct character. */ + to look up the correct character. - /* EV_MODIFIERS2 uses parse_solitary_modifier on all known + EV_MODIFIERS2 uses parse_solitary_modifier on all known modifier keys, which returns 0 for shift-like modifiers. Therefore its return value is the set of control-like - modifiers. */ - Lisp_Object kind = fnKeysym ? QCfunction : QCordinary; - emacs_event->modifiers = EV_MODIFIERS2 (flags, kind); + modifiers. - /* Function keys (such as the F-keys, arrow keys, etc.) set + Function keys (such as the F-keys, arrow keys, etc.) set modifiers as though the fn key has been pressed when it hasn't. Also some combinations of fn and a function key return a different key than was pressed (e.g. fn- gives - ). We need to unset the fn modifier in these cases. - FIXME: Can we avoid setting it in the first place? */ - if (fnKeysym && (flags & NS_FUNCTION_KEY_MASK)) - emacs_event->modifiers - ^= parse_solitary_modifier (mod_of_kind (ns_function_modifier, - QCfunction)); + ). EV_MODIFIERS2 avoids setting the the fn modifier in + these cases. */ + + Lisp_Object kind = fnKeysym ? QCfunction : QCordinary; + emacs_event->modifiers = EV_MODIFIERS2 (flags, kind); if (NS_KEYLOG) fprintf (stderr, "keyDown: code =%x\tfnKey =%x\tflags = %x\tmods = %x\n", -- 2.26.1 --XsQoSWH+UP9D9v3l--