bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57693: 29.0.50; Is there a more reliable version of `char-displayabl


From: Eli Zaretskii
Subject: bug#57693: 29.0.50; Is there a more reliable version of `char-displayable-p'?
Date: Tue, 13 Sep 2022 14:19:01 +0300

> From: Ihor Radchenko <yantar92@gmail.com>
> Cc: 57693@debbugs.gnu.org
> Date: Tue, 13 Sep 2022 09:44:06 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > If the terminal's encoding is UTF-8, and it doesn't support the method
> > we use to query about individual glyphs, char-displayable-p may return
> > non-nil when the character cannot be displayed, i.e. will show as an
> > empty box or something.  Otherwise, char-displayable-p does provide
> > the correct answer for TTY frames.
> 
> Do I understand correctly that:
> 1. `font-at' is not sufficient for terminals, and we also need to use
>    `char-displayable-p'
> 2. `char-displayable-p' works on many terminals but may be inaccurate in some

More or less.  More accurately:

 . font-at is not useful on text-mode frames
 . char-displayable-p, when invoked on text-mode frames, in most cases
   reports only whether the character can be safely encoded by
   terminal-coding-system
 . if terminal-coding-system is UTF-8, char-displayable-p will
   generally trivially return non-nil, unless the terminal supports
   queries about glyphs that it has for specific characters
 . the only terminal I know of that supports the above queries is the
   Linux console, which I think is not very popular among Emacs users
 . for terminals that do support such queries, you can use this:

      (internal-char-font nil CHAR)

   which will return a positive number if CHAR can be displayed,
   negative number if it cannot, or nil if the query is not supported.

So an efficient method of testing this for terminal would be:

  . if terminal-coding-system is UTF-8, call internal-char-font to see
    if the character is supported, and if it returns a number,
    consider the character supported if the number is positive, not
    supported otherwise
  . otherwise, if terminal-coding-system is UTF-8, consider character
    supported (and pray)
  . otherwise call char-displayable-p and judge by its value

This is more efficient than calling char-displayable-p because I
expect most terminals these days to use UTF-8 encoding, and for them
the above is optimized.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]