【问题标题】:Binding numeric keypad keys with Emacs 24 and OS/X将数字键盘键与 Emacs 24 和 OS/X 绑定
【发布时间】:2011-04-21 05:33:47
【问题描述】:

我目前正在按照本文所述在 OS/X 上试用 Emacs 24 的 Git HEAD 版本:

http://www.viget.com/extend/emacs-24-rails-development-environment-from-scratch-to-productive-in-5-minu/

我想将一些 Macintosh 扩展键盘数字小键盘键绑定到 Emacs 功能,但它似乎不起作用。当我执行“c-h k”检查按键详细信息时,按键无法识别。如果我在 (global-set-key (kbd "kp-minus") ...) 设置中引用它们也是如此。

这是使用 Emacs 24 开发版的问题,还是与 Macintosh 键盘硬件以及 Emacs 的看法有关?任何人都可以建议解决此问题的最佳方法吗?

提前致谢,

学习

【问题讨论】:

  • 该问题也出现在 Emacs 23 和 Aquamacs 2.0 中,但在 Aquamacs 1.9 中没有。我对此进行了一些调查,但没有找到解决方案。
  • 我很确定 Mac OS 的解释是非常不同的......你应该考虑将值打印到一个变量并用调试器检查它,看看你得到了什么......我试过了是的,它没有提供任何东西...可能是因为需要添加一些额外的头文件...
  • 这已在昨天发布的 Emacs 24.4 中得到修复。 (从emacsformacosx.com下载)

标签: macos binding emacs emacs24


【解决方案1】:

我在构建 emacs 24 时遇到了同样的问题。问题与 emacs 23 相同。我按如下方式修补了 emacs 24 代码以纠正问题。不确定这是一个好的解决方案,但对我来说效果很好。

index 91f0cbb..d537ee3 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -87,6 +87,7 @@ static unsigned convert_ns_to_X_keysym[] =
   NSBeginFunctionKey,           0x58,
   NSSelectFunctionKey,          0x60,
   NSPrintFunctionKey,           0x61,
+  NSClearLineFunctionKey,       0x0B,
   NSExecuteFunctionKey,         0x62,
   NSInsertFunctionKey,          0x63,
   NSUndoFunctionKey,            0x65,
@@ -134,6 +135,35 @@ static unsigned convert_ns_to_X_keysym[] =
   0x1B,                0x1B   /* escape */
 };

+static unsigned convert_nskeypad_to_X_keysym[] =
+{
+  /* Arrow keys are both function and keypad keys */
+  NSLeftArrowFunctionKey,       0x51,
+  NSUpArrowFunctionKey,         0x52,
+  NSRightArrowFunctionKey,      0x53,
+  NSDownArrowFunctionKey,       0x54,
+
+  0x41,                         0xAE,  /* KP_Decimal */
+  0x43,                         0xAA,  /* KP_Multiply */
+  0x45,                         0xAB,  /* KP_Add */
+  0x4B,                         0xAF,  /* KP_Divide */
+  0x4E,                         0xAD,  /* KP_Subtract */
+  0x51,                         0xBD,  /* KP_Equal */
+  0x52,                         0xB0,  /* KP_0 */
+  0x53,                         0xB1,  /* KP_1 */
+  0x54,                         0xB2,  /* KP_2 */
+  0x55,                         0xB3,  /* KP_3 */
+  0x56,                         0xB4,  /* KP_4 */
+  0x57,                         0xB5,  /* KP_5 */
+  0x58,                         0xB6,  /* KP_6 */
+  0x59,                         0xB7,  /* KP_7 */
+  0x5B,                         0xB8,  /* KP_8 */
+  0x5C,                         0xB9,  /* KP_9 */
+
+  // The enter key is on the keypad but modifier isnt set
+  NSEnterCharacter,        0x8D
+};
+

 static Lisp_Object Qmodifier_value;
 Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper, Qnone;
@@ -1924,13 +1954,33 @@ ns_convert_key (unsigned code)
   unsigned keysym;
   /* An array would be faster, but less easy to read. */
   for (keysym = 0; keysym < last_keysym; keysym += 2)
