Subject: Re: bug#54970: 28.1; Some emoji no longer display

From: Eli Zaretskii <[email-masked]>
Date: Sat, 23 Apr 2022 10:51:15 +0300

> From: Howard Melman <[email-masked]>
> Date: Fri, 22 Apr 2022 17:56:34 -0400
> Cc: Robert Pluim <[email-masked]>,
>  Alan Third <[email-masked]>,
>  Lars Ingebrigtsen <[email-masked]>,
>  [email-masked]
> 
> First, is composition supposed to work everywhere?

Yes -- as long as the font used for the characters supports that.  In
particular, all the characters of a sequence that's expected to be
composed should be supported by a single font that is used for the
character (usually, but not always, the first character of the
composed sequence) that triggers the composition rule.

> I have the following
> code to add to the C-x 8 map and I use which-key from gnu elpa but its
> displayed help isn't composing.  It's just a buffer named " *which-key*"
> and I can switch to it but can't do anything in it to inspect things.  It's hard
> to follow how they're writing to it.  I can open a which-key bug but I wanted
> to understand more about composing and if it's supposed to be enabled
> everywhere (which-key doesn't reference it at all)

Please discuss this with the developer of which-key, or ask him to
join this discussions and answer your questions about which-key.  That
package is highly non-trivial, weighs in at 2700 lines of Lisp, and
defines several faces (which might affect character composition), so
it isn't easy to understand what it does and how, and isn't really our
job here.  If and when the which-key developer decides there's a core
bug/issue, please come back and show a recipe starting from "emacs -Q"
for reproducing the bug/issue, and we will look into that.

> Second, I'm using this now for emoji fonts:
> 
> (set-fontset-font t 'symbol '("Apple Color Emoji" . "iso10646-1") nil 'prepend)
> 
> I saw from a related reddit post that the font Symbola has some other glyphs
> that seemed of interest.  It renders things as plain graphics not as color
> emoji which is fine (or preferred) for math symbols.  I'd like to use Apple
> Color Emoji first and then if it doesn't support a character fall back on
> Symbola.  I thought to do that with:
> 
> (set-fontset-font t 'symbol '("Symbola" . "iso10646-1") nil 'prepend)
> (set-fontset-font t 'symbol '("Apple Color Emoji" . "iso10646-1") nil 'prepend)
> 
> But it didn't work.  Most emoji were rending as Symbola.  I then removed the
> first line and restarted emacs (so just my original line is in the init) and emoji
> were *still* rendered with Symbola.  It wasn't until I disabled the font in the
> mac utility Font Book.app that it went back to full color emoji rendering. I recall
> a similar issue a year ago trying to get Julia Mono working too.

What was the value of use-default-font-for-symbols?  If it was
non-nil, Emacs will in general try to ignore the fontset when it needs
a font for a character belonging to the 'symbol' pseudo-script.

Also, what does the fontset entry for the relevant character(s) say?
(Invoke "M-x describe-fontset RET fontset-default RET" and look for
the entry that corresponds to the codepoints of the characters you are
interested in.)  Note that the default fontset with which Emacs starts
already includes references to Symbola, even without any
customizations.

And what else is in your init files, besides those two lines?

IOW, you didn't provide enough details to help you understand what
happened in your case.  You didn't even tell what characters you tried
to display, without which it is hard to make any progress here.

> What's the right incantation to do this?

To do what?

> How and when is emacs searching for fonts to use and how does it
> relate to the above set-fontset-font calls?

This question is too general.  In general, Emacs looks for a font when
the default font doesn't have a glyph for a character; it first tries
to find a loaded font that supports the character, and if not found
looks in the fonts specified by the fontsets.

> It's nice that emacs just finds fonts, but it's unnerving that
> merely installing a font can break what emacs displays.

Sorry, I didn't see anything in your report that could be qualified as
"breakage".  Emacs just used a font other than the one you intended to
display some (unnamed) characters, probably because you didn't
sufficiently understand the intricacies of setting up fontsets.  That
doesn't qualify as breakage, IMO.  And yes, setting up fontsets is a
subtle art.