From: John Wiegley Date: Tue, 28 Nov 2017 21:58:38 +0000 (-0800) Subject: Add support for `:hook` X-Git-Tag: emacs-29.0.90~1306^2~15^2~246 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4ad4a59685;p=emacs.git Add support for `:hook` Fixes https://github.com/jwiegley/use-package/issues/444 --- diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index cc8a76bd1c2..648e2c7c8ae 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -158,6 +158,7 @@ the user specified." :defines :functions :defer + :hook :custom :custom-face :init @@ -1409,6 +1410,54 @@ deferred until the prefix key sequence is pressed." (message (format "Cannot load %s" ',name))) ,@config-body))))))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; :hook +;; + +(defun use-package-normalize/:hook (name keyword args) + (use-package-as-one (symbol-name keyword) args + (lambda (label arg) + (unless (or (symbolp arg) (consp arg)) + (use-package-error + (concat label " a or a ( . )" + " or list of these"))) + (use-package-normalize-pairs + #'(lambda (k) + (or (symbolp k) + (and (listp k) + (listp (cdr k)) + (seq-every-p #'symbolp k)))) + #'(lambda (v) + (or (symbolp v) (functionp v))) + name label arg)))) + +(defun use-package-handler/:hook (name keyword args rest state) + "Generate use-package custom keyword code." + (let ((commands (let (funs) + (dolist (def args) + (if (symbolp (cdr def)) + (setq funs (cons (cdr def) funs)))) + (nreverse funs)))) + (use-package-concat + (use-package-process-keywords name + (if commands + (use-package-sort-keywords + (use-package-plist-maybe-put rest :defer t)) + rest) + (if commands + (use-package-plist-append state :commands commands) + state)) + (cl-mapcan + (lambda (def) + (let ((syms (car def)) + (fun (cdr def))) + (mapcar + #'(lambda (sym) + `(add-hook (quote ,(intern (format "%s-hook" sym))) + (function ,fun))) + (if (symbolp syms) (list syms) syms)))) args)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; :custom