rougier / nano-modeline

GNU Emacs / N Λ N O Modeline
GNU General Public License v3.0
170 stars 29 forks source link

[Question] How to update modeline when switching themes? #63

Open SophieBosio opened 11 months ago

SophieBosio commented 11 months ago

Hi,

I have an issue where the colour of the modeline does not update when switching themes.

Here is a screenshot of the theme I use on start-up, the doom-nord theme.

image

And here is a screenshot after switching to ef-maris-light, where the modeline retains the doom-nord colours.

image

This problem is persistent with all themes. For instance, if I use ef-maris-light on start-up and switch to doom-nord, then doom-nord will have a ef-maris-light-coloured modeline.

I had some issues with lingering borders when switching themes, so in my configuration, I have this code snippet that advices load-theme to always disable the current theme when switching themes. This has resolved the issue for borders and other UI elements, such as source code blocks in Org-documents, but does not seem to affect nano-modeline. Removing this snippet also does not resolve the nano-modeline issue.

(defadvice load-theme
  (before disable-before-load (theme &optional no-confirm no-enable) activate)
  (mapc 'disable-theme custom-enabled-themes))

I would really appreciate any help! My full config is also available https://github.com/SophieBosio/.emacs.d.

rougier commented 11 months ago

I think the problem is quite generic and the solution you've found seems to be the "official" one:

The reason might be that some theme do not modify everything (nor does nano-modeline) such that if a theme modify something that is not overwritten by the new theme, it will remains as it is (i.e. from previous theme)

SophieBosio commented 11 months ago

Thank you for the response! Seems like it is indeed a question of what things the new theme modifies when switching.

I also noticed that the nano themes do in fact change the colour of the modeline, so when I want to switch to a theme that doesn't update the modeline colour, so a hacky solution is to always change to a nano theme before changing to a different theme. E.g., to change from doom-nord to ef-maris-light, I can first change to nano-light and then to ef-maris-light. Then the modeline colour is fitting even if it's not the exact colour of the theme I'm using.

rougier commented 11 months ago

Did you try (disable-theme 'nano-theme)? (never tested though)

SophieBosio commented 11 months ago

That's interesting! When I switch from doom-nord to nano-light everything including the modeline updates. Then, if I run M-x disable-theme RET nano-theme RET, the theme switches to the Emacs default but the doom-nord modeline colours come back. So somehow, it seems that the theme used at startup is the modeline's "fallback" colours.

Putting (disable-theme 'nano-theme) in the load-theme advice didn't seem to have any effect, unfortunately.

rougier commented 11 months ago

Hum, maybe I set some settings without using the custom machinery, that may explain things. I need to have a closer look at the sources.

SophieBosio commented 11 months ago

Thank you for looking into this, I appreciate it!

rougier commented 11 months ago

Ok, now I remember: https://github.com/rougier/nano-modeline/issues/54 This means I need to remove the indirect mechanism in favor of regular faces. I'll re-open the issue since I'm not too sure when I can make the change. Don't hesitate to ping me here to enquiry about any advance.

PavelNovichkov commented 3 days ago

A workaround that works for me is to explicitly reset nano-modeline-active face to its default value after switching themes:

(defun my/nano-modeline-update (&rest _)
    "Update nano-modeline active face."
    (custom-set-faces
     `(nano-modeline-active
       ((t (:foreground ,(face-foreground 'default)
            :background ,(face-background 'header-line nil t)
            :box (:line-width 1 :color ,(face-background 'default))))))))
(add-hook 'enable-theme-functions #'my/nano-modeline-update)