unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Working with colors in --batch mode
@ 2022-12-25 17:50 Kévin Le Gouguec
  2022-12-25 18:05 ` Eli Zaretskii
  2022-12-26 17:40 ` Kévin Le Gouguec
  0 siblings, 2 replies; 6+ messages in thread
From: Kévin Le Gouguec @ 2022-12-25 17:50 UTC (permalink / raw)
  To: help-gnu-emacs

Hello Emacs,

For some reason, today finds me playing with color contrast, and having
a devil of a time doing so in --batch mode.

Specifically, I'm stumped by…

$ emacs --batch \
    --eval '(message "color-name-to-rgb: %s"
                     (color-name-to-rgb "#abcdef"))'

… returning…

> color-name-to-rgb: (0.0 1.0 1.0)

… whereas in a non-batch session on an X display, I get something more
relevant to my usual Emacs experience (i.e. (window-system) ↦ x):

> color-name-to-rgb: (0.6705882352941176 0.803921568627451 0.9372549019607843)

The --batch behaviour thwarts my attempts to write a script that calls
modus-themes-contrast, since that function relies on color-name-to-rgb.

I think I've traced this to (color-values COLOR &optional FRAME) taking
a "wrong turn" because emacs --batch does not bother setting up
graphical frames; I tried coaxing Emacs into doing that prior to calling
any color function, with various combinations of…

* --display :0
* --eval "(make-frame '((display . \":0\") (window-system . x)))"
* --eval '(make-frame-on-display ":0")'

… to no avail; Emacs merely tells me "I/O possible" then terminates with
code 157 (-128=29, which tracks with signal(7) mapping this to SIGIO).

It might just be me not finding the right terms, but none of my research
(Emacs & Elisp info manuals; some googling) led me to examples of
handling graphical frames in batch mode.

I'm guessing it's just a matter of finding x such that…

$ emacs --batch \
    --eval "$x" \
    --eval '(message "color-name-to-rgb: %s"
                     (color-name-to-rgb "#abcdef"))'

… sets up enough "graphical terminal" support that display-graphic-p
holds, and (color-values "#abcdef") returns (43947 52685 61423) instead
of (0 65535 65535), but x eludes me thus far.

Alternatively, I could drop --batch and switch to princ +
external-debugging-output + kill-emacs, I guess.


There's still a bunch of things for me to consult before I feel
completely stuck ((elisp) Window Systems, (elisp) Frames, (emacs)
Display X, src/emacs.c, lisp/startup.el, ChatGPT); in the meantime,
bottling up this message and throwing it at the list in case someone
happens to be… sailing by?


Wishing y'all a merry time 🙏



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

end of thread, other threads:[~2022-12-26 22:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-25 17:50 Working with colors in --batch mode Kévin Le Gouguec
2022-12-25 18:05 ` Eli Zaretskii
2022-12-25 18:22   ` Eli Zaretskii
2022-12-25 18:49     ` Kévin Le Gouguec
2022-12-26 17:40 ` Kévin Le Gouguec
2022-12-26 22:57   ` Stefan Monnier via Users list for the GNU Emacs text editor

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