unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Getting `load-theme` to work in `-batch` mode?
@ 2024-02-13 15:06 Konstantin Kharlamov
  2024-02-14 14:59 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Kharlamov @ 2024-02-13 15:06 UTC (permalink / raw)
  To: help-gnu-emacs

I'm writing tests for color-identifiers-mode, and as part of the
testing I need to check it reacts correctly to theme being changed.

There are already tests that work fine so far, but it turns out `load-
theme` doesn't work as is. More specifically, even though `(load-theme
'adwait)` works fine, but background/foreground have no color:

   emacs -batch --eval "(progn (load-theme 'adwaita) (print (face-
   attribute 'default :foreground)) (print (face-attribute 'default
   :background)))"
   
   "unspecified-fg"
   
   "unspecified-bg"

I asked on Emacs stackexchange¹ and I was hinted that it's because
batch-mode doesn't initialize a windowing system.

But is there no function I can call to make `load-theme` assign colors
as in non-batch mode?

P.S.: pls keep in in CC

1:
https://emacs.stackexchange.com/questions/80358/unspecified-fg-bg-in-batch-mode-when-querying-foreground-background-colors/80370#80370



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

* Re: Getting `load-theme` to work in `-batch` mode?
  2024-02-13 15:06 Getting `load-theme` to work in `-batch` mode? Konstantin Kharlamov
@ 2024-02-14 14:59 ` Eli Zaretskii
  2024-02-14 15:14   ` Konstantin Kharlamov
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-02-14 14:59 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Konstantin Kharlamov

> From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
> Date: Tue, 13 Feb 2024 18:06:43 +0300
> 
> I'm writing tests for color-identifiers-mode, and as part of the
> testing I need to check it reacts correctly to theme being changed.
> 
> There are already tests that work fine so far, but it turns out `load-
> theme` doesn't work as is. More specifically, even though `(load-theme
> 'adwait)` works fine, but background/foreground have no color:
> 
>    emacs -batch --eval "(progn (load-theme 'adwaita) (print (face-
>    attribute 'default :foreground)) (print (face-attribute 'default
>    :background)))"
>    
>    "unspecified-fg"
>    
>    "unspecified-bg"

Those are the default colors of a text-mode frame.

> I asked on Emacs stackexchange¹ and I was hinted that it's because
> batch-mode doesn't initialize a windowing system.

That's right.

> But is there no function I can call to make `load-theme` assign colors
> as in non-batch mode?

What do you mean by that?  The GUI colors are not necessarily
supported by text-mode frames.  So what do you expect from the above?

Btw, if you look at adwaita-theme.el, you will see that it doesn't
bother supporting frames which support less than 89 colors, and the
default frame used by batch sessions certainly doesn't support such a
large number of colors.



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

* Re: Getting `load-theme` to work in `-batch` mode?
  2024-02-14 14:59 ` Eli Zaretskii
@ 2024-02-14 15:14   ` Konstantin Kharlamov
  2024-02-14 15:34     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Kharlamov @ 2024-02-14 15:14 UTC (permalink / raw)
  To: Eli Zaretskii, help-gnu-emacs

On Wed, 2024-02-14 at 16:59 +0200, Eli Zaretskii wrote:
> > From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
> > Date: Tue, 13 Feb 2024 18:06:43 +0300
> > 
> > I'm writing tests for color-identifiers-mode, and as part of the
> > testing I need to check it reacts correctly to theme being changed.
> > 
> > There are already tests that work fine so far, but it turns out
> > `load-
> > theme` doesn't work as is. More specifically, even though `(load-
> > theme
> > 'adwait)` works fine, but background/foreground have no color:
> > 
> >    emacs -batch --eval "(progn (load-theme 'adwaita) (print (face-
> >    attribute 'default :foreground)) (print (face-attribute 'default
> >    :background)))"
> >    
> >    "unspecified-fg"
> >    
> >    "unspecified-bg"
> 
> Those are the default colors of a text-mode frame.
> 
> > I asked on Emacs stackexchange¹ and I was hinted that it's because
> > batch-mode doesn't initialize a windowing system.
> 
> That's right.
> 
> > But is there no function I can call to make `load-theme` assign
> > colors
> > as in non-batch mode?
> 
> What do you mean by that?  The GUI colors are not necessarily
> supported by text-mode frames.  So what do you expect from the above?
> 
> Btw, if you look at adwaita-theme.el, you will see that it doesn't
> bother supporting frames which support less than 89 colors, and the
> default frame used by batch sessions certainly doesn't support such a
> large number of colors.

