I have several hundred lines of customization code for org-mode in a private layer. In Spacemacs, customization code typically goes in a function called $LAYER/init-$PACKAGE or in my case, joe/post-init-org.

However, this adds three layers of indentation and is annoying to re-eval code segments when modifying a config.

(defun joe/post-init-org ()
  "Init org."
  (use-package org
      ;; Extensive list of customization...

Is there a proper way to do this in Spacemacs? Or should I just do something like:

(defun joe/post-init-org ()
  "Init org."
  (use-package org
      (load "~/path/to/my/file")

2 Answers 2


AFAIK, there is no 'proper' way of doing this. What I use in such cases is not load but require. Every private layer that has such configurations files (features / packages) has a folder named extra. And I just add that folder to load path using add-to-load-path. After that I use require to load configurations inside of :config just like you use load.

I understand that this might sound like a total overhead, but Spacemacs is about lazy loading and such approach doesn't break this principle. If you don't care about lazy loading - you can force load org and configure without any indentations.

Also, it's pretty easy to automate the step where you add extra folder to load-path using following snippet.

(defun d12-layers/add-extra-to-load-path (layer)
  "Add 'extra' folder to `load-path' for a given LAYER.

Load-path is modified only when such folder exists."
  (let* ((layer-path (configuration-layer/get-layer-path layer))
         (layer-root (format "%s%s/" layer-path layer))
         (extra-path (concat layer-root "extra/")))
    (when (file-exists-p extra-path)
        (add-to-load-path extra-path))))

(mapc #'d12-layers/add-extra-to-load-path (configuration-layer/get-layers-list))

This saves you from using layer name somewhere except of list of layers.


Forgot to say, how to use this. Just put declaration of d12-layers/add-extra-to-load-path function somewhere in .spacemacs or $SPACEMACSDIR/init.el (based on what you're using) and then place following snippet in your dotspacemacs/user-init function:

(mapc #'d12-layers/add-extra-to-load-path

I understand that using 'private' configuration-layer//declare-layers function is far from good, but it's better to setup load-path before layers are loaded, so we can require in config.el and funcs.el.

  • Nice approach. I like that it works automatically.
    – Joe
    May 24, 2016 at 20:34
  • Glad that you like it :) Have fun with Spacemacs!
    – d12frosted
    May 24, 2016 at 20:35

Below is the way set up all my customizations for layers. I am using the .spacemacs.d directory and the init.el, but this should also work fine in .spacemacs file. It does not separate them into their own files, but I like to keep mine all in the init file.

(spacemacs|use-package-add-hook org-mode
      ;; custom settings follow
  • 1
    But this doesn't fix the initial problem - indentation and evaluation bizarre. As far as I understand, the problem of OP is not the layers system, but code organisation - your configs are nested. spacemacs|use-package-add-hook just allows to avoid creating layer for custom configuration of specific package.
    – d12frosted
    May 24, 2016 at 7:12
  • @d12frosted you are correct, I misread the OP. My bad.
    – MaDhAt2r
    May 24, 2016 at 11:57
  • Don't worry :) Though spacemacs|use-package-add-hook is really good macro if you have to make a minor configuration for package that you don't want to configure in any of private layers.
    – d12frosted
    May 24, 2016 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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