2

Using Emacs 26.3. I made a theme file. If I change the theme, then restart Emacs the change is not applied. I have to close Emacs a second time, and then only on the second start up does the change take effect.

init.el:

(load-theme 'foo t)
(package-install-file (expand-file-name "foo-theme.el" user-emacs-directory))

Within the theme:

  ... other stuff ...
  (custom-theme-set-faces
   'foo
        ;; DEFAULT
        `(default ((,class (:foreground "#FFFFFF" :background "#000000" :distant-foreground "#000000"))))

If I perform the following:

  1. Comment out the default face in foo-theme.el
  2. Save foo-theme.el
  3. Close Emacs.
  4. Open Emacs, open foo-theme.el, I see the change is still there but the face change was not applied to the default face (Emacs looks the same).
  5. Close Emacs.
  6. Open Emacs, and now I see that foo-theme has been applied correctly (default face looks as it should), and the my-theme.el file remains the same.

Why does it not apply correctly on the next start up of Emacs? How to fix it to load the theme correctly (maybe it is caching it somewhere)?

5
  • More testing, if I make a change, restart, the change is not applied, then if I undo the change save, restart, then the change is applied, even though it doesnt appear in the file! – run_the_race Mar 24 '20 at 17:29
  • Not able to reproduce - theme settings are reloaded every restart This probably points out that the issue is elsewhere. Here is the mock theme I am using: lisp ;; dummy theme ;; http://emacsfodder.github.io/blog/notes-on-deftheme/ (deftheme foo) (custom-theme-set-faces 'foo '(default ((t (:foreground "#00feff" :background "black")))) '(fringe ((t (:background "#00ff00"))))) (provide-theme 'foo) In addition, I think that package-install-file might not be necessary. (load-theme 'foo t) should be sufficient (assuming custom-theme-directory is set properly). What version of emacs are – Haskell Curry Mar 24 '20 at 23:50
  • The three lines you quote from your init.el are weird. Where do they come from? E.g. you shouldn't re-package-install every time. And you shouldn't have Elisp files inside user-emacs-directory (you can put them inside a subdirectory of user-emacs-directory on the other hand). – Stefan Mar 25 '20 at 13:02
  • @Stefan Those lines from init.el are from me! foo-theme.el is my own custom theme placed in my .emacs.d (part of my dot emacs git check out). Why not put .el files within ~/.emacs.d, is that not what it is for? – run_the_race Mar 26 '20 at 9:53
  • Because .emacs.d/<foo>.el is often used by package <foo> to keep some internal information (like a history of use). Always put your Elisp files in some subdirectory if you want to use .emacs.d, e.g. ~/.emacs.d/myfiles/<foo>.el. – Stefan Mar 26 '20 at 15:18
4

My crystal ball says:

  • load-theme loads the theme from ~/.emacs.d/elpa/foo-theme-<version>
  • then package-install-file takes your ~/.emacs.d/foo-theme.el and installs it (aka copies it and compiles it) into ~/.emacs.d/elpa/foo-theme-<version>.

So the first time you run Emacs after changing ~/.emacs.d/foo-theme you load the "old" file (and copy the new file to the elpa location, so you'll get to see the change on the second invocation).

1
  • Your crystal ball was right. I changed the order to package-install-file then load-theme. Thanks! – run_the_race Apr 1 '20 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.