2

I'm trying to create a layer where one package in the layer depends on the functionality of another package in the same layer. As spacemacs loads the packages alphabetically (I assume) this only works if the dependend package has a name that is loaded after the name of the package with the required functionality - otherwise it doesn't compile. Minimal example:

emacs/private/testlayer
    - packages.el
    - local
        - a-package
            a-package.el
        - b-package
            b-package.el

Where packages.el:

;; the order of the arguments in the package-list doesn't matter
;; for the loading process
(defconst testlayer-packages
  '((a-package :location local)
    (b-package :location local))
)

;; the order of the init functions in the file doesn't matter
;; for the loading process
(defun testlayer/init-a-package ()
  (use-package a-package)
)

(defun testlayer/init-b-package ()
  (use-package b-package)
)

and a-package.el:

(require 'b-package)

(defun a-pack-fun ()
  (b-pack-fun)
  )

(provide 'a-package)

and b-package.el:

(defun b-pack-fun ()
   (message "b-pack-fun")
)

(provide 'b-package)

Adding testpackage to dotspacemacs-configuration-layers in .spacemacs and trying to load it results in the following error message:

Warning (initialization): An error occurred while loading 
`/home/user/.emacs.d/init.el':

File error: Cannot open load file, no such file or directory, b-package

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

If the dependencies are the other way around (b-package calls functionality from a-package) everything works just fine due to the alphabetical loading order.

Now, how can I specify the loading order so that b-package is loaded before a-package?

3

You are free to update the load-path variable anywhere in packages.el but I would put it in config.el file though.

In your example, add a config.el file in your layer with the following content:

(add-to-list 'load-path (concat (configuration-layer/get-layer-local-dir 'testlayer)
                                "b-package/")

EDIT: you can also use use-package keyword :load-path. I suggest you to use this keyword instead of config.el.

Extending the load-path

If your package needs a directory added to the load-path in order to load, use :load-path. This takes a symbol, a function, a string or a list of strings. If the path is relative, it is expanded within user-emacs-directory:

(use-package ess-site
  :load-path "site-lisp/ess/lisp/"
  :commands R)

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.