unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to use "smart kerning" font features in Emacs using composition-function-table
@ 2023-11-26 15:48 Steve Molitor
  2023-11-26 17:52 ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Steve Molitor @ 2023-11-26 15:48 UTC (permalink / raw)
  To: emacs-devel

Using composition-function-table, is it possible to have the font
render a glyph for each character, based on the previous and following
character, in a moving window? For example, the rendering of character
1 will depend on what characters 0 and 2 are, character 2 depends on 1
and 3, etc.

Context:

The Commit Mono font has a feature that it calls "smart kerning". The
Monaspace font has a similar feature that it calls "texture healing."
Characters are moved around slightly, or swapped out for a slightly
larger or smaller character to even out the spacing, for example, when
a wide character like an 'm' is followed by a narrow character like an
'l'. It works by looking at the size class of the previous and
following characters to determine if it needs to shift the current
character to the left or right. For reference, the smart kerning
implementation in Commit Mono is here:

https://github.com/eigilnikolajsen/commit-mono/blob/main/src/features/kern_smartkerning.fea

I decided to see if I could get it to work just for the "Commit"
string by adding the following elisp:

    (set-char-table-range composition-function-table ?o
                                     '(["Com" 1 font-shape-gstring]))
    (set-char-table-range composition-function-table ?m
                                    '(["mmi" 1 font-shape-gstring]))

My thinking was if the current character is "o", preceded by a "C" and
followed by an "m", let the font replace the "o". Next, if the current
character is an "m" preceded by an "m" and followed by an "i", let the
font render the middle "m". If that worked I was going to do something
more generic.

It half worked. If I type "Com" it works as expected - the "o" shifts
slightly to the left when I type the "m":

https://cdn.zappy.app/f1506de028c470750428ebf984dfbe41.gif

If I type "mmi" on a separate line it also works - the second "m"
shifts to the left when I type the "i":

https://cdn.zappy.app/6a1a90013d102bfb494fc7d1de54ca32.gif

However, if I type "Commit", the "Com" works (the "o" shifts"), but
nothing happens when I type "mit". If I use three m's and type
"Commmit" I do see the effect on the final "mit":

https://cdn.zappy.app/e98141872235a25bf52f6e332b610d7b.gif

It seems I've created 3 character, non-overlapping gifs, which is not
the effect I want.

For comparison, here it is in VSCode, typing "Commit". Various
shifting effects happen as expected:

https://cdn.zappy.app/8f3bc49a174c4673747c402f7b39d54b.gif

I think when Emacs matches the 3 character regexp in the composition
function table, it assumes that those 3 characters constitute a single
glyph or ligature. That makes sense for ligatures, but it's not what I
want here. I want a "moving window" where the glyph for each character
depends on the previous and following character.

Is this possible to do in Emacs currently?

Thanks!

Steve



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-26 15:48 How to use "smart kerning" font features in Emacs using composition-function-table Steve Molitor
@ 2023-11-26 17:52 ` Eli Zaretskii
  2023-11-26 19:49   ` Steve Molitor
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-11-26 17:52 UTC (permalink / raw)
  To: Steve Molitor; +Cc: emacs-devel

> From: Steve Molitor <stevemolitor@gmail.com>
> Date: Sun, 26 Nov 2023 09:48:34 -0600
> 
> Using composition-function-table, is it possible to have the font
> render a glyph for each character, based on the previous and following
> character, in a moving window? For example, the rendering of character
> 1 will depend on what characters 0 and 2 are, character 2 depends on 1
> and 3, etc.

Not really, see below.

> I decided to see if I could get it to work just for the "Commit"
> string by adding the following elisp:
> 
>     (set-char-table-range composition-function-table ?o
>                                      '(["Com" 1 font-shape-gstring]))
>     (set-char-table-range composition-function-table ?m
>                                     '(["mmi" 1 font-shape-gstring]))
> 
> My thinking was if the current character is "o", preceded by a "C" and
> followed by an "m", let the font replace the "o". Next, if the current
> character is an "m" preceded by an "m" and followed by an "i", let the
> font render the middle "m". If that worked I was going to do something
> more generic.
> 
> It half worked. If I type "Com" it works as expected - the "o" shifts
> slightly to the left when I type the "m":
> 
> https://cdn.zappy.app/f1506de028c470750428ebf984dfbe41.gif
> 
> If I type "mmi" on a separate line it also works - the second "m"
> shifts to the left when I type the "i":
> 
> https://cdn.zappy.app/6a1a90013d102bfb494fc7d1de54ca32.gif
> 
> However, if I type "Commit", the "Com" works (the "o" shifts"), but
> nothing happens when I type "mit". If I use three m's and type
> "Commmit" I do see the effect on the final "mit":
> 
> https://cdn.zappy.app/e98141872235a25bf52f6e332b610d7b.gif
> 
> It seems I've created 3 character, non-overlapping gifs, which is not
> the effect I want.
> 
> For comparison, here it is in VSCode, typing "Commit". Various
> shifting effects happen as expected:
> 
> https://cdn.zappy.app/8f3bc49a174c4673747c402f7b39d54b.gif
> 
> I think when Emacs matches the 3 character regexp in the composition
> function table, it assumes that those 3 characters constitute a single
> glyph or ligature. That makes sense for ligatures, but it's not what I
> want here. I want a "moving window" where the glyph for each character
> depends on the previous and following character.
> 
> Is this possible to do in Emacs currently?

No, it's not possible.  When characters are composed successfully
(i.e., they match some rule in composition-function-table, and the
font support their composition), Emacs will not examine them again for
other rules.  It will restart examining from the first character
_after_ those which matched.

So to use kerning like the one you describe, I think you must have a
rule that matches any sequence of ASCII letters, not just the triplets
where the kerning is supposed to happen.  Which means that every word
using ASCII characters will be passed to the text-shaping engine.
Then the shaping engine will decide on its own where to use the
kerning, and I think you should get what you want, appearance-wise.

But -- and it's a very significant "but" -- displaying text via the
shaping engine is expensive -- it involves calls from the display
engine to Lisp, which then calls back into C.  So rules that match any
sequence of ASCII letters will slow down redisplay of almost any text
in Emacs.  This is why Emacs by default doesn't use the text-shaping
engine except for scripts that cannot be displayed without non-trivial
character compositions.  So if you go the above way, don't be
surprised if you see slower redisplay.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-26 17:52 ` Eli Zaretskii
@ 2023-11-26 19:49   ` Steve Molitor
  2023-11-26 20:16     ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Steve Molitor @ 2023-11-26 19:49 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Thanks for the clear response! It makes perfect sense and confirms what
I was seeing.

> So to use kerning like the one you describe, I think you must have a
> rule that matches any sequence of ASCII letters, not just the triplets
> where the kerning is supposed to happen.

Thanks. This indeed does work (matching against the characters Commit
Mono applies its kerning effect to):

(set-char-table-range
 composition-function-table
 t
 `(["[ ,-.:;A-Z_a-z]+" 0 font-shape-gstring]))

I see the "smart kerning" effect as expected. So far after a quick test
performance seems ok but we'll see. I did notice that if I changed the
PREV-CHARS value from 0 to 1 I would get seconds-long redisplay delays!

> But -- and it's a very significant "but" -- displaying text via the
> shaping engine is expensive -- it involves calls from the display
> engine to Lisp, which then calls back into C. So rules that match any
> sequence of ASCII letters will slow down redisplay of almost any text
> in Emacs. This is why Emacs by default doesn't use the text-shaping
> engine except for scripts that cannot be displayed without non-trivial
> character compositions.

Which scripts use the text-shaping engine? Is it possible to optionally
use the text-shaping engine and bypass Lisp in say the "English" script?
I understand that certain features like mode-specific ligatures might
stop working, but it could be a nice option.

Thanks again,

Steve



On Sun, Nov 26, 2023 at 11:53 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Steve Molitor <stevemolitor@gmail.com>
> > Date: Sun, 26 Nov 2023 09:48:34 -0600
> >
> > Using composition-function-table, is it possible to have the font
> > render a glyph for each character, based on the previous and following
> > character, in a moving window? For example, the rendering of character
> > 1 will depend on what characters 0 and 2 are, character 2 depends on 1
> > and 3, etc.
>
> Not really, see below.
>
> > I decided to see if I could get it to work just for the "Commit"
> > string by adding the following elisp:
> >
> >     (set-char-table-range composition-function-table ?o
> >                                      '(["Com" 1 font-shape-gstring]))
> >     (set-char-table-range composition-function-table ?m
> >                                     '(["mmi" 1 font-shape-gstring]))
> >
> > My thinking was if the current character is "o", preceded by a "C" and
> > followed by an "m", let the font replace the "o". Next, if the current
> > character is an "m" preceded by an "m" and followed by an "i", let the
> > font render the middle "m". If that worked I was going to do something
> > more generic.
> >
> > It half worked. If I type "Com" it works as expected - the "o" shifts
> > slightly to the left when I type the "m":
> >
> > https://cdn.zappy.app/f1506de028c470750428ebf984dfbe41.gif
> >
> > If I type "mmi" on a separate line it also works - the second "m"
> > shifts to the left when I type the "i":
> >
> > https://cdn.zappy.app/6a1a90013d102bfb494fc7d1de54ca32.gif
> >
> > However, if I type "Commit", the "Com" works (the "o" shifts"), but
> > nothing happens when I type "mit". If I use three m's and type
> > "Commmit" I do see the effect on the final "mit":
> >
> > https://cdn.zappy.app/e98141872235a25bf52f6e332b610d7b.gif
> >
> > It seems I've created 3 character, non-overlapping gifs, which is not
> > the effect I want.
> >
> > For comparison, here it is in VSCode, typing "Commit". Various
> > shifting effects happen as expected:
> >
> > https://cdn.zappy.app/8f3bc49a174c4673747c402f7b39d54b.gif
> >
> > I think when Emacs matches the 3 character regexp in the composition
> > function table, it assumes that those 3 characters constitute a single
> > glyph or ligature. That makes sense for ligatures, but it's not what I
> > want here. I want a "moving window" where the glyph for each character
> > depends on the previous and following character.
> >
> > Is this possible to do in Emacs currently?
>
> No, it's not possible.  When characters are composed successfully
> (i.e., they match some rule in composition-function-table, and the
> font support their composition), Emacs will not examine them again for
> other rules.  It will restart examining from the first character
> _after_ those which matched.
>
> So to use kerning like the one you describe, I think you must have a
> rule that matches any sequence of ASCII letters, not just the triplets
> where the kerning is supposed to happen.  Which means that every word
> using ASCII characters will be passed to the text-shaping engine.
> Then the shaping engine will decide on its own where to use the
> kerning, and I think you should get what you want, appearance-wise.
>
> But -- and it's a very significant "but" -- displaying text via the
> shaping engine is expensive -- it involves calls from the display
> engine to Lisp, which then calls back into C.  So rules that match any
> sequence of ASCII letters will slow down redisplay of almost any text
> in Emacs.  This is why Emacs by default doesn't use the text-shaping
> engine except for scripts that cannot be displayed without non-trivial
> character compositions.  So if you go the above way, don't be
> surprised if you see slower redisplay.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-26 19:49   ` Steve Molitor
@ 2023-11-26 20:16     ` Eli Zaretskii
  2023-11-26 20:42       ` Steve Molitor
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-11-26 20:16 UTC (permalink / raw)
  To: Steve Molitor; +Cc: emacs-devel

> From: Steve Molitor <stevemolitor@gmail.com>
> Date: Sun, 26 Nov 2023 13:49:13 -0600
> Cc: emacs-devel@gnu.org
> 
> Thanks. This indeed does work (matching against the characters Commit
> Mono applies its kerning effect to):
> 
> (set-char-table-range
>  composition-function-table
>  t
>  `(["[ ,-.:;A-Z_a-z]+" 0 font-shape-gstring]))

Do you really need the space character there?  What happens if you
omit it?

And what about '?' and '!'?

> > But -- and it's a very significant "but" -- displaying text via the
> > shaping engine is expensive -- it involves calls from the display
> > engine to Lisp, which then calls back into C. So rules that match any
> > sequence of ASCII letters will slow down redisplay of almost any text
> > in Emacs. This is why Emacs by default doesn't use the text-shaping
> > engine except for scripts that cannot be displayed without non-trivial
> > character compositions.
> 
> Which scripts use the text-shaping engine?

Arabic, Korean (Hangul), various Indian scripts (Devanagar, Bengali,
Gurmukhi), and some others.  Grep for composition-function-table in
lisp/language/*.el, and you will see them all.

Typically, only specific sequences of codepoints are composed, with
rare exceptions, even if a script needs compositions.  This is again
for performance reasons.

> Is it possible to optionally use the text-shaping engine and bypass
> Lisp in say the "English" script?

No, not the way character composition was designed and implemented in
Emacs.  Character composition in Emacs was never meant to be used for
ASCII characters, nor, more generally, for a significant fraction of
buffer text, except in several scripts (such as Arabic) where all the
text must be shaped to be legible.  The calls to Lisp are so that
complex logic of composition and shaping required by some scripts
could be easily implemented and maintained.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-26 20:16     ` Eli Zaretskii
@ 2023-11-26 20:42       ` Steve Molitor
  2023-11-27 12:03         ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Steve Molitor @ 2023-11-26 20:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

> Do you really need the space character there? What happens if you omit
> it?

If I type:

  x mm

Then the second "m" is supposed to get shifted away from the first m. If
I take away the space character that stops working. Commit Mono looks at
3 character sequences to do the kerning.

> And what about '?' and '!'?

Commit Mono doesn't seem to take them into account when kerning. Other
fonts like Github's Monaspace might, however.

For ligature support, I do need something like this for Commit Mono:

    (set-char-table-range
     composition-function-table
     t
     `([" [,-.:;A-Z_a-z><=!&|+-?/\\]+" 0 font-shape-gstring]))

(I'm probably missing some characters but common ligatures and the
kerning work. I could finesse it to support mode-specific ligatures.)

> Character composition in Emacs was never meant to be used for ASCII
> characters, nor, more generally, for a significant fraction of buffer
> text, except in several scripts (such as Arabic) where all the text
> must be shaped to be legible.

Does performance suffer a lot in those languages, like Arabic?

Thanks again for the responses, I appreciate it. I have more understanding
of how character composition works in Emacs now.

On Sun, Nov 26, 2023 at 2:16 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Steve Molitor <stevemolitor@gmail.com>
> > Date: Sun, 26 Nov 2023 13:49:13 -0600
> > Cc: emacs-devel@gnu.org
> >
> > Thanks. This indeed does work (matching against the characters Commit
> > Mono applies its kerning effect to):
> >
> > (set-char-table-range
> >  composition-function-table
> >  t
> >  `(["[ ,-.:;A-Z_a-z]+" 0 font-shape-gstring]))
>
> Do you really need the space character there?  What happens if you
> omit it?
>
> And what about '?' and '!'?
>
> > > But -- and it's a very significant "but" -- displaying text via the
> > > shaping engine is expensive -- it involves calls from the display
> > > engine to Lisp, which then calls back into C. So rules that match any
> > > sequence of ASCII letters will slow down redisplay of almost any text
> > > in Emacs. This is why Emacs by default doesn't use the text-shaping
> > > engine except for scripts that cannot be displayed without non-trivial
> > > character compositions.
> >
> > Which scripts use the text-shaping engine?
>
> Arabic, Korean (Hangul), various Indian scripts (Devanagar, Bengali,
> Gurmukhi), and some others.  Grep for composition-function-table in
> lisp/language/*.el, and you will see them all.
>
> Typically, only specific sequences of codepoints are composed, with
> rare exceptions, even if a script needs compositions.  This is again
> for performance reasons.
>
> > Is it possible to optionally use the text-shaping engine and bypass
> > Lisp in say the "English" script?
>
> No, not the way character composition was designed and implemented in
> Emacs.  Character composition in Emacs was never meant to be used for
> ASCII characters, nor, more generally, for a significant fraction of
> buffer text, except in several scripts (such as Arabic) where all the
> text must be shaped to be legible.  The calls to Lisp are so that
> complex logic of composition and shaping required by some scripts
> could be easily implemented and maintained.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-26 20:42       ` Steve Molitor
@ 2023-11-27 12:03         ` Eli Zaretskii
       [not found]           ` <CAJrM8VW0P+-cO_cup6W-teoJV46nZTcsPrFbaKdXDD_CK_5Rxw@mail.gmail.com>
  2023-11-28  5:18           ` Yuan Fu
  0 siblings, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-11-27 12:03 UTC (permalink / raw)
  To: Steve Molitor; +Cc: emacs-devel

> From: Steve Molitor <stevemolitor@gmail.com>
> Date: Sun, 26 Nov 2023 14:42:36 -0600
> Cc: emacs-devel@gnu.org
> 
> For ligature support, I do need something like this for Commit Mono:
> 
>     (set-char-table-range
>      composition-function-table
>      t
>      `([" [,-.:;A-Z_a-z><=!&|+-?/\\]+" 0 font-shape-gstring]))

Beware: composition-function-table is global, so the above will ligate
characters on the mode line as well, which might not be what you want.

> > Character composition in Emacs was never meant to be used for ASCII
> > characters, nor, more generally, for a significant fraction of buffer
> > text, except in several scripts (such as Arabic) where all the text
> > must be shaped to be legible.
> 
> Does performance suffer a lot in those languages, like Arabic?

It suffers some, yes.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
       [not found]           ` <CAJrM8VW0P+-cO_cup6W-teoJV46nZTcsPrFbaKdXDD_CK_5Rxw@mail.gmail.com>
@ 2023-11-27 15:22             ` Eli Zaretskii
  2023-11-27 16:16               ` Steve Molitor
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-11-27 15:22 UTC (permalink / raw)
  To: Steve Molitor; +Cc: emacs-devel

> From: Steve Molitor <stevemolitor@gmail.com>
> Date: Mon, 27 Nov 2023 08:47:41 -0600
> 
> Thanks again. Last question: Does it make sense to optimize for shorter
> matches? For example, I could pull out the space to only match "words",
> and pull out and handle the "/" separately, to avoid matching against
> long file paths.

Optimize for what purpose?  If almost everything is going to be
matched anyway, I think it is better to send larger chunks of text to
the shaping engine, as that causes fewer calls and the shaping engine
will be able to produce better visuals.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-27 15:22             ` Eli Zaretskii
@ 2023-11-27 16:16               ` Steve Molitor
  0 siblings, 0 replies; 13+ messages in thread
From: Steve Molitor @ 2023-11-27 16:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Got it, thanks!

On Mon, Nov 27, 2023 at 9:22 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Steve Molitor <stevemolitor@gmail.com>
> > Date: Mon, 27 Nov 2023 08:47:41 -0600
> >
> > Thanks again. Last question: Does it make sense to optimize for shorter
> > matches? For example, I could pull out the space to only match "words",
> > and pull out and handle the "/" separately, to avoid matching against
> > long file paths.
>
> Optimize for what purpose?  If almost everything is going to be
> matched anyway, I think it is better to send larger chunks of text to
> the shaping engine, as that causes fewer calls and the shaping engine
> will be able to produce better visuals.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-27 12:03         ` Eli Zaretskii
       [not found]           ` <CAJrM8VW0P+-cO_cup6W-teoJV46nZTcsPrFbaKdXDD_CK_5Rxw@mail.gmail.com>
@ 2023-11-28  5:18           ` Yuan Fu
  2023-11-28 13:27             ` Steve Molitor
  2023-11-28 14:20             ` Eli Zaretskii
  1 sibling, 2 replies; 13+ messages in thread
From: Yuan Fu @ 2023-11-28  5:18 UTC (permalink / raw)
  To: emacs-devel



On 11/27/23 4:03 AM, Eli Zaretskii wrote:
>> From: Steve Molitor <stevemolitor@gmail.com>
>> Date: Sun, 26 Nov 2023 14:42:36 -0600
>> Cc: emacs-devel@gnu.org
>>
>> For ligature support, I do need something like this for Commit Mono:
>>
>>      (set-char-table-range
>>       composition-function-table
>>       t
>>       `([" [,-.:;A-Z_a-z><=!&|+-?/\\]+" 0 font-shape-gstring]))
> Beware: composition-function-table is global, so the above will ligate
> characters on the mode line as well, which might not be what you want.
Is there any way to make it local? If I make composition-function-table 
buffer-local and set the buffer-local variable, would it work? The 
use-case I'm thinking about is using Commit Mono for Info buffers and 
help buffers, which have large bodies of monospaced text. The improved 
readability would help a lot there.

Yuan



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-28  5:18           ` Yuan Fu
@ 2023-11-28 13:27             ` Steve Molitor
  2023-11-29  0:58               ` Yuan Fu
  2023-11-28 14:20             ` Eli Zaretskii
  1 sibling, 1 reply; 13+ messages in thread
From: Steve Molitor @ 2023-11-28 13:27 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

Yes, you can make the composition-function-table buffer-local and
mode-specific. Here is an example:

https://github.com/mickeynp/ligature.el/issues/53#issuecomment-1828732077

Steve

On Tue, Nov 28, 2023 at 12:40 AM Yuan Fu <casouri@gmail.com> wrote:
>
>
>
> On 11/27/23 4:03 AM, Eli Zaretskii wrote:
> >> From: Steve Molitor <stevemolitor@gmail.com>
> >> Date: Sun, 26 Nov 2023 14:42:36 -0600
> >> Cc: emacs-devel@gnu.org
> >>
> >> For ligature support, I do need something like this for Commit Mono:
> >>
> >>      (set-char-table-range
> >>       composition-function-table
> >>       t
> >>       `([" [,-.:;A-Z_a-z><=!&|+-?/\\]+" 0 font-shape-gstring]))
> > Beware: composition-function-table is global, so the above will ligate
> > characters on the mode line as well, which might not be what you want.
> Is there any way to make it local? If I make composition-function-table
> buffer-local and set the buffer-local variable, would it work? The
> use-case I'm thinking about is using Commit Mono for Info buffers and
> help buffers, which have large bodies of monospaced text. The improved
> readability would help a lot there.
>
> Yuan
>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-28  5:18           ` Yuan Fu
  2023-11-28 13:27             ` Steve Molitor
@ 2023-11-28 14:20             ` Eli Zaretskii
  2023-11-29  0:57               ` Yuan Fu
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2023-11-28 14:20 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> Date: Mon, 27 Nov 2023 21:18:18 -0800
> From: Yuan Fu <casouri@gmail.com>
> 
> 
> 
> On 11/27/23 4:03 AM, Eli Zaretskii wrote:
> >> From: Steve Molitor <stevemolitor@gmail.com>
> >> Date: Sun, 26 Nov 2023 14:42:36 -0600
> >> Cc: emacs-devel@gnu.org
> >>
> >> For ligature support, I do need something like this for Commit Mono:
> >>
> >>      (set-char-table-range
> >>       composition-function-table
> >>       t
> >>       `([" [,-.:;A-Z_a-z><=!&|+-?/\\]+" 0 font-shape-gstring]))
> > Beware: composition-function-table is global, so the above will ligate
> > characters on the mode line as well, which might not be what you want.
> Is there any way to make it local? If I make composition-function-table 
> buffer-local and set the buffer-local variable, would it work?

It will work to affect compositions when the buffer is the current
one, but it will not work to avoid compositions on the mode line of
the window(s) which display(s) that buffer.

> The use-case I'm thinking about is using Commit Mono for Info
> buffers and help buffers, which have large bodies of monospaced
> text. The improved readability would help a lot there.

I think if you like these features enough, you should want it in any
major mode that displays human-readable text.  But that's me.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-28 14:20             ` Eli Zaretskii
@ 2023-11-29  0:57               ` Yuan Fu
  0 siblings, 0 replies; 13+ messages in thread
From: Yuan Fu @ 2023-11-29  0:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel



On 11/28/23 6:20 AM, Eli Zaretskii wrote:
>> Date: Mon, 27 Nov 2023 21:18:18 -0800
>> From: Yuan Fu <casouri@gmail.com>
>>
>>
>>
>> On 11/27/23 4:03 AM, Eli Zaretskii wrote:
>>>> From: Steve Molitor <stevemolitor@gmail.com>
>>>> Date: Sun, 26 Nov 2023 14:42:36 -0600
>>>> Cc: emacs-devel@gnu.org
>>>>
>>>> For ligature support, I do need something like this for Commit Mono:
>>>>
>>>>       (set-char-table-range
>>>>        composition-function-table
>>>>        t
>>>>        `([" [,-.:;A-Z_a-z><=!&|+-?/\\]+" 0 font-shape-gstring]))
>>> Beware: composition-function-table is global, so the above will ligate
>>> characters on the mode line as well, which might not be what you want.
>> Is there any way to make it local? If I make composition-function-table
>> buffer-local and set the buffer-local variable, would it work?
> It will work to affect compositions when the buffer is the current
> one, but it will not work to avoid compositions on the mode line of
> the window(s) which display(s) that buffer.
Cool!
>> The use-case I'm thinking about is using Commit Mono for Info
>> buffers and help buffers, which have large bodies of monospaced
>> text. The improved readability would help a lot there.
> I think if you like these features enough, you should want it in any
> major mode that displays human-readable text.  But that's me.

I tend to you variable width fonts for human-readable text whenever 
possible. But for Info and help buffers, very often the content relies 
on monospacing for text layout. So I can't use variables-width font for 
those.

Yuan



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to use "smart kerning" font features in Emacs using composition-function-table
  2023-11-28 13:27             ` Steve Molitor
@ 2023-11-29  0:58               ` Yuan Fu
  0 siblings, 0 replies; 13+ messages in thread
From: Yuan Fu @ 2023-11-29  0:58 UTC (permalink / raw)
  To: Steve Molitor; +Cc: emacs-devel



On 11/28/23 5:27 AM, Steve Molitor wrote:
> Yes, you can make the composition-function-table buffer-local and
> mode-specific. Here is an example:
>
> https://github.com/mickeynp/ligature.el/issues/53#issuecomment-1828732077
>
> Steve

That's great. Thanks! Also thanks for bringing up Commit Mono, smart 
kerning is very cool.

Yuan



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-11-29  0:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-26 15:48 How to use "smart kerning" font features in Emacs using composition-function-table Steve Molitor
2023-11-26 17:52 ` Eli Zaretskii
2023-11-26 19:49   ` Steve Molitor
2023-11-26 20:16     ` Eli Zaretskii
2023-11-26 20:42       ` Steve Molitor
2023-11-27 12:03         ` Eli Zaretskii
     [not found]           ` <CAJrM8VW0P+-cO_cup6W-teoJV46nZTcsPrFbaKdXDD_CK_5Rxw@mail.gmail.com>
2023-11-27 15:22             ` Eli Zaretskii
2023-11-27 16:16               ` Steve Molitor
2023-11-28  5:18           ` Yuan Fu
2023-11-28 13:27             ` Steve Molitor
2023-11-29  0:58               ` Yuan Fu
2023-11-28 14:20             ` Eli Zaretskii
2023-11-29  0:57               ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).