unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#51715: defface forms not having dynamic value
@ 2021-11-09 11:41 irenezerafa via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-11-09 13:26 ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: irenezerafa via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 11:41 UTC (permalink / raw)
  To: 51715

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

I am getting into quite messy code because my macro creates
defface forms. Those do not have a dynamic value, but use the
value they get at the time they are evaluated. So using something
like a variable purple-intense does not help, because its value
would be a reference to one value, not a function that returns a
value (and having a function as a value would not be possible for
a face).

Because the purpose of faces is to be configurable by the user,
could there be some improvements to easily tackle such problems?

[-- Attachment #2: Type: text/html, Size: 668 bytes --]

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

* bug#51715: defface forms not having dynamic value
  2021-11-09 11:41 bug#51715: defface forms not having dynamic value irenezerafa via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-11-09 13:26 ` Eli Zaretskii
  2021-11-09 14:17   ` irenezerafa
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2021-11-09 13:26 UTC (permalink / raw)
  To: irenezerafa; +Cc: 51715

> Date: Tue, 09 Nov 2021 11:41:10 +0000
> From:  irenezerafa via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> I am getting into quite messy code because my macro creates
> defface forms.  Those do not have a dynamic value, but use the
> value they get at the time they are evaluated. So using something
> like a variable purple-intense does not help, because its value
> would be a reference to one value, not a function that returns a
> value (and having a function as a value would not be possible for
> a face).
> 
> Because the purpose of faces is to be configurable by the user,
> could there be some improvements to easily tackle such problems?

Please tell more.  Which face attributes did you want to make dynamic,
and how?





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

* bug#51715: defface forms not having dynamic value
  2021-11-09 13:26 ` Eli Zaretskii
@ 2021-11-09 14:17   ` irenezerafa
  2021-11-09 15:00     ` Eli Zaretskii
  2021-11-10  0:36     ` Lars Ingebrigtsen
  0 siblings, 2 replies; 10+ messages in thread
From: irenezerafa @ 2021-11-09 14:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 51715

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Tuesday, November 9th, 2021 at 1:26 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Tue, 09 Nov 2021 11:41:10 +0000
> > From: irenezerafa via "Bug reports for GNU Emacs,
> > the Swiss army knife of text editors" bug-gnu-emacs@gnu.org
> >
> > I am getting into quite messy code because my macro creates
> > defface forms. Those do not have a dynamic value, but use the
> > value they get at the time they are evaluated. So using something
> > like a variable purple-intense does not help, because its value
> > would be a reference to one value, not a function that returns a
> > value (and having a function as a value would not be possible for
> > a face).
> >
> > Because the purpose of faces is to be configurable by the user,
> > could there be some improvements to easily tackle such problems?
>
> Please tell more. Which face attributes did you want to make dynamic,
> and how?

I take rainbow-delimiters as example.  Specifically, the

(eval-when-compile
  (defmacro rainbow-delimiters--define-depth-faces ()
    (let ( (faces '())
           (dark-colors  [ "#ff62d4"  "#3fdfd0"  "#fba849"  "#9f80ff"
            "#4fe42f"  "#fe6060"  "#4fafff"  "#f0dd60" "#ffffff" ])
	   (light-colors [ "#a8007f"  "#005f88"  "#904200"  "#7f10d0"
            "#006800"  "#b60000"  "#1f1fce"  "#605b00" "#000000"]) )
      (dotimes (i 9)
        (push `( defface ,(intern (format "rainbow-delimiters-depth-%d-face" (1+ i)))
		 '( (default (:inherit rainbow-delimiters-base-face))
                    ( ((class color) (background dark))
		      :foreground ,(aref dark-colors  i))
		    ( ((class color) (background light))
		      :foreground ,(aref light-colors i)) )
                 ,(format "Nested delimiter face, depth %d." (1+ i))
                 :group 'rainbow-delimiters-faces )
	      faces))
      `(progn ,@faces)) ))

(rainbow-delimiters--define-depth-faces)

Now, suppose I want to use a colour scheme from modus-themes.

(require 'modus-themes)

(eval-when-compile
  (defmacro rainbow-delimiters--define-depth-faces ()
    (let ( (faces '())
           (dark-colors (rainbow-delimiters-modus-vivendi-intense-colours
			 (list magenta-intense cyan-intense orange-intense
			       purple-intense green-intense red-intense
			       blue-intense yellow-intense fg-main)))
           (light-colors (rainbow-delimiters-modus-operandi-intense-colours
                          (list magenta-intense cyan-intense orange-intense
				purple-intense green-intense red-intense
				blue-intense yellow-intense fg-main))) )
      (dotimes (i 9)
	(push `(defface ,(intern (format "rainbow-delimiters-depth-%d-face" (1+ i)))
		 '( (default (:inherit rainbow-delimiters-base-face))
                    ( ((class color) (background light))
		      :foreground ,(nth i light-colors))
                    ( ((class color) (background dark))
		      :foreground ,(nth i dark-colors)) )
		 ,(format "Nested delimiter face, depth %d." (1+ i))
		 :group 'rainbow-delimiters-faces)
              faces))
      `(progn ,@faces)) ))

This would not be workable in practice.  Because the dependency only
matters when your macro is being evaluated and the faces are reified.
Since you have a package, that will be the moment the package gets
required. So you are making it a dependency for everyone.

Ideally, one could simply add the colour values directly so it would
work everywhere, or use the modus-themes dependency for those who are
using modus-themes.








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

* bug#51715: defface forms not having dynamic value
  2021-11-09 14:17   ` irenezerafa
