~protesilaos/fontaine

7 2

"Default" Presets

Details
Message ID
<87y1zcmo67.fsf@zenithia.net>
DKIM signature
missing
Download raw message
Hi Prot,

This package implements a cleaner version of something I was doing
manually, which is really nice. But I think it could be a bit cleaner if
there were a way to specify properties that apply to all presets unless
overridden. Let me explain the background:

  (setq fontaine-presets
	'((normal
	   :default-family "Iosevka Term"
	   :default-height 120
	   :variable-pitch-family "Iosevka Etoile")
	  (small
	   :default-family "Iosevka Term"
	   :default-height 100
	   :variable-pitch-family "Iosevka Etoile")
	  (big
	   :default-family "Iosevka Term"
	   :default-height 140
	   :variable-pitch-family "Iosevka Etoile")
	  (presentation
	   :default-family "Iosevka Term"
	   :default-height 180
	   :variable-pitch-family "Iosevka Etoile")))

That's the config I just put together; my own version just had
normal/presentation and a function to toggle between the two.

It feels a bit repetitive to specify the same fonts for all four of
them, so if there was a way to specify "default" properties, (distinct
from `default`, so presumably with some other name) and only specify the
fonts once, that would make things a little bit cleaner. Although I
fully understand if you'd rather not optimize for saving six lines off
of a simple configuration. :)

It's possible that this is doable with the `fontaine-set-face-font`
function, in which case I can just use that for this specific purpose,
and maybe a note can be added to the readme for this example. OTOH, the
docs for that function suggest against using it from code, so perhaps it
wouldn't work for this purpose.

I did also attempt to produce this myself by mapping over partial
presets with a function that uses cons or push to add the families and
couldn't figure out how to make that work.

Thanks in advance, and as an aside I really appreciate your work, both
the videos and the packages.

-- Ted Reed
Details
Message ID
<87zgjsv2tp.fsf@protesilaos.com>
In-Reply-To
<87y1zcmo67.fsf@zenithia.net> (view parent)
DKIM signature
missing
Download raw message
> From: Ted Reed <treed@zenithia.net>
> Date: Sun, 08 May 2022 00:52:54 -0700
>
> Hi Prot,

Hello Ted,

> This package implements a cleaner version of something I was doing
> manually, which is really nice. But I think it could be a bit cleaner if
> there were a way to specify properties that apply to all presets unless
> overridden.
>
> [...]
>
> It feels a bit repetitive to specify the same fonts for all four of
> them, so if there was a way to specify "default" properties, (distinct
> from `default`, so presumably with some other name) and only specify the
> fonts once, that would make things a little bit cleaner. Although I
> fully understand if you'd rather not optimize for saving six lines off
> of a simple configuration. :)

Yes, this is an obvious limitation of the current design.  We should
provide a means to set a default/fallback value.

I am not sure right now what the best approach is.  Let me tinker with
it for a while and I will report back to you.

> Thanks in advance, and as an aside I really appreciate your work, both
> the videos and the packages.

Thank you!

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<87wnewv2a2.fsf@protesilaos.com>
In-Reply-To
<87zgjsv2tp.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Patch: +9 -5
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Sun, 08 May 2022 11:36:02 +0300
>
> Yes, this is an obvious limitation of the current design.  We should
> provide a means to set a default/fallback value.
>
> I am not sure right now what the best approach is.  Let me tinker with
> it for a while and I will report back to you.

I'm back earlier than expected.  I think I have found a solution, but I
need to test it more thoroughly.

Can you please try the diff that I copy further below?  The way it works
is that the 't' preset is the fallback.  If a property is specified in
another preset, say, 'regular', then it takes precedence over 't'.
Otherwise we get the value of 't'.

