caldwell / build-emacs

Build scripts for www.emacsformacosx.com
http://www.emacsformacosx.com/about
GNU General Public License v3.0
368 stars 62 forks source link

Option keys mysteriously swapped on Mojave #74

Closed dmolesUC closed 2 years ago

dmolesUC commented 6 years ago

I have a shared init.el that I use on several machines, all of which (till last week) were running High Sierra. It contains the following:

(when (eq system-type 'darwin)
  ;; leave right option available for international keys
  (setq mac-right-option-modifier nil)
)

The intent is to allow me to use left option as meta, and right option for accented characters etc.

However, since I reformatted one of the machines and installed Mojave, it doesn't seem to be working properly.

  1. in the standalone app, left option gets me accented characters, right option works as meta (backwards)
  2. in the terminal with /Applications/Emacs.app/Contents/MacOS/Emacs -nw, both option keys work as meta.

(#2 is probably Terminal's fault, and I can't confirm at the moment whether it ever worked in High Sierra.)

As a further complication, I'm using a PC keyboard with option and command switched via Keyboard Preferences / Keyboard / Modifier Keys.

I confirmed with eval-expression that the relevant variables (what I think are the relevant variables) are set correctly -- mac-right-option-modifier is nil, and mac-option-modifier is meta.

That said, I'm not sure where I found the mac- variables, and I see the variables on the Tips page are different. But they also seem correct -- ns-alternate-modifier is meta, and ns-right-alternate-modifier is nil.

If I set ns-right-alternate-modifier to meta, I get both keys acting as meta (i.e., I lose the modifier). If I then set ns-alternate-modifier to none, I get left alt as meta, right alt as modifier. So I can get the behavior I want, but only by setting the variables backwards; and I'm reluctant to do it in my shared init.el as it may break the other machines.

dmolesUC commented 6 years ago

Update: Whatever it is, it seems to be specific to the PC external keyboard (i.e., the MacBook's internal keyboard treats ns-right-alternate as right and ns-alternate as left.) Now if I only knew how to detect that…

dmolesUC commented 6 years ago

I posted a related question on StackExchange and one of the commenters suggested disabling modifications. It looks like when I un-switch option and command in Keyboard Preferences, the problem goes away, which would also explain why it works on the internal keyboard.