@ 2021-11-09 15:00     ` Eli Zaretskii
  2021-11-09 15:36       ` irenezerafa
  2021-11-09 15:40       ` irenezerafa
  2021-11-10  0:36     ` Lars Ingebrigtsen
  1 sibling, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2021-11-09 15:00 UTC (permalink / raw)
  To: irenezerafa; +Cc: 51715

> Date: Tue, 09 Nov 2021 14:17:03 +0000
> From: irenezerafa <irenezerafa@protonmail.com>
> Cc: 51715@debbugs.gnu.org
> >
> > Please tell more. Which face attributes did you want to make dynamic,
> > and how?
> 
> I take rainbow-delimiters as example.  Specifically, the
> 
> (eval-when-compile
>   (defmacro rainbow-delimiters--define-depth-faces ()
>     (let ( (faces '())
>            (dark-colors  [ "#ff62d4"  "#3fdfd0"  "#fba849"  "#9f80ff"
>             "#4fe42f"  "#fe6060"  "#4fafff"  "#f0dd60" "#ffffff" ])
> 	   (light-colors [ "#a8007f"  "#005f88"  "#904200"  "#7f10d0"
>             "#006800"  "#b60000"  "#1f1fce"  "#605b00" "#000000"]) )
>       (dotimes (i 9)
>         (push `( defface ,(intern (format "rainbow-delimiters-depth-%d-face" (1+ i)))
> 		 '( (default (:inherit rainbow-delimiters-base-face))
>                     ( ((class color) (background dark))
> 		      :foreground ,(aref dark-colors  i))
> 		    ( ((class color) (background light))
> 		      :foreground ,(aref light-colors i)) )
>                  ,(format "Nested delimiter face, depth %d." (1+ i))
>                  :group 'rainbow-delimiters-faces )
> 	      faces))
>       `(progn ,@faces)) ))
> 
> (rainbow-delimiters--define-depth-faces)
> 
> Now, suppose I want to use a colour scheme from modus-themes.
> 
> (require 'modus-themes)
> 
> (eval-when-compile
>   (defmacro rainbow-delimiters--define-depth-faces ()
>     (let ( (faces '())
>            (dark-colors (rainbow-delimiters-modus-vivendi-intense-colours
> 			 (list magenta-intense cyan-intense orange-intense
> 			       purple-intense green-intense red-intense
> 			       blue-intense yellow-intense fg-main)))
>            (light-colors (rainbow-delimiters-modus-operandi-intense-colours
>                           (list magenta-intense cyan-intense orange-intense
> 				purple-intense green-intense red-intense
> 				blue-intense yellow-intense fg-main))) )
>       (dotimes (i 9)
> 	(push `(defface ,(intern (format "rainbow-delimiters-depth-%d-face" (1+ i)))
> 		 '( (default (:inherit rainbow-delimiters-base-face))
>                     ( ((class color) (background light))
> 		      :foreground ,(nth i light-colors))
>                     ( ((class color) (background dark))
> 		      :foreground ,(nth i dark-colors)) )
> 		 ,(format "Nested delimiter face, depth %d." (1+ i))
> 		 :group 'rainbow-delimiters-faces)
>               faces))
>       `(progn ,@faces)) ))
> 
> This would not be workable in practice.  Because the dependency only
> matters when your macro is being evaluated and the faces are reified.
> Since you have a package, that will be the moment the package gets
> required. So you are making it a dependency for everyone.

I'm still not sure I get this.  You want to be able to control the
colors of a face indirectly, by changing some variable which the face
references?  If not, what do you mean by "the dependency"?

IOW, what is it that you want to be able to do that isn't possible by
calling set-face-attribute?





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

* bug#51715: defface forms not having dynamic value
  2021-11-09 15:00     ` Eli Zaretskii
@ 2021-11-09 15:36       ` irenezerafa
  2021-11-09 15:40       ` irenezerafa
  1 sibling, 0 replies; 10+ messages in thread
From: irenezerafa @ 2021-11-09 15:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 51715

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Tuesday, November 9th, 2021 at 3:00 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Tue, 09 Nov 2021 14:17:03 +0000
> >
> > From: irenezerafa irenezerafa@protonmail.com
> >
> > Cc: 51715@debbugs.gnu.org
> >
> > > Please tell more. Which face attributes did you want to make dynamic,
> > > and how?
> >
> > I take rainbow-delimiters as example. Specifically, the
> >
> > (eval-when-compile
> >
> > (defmacro rainbow-delimiters--define-depth-faces ()
> > (let ( (faces '())
> > (dark-colors [ "#ff62d4" "#3fdfd0" "#fba849" "#9f80ff"
> > "#4fe42f" "#fe6060" "#4fafff" "#f0dd60" "#ffffff" ])
> > (light-colors [ "#a8007f" "#005f88" "#904200" "#7f10d0"
> > "#006800" "#b60000" "#1f1fce" "#605b00" "#000000"]) )
> >
> > (dotimes (i 9)
> > (push `( defface ,(intern (format "rainbow-delimiters-depth-%d-face" (1+ i))) '( (default (:inherit rainbow-delimiters-base-face)) ( ((class color) (background dark)) :foreground ,(aref dark-colors i)) ( ((class color) (background light)) :foreground ,(aref light-colors i)) ) ,(format "Nested delimiter face, depth %d." (1+ i)) :group 'rainbow-delimiters-faces ) faces))` (progn ,@faces)) ))
> >
> > (rainbow-delimiters--define-depth-faces)
> >
> > Now, suppose I want to use a colour scheme from modus-themes.
> >
> > (require 'modus-themes)
> >
> > (eval-when-compile
> > (defmacro rainbow-delimiters--define-depth-faces ()
> > (let ( (faces '())
> > (dark-colors (rainbow-delimiters-modus-vivendi-intense-colours
> > (list magenta-intense cyan-intense orange-intense
> > purple-intense green-intense red-intense
> > blue-intense yellow-intense fg-main)))
> > (light-colors (rainbow-delimiters-modus-operandi-intense-colours
> > (list magenta-intense cyan-intense orange-intense
> > purple-intense green-intense red-intense
> > blue-intense yellow-intense fg-main))) )
> > (dotimes (i 9)
> > (push `(defface ,(intern (format "rainbow-delimiters-depth-%d-face" (1+ i))) '( (default (:inherit rainbow-delimiters-base-face)) ( ((class color) (background light)) :foreground ,(nth i light-colors)) ( ((class color) (background dark)) :foreground ,(nth i dark-colors)) ) ,(format "Nested delimiter face, depth %d." (1+ i)) :group 'rainbow-delimiters-faces) faces))` (progn ,@faces)) ))
> >
> > This would not be workable in practice. Because the dependency only
> > matters when your macro is being evaluated and the faces are reified.
> > Since you have a package, that will be the moment the package gets
> > required. So you are making it a dependency for everyone.

> I'm still not sure I get this. You want to be able to control the
> colors of a face indirectly, by changing some variable which the face
> references? If not, what do you mean by "the dependency"?

> IOW, what is it that you want to be able to do that isn't possible by
> calling set-face-attribute?

I would like to require modus-themes (and get the list of intense colours frem there
as defined) if modus-themes is being used.  Otherwise, get the rainbow-delimiters
package to set the face attributes directly (by hex values) using aref.

One could have a flag before calling (require 'rainbow-delimiters), which the package
could pick up.  That could work at runtime.  But not at compile time, a situation that
users are likely going to get (the compiled form) to install the package.






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

* bug#51715: defface forms not having dynamic value
  2021-11-09 15:00     ` Eli Zaretskii
  2021-11-09 15:36       ` irenezerafa
@ 2021-11-09 15:40       ` irenezerafa
  1 sibling, 0 replies; 10+ messages in thread
From: irenezerafa @ 2021-11-09 15:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 51715



Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Tuesday, November 9th, 2021 at 3:00 PM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Tue, 09 Nov 2021 14:17:03 +0000
> > From: irenezerafa irenezerafa@protonmail.com
> > Cc: 51715@debbugs.gnu.org

> > > Please tell more. Which face attributes did you want to make dynamic,
> > > and how?

> > The dependency only matters when your macro is being evaluated and the faces
> > are reified.  Since you have a package, that will be the moment the package
> > gets required. So you are making it a dependency for everyone.

> I'm still not sure I get this. You want to be able to control the
> colors of a face indirectly, by changing some variable which the face
> references? If not, what do you mean by "the dependency"?

> IOW, what is it that you want to be able to do that isn't possible by
> calling set-face-attribute?

I don't think so, because set-face-attribute and related functions are
meant to edit existing faces, not define them.  In practice, they are
used in user init files, since it is bad form for a package to edit the
definition of a face in another package.






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

* bug#51715: defface forms not having dynamic value
  2021-11-09 14:17   ` irenezerafa
  2021-11-09 15:00     ` Eli Zaretskii
@ 2021-11-10  0:36     ` Lars Ingebrigtsen
  2021-11-10 15:08       ` Stefan Kangas
  1 sibling, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-10  0:36 UTC (permalink / raw)
  To: irenezerafa; +Cc: 51715

irenezerafa <irenezerafa@protonmail.com> writes:

> 		 '( (default (:inherit rainbow-delimiters-base-face))
>                     ( ((class color) (background light))
> 		      :foreground ,(nth i light-colors))
>                     ( ((class color) (background dark))
> 		      :foreground ,(nth i dark-colors)) )
> 		 ,(format "Nested delimiter face, depth %d." (1+ i))

This would be nice if possible, but I don't think it's practical.  It
would mean that (in general) Emacs would have to recalculate faces
whenever a variable changes, and that would make Emacs very slow.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#51715: defface forms not having dynamic value
  2021-11-10  0:36     ` Lars Ingebrigtsen
@ 2021-11-10 15:08       ` Stefan Kangas
  2021-11-10 16:48         ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Kangas @ 2021-11-10 15:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 51715, irenezerafa

Lars Ingebrigtsen <larsi@gnus.org> writes:

> irenezerafa <irenezerafa@protonmail.com> writes:
>
>> 		 '( (default (:inherit rainbow-delimiters-base-face))
>>                     ( ((class color) (background light))
>> 		      :foreground ,(nth i light-colors))
>>                     ( ((class color) (background dark))
>> 		      :foreground ,(nth i dark-colors)) )
>> 		 ,(format "Nested delimiter face, depth %d." (1+ i))
>
> This would be nice if possible, but I don't think it's practical.  It
> would mean that (in general) Emacs would have to recalculate faces
> whenever a variable changes, and that would make Emacs very slow.

But maybe we could allow the above in combination with a function to
refresh all face definitions?  I'm not sure it's worth the effort in
comparison with just fixing the load order though, so it might still be
a wontfix.





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

* bug#51715: defface forms not having dynamic value
  2021-11-10 15:08       ` Stefan Kangas
@ 2021-11-10 16:48         ` Eli Zaretskii
  2021-11-14  2:28           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2021-11-10 16:48 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 51715, larsi, irenezerafa

> From: Stefan Kangas <stefan@marxist.se>
> Date: Wed, 10 Nov 2021 07:08:59 -0800
> Cc: irenezerafa <irenezerafa@protonmail.com>, 51715@debbugs.gnu.org, 
> 	Eli Zaretskii <eliz@gnu.org>
> 
> >> 		 '( (default (:inherit rainbow-delimiters-base-face))
> >>                     ( ((class color) (background light))
> >> 		      :foreground ,(nth i light-colors))
> >>                     ( ((class color) (background dark))
> >> 		      :foreground ,(nth i dark-colors)) )
> >> 		 ,(format "Nested delimiter face, depth %d." (1+ i))
> >
> > This would be nice if possible, but I don't think it's practical.  It
> > would mean that (in general) Emacs would have to recalculate faces
> > whenever a variable changes, and that would make Emacs very slow.
> 
> But maybe we could allow the above in combination with a function to
> refresh all face definitions?  I'm not sure it's worth the effort in
> comparison with just fixing the load order though, so it might still be
> a wontfix.

Isn't that what :inherit already does?





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

* bug#51715: defface forms not having dynamic value
  2021-11-10 16:48         ` Eli Zaretskii
@ 2021-11-14  2:28           ` Lars Ingebrigtsen
  0 siblings, 0 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-14  2:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 51715, Stefan Kangas, irenezerafa

Eli Zaretskii <eliz@gnu.org> writes:

>> But maybe we could allow the above in combination with a function to
>> refresh all face definitions?  I'm not sure it's worth the effort in
>> comparison with just fixing the load order though, so it might still be
>> a wontfix.
>
> Isn't that what :inherit already does?

I think so.

So I think this is a WONTFIX, and I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2021-11-14  2:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 11:41 bug#51715: defface forms not having dynamic value irenezerafa via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09 13:26 ` Eli Zaretskii
2021-11-09 14:17   ` irenezerafa
2021-11-09 15:00     ` Eli Zaretskii
2021-11-09 15:36       ` irenezerafa
2021-11-09 15:40       ` irenezerafa
2021-11-10  0:36     ` Lars Ingebrigtsen
2021-11-10 15:08       ` Stefan Kangas
2021-11-10 16:48         ` Eli Zaretskii
2021-11-14  2:28           ` Lars Ingebrigtsen

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).