aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Kaludercic2024-02-12 18:29:50 +0100
committerPhilip Kaludercic2024-02-13 21:09:23 +0100
commit371ccf09fea26892a2fada028d27fb4b596636df (patch)
treebdace9224a48a0d7377757e38266e83ae9216fab
parent10bf810e845061a83d466cd7367ab7d220653296 (diff)
downloademacs-371ccf09fea26892a2fada028d27fb4b596636df.tar.gz
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)
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/cus-edit.el35
2 files changed, 39 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index f89c8ce1d8d..e6b1d424499 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1336,6 +1336,10 @@ in Buffer menu mode.
1336*** New command 'customize-dirlocals'. 1336*** New command 'customize-dirlocals'.
1337This command pops up a buffer to edit the settings in ".dir-locals.el". 1337This command pops up a buffer to edit the settings in ".dir-locals.el".
1338 1338
1339---
1340** New command 'customize-toggle-option'.
1341This command can toggle boolean options for the duration of a session.
1342
1339** Calc 1343** Calc
1340 1344
1341+++ 1345+++
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."
1228 (message "`%s' is an alias for `%s'" symbol basevar)))) 1228 (message "`%s' is an alias for `%s'" symbol basevar))))
1229 1229
1230;;;###autoload 1230;;;###autoload
1231(defun customize-toggle-option (symbol)
1232 "Toggle the value of boolean option SYMBOL for this session."
1233 (interactive (let ((prompt "Toggle boolean option: ") opts)
1234 (mapatoms
1235 (lambda (sym)
1236 (when (eq (get sym 'custom-type) 'boolean)
1237 (push sym opts))))
1238 (list (intern (completing-read prompt opts nil nil nil nil
1239 (symbol-at-point))))))
1240 (let* ((setter (or (get symbol 'custom-set) #'set-default))
1241 (getter (or (get symbol 'custom-get) #'symbol-value))
1242 (value (condition-case nil
1243 (funcall getter symbol)
1244 (void-variable (error "`%s' is not bound" symbol))))
1245 (type (get symbol 'custom-type)))
1246 (cond
1247 ((eq type 'boolean))
1248 ((and (null type)
1249 (yes-or-no-p
1250 (format "`%s' doesn't have a type, and has the value %S. \
1251Proceed to toggle?" symbol value))))
1252 ((yes-or-no-p
1253 (format "`%s' is of type %s, and has the value %S. \
1254Proceed to toggle?"
1255 symbol type value)))
1256 ((error "Abort toggling of option `%s'" symbol)))
1257 (message "%s user options `%s'."
1258 (if (funcall setter symbol (not value))
1259 "Enabled" "Disabled")
1260 symbol)))
1261
1262;;;###autoload
1263(defalias 'toggle-option #'customize-toggle-option)
1264
1265;;;###autoload
1231(defalias 'customize-variable-other-window 'customize-option-other-window) 1266(defalias 'customize-variable-other-window 'customize-option-other-window)
1232 1267
1233;;;###autoload 1268;;;###autoload