Subject: bug#69079: closed (Re: bug#69079: [PATCH] Add 'customize-toggle-option' command)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 13 Feb 2024 20:11:01 +0000

Your bug report

#69079: [PATCH] Add 'customize-toggle-option' command

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
69079: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69079
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#69079: [PATCH] Add 'customize-toggle-option' command
From: Philip Kaludercic <[email-masked]>
To: Eshel Yaron <[email-masked]>
Cc: Eli Zaretskii <[email-masked]>, [email-masked]
Date: Tue, 13 Feb 2024 20:09:46 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Eshel Yaron <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Philip Kaludercic <[email-masked]>
>>> Cc: [email-masked]
>>> 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.

Subject: [PATCH] Add 'customize-toggle-option' command
From: Philip Kaludercic <[email-masked]>
To: [email-masked]
Date: Mon, 12 Feb 2024 17:32:37 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

I have had this option in my own init.el for a while, and think it would
be nice to upstream it.  Any comments:

>From 65cbe5deb81bd5b3bc7ebcc52a98952497dbe1a6 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
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