12

My Emacs always prompts me if it should trust selected colour theme or not. I always answer y and y to trust and remember my choice. I'm loading colour theme manually:

(load-theme 'my-favourite-theme)

I suppose this is because easy customizations are placed below colour theme loading. Is it some way to fix it? Or should I just delegate colour theme loading to easy customizations too?

Geradlus_RU
  • 625
  • 7
  • 17
  • 2
    `load-theme` has optional arguments: `(load-theme THEME &optional NO-CONFIRM NO-ENABLE)` -- *If used directly in your init file, it should be called with a non-nil NO-CONFIRM argument . . .* In other words, use: `(load-theme 'my-favourite-theme t)` – lawlist Mar 23 '15 at 19:30
  • 1
    so I need `(load-theme 'name t nil)` or just `(load-theme 'name t)`? – Geradlus_RU Mar 23 '15 at 19:31
  • 2
    Optional arguments that are `nil` need to be included ONLY if a subsequent optional argument is non-`nil`. For example, if you wanted the first optional argument to be `nil` and the second optional argument to be `t`, then `nil` would be needed for the first argument. Since the second optional argument is `nil` -- you may omit or include it -- it makes no difference. Sometimes I use `nil` for optional arguments when there is no subsequent non-`nil` optional argument just so that I know how many optional arguments are possible for a particular function -- i.e., a visual reminder. – lawlist Mar 23 '15 at 19:34
  • What @lawlist is suggesting is a workaround, not a solution. It's preferable to figure out why you're getting this problem as it can possibly cause other issues. In fact, I've seen this issue around a lot, so I'd very much like to know the reason. – Malabarba Mar 23 '15 at 23:43
  • @Geradlus_RU If you haven't specified the NO-CONFIRM argument to be `t`, emacs will ask you that question again each time after that theme package is updated (because its .el checksum changes). Is that the case? If you keep on getting those prompts each time you start emacs (even when the theme .el hasn't been updated), then make sure that the theme checksum is been saved by emacs and also being read by emacs during start-up. One possible scenario is that you have saved the custom.el as a separate file (emacs is memorizing the safe themes to those) but you are not loading that file in init. – Kaushal Modi Mar 24 '15 at 10:59
  • @kaushalmodi, no, I haven't specified `NO-CONFIRM` argument to `load-theme` function and Emacs always prompts me. My easy customizations are written in the same file, i.e. `.emacs`. I supposed this could be because customizations are written not at the end file, but right above `(provide .emacs) ;;; .emacs ends here` lines, however even when I move customizations above mentioned lines the behaviour still the same. – Geradlus_RU Mar 24 '15 at 11:52
  • @Geradlus_RU yes, try moving your customizations to the top. – Malabarba Mar 24 '15 at 12:22
  • @Geradlus_RU Also, you do not need `(provide .emacs)` if you are not requiring that file anywhere else. – Kaushal Modi Mar 24 '15 at 12:51
  • @Malabarba, thank you! Moving customizations code to the top solved issue! Will you post an answer? As for `provide` warnings are annoying me, but thanks again for clarification. – Geradlus_RU Mar 24 '15 at 13:36

2 Answers2

10

Your init.el file probably contains a snippet like this:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 ...)

Amongst many other things, this snippet is responsible for saving and restoring the custom-safe-themes variable. Therefore, if this happens to be at the end of your init file (as is usually the case) you probably added your (load-theme ...) line above it, which explains why Emacs doesn't know about your safe themes during startup.

Simply move that snippet to the top of your init-file, and that should solve your problem.

Malabarba
  • 22,878
  • 6
  • 78
  • 163
5

I'm using moe-them, and just

(require 'moe-theme)
(moe-dark)

will load the theme without error/warning/prompt, but if I M-x load-theme inside Emacs, it will prompt something like "treat the theme as safe", and I found out a solution for that:

(setq custom-safe-themes t)   ; Treat all themes as safe

I don't know if this will solve your problem, but you can give it a try.

CodyChan
  • 2,599
  • 1
  • 19
  • 33