From the documentation of insert-char
, I cannot see why
(insert-char "GREEK SMALL LETTER EPSILON")
doesn't work. Is there a non-interactive way to insert a character given its Unicode name?
From the documentation of insert-char
, I cannot see why
(insert-char "GREEK SMALL LETTER EPSILON")
doesn't work. Is there a non-interactive way to insert a character given its Unicode name?
From the documentation of
insert-char
, I cannot see why
(insert-char "GREEK SMALL LETTER EPSILON")
doesn't work.
It doesn't work because insert-char
understands Unicode character names only when called interactively (e.g. via C-x8RET or M-xinsert-char
RET), as stated in its docstring:
Interactively, prompt for CHARACTER. You can specify CHARACTER in one
of these ways:
- As its Unicode character name, e.g. "LATIN SMALL LETTER A".
Completion is available; if you type a substring of the name
preceded by an asterisk ‘*’, Emacs shows all names which include
that substring, not necessarily at the beginning of the name.
- As a hexadecimal code point, e.g. 263A. Note that code points in
Emacs are equivalent to Unicode up to 10FFFF (which is the limit of
the Unicode code space).
- As a code point with a radix specified with #, e.g. #o21430
(octal), #x2318 (hex), or #10r8984 (decimal).
The interactive
spec of insert-char
delegates to read-char-by-name
for Unicode name completion and translation to the corresponding character code.
When insert-char
is called from Lisp, its first argument CHARACTER
should satisfy the predicate characterp
.
Is there a non-interactive way to insert a character given its Unicode name?
There are multiple ways; here's one for Emacs 26 and subsequent versions:
(insert (char-from-name "GREEK SMALL LETTER EPSILON"))
Here's another for earlier Emacs versions:
(insert (cdr (assoc "GREEK SMALL LETTER EPSILON" (ucs-names))))