GNU bug report logs - #21551
[PATCH] Fix Mac OS X key bindings bug

Previous Next

Package: emacs;

Reported by: Kai Yu Zhang <yeannylam <at> gmail.com>

Date: Thu, 24 Sep 2015 16:46:02 UTC

Severity: normal

Tags: patch

Merged with 19977, 21330

Found in version 24.4

Done: Philipp Stephani <p.stephani2 <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21551 in the body.
You can then email your comments to 21551 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Thu, 24 Sep 2015 16:46:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kai Yu Zhang <yeannylam <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 24 Sep 2015 16:46:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kai Yu Zhang <yeannylam <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix Mac OS X key bindings bug
Date: Thu, 24 Sep 2015 21:19:45 +0800
[Message part 1 (text/plain, inline)]

[Message part 2 (text/html, inline)]
[0001-Fix-Mac-OS-X-key-bindings-bug.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Wed, 30 Dec 2015 08:51:01 GMT) Full text and rfc822 format available.

Message #8 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: Kai Yu Zhang <yeannylam <at> gmail.com>, 21551 <at> debbugs.gnu.org, 
 Philipp Stephani <p.stephani2 <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>
Subject: Re: Fix Mac OS X key bindings bug
Date: Wed, 30 Dec 2015 09:50:23 +0100
[Message part 1 (text/plain, inline)]
Hi,

I'm looking into a key binding bug on OS X reported multiple times (19977,
21330, 21551). Two different patches have been submitted.

