From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#69079: [PATCH] Add 'customize-toggle-option' command Date: Tue, 13 Feb 2024 00:14:38 +0000 Message-ID: <87r0hh1aq9.fsf@posteo.net> References: <87frxx37wq.fsf@posteo.net> <86plx1r2uq.fsf@gnu.org> <87le7p1pg8.fsf@posteo.net> <86frxxqxzw.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35361"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69079@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Feb 13 01:16:07 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rZgT1-0008xf-5S for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 13 Feb 2024 01:16:07 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZgSk-0007OM-9i; Mon, 12 Feb 2024 19:15:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZgSg-0007OA-5F for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 19:15:48 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZgSf-0004Ua-2x for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 19:15:45 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rZgSv-0005sC-Lw for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 19:16:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Feb 2024 00:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69079 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 69079-submit@debbugs.gnu.org id=B69079.170778330422303 (code B ref 69079); Tue, 13 Feb 2024 00:16:01 +0000 Original-Received: (at 69079) by debbugs.gnu.org; 13 Feb 2024 00:15:04 +0000 Original-Received: from localhost ([127.0.0.1]:36411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZgS0-0005nf-9C for submit@debbugs.gnu.org; Mon, 12 Feb 2024 19:15:04 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:51611) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZgRy-0005mT-HH for 69079@debbugs.gnu.org; Mon, 12 Feb 2024 19:15:03 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 57165240101 for <69079@debbugs.gnu.org>; Tue, 13 Feb 2024 01:14:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1707783279; bh=5nNVphN6FR/FM5uiMJhSsiFpB81RWQsUHvjMTRJ54aA=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=bdx2sQNJw7zMcGl+LsLPjCVOYK2JdmFivq+UnWbuiu8IJzyWfDqdSr5hZu4eUnj2m tn4Be+P/8rtWYOqj0smRV0/yhwAhTUy9HFbrOsHNXHsIVBx5Aw38N+M5TIonqtpkKm WTapABC609WYMDFnNdd9Zg1rLKstfAgc4CaxqO5oVuj1OXW4MPAvOd0KJLrgXi5bmP K+McdyT9KsczVtQOuQ2xe66AZYgzeMnr3T/nMAFv/X7B5X9bucWkz3rL9i9p3U0P4s 1bq9vhULK+NWASsvuNWtFdU5Qy0vXaNzvID4Bg1X/Ls4/WLZ/h8MOsy/2HEm/ak5fm 7BgNLsFPCNsTQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TYhf65kFdz6tm4; Tue, 13 Feb 2024 01:14:38 +0100 (CET) In-Reply-To: <86frxxqxzw.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 12 Feb 2024 21:32:51 +0200") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279935 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Philip Kaludercic >> Cc: 69079@debbugs.gnu.org >> Date: Mon, 12 Feb 2024 18:56:39 +0000 >> >> Eli Zaretskii writes: >> >> >> From: Philip Kaludercic >> >> 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? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-custom-variable-command.patch >From abb72681c82e30a52bcfa90174e0677757174971 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-=--