aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Wiegley2017-12-07 13:13:49 -0800
committerJohn Wiegley2017-12-07 13:13:49 -0800
commit80e8a599b4392bbb45a6263c8e750db267b8e4e9 (patch)
tree4b73b0883bbb4fb02dba15d4450829f0bbbb75d9
parent96ecfab9e4e219eb525d945ad14f6742562b11b1 (diff)
downloademacs-80e8a599b4392bbb45a6263c8e750db267b8e4e9.tar.gz
emacs-80e8a599b4392bbb45a6263c8e750db267b8e4e9.zip
Introduce new customization variable `use-package-merge-key-alist'
-rw-r--r--etc/USE-PACKAGE-NEWS7
-rw-r--r--lisp/use-package/use-package-core.el35
2 files changed, 36 insertions, 6 deletions
diff --git a/etc/USE-PACKAGE-NEWS b/etc/USE-PACKAGE-NEWS
index 265e98f2094..76556be9b2e 100644
--- a/etc/USE-PACKAGE-NEWS
+++ b/etc/USE-PACKAGE-NEWS
@@ -154,6 +154,13 @@
154 it is loaded, `helm-descbinds` itself is not loaded until the user presses 154 it is loaded, `helm-descbinds` itself is not loaded until the user presses
155 `C-h b`. 155 `C-h b`.
156 156
157- For extension authors, there is a new customization variable
158 `use-package-merge-key-alist` that specifies how values passed to multiple
159 occurences of the same key should be merged into a single value, during
160 normalization of the `use-package` declaration into a proper plist. The
161 default behavior is to simply append the values together (since they are
162 always normalized to lists).
163
157### Bug fixes 164### Bug fixes
158 165
159- Repeating a bind no longer causes duplicates in personal-keybindings. 166- Repeating a bind no longer causes duplicates in personal-keybindings.
diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el
index 82163d01514..175e023a5a4 100644
--- a/lisp/use-package/use-package-core.el
+++ b/lisp/use-package/use-package-core.el
@@ -179,6 +179,29 @@ t according to whether defaulting should be attempted."
179 (choice :tag "Enable if non-nil" sexp function))) 179 (choice :tag "Enable if non-nil" sexp function)))
180 :group 'use-package) 180 :group 'use-package)
181 181
182(defcustom use-package-merge-key-alist
183 '((:if . (lambda (new old) `(and ,new ,old)))
184 (:after . (lambda (new old) `(:all ,new ,old)))
185 (:defer . (lambda (new old) old)))
186 "Alist of keys and the functions used to merge multiple values.
187For example, if the following form is provided:
188
189 (use-package foo :if pred1 :if pred2)
190
191Then based on the above defaults, the merged result will be:
192
193 (use-package foo :if (and pred1 pred2))
194
195This is done so that, at the stage of invoking handlers, each
196handler is called only once."
197 :type `(repeat
198 (cons (choice :tag "Keyword"
199 ,@(mapcar #'(lambda (k) (list 'const k))
200 use-package-keywords)
201 (const :tag "Any" t))
202 function))
203 :group 'use-package)
204
182(defcustom use-package-hook-name-suffix "-hook" 205(defcustom use-package-hook-name-suffix "-hook"
183 "Text append to the name of hooks mentioned by :hook. 206 "Text append to the name of hooks mentioned by :hook.
184Set to nil if you don't want this to happen; it's only a 207Set to nil if you don't want this to happen; it's only a
@@ -484,8 +507,8 @@ extending any keys already present."
484 name tail plist merge-function)) 507 name tail plist merge-function))
485 (plist-put plist keyword 508 (plist-put plist keyword
486 (if (plist-member plist keyword) 509 (if (plist-member plist keyword)
487 (funcall merge-function keyword 510 (funcall merge-function keyword arg
488 arg (plist-get plist keyword)) 511 (plist-get plist keyword))
489 arg))) 512 arg)))
490 (use-package-error (format "Unrecognized keyword: %s" keyword)))))) 513 (use-package-error (format "Unrecognized keyword: %s" keyword))))))
491 514
@@ -498,10 +521,10 @@ extending any keys already present."
498 args) 521 args)
499 522
500(defun use-package-merge-keys (key new old) 523(defun use-package-merge-keys (key new old)
501 (cond ((eq :if key) `(and ,new ,old)) 524 (let ((merger (assq key use-package-merge-key-alist)))
502 ((eq :after key) `(:all ,new ,old)) 525 (if merger
503 ((eq :defer key) old) 526 (funcall (cdr merger) new old)
504 (t (append new old)))) 527 (append new old))))
505 528
506(defun use-package-sort-keywords (plist) 529(defun use-package-sort-keywords (plist)
507 (let (plist-grouped) 530 (let (plist-grouped)