emacs create key modifier

十年热恋 提交于 2020-01-02 05:21:08

问题


I am using emacs on mac os. I would like to map a modifier (Meta, Control,...) to a simple key. Basically this is what I need : (global-set-key (kbd "a") 'hyper) Here a is just the a key, no Control-a or whatever, just "a" alone whithout modifier. I want "a" to become hyper for example but I can't find a solution for this.

Someone have a clue ?


回答1:


This approach won't make a modifier key in the sense that you press another key with the modifier held down, but it lets you use hyper bindings nevertheless.

By default you can utilise the additional modifier keys via the C-x@ prefix. See C-x@C-h for the full list.

These bindings are in function-key-map, and you can use the same method to get your own OS-independent bindings. e.g.:

(define-key function-key-map (kbd "C-c H") 'event-apply-hyper-modifier)

function-key-map is the parent for all local-function-key-map instances. Note carefully:

Entries in `local-function-key-map' are ignored if they conflict with bindings made in the minor mode, local, or global keymaps. I.e. the remapping only applies if the original key sequence would otherwise not have any binding.

C-hig (elisp) Translation Keymaps RET

So ensure that you use a key sequence with no existing bindings. (In theory that's quite limiting, but YMMV.)

Edit: To clarify, this gives you a way to access any existing 'hyper' bindings when you are using a machine without a hyper modifier key, but does not actually create a new modifier key. If you have no existing bindings to access, this technique has no advantages over a regular prefix binding.

I believe it's the case that, as Peter commented, creating a genuine modifier key is an OS-level task. AFAIK when you press a modifier key on its own, Emacs does not receive any input, and when you press a non-modifier with a modifier, Emacs receives the (modified) input. Conversely when you press/hold a non-modifier key, Emacs receives input immediately, and has no way to combine that input with some other input and treat it all as a single (modified) event.

IIRC, xmodmap would be the typical mechanism for achieving this in Unix systems, so that may well be the case for OSX. The following links may help:

  • http://computing.fnal.gov/docs/products/xemacs/v21_1/xemacs.info,.SuperandHyperKeys.html
  • http://www.emacswiki.org/emacs/XModMap
  • http://www.emacswiki.org/emacs/MetaKeyProblems


来源:https://stackoverflow.com/questions/10730775/emacs-create-key-modifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!