3

I want to change the menu bar color of my Emacs installation ( version 24.5.1 with GTK+3 and runs on Debian Testing with KDE desktop ). After browsing in the web, I know that the menu bar color cannot be changed within Emacs itself, but one has to use the GTK+3 resources. I used the approach which is described in this reference: GTK+ 3 Menu configuration for Emacs

First I created a folder with the following path "/home/USERHOME/.themes/.configure/gtk-3.0". Then I created 2 css-files in this folder, which are named "emacs.css" and "gtk.css". The content of "gtk.css" is

@import url("/home/zufall/.themes/Emacs/gtk-3.0/emacs.css") 

And in "emacs.css" I wrote

#pane #menubar
{
    background-color: #00FF00;
    foreground-color: #000000;
    border: none;
    padding: 0px 0px;
    margin: 25px;
}

Unfortunately, this setup didn't work, the color of the menu bar is still the default one ( foreground: black, background: grey ). I think, that the "emacs.css"-file is not complete, but I'm not sure what exactly I have to add. Can someone give me hint, what I possibly have missed?

0

1 Answer 1

2

I tested saving your sample CSS file into a file emacs-zufall.css which I imported from my locally modified gtk.css file using

@import url("apps/emacs-zufall.css");

and it worked: my menubar turned into psychedelic green color with black text.

I am guessing your emacs is not even reading the file in the location you created it. The location depends on the name of the theme. I am using theme Orion and emacs is trying to load read gtk.css using path

~/.local/share/themes/Orion/gtk-3.0/gtk.css

and if failing then from

~/.themes/Orion/gtk-3.0/gtk.css

Easiest way to see this to just trace the system calls. If using Linux, you can run

$ strace -o strace.log emacs &

and search for string themes in strace.log using your favorite pager or editor (for exmple emacs!). There is a lot of output, but you can quickly find the path using that search string (to match the attempts to find the theme file). Here's what I found in my strace output when I temporarily moved the locally modified theme directory away:

access("/home/foof/.local/share/themes/Orion/gtk-3.0/gtk.css", F_OK) = -1 ENOENT (No such file or directory)
access("/home/foof/.themes/Orion/gtk-3.0/gtk.css", F_OK) = -1 ENOENT (No such file or directory)
access("/usr/share/themes/Orion/gtk-3.0/gtk.css", F_OK) = 0

If you see similar ENOENT result indicating your emacs and you have different opinion about where to look for the CSS files, you can:

  1. copy the theme to your local directory and do the necessary modifications:

    $ mkdir -pv ~/.local/share/themes/Orion
    $ cp -ai /usr/share/themes/Orion/gtk-3.0 ~/.local/share/themes/Orion/
    
  2. add the @import statement to the locally modified gtk.css file:

    @import url("apps/emacs.css");
    
  3. and create or make sure file apps/emacs.css exists in the expected location with the desired modifications.

Remember to launch emacs using command line to see any possible CSS related errors. In my experience there is no theme caching so it was possible to have multiple emacs applications open with different theme settings contrary to what the linked superuser answer said; but this might be because I am not running Gnome desktop system (KDE is my choice).

If you are using another operating system, then there should be other utility to trace the system calls. OS X and maybe other BSD systems use DTrace etc. You could also consider running emacs under debugger if you cannot find how to trace the system calls on your system, though this is much more troublesome.

3
  • This works just fine, but why do I get Theme parsing error: emacs.css:5:12: 'foreground' is not a valid property name ? Similarly when using foreground-color...!???
    – kavadias
    Commented Aug 15, 2020 at 20:34
  • Maybe just color? I have no way to test this now. But "CSS foreground color" web search top results tell to use color. It could be that in the four years since this answer, the CSS parsing was made more strict?!?
    – FooF
    Commented Aug 17, 2020 at 3:42
  • Plain color didn't work. It is an accepted keyword, but does not change the font color in the menubar. Thanks anyway...
    – kavadias
    Commented Aug 18, 2020 at 2:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .