summaryrefslogtreecommitdiff
path: root/lisp/cus-edit.el
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2024-02-12 18:29:50 +0100
committerPhilip Kaludercic <philipk@posteo.net>2024-02-13 21:09:23 +0100
commit371ccf09fea26892a2fada028d27fb4b596636df (patch)
treebdace9224a48a0d7377757e38266e83ae9216fab /lisp/cus-edit.el
parent10bf810e845061a83d466cd7367ab7d220653296 (diff)
downloademacs-371ccf09fea26892a2fada028d27fb4b596636df.tar.gz
emacs-371ccf09fea26892a2fada028d27fb4b596636df.tar.bz2
emacs-371ccf09fea26892a2fada028d27fb4b596636df.zip
Add 'custom-variable' command
* lisp/cus-edit.el (customize-toggle-option): Add command. (toggle-option): Add shorter alias for 'customize-toggle-option'. * etc/NEWS: Document it. (Bug#69079)
Diffstat (limited to 'lisp/cus-edit.el')
-rw-r--r--lisp/cus-edit.el35
1 files changed, 35 insertions, 0 deletions
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 38b6ec984ab..8fad51dc116 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1228,6 +1228,41 @@ If OTHER-WINDOW is non-nil, display in another window."
(message "`%s' is an alias for `%s'" symbol basevar))))
;;;###autoload
+(defun customize-toggle-option (symbol)
+ "Toggle the value of boolean option SYMBOL for this session."
+ (interactive (let ((prompt "Toggle boolean option: ") opts)
+ (mapatoms
+ (lambda (sym)
+ (when (eq (get sym 'custom-type) 'boolean)
+ (push sym opts))))
+ (list (intern (completing-read prompt opts nil nil nil nil
+ (symbol-at-point))))))
+ (let* ((setter (or (get symbol 'custom-set) #'set-default))
+ (getter (or (get symbol 'custom-get) #'symbol-value))
+ (value (condition-case nil
+ (funcall getter symbol)
+ (void-variable (error "`%s' is not bound" symbol))))
+ (type (get symbol 'custom-type)))
+ (cond
+ ((eq type 'boolean))
+ ((and (null type)
+ (yes-or-no-p
+ (format "`%s' doesn't have a type, and has the value %S. \
+Proceed to toggle?" symbol value))))
+ ((yes-or-no-p
+ (format "`%s' is of type %s, and has the value %S. \
+Proceed to toggle?"
+ symbol type value)))
+ ((error "Abort toggling of option `%s'" symbol)))
+ (message "%s user options `%s'."
+ (if (funcall setter symbol (not value))
+ "Enabled" "Disabled")
+ symbol)))
+
+;;;###autoload
+(defalias 'toggle-option #'customize-toggle-option)
+
+;;;###autoload
(defalias 'customize-variable-other-window 'customize-option-other-window)
;;;###autoload