From 8ef7978028c3edaf47fb40a84fee576c4355753f Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Sat, 22 Aug 2020 18:42:36 -0400 Subject: [PATCH 1/4] set saved-variable-comment from :custom GitHub-reference: https://github.com/jwiegley/use-package/issues/861 --- lisp/use-package/use-package-core.el | 3 ++- test/lisp/use-package/use-package-tests.el | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index cd5b907a0b0..540c7349db0 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -1396,7 +1396,8 @@ no keyword implies `:all'." (setq comment (format "Customized with use-package %s" name))) `(funcall (or (get (quote ,variable) 'custom-set) #'set-default) (quote ,variable) - ,value))) + ,value) + `(put (quote ,variable) 'saved-variable-comment ,comment))) args) (use-package-process-keywords name rest state))) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 42bf07453b4..38c2025cac6 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -1138,6 +1138,19 @@ (get 'foo 'custom-set) (function set-default)) 'foo bar) + (set 'foo 'saved-variable-comment "Customized with use-package foo") + (require 'foo nil nil)))) + +(ert-deftest use-package-test/:custom-with-comment1 () + (match-expansion + (use-package foo :custom (foo bar "commented")) + `(progn + (funcall + (or + (get 'foo 'custom-set) + (function set-default)) + 'foo bar) + (set 'foo 'saved-variable-comment "commented") (require 'foo nil nil)))) (ert-deftest use-package-test/:custom-face-1 () From 3e24a7363b2966776c8e5145acf3d918ae1f5c6e Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Sun, 8 Nov 2020 14:58:08 +0000 Subject: [PATCH 2/4] Revert "use-package-core.el: use the Emacs set-default function to avoid saving :custom vars twice" This reverts commit 8c31c57106e2938d627bf4107627c003620d2dd5. --- lisp/use-package/use-package-core.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index 540c7349db0..be43c65cd4f 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -1394,10 +1394,7 @@ no keyword implies `:all'." (comment (nth 2 def))) (unless (and comment (stringp comment)) (setq comment (format "Customized with use-package %s" name))) - `(funcall (or (get (quote ,variable) 'custom-set) #'set-default) - (quote ,variable) - ,value) - `(put (quote ,variable) 'saved-variable-comment ,comment))) + `(customize-set-variable (quote ,variable) ,value ,comment))) args) (use-package-process-keywords name rest state))) From 5ceb51ae198cca77cdf911feee81924d800bdd75 Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Sun, 8 Nov 2020 14:59:58 +0000 Subject: [PATCH 3/4] set property theme-value to avoid saving variable --- lisp/use-package/use-package-core.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index be43c65cd4f..933e94aa2bd 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -1394,7 +1394,8 @@ no keyword implies `:all'." (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))) + `(customize-set-variable (quote ,variable) ,value ,comment) + `(put ',variable 'theme-value '((use-package-synthetic-theme ignore-just-for-saving))))) args) (use-package-process-keywords name rest state))) From a3c310c11a9ec311a4028d7ce8da4c2fd204a46b Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Sun, 29 Nov 2020 12:23:02 +0000 Subject: [PATCH 4/4] Create new "use-package" themse and use it for :custom with custom-theme-set-variables --- lisp/use-package/use-package-core.el | 10 ++++++++-- test/lisp/use-package/use-package-tests.el | 21 +++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index 933e94aa2bd..c44c36f77fd 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el @@ -43,6 +43,11 @@ (require 'cl-lib) (require 'tabulated-list) +;; Declare a synthetic theme for :custom variables. +;; Necessary in order to avoid having those variables saved by custom.el. +(deftheme use-package) +(enable-theme 'use-package) + (if (and (eq emacs-major-version 24) (eq emacs-minor-version 3)) (defsubst hash-table-keys (hash-table) "Return a list of keys in HASH-TABLE." @@ -1394,8 +1399,9 @@ no keyword implies `:all'." (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) - `(put ',variable 'theme-value '((use-package-synthetic-theme ignore-just-for-saving))))) + `(let ((custom--inhibit-theme-enable nil)) + (custom-theme-set-variables 'use-package + '(,variable ,value nil () ,comment))))) args) (use-package-process-keywords name rest state))) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 38c2025cac6..a68491cfb7b 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -1129,28 +1129,25 @@ ;; '((foo bar baz)))) )) + (ert-deftest use-package-test/:custom-1 () (match-expansion (use-package foo :custom (foo bar)) `(progn - (funcall - (or - (get 'foo 'custom-set) - (function set-default)) - 'foo bar) - (set 'foo 'saved-variable-comment "Customized with use-package foo") + (let + ((custom--inhibit-theme-enable nil)) + (custom-theme-set-variables 'use-package + '(foo bar nil nil "Customized with use-package foo"))) (require 'foo nil nil)))) (ert-deftest use-package-test/:custom-with-comment1 () (match-expansion (use-package foo :custom (foo bar "commented")) `(progn - (funcall - (or - (get 'foo 'custom-set) - (function set-default)) - 'foo bar) - (set 'foo 'saved-variable-comment "commented") + (let + ((custom--inhibit-theme-enable nil)) + (custom-theme-set-variables 'use-package + '(foo bar nil nil "commented"))) (require 'foo nil nil)))) (ert-deftest use-package-test/:custom-face-1 ()