From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Reitter Newsgroups: gmane.emacs.devel Subject: Mac: modifier key remapping revised [patch] Date: Mon, 18 Apr 2005 18:02:59 +0100 Message-ID: <622c88af84f92a1149662bd6ba5bf4e1@gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v622) Content-Type: multipart/mixed; boundary=Apple-Mail-10-245109565 X-Trace: sea.gmane.org 1113843862 10501 80.91.229.2 (18 Apr 2005 17:04:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 18 Apr 2005 17:04:22 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 18 19:04:20 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DNZcQ-0002pp-Hc for ged-emacs-devel@m.gmane.org; Mon, 18 Apr 2005 19:01:07 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DNZgY-0000Gy-RZ for ged-emacs-devel@m.gmane.org; Mon, 18 Apr 2005 13:05:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DNZfH-0008K8-Kq for emacs-devel@gnu.org; Mon, 18 Apr 2005 13:04:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DNZfG-0008JY-6J for emacs-devel@gnu.org; Mon, 18 Apr 2005 13:04:03 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DNZfG-0007q2-3U for emacs-devel@gnu.org; Mon, 18 Apr 2005 13:04:02 -0400 Original-Received: from [129.215.216.3] (helo=nutty.inf.ed.ac.uk) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1DNZg6-0006Me-CZ for emacs-devel@gnu.org; Mon, 18 Apr 2005 13:04:54 -0400 Original-Received: from [129.215.110.120] (dhcp-110-120.inf.ed.ac.uk [129.215.110.120]) by nutty.inf.ed.ac.uk (8.12.8/8.12.8) with ESMTP id j3IH31wv015469 for ; Mon, 18 Apr 2005 18:03:02 +0100 Original-To: emacs-devel@gnu.org X-Mailer: Apple Mail (2.622) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:36087 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:36087 --Apple-Mail-10-245109565 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Hi, the current state of affairs makes it difficult to map the standard Mac modifier keys (Ctrl, Option, Command) to Emacs modifiers. At this point, the default is that the command key is Meta, but by setting mac-command-key-is-meta to nil, one can map Option to Meta. An additional variable, mac-reverse-ctrl-meta, allows to swap Ctrl and (whatever is) Meta. Finally, a patch introduced in November last year allows us to map Option to whatever (e.g. Hyper or Meta) via the variable mac-option-modifier. This is complicated, and in effect does not allow me to map, for example Command to Hyper, which makes a lot of sense if you want to assign something to Command-X, without overriding M-x (or A-x) and without consequences for the choice of Option. Therefore I suggest to a) deprecate mac-command-key-is-meta and mac-reverse-ctrl-meta, and b) introduce mac-control-modifier and mac-command-modifier which allow, analogous to the recent mac-option-modifier, free mapping of the modifier keys. All of a sudden, the modifier key business becomes simple and straightforward: (setq mac-option-modifier 'meta) (setq mac-control-modifier 'ctrl) (setq mac-command-modifier 'hyper) In order to preserve backwards-compatibility, the two deprecated variables remain in effect unless at least one of the above mac-*-modifier variables is set to non-nil. Problems should only occur if somebody uses the old mac-option-modifier in combination with the deprecated variables; but the option variable has been introduced only recently and hasn't seen significant uptake yet (google it!). The attached patch implements this behavior, it applies against today's catch (of macterm.c). --Apple-Mail-10-245109565 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="mac-modifier-keys.new.patch" Content-Disposition: attachment; filename=mac-modifier-keys.new.patch Index: macterm.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/macterm.c,v retrieving revision 1.111 diff -r1.111 macterm.c 89,91c89,99 < /* Set of macros that handle mapping of Mac modifier keys to emacs. */ < #define macCtrlKey (NILP (Vmac_reverse_ctrl_meta) ? controlKey : \ < (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey)) --- > /* Set of macros that handle mapping of Mac modifier keys to emacs. > If any of the newer-style mac_*_modifier variables is set, these macros are basically out of function, > they just map to the normal keys - except for Meta, which is then (ESC or) command-control-option. > */ > > #define macOldModifierSetting ( NILP(Vmac_control_modifier) && NILP(Vmac_option_modifier) && NILP(Vmac_command_modifier) ) > > #define macCtrlKey (macOldModifierSetting ? \ > (NILP(Vmac_reverse_ctrl_meta) ? controlKey : \ > (NILP(Vmac_command_key_is_meta) ? optionKey : cmdKey)) : \ > controlKey) 93,96c101,109 < #define macMetaKey (NILP (Vmac_reverse_ctrl_meta) ? \ < (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \ < : controlKey) < #define macAltKey (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey) --- > > #define macMetaKey (macOldModifierSetting ? \ > (NILP(Vmac_reverse_ctrl_meta) ? \ > (NILP(Vmac_command_key_is_meta) ? optionKey : cmdKey) : controlKey) : \ > (cmdKey | controlKey | optionKey)) > > #define macAltKey (macOldModifierSetting ? (NILP(Vmac_command_key_is_meta) ? cmdKey : optionKey) : optionKey) > > #define macCmdKey (cmdKey) 98a112 > 241c255 < static Lisp_Object Qalt, Qhyper, Qsuper, Qmodifier_value; --- > static Lisp_Object Qalt, Qhyper, Qsuper, Qctrl, Qmeta, Qmodifier_value; 7195c7209,7210 < /* True if using command key as meta key. */ --- > /* True if using command key as meta key. > Deprecated; only use if macOldModifierSetting evaluates to true. */ 7197a7213,7215 > /* Modifier associated with the control key, or nil for normal behavior. */ > Lisp_Object Vmac_control_modifier; > 7201c7219,7223 < /* True if the ctrl and meta keys should be reversed. */ --- > /* Modifier associated with the command key, or nil for normal behavior. */ > Lisp_Object Vmac_command_modifier; > > /* True if the ctrl and meta keys should be reversed. > Deprecated; only use if macOldModifierSetting evaluates to true. */ 7276,7284c7298,7313 < if (mods & macCtrlKey) < result |= ctrl_modifier; < if (mods & macMetaKey) < result |= meta_modifier; < if (NILP (Vmac_command_key_is_meta) && (mods & macAltKey)) < result |= alt_modifier; < if (!NILP (Vmac_option_modifier) && (mods & optionKey)) { < Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value); < if (!NILP(val)) --- > > if (macOldModifierSetting) /* compatibility with old-style modifier keys */ > { > if (mods & macCtrlKey) > result |= ctrl_modifier; > if (mods & macMetaKey) > result |= meta_modifier; > > if ( NILP (Vmac_command_key_is_meta) && (mods & macAltKey) ) > result |= alt_modifier; > } else > { > /* new-style modifier keys */ > if (!NILP (Vmac_option_modifier) && (mods & optionKey)) { > Lisp_Object val = Fget(Vmac_option_modifier, Qmodifier_value); > if (!NILP(val)) 7286c7315,7335 < } --- > } else { /* default behavior if modifier variable is not set */ > if (mods & macAltKey) > result |= alt_modifier; > } > if (!NILP (Vmac_command_modifier) && (mods & cmdKey)) { > Lisp_Object val = Fget(Vmac_command_modifier, Qmodifier_value); > if (!NILP(val)) > result |= XUINT(val); > } else { /* default behavior if modifier variable is not set: assign hyper*/ > if (mods & macCmdKey) > result |= hyper_modifier; > } > if (!NILP (Vmac_control_modifier) && (mods & controlKey)) { > Lisp_Object val = Fget(Vmac_control_modifier, Qmodifier_value); > if (!NILP(val)) > result |= XUINT(val); > } else { /* default behavior if modifier variable is not set */ > if (mods & macCtrlKey) > result |= ctrl_modifier; > } > } 9059,9061c9108,9110 < if (er.modifiers & (controlKey | < (NILP (Vmac_command_key_is_meta) ? optionKey < : cmdKey))) --- > if (er.modifiers & (controlKey | > ((macOldModifierSetting && NILP (Vmac_command_key_is_meta)) ? > optionKey : cmdKey))) 9078,9079c9127,9128 < else if (!NILP (Vmac_option_modifier) < && (er.modifiers & optionKey)) --- > else if (!macOldModifierSetting > && (er.modifiers & (optionKey | controlKey | cmdKey) )) 9081c9130 < /* When using the option key as an emacs modifier, --- > /* When using a key as an emacs modifier, 9083,9084c9132,9138 < without the Mac option modifier applied. */ < int new_modifiers = er.modifiers & ~optionKey; --- > without the Mac modifier applied. > > Could we do something like > new_modifiers = er.modifiers & shiftKey > instead? > */ > int new_modifiers = er.modifiers & ~controlKey & ~optionKey & ~cmdKey; 9090,9092c9144,9146 < } < else < inev.code = er.message & charCodeMask; --- > } else > inev.code = er.message & charCodeMask; > 9096c9150 < --- > 9789a9844,9847 > Qctrl = intern ("ctrl"); > Fput (Qctrl, Qmodifier_value, make_number (ctrl_modifier)); > Qmeta = intern ("meta"); > Fput (Qmeta, Qmodifier_value, make_number (meta_modifier)); 9839a9898,9900 > /* Deprecated variables to configure modifier key assignment. > Retained for backward-compatibility. */ > 9842c9903,9904 < Otherwise the option key is used. */); --- > Otherwise the option key is used. This variable is DEPRECATED. > It is only in effect if all of the variables mac-*-modifier are nil. */); 9843a9906,9923 > > DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta, > doc: /* Non-nil means that the control and meta keys are reversed. This is > useful for non-standard keyboard layouts. This variable is DEPRECATED. > It is only in effect if none of the variables mac-*-modifier is non-nil. */); > Vmac_reverse_ctrl_meta = Qnil; > > > /* Variables to configure modifier key assignment. */ > > DEFVAR_LISP ("mac-control-modifier", &Vmac_control_modifier, > doc: /* Modifier to use for the Mac control key. The value can > be alt, hyper, or super for the respective modifier. If the value is > nil then the key will act as the normal Mac control modifier. However, if all > values of mac-{command|control|option}-modifier are nil, the deprecated > default assignment determined by mac-command-key-is-meta and > mac-reverse-ctrl-meta is used. */); > Vmac_control_modifier = Qnil; 9848c9928,9931 < nil then the key will act as the normal Mac option modifier. */); --- > nil then the key will act as the normal Mac option modifier. However, if all > values of mac-{command|control|option}-modifier are nil, the deprecated > default assignment determined by mac-command-key-is-meta and > mac-reverse-ctrl-meta is used. */); 9851,9854c9934,9941 < DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta, < doc: /* Non-nil means that the control and meta keys are reversed. This is < useful for non-standard keyboard layouts. */); < Vmac_reverse_ctrl_meta = Qnil; --- > DEFVAR_LISP ("mac-command-modifier", &Vmac_command_modifier, > doc: /* Modifier to use for the Mac command key. The value can > be alt, hyper, or super for the respective modifier. If the value is > nil then the key will act as the normal Mac option modifier. However, if all > values of mac-{command|control|option}-modifier are nil, the deprecated > default assignment determined by mac-command-key-is-meta and > mac-reverse-ctrl-meta is used. */); > Vmac_command_modifier = Qnil; --Apple-Mail-10-245109565 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --Apple-Mail-10-245109565--