-    if (code == convert_ns_to_X_keysym[keysym])
-      return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
+      
+      if (code == convert_ns_to_X_keysym[keysym]) {
+        return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
+      }
   return 0;
 /* if decide to use keyCode and Carbon table, use this line:
      return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
 }

+static unsigned
+ns_convert_keypad (unsigned code)
+/* --------------------------------------------------------------------------
+    Internal call used by NSView-keyDown.
+   -------------------------------------------------------------------------- */
+{
+  const unsigned last_keysym = (sizeof (convert_nskeypad_to_X_keysym)
+                                / sizeof (convert_nskeypad_to_X_keysym[0]));
+  unsigned keysym;
+  /* An array would be faster, but less easy to read. */
+  for (keysym = 0; keysym < last_keysym; keysym += 2) {
+      if (code == convert_nskeypad_to_X_keysym[keysym]) {
+        return 0xFF00 | convert_nskeypad_to_X_keysym[keysym+1];
+      }
+  }
+  return 0;
+}
+

 char *
 x_get_keysym_name (int keysym)
@@ -4503,10 +4553,10 @@ ns_term_shutdown (int sig)
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (emacsframe);
   int code;
   unsigned fnKeysym = 0;
-  int flags;
   static NSMutableArray *nsEvArray;
   static BOOL firstTime = YES;
   int left_is_none;
+  unsigned int flags = [theEvent modifierFlags];

   NSTRACE (keyDown);

@@ -4550,9 +4600,13 @@ ns_term_shutdown (int sig)
       code = ([[theEvent charactersIgnoringModifiers] length] == 0) ?
         0 : [[theEvent charactersIgnoringModifiers] characterAtIndex: 0];
       /* (Carbon way: [theEvent keyCode]) */
+      

       /* is it a "function key"? */
