5

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?

Dan
  • 32,584
  • 6
  • 98
  • 168
Running Turtle
  • 467
  • 1
  • 4
  • 7

1 Answers1

4

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.

Dan
  • 32,584
  • 6
  • 98
  • 168