jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.39k stars 259 forks source link

`use-package` requires setting `custom-theme-load-path` when loading a local theme with `:load-path` #963

Closed topikettunen closed 1 year ago

topikettunen commented 2 years ago

Hi!

I noticed this weird issue on my setup which I'm pretty sure wasn't happening earlier.

Currently when I load my local theme with:

(use-package tok-theme
  :load-path "themes/tok-theme"
  :defer nil
  :if window-system
  :config
  (load-theme 'tok t))

It can't find the theme called tok. But when I add:

(use-package tok-theme
  :load-path "themes/tok-theme"
  :defer nil
  :if window-system
  ;; For some reason when I load my theme with use-package I need to set this explicitly.
  :init
  (add-to-list 'custom-theme-load-path "~/.emacs.d/themes/tok-theme")
  (load-theme 'tok t))

it finds it with no issue. I'm pretty sure that at one point for me adding that :load-path worked just fine when loading my theme.

There are also no issues when I load the theme with:

(add-to-list 'load-path "~/.emacs.d/themes/tok-theme")
(require 'tok-theme)
(load-theme 'tok t)

So most likely the issue is not in my theme. My theme is located at https://github.com/topikettunen/tok-theme and in there I also do:

;;;###autoload
(when (and (boundp 'custom-theme-load-path) load-file-name)
  (add-to-list 'custom-theme-load-path
               (file-name-as-directory (file-name-directory load-file-name))))

which should add the theme to your custom-theme-load-path (and it does when I require the theme and load it without use-package.

My theme is also at MELPA so when I load it without :load-path, e.g.:

(use-package tok-theme
  :defer nil
  :if window-system
  :init
  (load-theme 'tok t))

it works fine.

Am I doing something terribly wrong here?

Thanks in advance!

doolio commented 1 year ago

Is the tok-theme.el within a subdirectory called tok-theme? If not then you should only need to specify the subdirectory themes. In addition, use of window-system as a boolean is deprecated. You should use display-graphics-p instead. Also, the :defer nil line seems unnecessary. if you have use-package-always-defer set to t you should use something like :demand t. Lastly, you should probably use load-theme within an :init form rather than :config. So perhaps something like the following:

(use-package tok-theme
  :load-path "themes"
  :demand t 
  :init
  (if (display-graphic-p)
    (load-theme 'tok t)))
topikettunen commented 1 year ago

Basically, I have a submodule of my theme as a directory under themes, currently called tok, and my use-package as the time of writing this is as follows:

(use-package tok-theme
  :load-path "themes/tok"
  :init
  (add-to-list 'custom-theme-load-path (emacs-path "themes/tok"))
  (load-theme 'tok t))

and I have tested it in and out with :demand t, without it, and other configs that you mentioned, but still it doesn't load without the add-to-list, which is odd since I do remember it working at some point as I mentioned in the opening post. I mean it's not the end of the world, and currently it works as intended. I was just wondering was there some sort of regression at some point.

doolio commented 1 year ago

Was it always a submodule even when it worked in the past?

topikettunen commented 1 year ago

It has been both just under themes and also without being submodule in the subdirectory. I have just since released it in MELPA, which is why I refactored it into its own repo and am using it as a submodule.

doolio commented 1 year ago

OK, I thought perhaps it being a submodule might be the reason but if it didn't worked when the .el file was just in the themes directory then it can't be the reason.

topikettunen commented 1 year ago

;;;###autoload was the culprit here. Works as intended.