The original code looks like:

      if (is_left_key)
        {
          emacs_event->modifiers |= parse_solitary_modifier
            (ns_command_modifier);

          /* if super (default), take input manager's word so things like
             dvorak / qwerty layout work */
          if (EQ (ns_command_modifier, Qsuper)
              && !fnKeysym
              && [[theEvent characters] length] != 0)
            {
              /* XXX: the code we get will be unshifted, so if we have
                 a shift modifier, must convert ourselves */
              if (!(flags & NSShiftKeyMask))
                code = [[theEvent characters] characterAtIndex: 0];

One of the patches simply removes the `if (EQ(...))' statement. The other
modifies the code to strip away modifiers.

First question: What is the code in the `if (EQ(...))' supposed to do? In
other words, what will stop working if it is removed?

Second question: if it is needed for the LEFT command key, should the
corresponding code be added for the RIGHT?

I've tested removing the `if' and Emacs still seems to be working as
intended, both with a normal key layout and when Dvorak is used. If no one
comes up with a reason to keep the code, I will remove it.

Third question: Does anybody know of a good way to automatically test
things like this? What I'm looking for is a way to send keystrokes like
Cmd-Alt-a to Emacs, that way it could be possible to write tests ensuring
that things like this don't break in the future.

    -- Anders Lindgren
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Sat, 02 Jan 2016 08:09:02 GMT) Full text and rfc822 format available.

Message #11 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: Kai Yu Zhang <yeannylam <at> gmail.com>, 21551 <at> debbugs.gnu.org, 
 Philipp Stephani <p.stephani2 <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>
Subject: Re: Fix Mac OS X key bindings bug
Date: Sat, 2 Jan 2016 09:08:16 +0100
[Message part 1 (text/plain, inline)]
I found a case where the code in question is needed, which none of the
suggested patches handle correctly.

Steps to repeat:

    (setq ns-alternate-modifier nil)

    Press left CMD-ALT-9

    An unmodified Emacs replies "s-]" is not bound. (This assumes a Swedish
keyboard layout, other layouts would yield a different character, but the
principle is the same).

    With either of the two patches, Emacs respond with "s-9" is not bound,
which isn't correct.

Unfortunately, I don't know how to distinguish between the cases where we
need to strip away modifiers (C-s-a) and when we shouldn't, so I'm leaving
this open for now.

    -- Anders Lindgren


On Wed, Dec 30, 2015 at 9:50 AM, Anders Lindgren <andlind <at> gmail.com> wrote:

> Hi,
>
> I'm looking into a key binding bug on OS X reported multiple times (19977,
> 21330, 21551). Two different patches have been submitted.
>
> The original code looks like:
>
>       if (is_left_key)
>         {
>           emacs_event->modifiers |= parse_solitary_modifier
>             (ns_command_modifier);
>
>           /* if super (default), take input manager's word so things like
>              dvorak / qwerty layout work */
>           if (EQ (ns_command_modifier, Qsuper)
>               && !fnKeysym
>               && [[theEvent characters] length] != 0)
>             {
>               /* XXX: the code we get will be unshifted, so if we have
>                  a shift modifier, must convert ourselves */
>               if (!(flags & NSShiftKeyMask))
>                 code = [[theEvent characters] characterAtIndex: 0];
>
> One of the patches simply removes the `if (EQ(...))' statement. The other
> modifies the code to strip away modifiers.
>
> First question: What is the code in the `if (EQ(...))' supposed to do? In
> other words, what will stop working if it is removed?
>
> Second question: if it is needed for the LEFT command key, should the
> corresponding code be added for the RIGHT?
>
> I've tested removing the `if' and Emacs still seems to be working as
> intended, both with a normal key layout and when Dvorak is used. If no one
> comes up with a reason to keep the code, I will remove it.
>
> Third question: Does anybody know of a good way to automatically test
> things like this? What I'm looking for is a way to send keystrokes like
> Cmd-Alt-a to Emacs, that way it could be possible to write tests ensuring
> that things like this don't break in the future.
>
>     -- Anders Lindgren
>
>
[Message part 2 (text/html, inline)]

Merged 19977 21330 21551. Request was from Anders Lindgren <andlind <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 05 Jan 2016 06:34:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Mon, 26 Dec 2016 20:14:03 GMT) Full text and rfc822 format available.

Message #16 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: "Mikhail Gusarov" <dottedmag <at> dottedmag.net>
To: "Anders Lindgren" <andlind <at> gmail.com>,
 "Kai Yu Zhang" <yeannylam <at> gmail.com>, 21551 <at> debbugs.gnu.org,
 "Philipp Stephani" <p.stephani2 <at> gmail.com>, 21330 <at> debbugs.gnu.org,
 19977 <at> debbugs.gnu.org
Subject: Re: Fix Mac OS X key bindings bug
Date: Mon, 26 Dec 2016 21:12:46 +0100
[Message part 1 (text/plain, inline)]
Hi Anders,

I have tried reproducing this discrepancy using my patch from #21330
on top of branch emacs-25.

Swedish layout, ns-alternate-modifier set to nil, LCmd-LAlt-9 replies
"s-]".

Maybe you could check again as well?

Best regards,
Mikhail.

On 2 Jan 2016, at 9:08, Anders Lindgren wrote:

> I found a case where the code in question is needed, which none of the
> suggested patches handle correctly.
>
> Steps to repeat:
>
>     (setq ns-alternate-modifier nil)
>
>     Press left CMD-ALT-9
>
>     An unmodified Emacs replies "s-]" is not bound. (This assumes a Swedish
> keyboard layout, other layouts would yield a different character, but the
> principle is the same).
>
>     With either of the two patches, Emacs respond with "s-9" is not bound,
> which isn't correct.
>
> Unfortunately, I don't know how to distinguish between the cases where we
> need to strip away modifiers (C-s-a) and when we shouldn't, so I'm leaving
> this open for now.
>
>     -- Anders Lindgren
>
>
> On Wed, Dec 30, 2015 at 9:50 AM, Anders Lindgren <andlind <at> gmail.com> wrote:
>
>> Hi,
>>
>> I'm looking into a key binding bug on OS X reported multiple times (19977,
>> 21330, 21551). Two different patches have been submitted.
>>
>> The original code looks like:
>>
>>       if (is_left_key)
>>         {
>>           emacs_event->modifiers |= parse_solitary_modifier
>>             (ns_command_modifier);
>>
>>           /* if super (default), take input manager's word so things like
>>              dvorak / qwerty layout work */
>>           if (EQ (ns_command_modifier, Qsuper)
>>               && !fnKeysym
>>               && [[theEvent characters] length] != 0)
>>             {
>>               /* XXX: the code we get will be unshifted, so if we have
>>                  a shift modifier, must convert ourselves */
>>               if (!(flags & NSShiftKeyMask))
>>                 code = [[theEvent characters] characterAtIndex: 0];
>>
>> One of the patches simply removes the `if (EQ(...))' statement. The other
>> modifies the code to strip away modifiers.
>>
>> First question: What is the code in the `if (EQ(...))' supposed to do? In
>> other words, what will stop working if it is removed?
>>
>> Second question: if it is needed for the LEFT command key, should the
>> corresponding code be added for the RIGHT?
>>
>> I've tested removing the `if' and Emacs still seems to be working as
>> intended, both with a normal key layout and when Dvorak is used. If no one
>> comes up with a reason to keep the code, I will remove it.
>>
>> Third question: Does anybody know of a good way to automatically test
>> things like this? What I'm looking for is a way to send keystrokes like
>> Cmd-Alt-a to Emacs, that way it could be possible to write tests ensuring
>> that things like this don't break in the future.
>>
>>     -- Anders Lindgren
>>
>>


[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Sun, 11 Feb 2018 17:58:02 GMT) Full text and rfc822 format available.

Message #19 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Anders Lindgren <andlind <at> gmail.com>
Cc: 21551 <at> debbugs.gnu.org, Kai Yu Zhang <yeannylam <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>
Subject: Re: Fix Mac OS X key bindings bug
Date: Sun, 11 Feb 2018 17:57:32 +0000
[Message part 1 (text/plain, inline)]
Anders Lindgren <andlind <at> gmail.com> schrieb am Sa., 2. Jan. 2016 um
09:08 Uhr:

> I found a case where the code in question is needed, which none of the
> suggested patches handle correctly.
>
> Steps to repeat:
>
>     (setq ns-alternate-modifier nil)
>
>     Press left CMD-ALT-9
>
>     An unmodified Emacs replies "s-]" is not bound. (This assumes a
> Swedish keyboard layout, other layouts would yield a different character,
> but the principle is the same).
>
>     With either of the two patches, Emacs respond with "s-9" is not bound,
> which isn't correct.
>

In the current master this is now interpreted as M-s-9, which is at least
somewhat reasonable.


>
> Unfortunately, I don't know how to distinguish between the cases where we
> need to strip away modifiers (C-s-a) and when we shouldn't, so I'm leaving
> this open for now.
>

It seems like in the macOS input model, we can't: either we strip away all
modifiers, or none.


>
>     -- Anders Lindgren
>
>
> On Wed, Dec 30, 2015 at 9:50 AM, Anders Lindgren <andlind <at> gmail.com>
> wrote:
>
>> Hi,
>>
>> I'm looking into a key binding bug on OS X reported multiple times
>> (19977, 21330, 21551). Two different patches have been submitted.
>>
>> The original code looks like:
>>
>>       if (is_left_key)
>>         {
>>           emacs_event->modifiers |= parse_solitary_modifier
>>             (ns_command_modifier);
>>
>>           /* if super (default), take input manager's word so things like
>>              dvorak / qwerty layout work */
>>           if (EQ (ns_command_modifier, Qsuper)
>>               && !fnKeysym
>>               && [[theEvent characters] length] != 0)
>>             {
>>               /* XXX: the code we get will be unshifted, so if we have
>>                  a shift modifier, must convert ourselves */
>>               if (!(flags & NSShiftKeyMask))
>>                 code = [[theEvent characters] characterAtIndex: 0];
>>
>> One of the patches simply removes the `if (EQ(...))' statement. The other
>> modifies the code to strip away modifiers.
>>
>> First question: What is the code in the `if (EQ(...))' supposed to do? In
>> other words, what will stop working if it is removed?
>>
>> Second question: if it is needed for the LEFT command key, should the
>> corresponding code be added for the RIGHT?
>>
>> I've tested removing the `if' and Emacs still seems to be working as
>> intended, both with a normal key layout and when Dvorak is used. If no one
>> comes up with a reason to keep the code, I will remove it.
>>
>> Third question: Does anybody know of a good way to automatically test
>> things like this? What I'm looking for is a way to send keystrokes like
>> Cmd-Alt-a to Emacs, that way it could be possible to write tests ensuring
>> that things like this don't break in the future.
>>
>>     -- Anders Lindgren
>>
>>
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Tue, 13 Feb 2018 18:57:01 GMT) Full text and rfc822 format available.

Message #22 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: 21551 <at> debbugs.gnu.org, Kai Yu Zhang <yeannylam <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>, Anders Lindgren <andlind <at> gmail.com>
Subject: Re: bug#21551: Fix Mac OS X key bindings bug
Date: Tue, 13 Feb 2018 18:56:20 +0000
[Message part 1 (text/plain, inline)]
On Sun, Feb 11, 2018 at 05:57:32PM +0000, Philipp Stephani wrote:
> Anders Lindgren <andlind <at> gmail.com> schrieb am Sa., 2. Jan. 2016 um
> 09:08 Uhr:
> 
> > I found a case where the code in question is needed, which none of the
> > suggested patches handle correctly.
> >
> > Steps to repeat:
> >
> >     (setq ns-alternate-modifier nil)
> >
> >     Press left CMD-ALT-9
> >
> >     An unmodified Emacs replies "s-]" is not bound. (This assumes a
> > Swedish keyboard layout, other layouts would yield a different character,
> > but the principle is the same).
> >
> >     With either of the two patches, Emacs respond with "s-9" is not bound,
> > which isn't correct.
> >
> 
> In the current master this is now interpreted as M-s-9, which is at least
> somewhat reasonable.

For me it’s s-9, not M-s-9.

> > Unfortunately, I don't know how to distinguish between the cases where we
> > need to strip away modifiers (C-s-a) and when we shouldn't, so I'm leaving
> > this open for now.
> >
> 
> It seems like in the macOS input model, we can't: either we strip away all
> modifiers, or none.

It appears you can using some Carbon stuff. Half‐assed proof of
concept patch attached.

(It’s broken the arrow keys, and I don’t know why...)
-- 
Alan Third
[poc.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Wed, 14 Feb 2018 21:45:02 GMT) Full text and rfc822 format available.

Message #25 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: 21551 <at> debbugs.gnu.org, Kai Yu Zhang <yeannylam <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>, Anders Lindgren <andlind <at> gmail.com>
Subject: Re: bug#21551: Fix Mac OS X key bindings bug
Date: Wed, 14 Feb 2018 21:44:44 +0000
[Message part 1 (text/plain, inline)]
On Tue, Feb 13, 2018 at 06:56:20PM +0000, Alan Third wrote:
> On Sun, Feb 11, 2018 at 05:57:32PM +0000, Philipp Stephani wrote:
> > It seems like in the macOS input model, we can't: either we strip away all
> > modifiers, or none.
> 
> It appears you can using some Carbon stuff. Half‐assed proof of
> concept patch attached.

Better version attached.

Is there any reason to avoid Carbon code? I’m not aware of any, and if
it’s OK then I think this finally solves this problem.

(It might be best to get someone with a different keyboard layout than
me to test it. The only reason I have for using alt as a shift key is
to type ‘#’ or ‘€’.)
-- 
Alan Third
[0001-Fix-modifier-key-handling-on-macOS.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Sat, 17 Feb 2018 12:37:02 GMT) Full text and rfc822 format available.

Message #28 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: 21551 <at> debbugs.gnu.org, Kai Yu Zhang <yeannylam <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>, Anders Lindgren <andlind <at> gmail.com>
Subject: Re: bug#21551: Fix Mac OS X key bindings bug
Date: Sat, 17 Feb 2018 12:36:29 +0000
On Wed, Feb 14, 2018 at 09:44:44PM +0000, Alan Third wrote:
> On Tue, Feb 13, 2018 at 06:56:20PM +0000, Alan Third wrote:
> > On Sun, Feb 11, 2018 at 05:57:32PM +0000, Philipp Stephani wrote:
> > > It seems like in the macOS input model, we can't: either we strip away all
> > > modifiers, or none.
> > 
> > It appears you can using some Carbon stuff. Half‐assed proof of
> > concept patch attached.
> 
> Better version attached.

Pushed to master.
-- 
Alan Third




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Sun, 18 Feb 2018 22:00:02 GMT) Full text and rfc822 format available.

Message #31 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Alan Third <alan <at> idiocy.org>
Cc: 21551 <at> debbugs.gnu.org, Kai Yu Zhang <yeannylam <at> gmail.com>,
 Mikhail Gusarov <dottedmag <at> dottedmag.net>, Anders Lindgren <andlind <at> gmail.com>
Subject: Re: bug#21551: Fix Mac OS X key bindings bug
Date: Sun, 18 Feb 2018 21:59:29 +0000
[Message part 1 (text/plain, inline)]
Alan Third <alan <at> idiocy.org> schrieb am Mi., 14. Feb. 2018 um 22:44 Uhr:

> On Tue, Feb 13, 2018 at 06:56:20PM +0000, Alan Third wrote:
> > On Sun, Feb 11, 2018 at 05:57:32PM +0000, Philipp Stephani wrote:
> > > It seems like in the macOS input model, we can't: either we strip away
> all
> > > modifiers, or none.
> >
> > It appears you can using some Carbon stuff. Half‐assed proof of
> > concept patch attached.
>
> Better version attached.
>
> Is there any reason to avoid Carbon code? I’m not aware of any, and if
> it’s OK then I think this finally solves this problem.
>
>
Carbon is deprecated, isn't it? That means it's quite likely that patches
relying on Carbon will have to be removed later, should Carbon be ever
removed completely.
For now, it's probably fine though to use Carbon if there's no alternative.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21551; Package emacs. (Mon, 19 Feb 2018 15:06:01 GMT) Full text and rfc822 format available.

Message #34 received at 21551 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: 21551 <at> debbugs.gnu.org, alan <at> idiocy.org, dottedmag <at> dottedmag.net,
 yeannylam <at> gmail.com, andlind <at> gmail.com
Subject: Re: bug#21551: Fix Mac OS X key bindings bug
Date: Mon, 19 Feb 2018 10:05:17 -0500
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > Carbon is deprecated, isn't it?

Does that mean we are in favor of carbon omissions?   ;-).

-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
Skype: No way! See https://stallman.org/skype.html.





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 20 Mar 2018 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 45 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.