Subject: Re: bug#70993: set-fontset-font doesn't use specified font for some scripts

From: Rodrigo Morales <[email-masked]>
Date: Sat, 18 May 2024 01:17:33 -0500

Eli Zaretskii <[email-masked]> writes:

> In any case, it sounds like Emacs rejects the Cozette font for some
> scripts.  Why that happens, I don't know, sorry.  Can you set font-log
> to nil before you visit your a.txt file, and then post the value of
> font-log after the file is displayed?  That could perhaps tell us
> something about the cause of this behavior.

I performed two experiments. I emptied ~/.config/emacs/init.el and
inserted the sexps showed in the first code block below. The content of
=/tmp/a.txt= is shown in the second code block below.

#+HEADER: :tangle ~/.config/emacs/init.el
#+BEGIN_SRC elisp
(set-fontset-font t 'brahmi (font-spec :family "Cozette"))
(set-fontset-font t 'egyptian (font-spec :family "Cozette"))
(set-fontset-font t 'ethiopic (font-spec :family "Cozette"))
(set-fontset-font t 'tagbanwa (font-spec :family "Cozette"))
(set-fontset-font t 'han (font-spec :family "Cozette"))
#+END_SRC

#+HEADER: :tangle /tmp/a.txt
#+BEGIN_SRC text
The following lines were retrieved from the HELLO buffer which is
opened by calling view-hello-file in GNU Emacs 29.3.
Brahmi (𑀩𑁆𑀭𑀸𑀳𑁆𑀫𑀻)	𑀦𑀫𑀲𑁆𑀢𑁂
Egyptian Hieroglyphs (𓂋𓏤𓈖𓆎𓅓‌𓏏𓊖)	𓅓𓊵𓏏𓊪, 𓇍𓇋𓂻𓍘𓇋
Amharic (አማርኛ)	ሠላም
Tagbanwa (ᝦᝪᝯ)	ᝫᝩᝬᝥ ᝣᝮᝧᝯ
Chinese (中文,普通话,汉语)	你好
#+END_SRC

1. I launched =emacs= without the =-Q= flag so that
   =~/.config/emacs/init.el= is read. Then, I evaluated =(setq
   font-log nil)=. Then, I evaluated =(find-file
   "/tmp/a.txt")=. Brahmi and Egyptian Hieroglyphs were shown as
   hexadecimal codes inside boxes. Amharic, Tagbanwa and Chinese
   characters were shown using other fonts. Then, I evaluated
   =(describe-variable 'font-log)=. The content of the =*Help*= buffer
   can be found here:
   http://web.archive.org/web/20240518060947/http://0x0.st/XPqh.txt

2. I launched =EMACS_FONT_LOG=1 emacs= without the =-Q= flag so that
   =~/.config/emacs/init.el= is read. Then, I evaluated =(find-file
   "/tmp/a.txt")=. Brahmi and Egyptian Hieroglyphs were shown as
   hexadecimal codes inside boxes. Amharic, Tagbanwa and Chinese
   characters were shown using other fonts. Then, I evaluated
   =(describe-variable 'font-log)=. The content of the =*Help*= buffer
   can be found here:
   http://web.archive.org/web/20240518061129/http://0x0.st/XPq7.txt

> In general, the Emacs font search and the related features are
> designed to find good fonts for displaying each character, whereas you
> are trying to do the opposite: force Emacs to choose a font that can
> NOT display characters.  The doc string of set-fontset-font explains
> how to set up a fontset so that certain characters have no font: use
> nil for the FONT-SPEC argument.  So if you want Amharic and Chinese
> characters to display as glyphless characters, use this:
>
>   (set-fontset-font t 'han nil)
>   (set-fontset-font t 'ethiopic nil)

I tried what you suggested. However, this didn't make Amharic and
Chinese characters to be shown as glyphless characters. See bug#71025.

> This is indeed a limitation for someone who modifies the fontsets a
> lot during a session, but unless someone submits patches to lift it,
> it will remain a limitation, sorry.

No problem. I will work on a patch when time allows. My initial thought
was that Emacs mantainers assumed that most users don't need to call
set-fontset-font in the middle of an Emacs session, so any user that
tries to do this shouldn't be taken into consideration and those users
need to adapt themselves to that constraint, this way of thinking goes
against the goal of Emacs of being a customizable text editor. However,
your last message proved my initial thoughts wrong.