summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2020-11-18 12:53:03 +0000
committerBasil L. Contovounesios <contovob@tcd.ie>2020-11-24 16:50:37 +0000
commitdea3d6aa18e54f0d8d75cd219b511bac5b3c87b1 (patch)
treef88602aab719cf200a3c265c3a893c415aa23c14 /test
parentb2ee6650243ed2777f3a6c400f194f770f00da6f (diff)
downloademacs-dea3d6aa18e54f0d8d75cd219b511bac5b3c87b1.tar.gz
Fix handling of defcustom :local tag
For discussion, see the following emacs-devel thread: https://lists.gnu.org/r/emacs-devel/2020-11/msg00734.html * lisp/custom.el (custom-declare-variable): Delay call to make-variable-buffer-local until after user option has been initialized with a value. Otherwise the user option may be initialized to nil. * test/lisp/custom-tests.el (custom--test-local-option) (custom--test-permanent-option): New :local user options. (custom-test-local-option): New test for defcustom :local keyword.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/custom-tests.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/lisp/custom-tests.el b/test/lisp/custom-tests.el
index 766e4844988..e71b7913f06 100644
--- a/test/lisp/custom-tests.el
+++ b/test/lisp/custom-tests.el
@@ -151,4 +151,42 @@
(widget-apply field :value-to-internal origvalue)
"bar"))))))
+(defcustom custom--test-local-option 'initial
+ "Buffer-local user option for testing."
+ :group 'emacs
+ :type '(choice (const initial) (const changed))
+ :local t)
+
+(defcustom custom--test-permanent-option 'initial
+ "Permanently local user option for testing."
+ :group 'emacs
+ :type '(choice (const initial) (const changed))
+ :local 'permanent)
+
+(ert-deftest custom-test-local-option ()
+ "Test :local user options."
+ ;; Initial default values.
+ (should (eq custom--test-local-option 'initial))
+ (should (eq custom--test-permanent-option 'initial))
+ (should (eq (default-value 'custom--test-local-option) 'initial))
+ (should (eq (default-value 'custom--test-permanent-option) 'initial))
+ (let ((obuf (current-buffer)))
+ (with-temp-buffer
+ ;; Changed buffer-local values.
+ (setq custom--test-local-option 'changed)
+ (setq custom--test-permanent-option 'changed)
+ (should (eq custom--test-local-option 'changed))
+ (should (eq custom--test-permanent-option 'changed))
+ (should (eq (default-value 'custom--test-local-option) 'initial))
+ (should (eq (default-value 'custom--test-permanent-option) 'initial))
+ (with-current-buffer obuf
+ (should (eq custom--test-local-option 'initial))
+ (should (eq custom--test-permanent-option 'initial)))
+ ;; Permanent variable remains unchanged.
+ (kill-all-local-variables)
+ (should (eq custom--test-local-option 'initial))
+ (should (eq custom--test-permanent-option 'changed))
+ (should (eq (default-value 'custom--test-local-option) 'initial))
+ (should (eq (default-value 'custom--test-permanent-option) 'initial)))))
+
;;; custom-tests.el ends here