]> git.eshelyaron.com Git - emacs.git/commitdiff
Add use-package-use-theme and avoid missing theme errors
authorTed Zlatanov <tzz@lifelogs.com>
Sat, 6 Feb 2021 10:16:10 +0000 (10:16 +0000)
committerTed Zlatanov <tzz@lifelogs.com>
Sat, 6 Feb 2021 10:46:00 +0000 (10:46 +0000)
lisp/use-package/use-package-core.el
test/lisp/use-package/use-package-tests.el

index 72e080001b2a474ebd0c707c09ecc8dbec6837d8..28bc5a50ed05e315b58975511a8dc2477de49de2 100644 (file)
@@ -135,6 +135,13 @@ arguments will be ignored in the `use-package' expansion."
   :type 'boolean
   :group 'use-package)
 
+(defcustom use-package-use-theme t
+  "If non-nil, use a custom theme to avoid saving :custom
+variables twice (once in the Custom file, once in the use-package
+call)."
+  :type 'boolean
+  :group 'use-package)
+
 (defcustom use-package-verbose nil
   "Whether to report about loading and configuration details.
 If you customize this, then you should require the `use-package'
@@ -1397,18 +1404,34 @@ no keyword implies `:all'."
 (defun use-package-handler/:custom (name _keyword args rest state)
   "Generate use-package custom keyword code."
   (use-package-concat
-   `((let ((custom--inhibit-theme-enable nil))
-       (custom-theme-set-variables
-        'use-package
-        ,@(mapcar
-           #'(lambda (def)
-               (let ((variable (nth 0 def))
-                     (value (nth 1 def))
-                     (comment (nth 2 def)))
-                 (unless (and comment (stringp comment))
-                   (setq comment (format "Customized with use-package %s" name)))
-                 `'(,variable ,value nil () ,comment)))
-           args))))
+   (if (bound-and-true-p use-package-use-theme)
+       `((let ((custom--inhibit-theme-enable nil))
+           ;; Declare the theme here so use-package can be required inside
+           ;; eval-and-compile without warnings about unknown theme.
+           (unless (memq 'use-package custom-known-themes)
+             (deftheme use-package)
+             (enable-theme 'use-package)
+             (setq custom-enabled-themes (remq 'use-package custom-enabled-themes)))
+           (custom-theme-set-variables
+            'use-package
+            ,@(mapcar
+               #'(lambda (def)
+                   (let ((variable (nth 0 def))
+                         (value (nth 1 def))
+                         (comment (nth 2 def)))
+                     (unless (and comment (stringp comment))
+                       (setq comment (format "Customized with use-package %s" name)))
+                     `'(,variable ,value nil () ,comment)))
+               args))))
+     (mapcar
+      #'(lambda (def)
+          (let ((variable (nth 0 def))
+                (value (nth 1 def))
+                (comment (nth 2 def)))
+            (unless (and comment (stringp comment))
+              (setq comment (format "Customized with use-package %s" name)))
+            `(customize-set-variable (quote ,variable) ,value ,comment)))
+      args))
    (use-package-process-keywords name rest state)))
 
 ;;;; :custom-face
index a68491cfb7b66d09068ea623682e2ef0b68a67e0..3825aa3648745aececd08ae7c2aba594ef6baa13 100644 (file)
    `(progn
       (let
           ((custom--inhibit-theme-enable nil))
+        (unless (memq 'use-package custom-known-themes)
+          (deftheme use-package)
+          (enable-theme 'use-package)
+          (setq custom-enabled-themes (remq 'use-package custom-enabled-themes)))
         (custom-theme-set-variables 'use-package
                                     '(foo bar nil nil "Customized with use-package foo")))
       (require 'foo nil nil))))
    `(progn
       (let
           ((custom--inhibit-theme-enable nil))
+        (unless (memq 'use-package custom-known-themes)
+          (deftheme use-package)
+          (enable-theme 'use-package)
+          (setq custom-enabled-themes (remq 'use-package custom-enabled-themes)))
         (custom-theme-set-variables 'use-package
                                     '(foo bar nil nil "commented")))
       (require 'foo nil nil))))