(unless (eq symbol basevar)
(message "`%s' is an alias for `%s'" symbol basevar))))
+(defface custom-boolean-option-on
+ '((t :inherit success))
+ "Face for the \"ON\" indicator of boolean user option.")
+
+(defface custom-boolean-option-off
+ '((t :inherit error))
+ "Face for the \"OFF\" indicator of boolean user option.")
+
+(defun customize-read-boolean-option-affixation (names)
+ (let ((on (propertize "ON " 'face 'custom-boolean-option-on))
+ (off (propertize "OFF " 'face 'custom-boolean-option-off)))
+ (mapcar
+ (lambda (name)
+ (list name (if (symbol-value (intern name)) on off) ""))
+ names)))
+
(defun customize-read-boolean-option (&optional any)
"Read a boolean user option and return its name as a symbol.
(val (completing-read
(format-prompt "Toggle option" default)
(completion-table-with-metadata
- obarray '(metadata (category . boolean-option)))
+ obarray '(metadata (category . boolean-option)
+ (affixation-function
+ . customize-read-boolean-option-affixation)))
pred t nil 'customize-option-history default)))
(when (string-empty-p val) (user-error "You didn't specify an option"))
(intern val)))
;;;###autoload
-(defun customize-toggle-option (symbol)
- "Toggle boolean user option SYMBOL.
+(defun customize-toggle-option (option)
+ "Toggle boolean user OPTION.
-Interactively, prompt for SYMBOL, with completion. Normally, completion
+Interactively, prompt for OPTION, with completion. Normally, completion
candidates include only option with custom type `boolean'. With a
prefix argument, completion candidates include all user options instead."
(interactive (list (customize-read-boolean-option current-prefix-arg)))
- (let* ((set (or (get symbol 'custom-set) #'set-default))
- (get (or (get symbol 'custom-get) #'symbol-value))
- (new (not (funcall get symbol))))
- (funcall set symbol new)
- (message "`%s' is now %s." symbol (if new "ON" "OFF"))))
+ (let* ((sym (if (symbolp option) option (intern option)))
+ (set (or (get sym 'custom-set) #'set-default))
+ (get (or (get sym 'custom-get) #'symbol-value))
+ (new (not (funcall get sym))))
+ (funcall set sym new)
+ (message "`%s' is now %s" sym
+ (if new
+ (propertize "ON" 'face 'success)
+ (propertize "OFF" 'face 'error)))))
;;;###autoload
(defalias 'toggle-option #'customize-toggle-option)