3

How can I make it so that H-g followed by a gives an alpha etc.?

4

There are several ways. A key difference is how close H-g a is to typing an actual character α would be if you had that key on your keyboard. For example, you can make H-g a a macro that inserts the string α:

(define-key global-map (kbd "H-g a") "α")

But then H-g a differs from inserting a character in several ways which may or may not be desirable. For example it won't trigger behaviors specific to self-insert-command (which is the case in some abbrev expansion/autocompletion packages), it is not grouped with other insertions for undo purposes, etc. This also allows H-g to be overridden by mode-specific bindings.

To make the translation really look like a character insertion and work before any ordinary key bindings, but after terminal-specific ones (so if you use a non-window Emacs on a terminal that sends an escape sequence for H-g, your binding will still work), put it in key-translation-map, which is pretty much designed for what you're doing.

(define-key key-translation-map (kbd "H-g a") "α")
…

Emacs has input methods for inserting characters that aren't on the keyboard, but I don't know how to use an input method for the next character only.

  • Apologies for the stupid question, but what is H-g? I know C-..., M-..., s-..., but never heard of H-.... – AstroFloyd Nov 11 at 11:27
  • 1
    @AstroFloyd It's the Hyper modifier. Not present by name on most keyboards, but a somewhat popular choice for the “Windows” keys on PC. – Gilles 'SO- stop being evil' Nov 11 at 23:23
2

To do this for all Greek letters, download library ucs-cmds.el, then put this in your init file:

(require 'ucs-cmds)
(ucsc-make-commands "^greek [a-z]+ letter")))
(global-set-key (kbd "H-g a") 'greek-small-letter-alpha)

That defines a command for each Greek letter, which inserts it. The command name is the same as the character (letter) it inserts, except that it is lowercase and spaces have been replaced by hyphens.

The return value of ucsc-make-commands is a list of the commands created (their symbols), so you can in fact iterate over it (or a subset) to create a set of key bindings for them all at once, if you like.

1

You can access one input method from another. Switch to your Greek input method and evaluate

(setq greek-map (quail-map))

Switch to your standard Latin input method and evaluate

(quail-defrule ",." greek-map)

Now, if you type ,.a, that will produce an alpha, &c.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.