all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Drew Adams <drew.adams@oracle.com>
Cc: 17954@debbugs.gnu.org, 6542@debbugs.gnu.org
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	[thread overview]
Message-ID: <8760v2so5s.fsf@gnus.org> (raw)
In-Reply-To: <9e5b6c5f-0dd9-44ef-b997-3cc032e7a107@default> (Drew Adams's message of "Sat, 5 Jul 2014 22:28:37 -0700 (PDT)")

Drew Adams <drew.adams@oracle.com> 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





  reply	other threads:[~2016-04-27 22:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-06  5:28 bug#17954: 24.4.50; [patch] `menu-bar-make-toggle' should allow for keywords Drew Adams
2016-04-27 22:05 ` Lars Ingebrigtsen [this message]
2020-09-19 16:24 ` bug#6542: " Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8760v2so5s.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=17954@debbugs.gnu.org \
    --cc=6542@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.