use-package icon indicating copy to clipboard operation
use-package copied to clipboard

feature request: support local and depth arguments for :hook

Open Hugo-Heagren opened this issue 3 years ago • 4 comments

I'm trying to port some of my old config into neater use-package declarations and I have a few add-hooks which use the optional DEPTH and LOCAL args of that function. These aren't currently supported by use-package, but it would be nice if they were. Perhaps something like one of these?

More consistent with use-package's use of keys:

(use-package foo
  :hook
  (bar-mode . foo-mode-hook :depth 80 :local t))

And more consistent with add-hook (though with the disadvantage that comes with all optional positional arguments -- specifying only the last one requires specifying the others as nil, which is kinda cluttered):

(use-package foo
  :hook
  (bar-mode . foo-mode-hook 80 t))

Personally I prefer the first, but either would be good. I would be happy to try implementing this and submit a PR..

Hugo-Heagren avatar Dec 10 '21 14:12 Hugo-Heagren

First of all, your grammar is invalid as Elisp

'(use-package foo
  :hook
  (bar-mode . foo-mode-hook :depth 80 :local t))
;;=> Debugger entered--Lisp error: (invalid-read-syntax ". in wrong context")
;;     read(#<buffer *scratch*>)
;;     elisp--preceding-sexp()
;;     elisp--eval-last-sexp(t)
;;     eval-last-sexp(t)
;;     eval-print-last-sexp(nil)
;;     funcall-interactively(eval-print-last-sexp nil)
;;     call-interactively(eval-print-last-sexp nil nil)
;;     command-execute(eval-print-last-sexp)

conao3 avatar Dec 10 '21 16:12 conao3

@conao3 you're right. I was rembering that it's possible to have many elements to the left of the ., and getting confused. Perhaps it could be done without cons cells, and just with a list, like this:

(use-package foo
  :hook
  (bar-mode foo-mode-hook :depth 80 :local t))

or this:

(use-package foo
  :hook
  (bar-mode foo-mode-hook 80 t))

Of course, for backwards compatibility the cons cell format could still be supported, it just wouldn't support the extra arguments. Or another way perhaps?

Hugo-Heagren avatar Dec 11 '21 16:12 Hugo-Heagren

This would be very helpful to have. There is no clean way to combine defer and hook addition at a non-default depth.

jdtsmith avatar Jul 14 '22 14:07 jdtsmith

@jdtsmith since making this request I have migrated to leaf. One of my reasons was that the maintainer seems much more active on the project, and requests like this (and my PR on use-package) are more likely to be acted upon. I just haven't got round to making them yet...

Hugo-Heagren avatar Jul 14 '22 17:07 Hugo-Heagren