I tested it with variants of this:

    (setq fontaine-presets
          '((regular
             :default-family "Hack"
             :default-weight normal
             :default-height 100)
            (medium
             :default-weight semilight
             :default-height 130)
            (t
             :default-family "Iosevka Comfy"
             :default-weight semilight
             :default-height 170
             :fixed-pitch-family nil ; falls back to :default-family
             :fixed-pitch-weight nil ; falls back to :default-weight
             :fixed-pitch-height 1.0
             :variable-pitch-family "FiraGO"
             :variable-pitch-weight normal
             :variable-pitch-height 1.05
             :bold-family nil ; use whatever the underlying face has
             :bold-weight extrabold
             :italic-family nil
             :italic-slant italic
             :line-spacing nil)))


    (let ((properties (append (alist-get 'regular fontaine-presets)
                              (alist-get t fontaine-presets))))
      (plist-get properties :default-family))


The diff:


 fontaine.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fontaine.el b/fontaine.el
index 8533587..214e5fc 100644
--- a/fontaine.el
+++ b/fontaine.el
@@ -354,7 +354,8 @@ ;;;; Apply preset configurations

(defun fontaine--apply-default-preset (preset &optional frame)
  "Set `default' face attributes based on PRESET for optional FRAME."
  (if-let ((properties (alist-get preset fontaine-presets)))
  (if-let ((properties (append (alist-get preset fontaine-presets)
                               (alist-get t fontaine-presets))))
      (progn
        (fontaine--set-face-attributes
         'default
@@ -367,7 +368,8 @@ (defun fontaine--apply-default-preset (preset &optional frame)

(defun fontaine--apply-fixed-pitch-preset (preset &optional frame)
  "Set `fixed-pitch' face attributes based on PRESET for optional FRAME."
  (if-let ((properties (alist-get preset fontaine-presets)))
  (if-let ((properties (append (alist-get preset fontaine-presets)
                               (alist-get t fontaine-presets))))
      (fontaine--set-face-attributes
       'fixed-pitch
       (or (plist-get properties :fixed-pitch-family) (plist-get properties :default-family))
@@ -378,7 +380,8 @@ (defun fontaine--apply-fixed-pitch-preset (preset &optional frame)

(defun fontaine--apply-variable-pitch-preset (preset &optional frame)
  "Set `variable-pitch' face attributes based on PRESET for optional FRAME."
  (if-let ((properties (alist-get preset fontaine-presets)))
  (if-let ((properties (append (alist-get preset fontaine-presets)
                               (alist-get t fontaine-presets))))
      (fontaine--set-face-attributes
       'variable-pitch
       (or (plist-get properties :variable-pitch-family) (plist-get properties :default-family))
@@ -389,7 +392,7 @@ (defun fontaine--apply-variable-pitch-preset (preset &optional frame)

(defun fontaine--apply-bold-preset (preset &optional frame)
  "Set `bold' face attributes based on PRESET for optional FRAME."
  (if-let ((properties (alist-get preset fontaine-presets)))
  (if-let ((properties (append (alist-get preset fontaine-presets) (alist-get t fontaine-presets))))
      (fontaine--set-face-attributes
       'bold
       (or (plist-get properties :bold-family) 'unspecified)
@@ -399,7 +402,8 @@ (defun fontaine--apply-bold-preset (preset &optional frame)

(defun fontaine--apply-italic-preset (preset &optional frame)
  "Set `italic' face attributes based on PRESET for optional FRAME."
  (if-let ((properties (alist-get preset fontaine-presets)))
  (if-let ((properties (append (alist-get preset fontaine-presets)
                               (alist-get t fontaine-presets))))
      (fontaine--set-italic-slant
       (or (plist-get properties :italic-family) 'unspecified)
       (or (plist-get properties :italic-slant) 'italic)


-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<87mtfrwzuv.fsf@zenithia.net>
In-Reply-To
<87wnewv2a2.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Protesilaos Stavrou <info@protesilaos.com> writes:

> I'm back earlier than expected.  I think I have found a solution, but I
> need to test it more thoroughly.
>
> Can you please try the diff that I copy further below?  The way it works
> is that the 't' preset is the fallback.  If a property is specified in
> another preset, say, 'regular', then it takes precedence over 't'.
> Otherwise we get the value of 't'.

Yes, this works great, thanks! And yes, I agree that `t` is a reasonably
common emacs idiom for this sort of thing.

I now have this for my full config:

(use-package fontaine
  :init
  (setq fontaine-presets
	'((t
	   :default-family "Iosevka Term"
	   :variable-pitch-family "Iosevka Etoile")
	  (normal :default-height 120)
	  (small :default-height 100)
	  (big :default-height 160)
	  (presentation :default-height 200)))
  :config
  (fontaine-set-preset 'normal))

I'm still trying to think of a good binding for `fontaine-set-preset`,
but beyond that, this is already a very nice enhancement.

I think the one item worth maybe noting is that `t` still appears in the
list of presets; unsure if maybe that would be better filtered out or if
users may want to be able to apply the fallback for some reason.

-- Ted Reed
Details
Message ID
<87o807z8kp.fsf@protesilaos.com>
In-Reply-To
<87mtfrwzuv.fsf@zenithia.net> (view parent)
DKIM signature
missing
Download raw message
> From: Ted Reed <treed@zenithia.net>
> Date: Sun, 08 May 2022 13:04:00 -0700
>
>
> Protesilaos Stavrou <info@protesilaos.com> writes:
>
>> I'm back earlier than expected.  I think I have found a solution, but I
>> need to test it more thoroughly.
>>
>> Can you please try the diff that I copy further below?  The way it works
>> is that the 't' preset is the fallback.  If a property is specified in
>> another preset, say, 'regular', then it takes precedence over 't'.
>> Otherwise we get the value of 't'.
>
> Yes, this works great, thanks! And yes, I agree that `t` is a reasonably
> common emacs idiom for this sort of thing.

Very well!  I have been using it since yesterday and am happy with it as
well.  Will polish the code, update the documentation and then push the
changes.

> I now have this for my full config:
>
> (use-package fontaine
>   :init
>   (setq fontaine-presets
> 	'((t
> 	   :default-family "Iosevka Term"
> 	   :variable-pitch-family "Iosevka Etoile")
> 	  (normal :default-height 120)
> 	  (small :default-height 100)
> 	  (big :default-height 160)
> 	  (presentation :default-height 200)))
>   :config
>   (fontaine-set-preset 'normal))

Looks neat!  Much better than before.

> I'm still trying to think of a good binding for `fontaine-set-preset`,
> but beyond that, this is already a very nice enhancement.

I use 'C-c f'.  For 'fontaine-set-face-font' I have 'C-c F'.

> I think the one item worth maybe noting is that `t` still appears in the
> list of presets; unsure if maybe that would be better filtered out or if
> users may want to be able to apply the fallback for some reason.

I noticed this.  I think it should be omitted from that list.

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<87h75zz27b.fsf@protesilaos.com>
In-Reply-To
<87o807z8kp.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hello again!

Just to inform you that I pushed the changes in commit 00a8b41.  Also
mentioned your name in the manual's "Acknowledgements" section.

Will now prepare the release of version 0.2.0.

Thanks again for your feedback!

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<87ilqfw20d.fsf@zenithia.net>
In-Reply-To
<87h75zz27b.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Protesilaos Stavrou <info@protesilaos.com> writes:

> Hello again!
>
> Just to inform you that I pushed the changes in commit 00a8b41.  Also
> mentioned your name in the manual's "Acknowledgements" section.
>
> Will now prepare the release of version 0.2.0.

Thanks for the quick turnaround on the feature request, and I'm glad I
could contribute, even in such a small way. :)

-- Ted Reed
Details
Message ID
<878rrbysho.fsf@protesilaos.com>
In-Reply-To
<87ilqfw20d.fsf@zenithia.net> (view parent)
DKIM signature
missing
Download raw message
> From: Ted Reed <treed@zenithia.net>
> Date: Mon, 09 May 2022 01:19:06 -0700
>
> Thanks for the quick turnaround on the feature request

You are welcome!

> and I'm glad I could contribute, even in such a small way. :)

"Small" but important nonetheless.

Version 0.2.0 is now available.  Release notes:
<https://protesilaos.com/codelog/2022-05-09-emacs-fontaine-0-2-0/>.

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)