sellout / emacs-color-theme-solarized

Emacs highlighting using Ethan Schoonover’s Solarized color scheme
http://ethanschoonover.com/solarized
MIT License
1.16k stars 202 forks source link

Loading theme via package system and user initialization #170

Open ghost opened 8 years ago

ghost commented 8 years ago

I recently went through the process of installing this package via package-install and then loading it directly through my ~/.emacs.d/init.el (a.k.a. ~/.emacs). I finally got it to work, and I thought it would be useful to include information about it in the README. (This is for Emacs 24.5.1.)

Here's what I did.

(defun personal/after-init-hook-function ()
  (when (memq 'color-theme-solarized package-activated-list)
    (load-theme 'solarized t)))

(add-hook 'after-init-hook 'personal/after-init-hook-function)

Technically speaking, you can also do this:

(require 'package)
(package-initialize)
(load-theme 'solarized t)

The only caveat with this second approach is outlined in the Emacs manual under Package Installation:

The reason automatic package loading occurs after loading the init file is that user options only receive their customized values after loading the init file, including user options which affect the packaging system.

It looks like the "accepted" way to load and use packages is lazily, which means making liberal use of the after-init-hook. I don't know if this is really what was intended, but packages are not available when your init.el is processed, so you either have to (a) ensure all customization is done through customize; (b) don't use customize for much of anything; (c) run package-initialize yourself (which may make some customizations not work); (d) load the packages and apply code-based customizations after the packages are loaded by Emacs, which is after the init.el is processed. (Hey, let's just rewrite Emacs in Haskell to solve this problem!(*))

I've used this to deal with all the stuff I've installed through packages and have migrated my code-based customizations accordingly. It appears to work. (What's odd is that, essentially, you end up having the after-init-hook load some other Elisp file to do the code-based customizations for packages.)

I have a feeling I'm missing something, but this doesn't feel like a horrible hack so I'm suggesting it for the time being. If I come across something else, I'll provide more information.

(*) No. And shame on you for even entertaining the idea for a number of picoseconds greater than 0.