How about this:
char-displayable-p
is an autoloaded compiled Lisp function in
`mule-util.el'.
(char-displayable-p CHAR)
Return non-nil if we should be able to display CHAR.
On a multi-font display, the test is only whether there is an
appropriate font from the selected frame's fontset to display
CHAR's charset in general. Since fonts may be specified on a
per-character basis, this may not be accurate.
Add-on by user Tobias:
The manual says that char-displayable-p
would return t if the character is displayable with selected frame's fontset:
— Function: char-displayable-p char
This function returns t if Emacs ought to be able to display char. More precisely, if the selected frame's fontset has a font to display the character set that char belongs to.
Fontsets can specify a font on a per-character basis; when the fontset does that, this function's value may not be accurate.
Tests and an analysis of the source code tell another story. Only the case of a graphical display is discussed in the following.
All fonts can display ASCII characters. There is a shortcut branch in char-displayable-p
returning t for that case.
Otherwise, if the font for the default face has a glyph for representing CHAR that font is returned. That is the first component of the return value of internal-char-font
. But, pityingly internal-char-font
is for internal use only.
The real implementation of char-displayable-p
in Emacs 26.1 interprets "displayable" a bit wider.
It may be that CHAR can be encoded by the current coding system (tested with encode-char
), but the glyph for CHAR is missing in the font for the default face. In that case char-displayable-p
returns the coding system and CHAR is represented by a square containing the code point.
For testing whether there is a glyph for CHAR in the font for the default face you could use the following test:
(or (< CHAR 128) (fontp (char-displayable-p CHAR)))
Side note:
If internal-char-font
wasn't internal you could also simply use (internal-char-font nil CHAR)
.
Maybe internal-char-font
is really an alternative since the return value of char-displayable-p
is also not specified in the documentation of that function.