Re: Automatic face re-application with frame-set-background-mode

Antonio Romano <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
Hello,

Eli Zaretskii <[email protected]> writes:
> This step signals an error here:
>
>   custom-theme-set-faces: Unknown theme ‘default’
>
> So I was unable to try reproducing further.


That totally slipped my eye. Sorry. Here's a version that works on my
side:

--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-
(deftheme mve "Minimal MVE")

(custom-theme-set-faces
 'mve-theme
 `(default
   ((((background light)) :background "white" :foreground "black")
    (((background dark))  :background "black" :foreground "white")))
 `(mode-line
   ((((background light)) :background "yellow" :foreground "black")
    (((background dark))  :background "red" :foreground "white"))))

(provide-theme 'mve)
(provide 'mve-theme)
--8<---------------cut here---------------end--------------->8---


>> >Call `(setopt frame-background-mode 'dark)`.
>> >
>> >Notable observations:
>> >
>> >* The fringe (unspecified in this theme) changes to black.
>
> Which is okay, right?  Because its defface says:
>
>     (((class color) (background dark))
>      :background "grey10")

It is ok, but kind of inconsistent with the behaviour exposed right below:

>> >* The mode-line stays yellow.
>
> Not here, it doesn't: it becomes this:
>
>     (((class color grayscale) (min-colors 88) (background dark))
>      :box (:line-width -1 :style released-button)
>      :background "grey20" :foreground "white")

If `mve` theme is applied, then it does stay yellow. Tell me if you
concur with this behaviour. Unlike the uncostumized face discussed right
above (fringe), this face does not get recalculated to its dark
spec. This is inconsistent and makes me doubt about its intended usage.

>> >* Syntax highlighting colors in emacs-lisp-mode update according to
>> >background-mode.
>
> Which is okay, right?

Same behaviour as `fringe`, so again, it is ok, but kind of inconsistent.

>> >* The default face does not change. This is true even with the
>> >`default` theme.
> Which is expected, right?

This makes the less sense. With `emacs -Q`, setting
`frame-background-mode` to 'dark then you'll notice that there are
recomputed faces for dark background but the `default` background stays
the light one. If you open C-x C-f you'll se cyan text on white
background.

>> >It seems that some faces do get re-applied after a `background-mode`
>> >switch, while others do not. Even when they do, they do not honor my
>> >`custom-theme-set-faces` settings.
>
> No, all of the faces get recalculated.  Are you talking about the
> default face only?

`mode-line` face is themed and stays yellow (its light spec) when
switching to dark, as explained above.

`default` also stays to its light spec, but that also happens when it is unthemed.

>> >I’m trying to understand:
>> >
>> >What conditions determine which faces are automatically recalculated
>> >when `frame-set-background-mode` is called?
>
> Basically, all of them are recalculated.
>> >Is this behavior hardcoded for built-in faces only?
>
> No.

What I've shown so far should contradict this.


>> At this point I'm pretty sure that `frame-set-backgroud-mode` only
>> recalculates faces for those that are neither user-customized nor themed. I
>> wonder what's the rationale behind that and if it's an intended behaviour.
>
> The rationale could be that calling frame-set-backgroud-mode at
> arbitrary points makes no sense.  The background mode is determined by
> the frame's background color, so it should be applied when we first
> show a frame, or when the frame's background color changes.

`frame-background-mode` is a user option, thus it seems to me that it
should be called at arbitrary points. I thought it was the source of
truth for determining the background color.

>> >Are there plans or best practices for making theme faces reactive to
>> >background-mode changes without manually reapplying the theme?
>
> I don't understand the question, please elaborate.

Implying that `frame-background-mode` is a user option (which is
debatable), how should one make a theme that accounts for such
specification? With what I've seen above, this acts in inconsistent
ways, or maybe I'm just abusing or misusing it.

Just to contextualize: what I'm trying to do is making a single theme that
defines both a light and a dark variant in it by using the `background
light` and `background light` display specs.

I hope I'm being clear enough. I can clarify further whenever times it
is needed.

TIA.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.