Sorry, I just don't know details about frames and themes
implementation, so it's hard for me to judge for myself…

Anyway, my usecase is: `color-identifiers-mode` chooses colors by
taking into account the background and foreground colors (to make sure
colors have good visibility). And it have an "advice" for `change-
theme` that regenerates the colors if theme is changed.

I just wanted to add a test to CI that makes sure that after `change-
theme` is called (via `load-theme` in this case) the colors are
regenerated as expected. But such test wouldn't work if calling `load-
theme` doesn't influence fg/bg colors (i.e. because colors remain
"unspecified").

So what's the correct course of action do you think here?



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

* Re: Getting `load-theme` to work in `-batch` mode?
  2024-02-14 15:14   ` Konstantin Kharlamov
@ 2024-02-14 15:34     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-02-14 15:34 UTC (permalink / raw)
  To: Konstantin Kharlamov; +Cc: help-gnu-emacs

> From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
> Date: Wed, 14 Feb 2024 18:14:05 +0300
> 
> On Wed, 2024-02-14 at 16:59 +0200, Eli Zaretskii wrote:
> > > From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
> > > Date: Tue, 13 Feb 2024 18:06:43 +0300
> > > 
> > > I'm writing tests for color-identifiers-mode, and as part of the
> > > testing I need to check it reacts correctly to theme being changed.
> > > 
> > > There are already tests that work fine so far, but it turns out
> > > `load-
> > > theme` doesn't work as is. More specifically, even though `(load-
> > > theme
> > > 'adwait)` works fine, but background/foreground have no color:
> > > 
> > >    emacs -batch --eval "(progn (load-theme 'adwaita) (print (face-
> > >    attribute 'default :foreground)) (print (face-attribute 'default
> > >    :background)))"
> > >    
> > >    "unspecified-fg"
> > >    
> > >    "unspecified-bg"
> > 
> > Those are the default colors of a text-mode frame.
> > 
> > > I asked on Emacs stackexchange¹ and I was hinted that it's because
> > > batch-mode doesn't initialize a windowing system.
> > 
> > That's right.
> > 
> > > But is there no function I can call to make `load-theme` assign
> > > colors
> > > as in non-batch mode?
> > 
> > What do you mean by that?  The GUI colors are not necessarily
> > supported by text-mode frames.  So what do you expect from the above?
> > 
> > Btw, if you look at adwaita-theme.el, you will see that it doesn't
> > bother supporting frames which support less than 89 colors, and the
> > default frame used by batch sessions certainly doesn't support such a
> > large number of colors.
> 
> Sorry, I just don't know details about frames and themes
> implementation, so it's hard for me to judge for myself…
> 
> Anyway, my usecase is: `color-identifiers-mode` chooses colors by
> taking into account the background and foreground colors (to make sure
> colors have good visibility). And it have an "advice" for `change-
> theme` that regenerates the colors if theme is changed.
> 
> I just wanted to add a test to CI that makes sure that after `change-
> theme` is called (via `load-theme` in this case) the colors are
> regenerated as expected. But such test wouldn't work if calling `load-
> theme` doesn't influence fg/bg colors (i.e. because colors remain
> "unspecified").
> 
> So what's the correct course of action do you think here?

Run your test not in batch mode?

Tests that involve display can only be run in batch mode if you are
very lucky.



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

end of thread, other threads:[~2024-02-14 15:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 15:06 Getting `load-theme` to work in `-batch` mode? Konstantin Kharlamov
2024-02-14 14:59 ` Eli Zaretskii
2024-02-14 15:14   ` Konstantin Kharlamov
2024-02-14 15:34     ` Eli Zaretskii

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