-      fnKeysym = ns_convert_key (code);
+      if (code < 0x00ff && (flags & NSNumericPadKeyMask) )
+   fnKeysym = ns_convert_keypad([theEvent keyCode]);
+      else
+   fnKeysym = ns_convert_key(code);
       if (fnKeysym)
         {
           /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
@@ -4565,7 +4619,6 @@ ns_term_shutdown (int sig)

       /* are there modifiers? */
       emacs_event->modifiers = 0;
-      flags = [theEvent modifierFlags];

       if (flags & NSHelpKeyMask)
           emacs_event->modifiers |= hyper_modifier;

【讨论】:

  • 谢谢,谢谢,谢谢!自从第 23 节出来以来,这一直让我抓狂。我已经在这个页面上发布了这个补丁的 Emacs 23.3 翻译。
【解决方案2】:

我用旧的 Emacs 试过这个:

这是 GNU Emacs 22.2.1(powerpc-apple-darwin9.5.0,GTK+ 版本 2.10.13)

使用 +gtk +x11 从端口集合构建并与 X11 服务器 XQuartz 2.1.6 (xorg-server 1.4.2-apple33) 一起使用,当我查看 C-h l我得到

<kp-0> ... <kp-9>

对于数字。和

<kp-enter> <kp-subtract> <kp-multiply> <kp-divide> <kp-equal>

对于其他键。

我建议使用选项 +gtk 和 +x11 从 MacPorts 构建最新的 Emacs。

然后我会得到最新的XQuartz 并在 X11 上运行 Emacs(我更喜欢这个而不是更原生的构建,因为这样 Emacs 总是表现相同,无论它是否在另一个操作系统上远程运行(通常通过 ssh -Y)或本地。

我将在下周将我的端口升级到最新的 Emacs 并添加这些结果。

【讨论】:

  • 我正在使用的 emacs(有这个问题)是 GNU Emacs 23.2.1 (x86_64-apple-darwin, NS apple-appkit-1038.29),我从 emacsformacosx.com 得到了一个简短的前一阵子。就像我说的,我知道这个问题也出现在 Aquamacs 2.0(基于 23.2.1)中,但不在 Aquamacs 1.9(基于 22.3.1)中。我相信这个问题在 22 到 23 之间蔓延,所以我很想看看你下周构建的 vi MacPorts 是否会解决这个问题。请告诉我...
  • 您不是通过 X11 使用 Emacs 吗?我想问题只存在于原生 Windowing Emacsen 而不是 X11 变体。但我会在下周尝试并告诉你,无论如何是时候升级我的端口了。
【解决方案3】:

这个问题是 emacs 的 Cocoa 变体独有的。在 Emacs22 的 Carbon 版本中不存在该问题。我更新了上面发布的补丁,现在效果更好了。它可能会使用 XCode 3 与 Emacs23 代码库一起使用。如果您使用 XCode 4,像我一样,您将需要使用 Emacs24 代码库,该代码库目前仅在 GIT 存储库中可用。这是关于通过 XCode 4 构建 Emacs24 的非常好的描述

[http://mikbe.tk/2011/04/18/build-emacs-with-xcode-4/][1]

【讨论】:

    【解决方案4】:

    这是 Emacs 24 补丁 M. D. Marchionna 发布在此页面上的 Emacs 23.3 翻译。

    --- nsterm-orig.m   2011-11-13 17:51:47.000000000 -0500
    +++ nsterm.m    2011-11-13 17:39:56.000000000 -0500
    @@ -87,6 +87,7 @@
       NSBeginFunctionKey,           0x58,
       NSSelectFunctionKey,          0x60,
       NSPrintFunctionKey,           0x61,
    +  NSClearLineFunctionKey,       0x0B,
       NSExecuteFunctionKey,         0x62,
       NSInsertFunctionKey,          0x63,
       NSUndoFunctionKey,            0x65,
    @@ -134,6 +135,33 @@
       0x1B,                         0x1B   /* escape */
     };
    
    +static unsigned convert_nskeypad_to_X_keysym[] =
    +{
    +  /* Arrow keys are both function and keypad keys */
    +  NSLeftArrowFunctionKey,       0x51,
    +  NSUpArrowFunctionKey,         0x52,
    +  NSRightArrowFunctionKey,      0x53,
    +  NSDownArrowFunctionKey,       0x54,
    +
    +  0x41,                         0xAE,  /* KP_Decimal */
    +  0x43,                         0xAA,  /* KP_Multiply */
    +  0x45,                         0xAB,  /* KP_Add */
    +  0x4B,                         0xAF,  /* KP_Divide */
    +  0x4E,                         0xAD,  /* KP_Subtract */
    +  0x51,                         0xBD,  /* KP_Equal */
    +  0x52,                         0xB0,  /* KP_0 */
    +  0x53,                         0xB1,  /* KP_1 */
    +  0x54,                         0xB2,  /* KP_2 */
    +  0x55,                         0xB3,  /* KP_3 */
    +  0x56,                         0xB4,  /* KP_4 */
    +  0x57,                         0xB5,  /* KP_5 */
    +  0x58,                         0xB6,  /* KP_6 */
    +  0x59,                         0xB7,  /* KP_7 */
    +  0x5B,                         0xB8,  /* KP_8 */
    +  0x5C,                         0xB9,  /* KP_9 */
    +  // The enter key is on the keypad but modifier isnt set
    +  NSEnterCharacter,        0x8D
    +};
    
     /* Lisp communications */
     Lisp_Object ns_input_file, ns_input_font, ns_input_fontsize, ns_input_line;
    @@ -1842,6 +1870,23 @@
          return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
     }
    
    +static unsigned
    +ns_convert_keypad (unsigned code)
    +/* --------------------------------------------------------------------------
    +    Internal call used by NSView-keyDown.
    +   -------------------------------------------------------------------------- */
    +{
    +  const unsigned last_keysym = (sizeof (convert_nskeypad_to_X_keysym)
    +                                / sizeof (convert_nskeypad_to_X_keysym[0]));
    +  unsigned keysym;
    +  /* An array would be faster, but less easy to read. */
    +  for (keysym = 0; keysym < last_keysym; keysym += 2) {
    +      if (code == convert_nskeypad_to_X_keysym[keysym]) {
    +        return 0xFF00 | convert_nskeypad_to_X_keysym[keysym+1];
    +      }
    +  }
    +  return 0;
    +}
    
     char *
     x_get_keysym_name (int keysym)
    @@ -4349,7 +4394,7 @@
       struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (emacsframe);
       int code;
       unsigned fnKeysym = 0;
    -  int flags;
    +  unsigned int flags = [theEvent modifierFlags];
       static NSMutableArray *nsEvArray;
       static BOOL firstTime = YES;
    
    @@ -4397,6 +4442,9 @@
           /* (Carbon way: [theEvent keyCode]) */
    
           /* is it a "function key"? */
    +      if (code < 0x00ff && (flags & NSNumericPadKeyMask) )
    +        fnKeysym = ns_convert_keypad([theEvent keyCode]);
    +      else
           fnKeysym = ns_convert_key (code);
           if (fnKeysym)
             {
    @@ -4410,8 +4458,6 @@
    
           /* are there modifiers? */
           emacs_event->modifiers = 0;
    -      flags = [theEvent modifierFlags];
    -
           if (flags & NSHelpKeyMask)
               emacs_event->modifiers |= hyper_modifier;
    

    【讨论】:

      猜你喜欢
      • 2010-09-14
      • 2011-10-10
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多