From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#6542: bug#17954: 24.4.50; [patch] `menu-bar-make-toggle' should allow for keywords Date: Thu, 28 Apr 2016 00:05:35 +0200 Message-ID: <8760v2so5s.fsf@gnus.org> References: <9e5b6c5f-0dd9-44ef-b997-3cc032e7a107@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1461794785 29208 80.91.229.3 (27 Apr 2016 22:06:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Apr 2016 22:06:25 +0000 (UTC) Cc: 17954@debbugs.gnu.org, 6542@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Apr 28 00:06:12 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1avXb2-0005v1-Eu for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Apr 2016 00:06:12 +0200 Original-Received: from localhost ([::1]:45619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avXb1-0002Lk-LF for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Apr 2016 18:06:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avXax-0002JD-4q for bug-gnu-emacs@gnu.org; Wed, 27 Apr 2016 18:06:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avXas-0003IK-AM for bug-gnu-emacs@gnu.org; Wed, 27 Apr 2016 18:06:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avXas-0003IG-7E for bug-gnu-emacs@gnu.org; Wed, 27 Apr 2016 18:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1avXas-0007mw-21 for bug-gnu-emacs@gnu.org; Wed, 27 Apr 2016 18:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 27 Apr 2016 22:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6542 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6542-submit@debbugs.gnu.org id=B6542.146179474029894 (code B ref 6542); Wed, 27 Apr 2016 22:06:02 +0000 Original-Received: (at 6542) by debbugs.gnu.org; 27 Apr 2016 22:05:40 +0000 Original-Received: from localhost ([127.0.0.1]:50882 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1avXaW-0007m4-6p for submit@debbugs.gnu.org; Wed, 27 Apr 2016 18:05:40 -0400 Original-Received: from hermes.netfonds.no ([80.91.224.195]:51276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1avXaU-0007lt-Cf; Wed, 27 Apr 2016 18:05:38 -0400 Original-Received: from cm-84.215.1.64.getinternet.no ([84.215.1.64] helo=mouse) by hermes.netfonds.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1avXaR-0004Oo-9S; Thu, 28 Apr 2016 00:05:37 +0200 In-Reply-To: <9e5b6c5f-0dd9-44ef-b997-3cc032e7a107@default> (Drew Adams's message of "Sat, 5 Jul 2014 22:28:37 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:116997 Archived-At: Drew Adams writes: > It cannot accept keywords in the normal way because it defines BODY as > an &rest parameter. This mistake should be corrected, making for an > incompatible change unfortunately, in order to allow a KEYWORDS &rest > parameter. > > BODY is seldom used. In the Emacs Lisp sources, there are only these > two occurrences of `menu-bar-make-toggle' that use BODY: > `toggle-save-place-globally' and `toggle-uniquify-buffer-names'. They > would just need to wrap the current BODY code in an explicit `progn'. I don't think such an incompatible change would be appropriate. > Of course, there may be 3rd-party code that uses parameter BODY. The > only way I can think of to be sensitive to that breakage is to use a new > macro name and code, and deprecate the old name `menu-bar-make-toggle'. > Perhaps this incompatible change could be tolerated, since BODY is rare > and the adaptation for any existing code is trivial (wrap with `progn'). And having two macros that do the same wouldn't be very appropriate, either... I think it would make more sense to extend the HELP parameter to be a list, and then it could be the keyword list. Your code as a patch included below. diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index cc7233e..ca40e94 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -629,31 +629,44 @@ menu-bar-make-mm-toggle :button (:toggle . (and (default-boundp ',fname) (default-value ',fname))))) -(defmacro menu-bar-make-toggle (name variable doc message help &rest body) +(defmacro menu-bar-make-toggle (command variable item-name message help + &optional setting-sexp &rest keywords) + "Define a menu-bar toggle command. +COMMAND (a symbol) is the toggle command to define. +VARIABLE (a symbol) is the variable to set. +ITEM-NAME (a string) is the menu-item name. +MESSAGE is a format string for the toggle message, with %s for the new + status. +HELP (a string) is the `:help' tooltip text and the doc string first + line (minus final period) for the command. +SETTING-SEXP is a Lisp sexp that sets VARIABLE, or it is nil meaning + set it according to its `defcustom' or using `set-default'. +KEYWORDS is a plist for `menu-item' for keywords other than `:help'." `(progn - (defun ,name (&optional interactively) + (defun ,command (&optional interactively) ,(concat "Toggle whether to " (downcase (substring help 0 1)) - (substring help 1) ". + (substring help 1) ". In an interactive call, record this option as a candidate for saving by \"Save Options\" in Custom buffers.") (interactive "p") - (if ,(if body `(progn . ,body) - `(progn + (if ,(if setting-sexp + `,setting-sexp + `(progn (custom-load-symbol ',variable) (let ((set (or (get ',variable 'custom-set) 'set-default)) (get (or (get ',variable 'custom-get) 'default-value))) (funcall set ',variable (not (funcall get ',variable)))))) - (message ,message "enabled globally") - (message ,message "disabled globally")) - ;; The function `customize-mark-as-set' must only be called when - ;; a variable is set interactively, as the purpose is to mark it as - ;; a candidate for "Save Options", and we do not want to save options - ;; the user have already set explicitly in his init file. - (if interactively (customize-mark-as-set ',variable))) - '(menu-item ,doc ,name - :help ,help - :button (:toggle . (and (default-boundp ',variable) - (default-value ',variable)))))) + (message ,message "enabled globally") + (message ,message "disabled globally")) + ;; `customize-mark-as-set' must only be called when a variable is set + ;; interactively, because the purpose is to mark the variable as a + ;; candidate for `Save Options', and we do not want to save options that + ;; the user has already set explicitly in the init file. + (when interactively (customize-mark-as-set ',variable))) + '(menu-item ,item-name ,command :help ,help + :button (:toggle . (and (default-boundp ',variable) + (default-value ',variable))) + ,@keywords))) ;; Function for setting/saving default font. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no