2

I am finding that in some cases (e.g. when TERM=xterm-16color), the expression

(frame-parameter nil 'background-mode)

...evaluates to light when it is in fact a dark background.

How does Emacs decide the value of a frame's background-mode at startup, and how can I affect the decision?

EDIT: I realize that I can always run (setq frame-background-mode 'whatever), but this is not what I mean by "affect the decision" above. Rather, I mean: how can I modify the way I invoke Emacs (including the shell environment in which I invoke it) so that its default algorithm for setting frame-background-mode at startup gets it right.

EDIT2: I do not see how the answers to Emacs Blue color too dark answer my post's main question, namely: how does Emacs figure out the value it should set frame-background-mode to at startup? (For the sake of this question, assume that there is no .emacs/initialization file at startup.)

Drew
  • 75,699
  • 9
  • 109
  • 225
kjo
  • 3,145
  • 14
  • 42
  • Does this answer your question? [Emacs Blue color too dark](https://emacs.stackexchange.com/questions/35959/emacs-blue-color-too-dark) – NickD Aug 01 '21 at 13:24
  • @NickD: thank you for the pointer, but I don't see the answer to my first question (i.e., how does Emacs set the value of `background-mode` to begin with) in that thread. Also, though that thread does give at least one way to affect the decision (namely, by running `(setq background-mode ...)`) this is heavier than what I was hoping to find. (My question's original version did not make this last point clear at all, but I just edited it to fix this.) – kjo Aug 01 '21 at 14:11
  • 1
    I meant to point to @wasamasa's answer in that question, not to the question itself but I messed it up. The links should be https://emacs.stackexchange.com/a/36032/14825. And as it turns out, he has also written an answer to your other question (TLDR: it is not pretty and it does not really work): https://emacs.stackexchange.com/a/16811/14825 and check out the blog post that he links to. AFAIK, nothing has changed in that area in the past 6 years. – NickD Aug 01 '21 at 15:19
  • @NickD: thank you for the clarification. I still find phils' post below is the one that best answers the question I asked. – kjo Aug 01 '21 at 21:03

1 Answers1

2

Have a look at the code for frame-set-background-mode and frame-terminal-default-bg-mode.

The latter "checks the ‘frame-background-mode’ variable, the X resource named "backgroundMode" (if FRAME is an X frame), and finally the ‘background-mode’ terminal parameter."

Customize the frame-background-mode user option to enforce a value.

Individual terminals/emulators are handled via the various files in the lisp/term/ directory; e.g.: /usr/local/share/emacs/27.2/lisp/term/ (but depending on how Emacs is installed); or else refer to https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/term

See the README file in that directory for details of how Emacs selects which of those files to load. Once you've established which file is in use, you would need to read the code to see how backgrounds are established, as functionality can vary between terminals.

phils
  • 48,657
  • 3
  • 76
  • 115