* bug#69079: [PATCH] Add 'customize-toggle-option' command
@ 2024-02-12 17:32 Philip Kaludercic
2024-02-12 17:47 ` Eli Zaretskii
0 siblings, 1 reply; 9+ messages in thread
From: Philip Kaludercic @ 2024-02-12 17:32 UTC (permalink / raw)
To: 69079
[-- Attachment #1: Type: text/plain, Size: 113 bytes --]
I have had this option in my own init.el for a while, and think it would
be nice to upstream it. Any comments:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Add 'custom-variable' command. --]
[-- Type: text/x-patch, Size: 1852 bytes --]
From 65cbe5deb81bd5b3bc7ebcc52a98952497dbe1a6 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Mon, 12 Feb 2024 18:29:50 +0100
Subject: [PATCH] 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.
---
etc/NEWS | 4 ++++
lisp/cus-edit.el | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index afc2c22e68b..6fae64728f2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1329,6 +1329,10 @@ in Buffer menu mode.
*** New command 'customize-dirlocals'.
This command pops up a buffer to edit the settings in ".dir-locals.el".
+---
+** New command 'customize-toggle-option'.
+This command can toggle boolean options for the duration of a session.
+
** Calc
+++
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 38b6ec984ab..2f08ffc8ba6 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1227,6 +1227,26 @@ customize-option
(unless (eq symbol basevar)
(message "`%s' is an alias for `%s'" symbol basevar))))
+;;;###autoload
+(defun customize-toggle-option (opt)
+ "Toggle the value of boolean option OPT for this session."
+ (interactive (let (opts)
+ (mapatoms
+ (lambda (sym)
+ (when (eq (get sym 'custom-type) 'boolean)
+ (push sym opts))))
+ (list (intern (completing-read "Option: " opts)))))
+ (message "%s user options '%s'."
+ (if (funcall (or (get opt 'custom-set) #'set-default)
+ opt (not (funcall (or (get opt 'custom-get)
+ #'symbol-value)
+ opt)))
+ "Enabled" "Disabled")
+ opt))
+
+;;;###autoload
+(defalias 'toggle-option #'customize-toggle-option)
+
;;;###autoload
(defalias 'customize-variable-other-window 'customize-option-other-window)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-12 17:32 bug#69079: [PATCH] Add 'customize-toggle-option' command Philip Kaludercic
@ 2024-02-12 17:47 ` Eli Zaretskii
2024-02-12 18:41 ` Drew Adams
2024-02-12 18:56 ` Philip Kaludercic
0 siblings, 2 replies; 9+ messages in thread
From: Eli Zaretskii @ 2024-02-12 17:47 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69079
> From: Philip Kaludercic <philipk@posteo.net>
> Date: Mon, 12 Feb 2024 17:32:37 +0000
>
> +;;;###autoload
> +(defun customize-toggle-option (opt)
> + "Toggle the value of boolean option OPT for this session."
> + (interactive (let (opts)
> + (mapatoms
> + (lambda (sym)
> + (when (eq (get sym 'custom-type) 'boolean)
> + (push sym opts))))
> + (list (intern (completing-read "Option: " opts)))))
> + (message "%s user options '%s'."
> + (if (funcall (or (get opt 'custom-set) #'set-default)
> + opt (not (funcall (or (get opt 'custom-get)
> + #'symbol-value)
> + opt)))
> + "Enabled" "Disabled")
> + opt))
Shouldn't this have some validation? what if the argument OPT is not a
boolean?
And the prompt should IMO say "Toggle boolean option: ".
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-12 17:47 ` Eli Zaretskii
@ 2024-02-12 18:41 ` Drew Adams
2024-02-12 18:56 ` Philip Kaludercic
1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2024-02-12 18:41 UTC (permalink / raw)
To: Eli Zaretskii, Philip Kaludercic; +Cc: 69079@debbugs.gnu.org
FWIW, (since 2006) Icicles has this, which is bound
to `M-i M-i` during completion.
With a prefix arg you can toggle options and other
variables whose values are generalized Booleans:
`nil' or non-`nil' (not just `t').
This is for toggling an option's current value; it
does only this: (set SYMBOL (not (eval SYMBOL))).
But the completion predicate determines the proper
candidates (depending on prefix arg).
There are (rightfully) many options whose values
are `nil' for false and non-`nil' for true. If the
command didn't let you toggle such options (with a
prefix arg) then it would be _far_ less useful.
___
Doc string:
Toggle option's value. This makes sense for binary (toggle) options.
By default, completion candidates are limited to user options that
have `boolean' custom types. However, there are many "binary" options
that allow other non-nil values than t.
You can use a prefix argument to change the set of completion
candidates, as follows:
- With a non-negative prefix arg, all user options are candidates.
- With a negative prefix arg, all variables are candidates.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-12 17:47 ` Eli Zaretskii
2024-02-12 18:41 ` Drew Adams
@ 2024-02-12 18:56 ` Philip Kaludercic
2024-02-12 19:32 ` Eli Zaretskii
1 sibling, 1 reply; 9+ messages in thread
From: Philip Kaludercic @ 2024-02-12 18:56 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 69079
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Date: Mon, 12 Feb 2024 17:32:37 +0000
>>
>> +;;;###autoload
>> +(defun customize-toggle-option (opt)
>> + "Toggle the value of boolean option OPT for this session."
>> + (interactive (let (opts)
>> + (mapatoms
>> + (lambda (sym)
>> + (when (eq (get sym 'custom-type) 'boolean)
>> + (push sym opts))))
>> + (list (intern (completing-read "Option: " opts)))))
>> + (message "%s user options '%s'."
>> + (if (funcall (or (get opt 'custom-set) #'set-default)
>> + opt (not (funcall (or (get opt 'custom-get)
>> + #'symbol-value)
>> + opt)))
>> + "Enabled" "Disabled")
>> + opt))
>
> Shouldn't this have some validation? what if the argument OPT is not a
> boolean?
My assumption was that the command would only be invoked interactivly,
so I can either make that explicit with an `interactive-only' or repeat
the check. What do you think would be better?
> And the prompt should IMO say "Toggle boolean option: ".
Good point.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-12 18:56 ` Philip Kaludercic
@ 2024-02-12 19:32 ` Eli Zaretskii
2024-02-13 0:14 ` Philip Kaludercic
0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2024-02-12 19:32 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69079
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 69079@debbugs.gnu.org
> Date: Mon, 12 Feb 2024 18:56:39 +0000
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> From: Philip Kaludercic <philipk@posteo.net>
> >> Date: Mon, 12 Feb 2024 17:32:37 +0000
> >>
> >> +;;;###autoload
> >> +(defun customize-toggle-option (opt)
> >> + "Toggle the value of boolean option OPT for this session."
> >> + (interactive (let (opts)
> >> + (mapatoms
> >> + (lambda (sym)
> >> + (when (eq (get sym 'custom-type) 'boolean)
> >> + (push sym opts))))
> >> + (list (intern (completing-read "Option: " opts)))))
> >> + (message "%s user options '%s'."
> >> + (if (funcall (or (get opt 'custom-set) #'set-default)
> >> + opt (not (funcall (or (get opt 'custom-get)
> >> + #'symbol-value)
> >> + opt)))
> >> + "Enabled" "Disabled")
> >> + opt))
> >
> > Shouldn't this have some validation? what if the argument OPT is not a
> > boolean?
>
> My assumption was that the command would only be invoked interactivly,
> so I can either make that explicit with an `interactive-only' or repeat
> the check. What do you think would be better?
I think an explicit test is better, since then we get to display a
user-friendly error message, instead of relying on Lisp errors to
explain themselves.
Btw, are you sure that the users can never succeed in inputting a
non-boolean option with the way you prompt them?
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-12 19:32 ` Eli Zaretskii
@ 2024-02-13 0:14 ` Philip Kaludercic
2024-02-13 12:40 ` Eli Zaretskii
0 siblings, 1 reply; 9+ messages in thread
From: Philip Kaludercic @ 2024-02-13 0:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 69079
[-- Attachment #1: Type: text/plain, Size: 1724 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 69079@debbugs.gnu.org
>> Date: Mon, 12 Feb 2024 18:56:39 +0000
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> From: Philip Kaludercic <philipk@posteo.net>
>> >> Date: Mon, 12 Feb 2024 17:32:37 +0000
>> >>
>> >> +;;;###autoload
>> >> +(defun customize-toggle-option (opt)
>> >> + "Toggle the value of boolean option OPT for this session."
>> >> + (interactive (let (opts)
>> >> + (mapatoms
>> >> + (lambda (sym)
>> >> + (when (eq (get sym 'custom-type) 'boolean)
>> >> + (push sym opts))))
>> >> + (list (intern (completing-read "Option: " opts)))))
>> >> + (message "%s user options '%s'."
>> >> + (if (funcall (or (get opt 'custom-set) #'set-default)
>> >> + opt (not (funcall (or (get opt 'custom-get)
>> >> + #'symbol-value)
>> >> + opt)))
>> >> + "Enabled" "Disabled")
>> >> + opt))
>> >
>> > Shouldn't this have some validation? what if the argument OPT is
>> > not a
>> > boolean?
>>
>> My assumption was that the command would only be invoked interactivly,
>> so I can either make that explicit with an `interactive-only' or repeat
>> the check. What do you think would be better?
>
> I think an explicit test is better, since then we get to display a
> user-friendly error message, instead of relying on Lisp errors to
> explain themselves.
>
> Btw, are you sure that the users can never succeed in inputting a
> non-boolean option with the way you prompt them?
No, that was not ensured, and I think it is better not to. I have
adjusted the patch to check and prompt the user if the user option is
non-boolean, in case they know what they are doing. WDYT?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-custom-variable-command.patch --]
[-- Type: text/x-patch, Size: 2620 bytes --]
From abb72681c82e30a52bcfa90174e0677757174971 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Mon, 12 Feb 2024 18:29:50 +0100
Subject: [PATCH] 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.
---
etc/NEWS | 4 ++++
lisp/cus-edit.el | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index afc2c22e68b..6fae64728f2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1329,6 +1329,10 @@ in Buffer menu mode.
*** New command 'customize-dirlocals'.
This command pops up a buffer to edit the settings in ".dir-locals.el".
+---
+** New command 'customize-toggle-option'.
+This command can toggle boolean options for the duration of a session.
+
** Calc
+++
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 38b6ec984ab..270d9b44908 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1227,6 +1227,40 @@ customize-option
(unless (eq symbol basevar)
(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)))))
+ (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)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-13 0:14 ` Philip Kaludercic
@ 2024-02-13 12:40 ` Eli Zaretskii
2024-02-13 12:46 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2024-02-13 12:40 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: 69079
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: 69079@debbugs.gnu.org
> Date: Tue, 13 Feb 2024 00:14:38 +0000
>
> >> My assumption was that the command would only be invoked interactivly,
> >> so I can either make that explicit with an `interactive-only' or repeat
> >> the check. What do you think would be better?
> >
> > I think an explicit test is better, since then we get to display a
> > user-friendly error message, instead of relying on Lisp errors to
> > explain themselves.
> >
> > Btw, are you sure that the users can never succeed in inputting a
> > non-boolean option with the way you prompt them?
>
> No, that was not ensured, and I think it is better not to. I have
> adjusted the patch to check and prompt the user if the user option is
> non-boolean, in case they know what they are doing. WDYT?
LGTM, although I haven't tried to actually use the code.
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-13 12:40 ` Eli Zaretskii
@ 2024-02-13 12:46 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-13 20:09 ` Philip Kaludercic
0 siblings, 1 reply; 9+ messages in thread
From: Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-13 12:46 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Philip Kaludercic, 69079
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 69079@debbugs.gnu.org
>> Date: Tue, 13 Feb 2024 00:14:38 +0000
>>
>> >> My assumption was that the command would only be invoked interactivly,
>> >> so I can either make that explicit with an `interactive-only' or repeat
>> >> the check. What do you think would be better?
>> >
>> > I think an explicit test is better, since then we get to display a
>> > user-friendly error message, instead of relying on Lisp errors to
>> > explain themselves.
>> >
>> > Btw, are you sure that the users can never succeed in inputting a
>> > non-boolean option with the way you prompt them?
>>
>> No, that was not ensured, and I think it is better not to. I have
>> adjusted the patch to check and prompt the user if the user option is
>> non-boolean, in case they know what they are doing. WDYT?
>
> LGTM, although I haven't tried to actually use the code.
>
> Thanks.
FWIW, I think it'd be nice to use the as the default minibuffer argument
symbol at point, if applicable.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#69079: [PATCH] Add 'customize-toggle-option' command
2024-02-13 12:46 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-02-13 20:09 ` Philip Kaludercic
0 siblings, 0 replies; 9+ messages in thread
From: Philip Kaludercic @ 2024-02-13 20:09 UTC (permalink / raw)
To: Eshel Yaron; +Cc: Eli Zaretskii, 69079-done
Eshel Yaron <me@eshelyaron.com> writes:
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Philip Kaludercic <philipk@posteo.net>
>>> Cc: 69079@debbugs.gnu.org
>>> Date: Tue, 13 Feb 2024 00:14:38 +0000
>>>
>>> >> My assumption was that the command would only be invoked interactivly,
>>> >> so I can either make that explicit with an `interactive-only' or repeat
>>> >> the check. What do you think would be better?
>>> >
>>> > I think an explicit test is better, since then we get to display a
>>> > user-friendly error message, instead of relying on Lisp errors to
>>> > explain themselves.
>>> >
>>> > Btw, are you sure that the users can never succeed in inputting a
>>> > non-boolean option with the way you prompt them?
>>>
>>> No, that was not ensured, and I think it is better not to. I have
>>> adjusted the patch to check and prompt the user if the user option is
>>> non-boolean, in case they know what they are doing. WDYT?
>>
>> LGTM, although I haven't tried to actually use the code.
>>
>> Thanks.
>
> FWIW, I think it'd be nice to use the as the default minibuffer argument
> symbol at point, if applicable.
Done and pushed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-13 20:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-12 17:32 bug#69079: [PATCH] Add 'customize-toggle-option' command Philip Kaludercic
2024-02-12 17:47 ` Eli Zaretskii
2024-02-12 18:41 ` Drew Adams
2024-02-12 18:56 ` Philip Kaludercic
2024-02-12 19:32 ` Eli Zaretskii
2024-02-13 0:14 ` Philip Kaludercic
2024-02-13 12:40 ` Eli Zaretskii
2024-02-13 12:46 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-13 20:09 ` Philip Kaludercic
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.