]> git.eshelyaron.com Git - emacs.git/commitdiff
Introduce new customization variable `use-package-merge-key-alist'
authorJohn Wiegley <johnw@newartisans.com>
Thu, 7 Dec 2017 21:13:49 +0000 (13:13 -0800)
committerJohn Wiegley <johnw@newartisans.com>
Thu, 7 Dec 2017 21:13:49 +0000 (13:13 -0800)
etc/USE-PACKAGE-NEWS
lisp/use-package/use-package-core.el

index 265e98f20942c397b605db89272a70de4c3dda80..76556be9b2e0c4ececcb90b2d1d4b82701b07c6c 100644 (file)
   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.
index 82163d01514ad80f2da580864a541b1fe2d1b0d5..175e023a5a46a3b8f3f5f3761d1e33da4706e533 100644 (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)