How can I make it so that
H-g followed by
a gives an alpha etc.?
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") "α")
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.
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.