Library ucs-cmds.el
can help.
It provides a macro, ucsc-make-commands
, for quickly creating a set of commands that insert Unicode characters. You provide a regexp to it, which is matched against all Unicode character names (in ucs-names
). An insertion
command is created for each of the characters whose name matches. (The command names are essentially the same as the char names - see below.)
Sample command creations:
(ucsc-make-commands "^math") ; Math symbols
(ucsc-make-commands "latin") ; Latin alphabet characters
(ucsc-make-commands "arabic")
(ucsc-make-commands "^cjk") ; Chinese, Japanese, Korean characters
(ucsc-make-commands "^box drawings ")
(ucsc-make-commands "^greek [a-z]+ letter") ; Greek characters
(ucsc-make-commands "\\(^hangul\\|^circled hangul\\|^parenthesized hangul\\)")
This is the doc string:
ucsc-make-commands is a Lisp macro in `ucs-cmds.el'.
(ucsc-make-commands REGEXP)
Create commands to insert Unicode characters whose names match REGEXP.
Letter case is ignored for matching.
The set of char names used is taken from `ucs-names'. There are
*many* such chars, so consider using a tighter regexp to limit the
number of commands created.
The commands created have the same names as the chars they insert,
except that `SPC' chars in the character names are replaced by
hyphens (`-'), and the command names are lowercase.
If you wanted to bind the commands you create to keys in a systematic way, then you could easily create a macro based on the code of ucsc-make-commands
that both creates the commands you want and binds them. Macro ucsc-make-commands
just iterates over all of the Unicode cars and creates commands for those whose names match the REGEXP
argument.
During an iteration you have access to the character name and its code point. Figure out a convenient regular mapping of either code points or char names to keys, and your macro can add the appropriate define-key
s in addition to the command defun
s.
The library also provides a command, ucsc-insert
, that can replace vanilla command
insert-char
. The behavior and code of ucsc-insert
are identical to those of
insert-char
except for what happens when you use a negative prefix argument:
It acts as if the prefix-arg value was positive. So a value of
-3 inserts three copies of the character, just as 3 does.
In addition to inserting the character, it defines a command
that you can use thereafter to insert that character. You can
use a prefix argument with that command to insert multiple
copies of the given character.
This gives you a command that is tailor-made to insert a given
Unicode character. You can then bind the command to a key
sequence, effectively adding Unicode characters to your keyboard.
Whenever insert-char
does anything (it does nothing for a
negative prefix arg), ucsc-insert
does the same thing. Because
of this, you can bind ucsc-insert
to C-x 8 RET
as
a replacement for insert-char
:
(define-key global-map [remap insert-char] 'ucsc-insert)
If you need only a few such commands for inserting particular
Unicode characters, then using ucsc-insert
to define them is
sufficiently convenient. If you need a lot of such commands then macro ucsc-make-commands
is your friend.