[Top][All Lists]

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

Re: Do Emacs support font ligatures?

From: Eli Zaretskii
Subject: Re: Do Emacs support font ligatures?
Date: Tue, 27 Sep 2016 17:26:10 +0300

> From: Oleksandr Gavenko <>
> Date: Mon, 26 Sep 2016 23:32:38 +0300
> Opened "geany" GTK based editor and select Monoid-9 font.
> Put text:
>   ==   =>   ->   -->
> It was shown as 4 ligatures.
> With "emacs -Q" and:
>   (set-frame-font "Monoid-9")
> I see separate glyphs for "=", ">", "-" instead of 4 ligatures.

If that is what you meant, then prettify-symbols-mode is exactly for
you.  I don't think I understand what caused you to think it is not
the feature you are looking for.  In your original message you wrote:

> Of course Emacs has trick with
>   (font-lock-add-keywords
>    'emacs-lisp-mode
>    `(("(\\<\\(lambda\\)\\>"
>       (1 (progn (compose-region (match-beginning 1) (match-end 1) ,(make-char 
> 'greek-iso8859-7 107)) font-lock-keyword-face)) )))
> and I think even formalized library:
>   prettify-symbols-mode

The prettify-symbols-mode is _not_ a "trick".  The way to tell Emacs
to shape a certain character sequence together as a single unit is by
defining a "composition rule", like shown above.  Emacs already has
composition rules defined for character sequences for which either
Unicode or some language or script mandate that.  For symbols such as
the arrows etc. there are no such rules, so by default Emacs displays
those characters as separate glyphs (and I'm not even sure it's
appropriate to ligate them by default in all buffers).  But if you
write such rules, or use prettify-symbols-mode with its infrastructure
to create those rules, these sequences will be displayed as ligatures
if the underlying font supports that.

> but I interested if ligatures supported by font rendering engines behind
> Emacs.

The way Emacs shapes sequences of characters together _is_ by asking
the shaping engine how to display them.  The shaping engine gets
passed the sequence of characters to display, and it returns a
sequence of one or more glyphs to display them with.  If your Emacs is
built with "complex script support" libraries, that is what happens
under the hood all the time, whether there are composition rules or
not.  Some scripts, such as Arabic, are actually barely legible if
shaping is not used, because those scripts define how the same
character should look in various parts of a word and when adjacent to
other characters.  So Emacs must shape them correctly to be relevant
in the cultures that use these scripts.

> Actually author of FiraCode collect tricks how to achieve similar effect in
> Emacs with his font:

Again, these are not "tricks", this is how this stuff should be done
in Emacs, since Emacs users should be able to control whether these
character sequences are or aren't displayed as ligatures, and in what
buffers/modes.  Doing that always is IMO not the Emacsy way for
implementing such features.

> Under page:
> there is "Ligatures" section and site CSS uses embedded fonts.
> If you open in modern Web browser (I've succeeded with Firefox 49) you see
> different arrows ligature instead of groups of 2/3 separated glyphs for
> =/</>/- characters.

Then perhaps EWW, the Emacs Web browser, should also support
prettify-symbols-mode, or maybe even turn it on by default.  Feel free
to file a feature request bug report about that.

> Is that usual for Emacs bug-report to include PNG screenshot?

You can attach any benign attachment that is relevant to the bug

However, the only issue worth reporting in this case I can think of is
extension of prettify-symbols-mode to more symbols and more major
modes, so that users won't need to write such complex Lisp if they
don't want to.  And maybe also EWW support for that.

reply via email to

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