Function: menu-bar-make-toggle-command

menu-bar-make-toggle-command is a macro defined in menu-bar.el.gz.

Signature

(menu-bar-make-toggle-command COMMAND VARIABLE ITEM-NAME MESSAGE HELP &optional SETTING-SEXP &rest KEYWORDS)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/menu-bar.el.gz
(defmacro menu-bar-make-toggle-command (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 ,command (&optional interactively)
       ,(concat "Toggle whether to " (downcase (substring help 0 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 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"))
       ;; `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))
       ;; Toggle menu items must make sure that the menu is updated so
       ;; that toggle marks are drawn in the right state.
       (force-mode-line-update t))
     '(menu-item ,item-name ,command :help ,help
                 :button (:toggle . (and (default-boundp ',variable)
                                         (default-value ',variable)))
                 ,@keywords)))