5

I've wrote this, and it works:

(use-package web-mode
  :ensure t
  :mode (("\\.php$" .  web-mode)
         ("\\.html$" .  web-mode))
  :preface
  (defun dg/web-mode-hook())
  :config
  (add-hook 'web-mode-hook 'dg/web-mode-hook))

It enables web-mode when opening .php or .html files. I've noticed that use-package also provides :hook directive, but it's not very clear how I can use it in this case.

Any clue?

Thanks in advance.

4

As others said I think https://github.com/jwiegley/use-package#hooks is pretty clear. :hook replaces add-hook and creates autoloads for you. Your example with :hook would be:

(use-package web-mode
  :ensure t
  :mode (("\\.php$" .  web-mode)
         ("\\.html$" .  web-mode))
  :hook (web-mode . dg/web-mode-hook)
  :config
  (defun dg/web-mode-hook()))
  • Thank you, I tought that :hook could some way save me from having to define a my-hook-fn(). – Daniele Mar 6 '18 at 8:43
  • @Daniele, you should be able to use a lambda form: (use-package web-mode :ensure t :mode (("\\.php$" . web-mode) ("\\.html$" . web-mode)) :hook (web-mode . (lambda () ...))) – paradoja Feb 15 at 13:48

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.