From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#69079: [PATCH] Add 'customize-toggle-option' command Date: Mon, 12 Feb 2024 21:32:51 +0200 Message-ID: <86frxxqxzw.fsf@gnu.org> References: <87frxx37wq.fsf@posteo.net> <86plx1r2uq.fsf@gnu.org> <87le7p1pg8.fsf@posteo.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31453"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69079@debbugs.gnu.org To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 12 21:11:15 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 1rZce3-0007wz-7s for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Feb 2024 21:11:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZcde-0005v8-Fe; Mon, 12 Feb 2024 15:10: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 1rZcda-0005uO-0M for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 15:10:46 -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 1rZcdZ-0005bm-OX for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 15:10:45 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rZcdq-0002Dq-Lv for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 15:11:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Feb 2024 20:11:02 +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.17077686238323 (code B ref 69079); Mon, 12 Feb 2024 20:11:02 +0000 Original-Received: (at 69079) by debbugs.gnu.org; 12 Feb 2024 20:10:23 +0000 Original-Received: from localhost ([127.0.0.1]:55088 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZcdC-0002A4-BL for submit@debbugs.gnu.org; Mon, 12 Feb 2024 15:10:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48026) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZcPj-0006kG-SR for 69079@debbugs.gnu.org; Mon, 12 Feb 2024 14:56:30 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZc2v-0006wH-EV; Mon, 12 Feb 2024 14:32:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=D7hC26ot3BOMaHWABZqPSzxz97HwjH00LRqIWZg1OLg=; b=ab7l59ub5DBL ygJRljJLTRADupG0FZWn6o3A4WAE+Un7nNWcvgRJWNq2rbEVrPU9D/2p7j72yyLLqsbVigFolrJX+ +giItyAPtSTPKx4bPbuxyf5eCYQOt+QtdEEsHCJ1OCi0Pg/qt4N2Y1/RzrCELH0c5Hmu7/ACUkbRa Okb95eWN7DETTjhwtP602T/dZTVoB0E5GAR3f/4siSI795pXj9Yiq0muJaVI4dGd39wKx7/PCl3a2 Gy7lt78JBZUCwtvFLgUvOevtv0+SN/wqSVX0XnifPQ010h3ALUcjD7Vzyi0Gu7DHASYe73ntjd3FW seTfih1XNaCeRIQ4JKYDzQ==; In-Reply-To: <87le7p1pg8.fsf@posteo.net> (message from Philip Kaludercic on Mon, 12 Feb 2024 18:56:39 +0000) 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:279925 Archived-At: > 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?