How do I run an arbitrary function upon starting up Emacs?

My specific problem: in spacemacs, I have added the following to the config section of my .spacemacs file:

(add-hook 'evil-insert-state-exit-hook 'linum-relative-on)
(add-hook 'evil-insert-state-entry-hook 'linum-relative-off)

It works well, but I've noticed that this config produces weird behaviour if I don't first execute linum-relative-toggle immediately after opening spacemacs and before editing a file.

How can I get Emacs to automatically execute linum-relative-toggle on start up?


Here are two basic options to run a function (in this case, linum-relative-toggle) at start-up.

Simple option: add (linum-relative-toggle) to your init file (probably at the end).

Somewhat more involved option (may be necessary if the simple option doesn't help for some reason): use (add-hook 'after-init-hook #'linum-relative-toggle).

after-init-hook's docstring:

Normal hook run after initializing the Emacs session. It is run after Emacs loads the init file, default library, the abbrevs file, and additional Lisp packages (if any), and setting the value of after-init-time.

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.