1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-29 08:31:35 -08:00

Introduce new customization variable `use-package-merge-key-alist'

This commit is contained in:
John Wiegley 2017-12-07 13:13:49 -08:00
parent 96ecfab9e4
commit 80e8a599b4
2 changed files with 36 additions and 6 deletions

View file

@ -154,6 +154,13 @@
it is loaded, `helm-descbinds` itself is not loaded until the user presses
`C-h b`.
- For extension authors, there is a new customization variable
`use-package-merge-key-alist` that specifies how values passed to multiple
occurences of the same key should be merged into a single value, during
normalization of the `use-package` declaration into a proper plist. The
default behavior is to simply append the values together (since they are
always normalized to lists).
### Bug fixes
- Repeating a bind no longer causes duplicates in personal-keybindings.

View file

@ -179,6 +179,29 @@ t according to whether defaulting should be attempted."
(choice :tag "Enable if non-nil" sexp function)))
:group 'use-package)
(defcustom use-package-merge-key-alist
'((:if . (lambda (new old) `(and ,new ,old)))
(:after . (lambda (new old) `(:all ,new ,old)))
(:defer . (lambda (new old) old)))
"Alist of keys and the functions used to merge multiple values.
For example, if the following form is provided:
(use-package foo :if pred1 :if pred2)
Then based on the above defaults, the merged result will be:
(use-package foo :if (and pred1 pred2))
This is done so that, at the stage of invoking handlers, each
handler is called only once."
:type `(repeat
(cons (choice :tag "Keyword"
,@(mapcar #'(lambda (k) (list 'const k))
use-package-keywords)
(const :tag "Any" t))
function))
:group 'use-package)
(defcustom use-package-hook-name-suffix "-hook"
"Text append to the name of hooks mentioned by :hook.
Set to nil if you don't want this to happen; it's only a
@ -484,8 +507,8 @@ extending any keys already present."
name tail plist merge-function))
(plist-put plist keyword
(if (plist-member plist keyword)
(funcall merge-function keyword
arg (plist-get plist keyword))
(funcall merge-function keyword arg
(plist-get plist keyword))
arg)))
(use-package-error (format "Unrecognized keyword: %s" keyword))))))
@ -498,10 +521,10 @@ extending any keys already present."
args)
(defun use-package-merge-keys (key new old)
(cond ((eq :if key) `(and ,new ,old))
((eq :after key) `(:all ,new ,old))
((eq :defer key) old)
(t (append new old))))
(let ((merger (assq key use-package-merge-key-alist)))
(if merger
(funcall (cdr merger) new old)
(append new old))))
(defun use-package-sort-keywords (plist)
(let (plist-grouped)