I am attempting to use magit-add-section-hook in dotspacemacs/user-init.

(defun dotspacemacs/user-config ()
  ;; Magit pull submodules.  Don't know why this fails.
  (magit-add-section-hook 'magit-status-sections-hook 'magit-insert-modules-overview 'append t)

This results in the following error while loading:

(Spacemacs) Error in dotspacemacs/user-config: Symbol’s function definition is void: magit-add-section-hook AND the magit-add-section-hook is not defined in emacs. Other magit operations appear to function properly.

When I remove the (magit-add-section-hook ...) from the dotspacemacs/user-initand restart the function magit-add-section-hook loads normally and can be used with the above expression.

*** Version Info***:

  • Emacs: GNU Emacs 27.1 (build 1, x86)64-mingw32) of 2020-11-19
  • Spacemacs: [email protected]
  • Magit: 20211011.1135 [>=3.3.0], Git 2.30.1, Emacs 27.1, windows-nt

1 Answer 1


You can't call a function that hasn't been defined, and that function won't be defined until the magit-section.el library has been loaded.

For Magit you're better to deal with the main magit.el library though. It will (indirectly) load magit-section.el along with the other core libraries, and in your particular case you're dealing with things which are defined in more than one of those libraries.

You can (require 'magit) to load it forcibly, but I would do this:

(with-eval-after-load "magit"
  (magit-add-section-hook ...))
  • With the proposed I get "Cannot add function to undefined hook variable magit-status-sections-hook" (with-eval-after-load 'magit-section (magit-add-section-hook 'magit-status-sections-hook 'magit-insert-modules-overview '(append t))) When I use the brute-force: (add-hook 'magit-mode-hook (lambda () (magit-add-section-hook 'magit-status-sections-hook 'magit-insert-modules-overview '(append t)))) It works (except for the append) portion. Feb 28, 2022 at 19:40
  • magit-status-sections-hook is defined in a different library which is loaded later. I've edited the answer to deal with magit.el instead, which eliminates any such sequencing issues.
    – phils
    Feb 28, 2022 at 20:52

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.