According to the use-package documentation these two are the same:

(use-package ace-jump-mode
  :hook (prog-mode . ace-jump-mode))

(use-package ace-jump-mode
  :commands ace-jump-mode
  (add-hook 'prog-mode-hook #'ace-jump-mode))

I have the following in my configs:

(use-package auctex
  :ensure t 
  :after latex
  ;; (TeX-after-compilation-finished-functions . TeX-revert-document-buffer) ; Causes errors?

If I take out the add-hook way and uncomments the :hook way then I get the following errors each time I compile a latex document followed by a subsequent pdf buffer revert:

error in process sentinel: image-display-size: Invalid image specification: nil
error in process sentinel: Invalid image specification: nil

Note that when I define the hooks using add-hook, that does not produce the errors.

Could someone tell what's going on?


You can find out what is going on yourself by putting the cursor after the use-package stanza and doing M-x pp-macroexpand-last-sexp. You will discover that the :hook line expands to

(add-hook 'TeX-after-compilation-finished-functions-hook #'TeX-revert-document-buffer)

which is not what you wanted.

Long story short: :hook only does what you want if the car of the alist names a hook in a rather simple-minded way. In your case, calling add-hook explicitly is the way to go.

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.