]> git.eshelyaron.com Git - emacs.git/commitdiff
Add support for variable customization
authorDamien Merenne <dam@cosinux.org>
Tue, 17 Oct 2017 17:35:19 +0000 (19:35 +0200)
committerDamien Merenne <dam@cosinux.org>
Fri, 10 Nov 2017 08:14:38 +0000 (09:14 +0100)
Allows customization of variable using customize-set-variables. This makes it
easier to manage customization in version control. Instead of having all the
variables written in a custom.el, the variable can be customized where the rest
of the package is configured.

lisp/use-package/use-package.el

index 969cd0beabfd10ca86c58f01d838b4f0799fe29e..7e36d6204a97491e81fef1e0ee859b0860faec3d 100644 (file)
@@ -158,6 +158,7 @@ the user specified."
     :defines
     :functions
     :defer
+    :custom
     :init
     :after
     :demand
@@ -1404,6 +1405,44 @@ deferred until the prefix key sequence is pressed."
                  (message (format "Cannot load %s" ',name)))
               ,@config-body)))))))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; :custom
+;;
+
+(defun use-package-normalize/:custom (name-symbol keyword arg)
+  "Normalize use-package custom keyword."
+  (let ((error-msg (format "%s wants a (<symbol> <form> <optional string comment>) or list of these" name-symbol)))
+    (unless (listp arg)
+      (use-package-error error-msg))
+    (dolist (def arg arg)
+      (unless (listp def)
+        (use-package-error error-msg))
+      (let ((variable (nth 0 def))
+            (value (nth 1 def))
+            (comment (nth 2 def)))
+        (when (or (not variable)
+                  (not value)
+                  (> (length def) 3)
+                  (and comment (not (stringp comment))))
+          (use-package-error error-msg))))))
+
+(defun use-package-handler/:custom (name keyword args rest state)
+  "Generate use-package custom keyword code."
+  (let ((body (use-package-process-keywords name rest state)))
+    (use-package-concat
+     (mapcar (lambda (def)
+               (let ((variable (nth 0 def))
+                     (value (nth 1 def))
+                     (comment (nth 2 def)))
+                 (unless comment
+                   (setq comment (format "Customized with use-package %s" name)))
+                 `(customize-set-variable (quote ,variable) ,value ,comment)))
+             args)
+     body)))
+
+
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
 ;;; :diminish
@@ -1550,6 +1589,7 @@ this file.  Usage:
 :load-path       Add to the `load-path' before attempting to load the package.
 :diminish        Support for diminish.el (if installed).
 :delight         Support for delight.el (if installed).
+:custom          Call `customize-set-variable' with each variable definition.
 :ensure          Loads the package using package.el if necessary.
 :pin             Pin the package to an archive."
   (declare (indent 1))