Add hook to default mode when using emacs -q -l

Viewed 238

I have been loading emacs with emacs -q -l "init.el" quite a bit and was trying to enable auto-complete in my scratch buffer. I was struggling to figure out why it wasn't working but realized it must have to do with the order of operations when emacs is loaded like this - a quick test with the following init file:

(package-initialize)
(require 'auto-complete)
(ac-config-default)
(add-hook 'lisp-interaction-mode-hook
      '(lambda ()
         (auto-complete-mode t)))

shows completion working as I would like when calling emacs as normal from the command line. But if I call it as emacs -q -l init.el there is no dropdown completion.

Question: How can I get this hook to run?

I've tried variations on after-init-hook but none seem to work.

2 Answers

If starting Emacs from the command line, you could invoke the function to run near the end of the loading sequence, as follows:

emacs -f lisp-interaction-mode

See Action Arguments in the manual:

‘-f function’

‘--funcall=function’

Call Lisp function function. If it is an interactive function (a command), it reads the arguments interactively just as if you had called the same function with a key sequence. Otherwise, it calls the function with no arguments.

Related