emacs create key modifier

1.1k views Asked by At

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

There are 1 answers

3
phils On BEST ANSWER

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: