1

short story: The theme just did not show up automatically at emacs start, when it is invoked by an after-init-hook. However, with emacs-startup-hook it worked as expected:

(use-package heaven-and-hell
  ...
;;:hook (after-init . heaven-and-hell-init-hook) ;; does not work
  :hook (emacs-startup . heaven-and-hell-init-hook) ;; this one does

I run plain emacs (emacs -l test.el -Q) with a test script (modified from this question)

test.el

(defun buffer-hook-function ()
  (append-to-file (format "%s" (buffer-list)) nil  "log.txt")
  (append-to-file "\n" nil  "log.txt")
  )

(append-to-file "Running ...\n" nil  "log.txt")

(add-hook 'emacs-startup-hook (lambda () (append-to-file "emacs-startup-hook\n" nil  "log.txt")))
(add-hook 'after-init-hook (lambda () (append-to-file "after-init-hook\n" nil  "log.txt")))
(add-hook 'before-init-hook (lambda () (append-to-file "before-init-hook\n" nil  "log.txt")))
(add-hook 'window-setup-hook (lambda () (append-to-file "window-setup-hook\n" nil  "log.txt")))
(add-hook 'emacs-startup-hook (lambda () (append-to-file "emacs-startup-hook after window-setup-hook\n" nil  "log.txt")))
(add-hook 'emacs-startup-hook (lambda () (append-to-file (format "after-init-time %.2fs (printed via emacs-startup-hook)\n" (float-time (time-subtract (current-time) after-init-time))) nil "log.txt")))
(add-hook 'buffer-list-update-hook 'buffer-hook-function)

log.txt

Running ...
  (*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*)
  after-init-time 0.03s (printed via emacs-startup-hook)
  emacs-startup-hook after window-setup-hook
  emacs-startup-hook
  window-setup-hook
  (*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*)

So after-init-hook does not appear, but after-init-time seems to be set, which seems to come from an after-init-hook.

I still do not see why after-init-hook is not called. This question refers to the command-line processing part of after-init-hook, so I tried different configurations, terminals and (non-)window modes.

  • Why after-init-hook is not called?
  • Does this mean, other packages with init hooks can also fail?

Edit: Using emacs 26.2, Manjaro Linux 18.0.4 xfce

Update: after rewriting my theme and addressing an issue in spacemacs-theme, after-init seems to work so far via heaven-and-hell. emacs-startup hook had other issues like additional syntax highlighting via prog-mode-hook did not work.

Update 2: The example test.el perhaps always fails. If you run without -Q it is invoked: emacs -l test.el:

Running ...
<snip>
  after-init-hook
  (*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*  *load*)
  Running ...
  (*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*)
  after-init-time 0.06s (printed via emacs-startup-hook)
  emacs-startup-hook after window-setup-hook
  emacs-startup-hook
  window-setup-hook
<snip>

1 Answer 1

3

Why after-init-hook is not called?

It is called, but it's called before test.el gets a chance to modify it. (elisp) Startup Summary:

 17. It runs the normal hook `after-init-hook'.

 [...]

 21. It processes any command-line options that were not handled
     earlier.

 [...]

 25. It runs `emacs-startup-hook'.

"command-line options that werer not handled earlier" includes -l test.el. So by the time you are adding to after-init-hook it is too late.

2
  • ok, I just guessed loading el-files must come earlier than after-init-hook processing (5. It does some basic parsing of the command-line arguments.?). Otherwise is there a way at all for loading custom init files via command line besides of the hardcoded options?
    – tdd
    Jul 12, 2019 at 7:18
  • I can answer my comment: No. See here: after-init-hook: This normal hook is run, once, just after loading all the init files (site-start.el, your init file, and default.el), before loading the terminal-specific library (if started on a text terminal) and processing the command-line action arguments.
    – tdd
    Jul 12, 2019 at 7:30

Your Answer

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

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