(if (keywordp doc)
(error "Doc string is missing"))
(let ((initialize #'custom-initialize-reset)
- (requests nil))
+ (requests nil)
+ ;; Whether automatically buffer-local.
+ buffer-local)
(unless (memq :group args)
(custom-add-to-group (custom-current-group) symbol 'custom-variable))
(while args
(put symbol 'safe-local-variable value))
((eq keyword :local)
(when (memq value '(t permanent))
- (make-variable-buffer-local symbol))
+ (setq buffer-local t))
(when (eq value 'permanent)
(put symbol 'permanent-local t)))
((eq keyword :type)
(put symbol 'custom-requests requests)
;; Do the actual initialization.
(unless custom-dont-initialize
- (funcall initialize symbol default)))
+ (funcall initialize symbol default))
+ (when buffer-local
+ (make-variable-buffer-local symbol)))
(run-hooks 'custom-define-hook)
symbol)
(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