1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-28 10:56:36 +00:00

(menu-bar-make-mm-toggle): New macro.

(showhide-menu-bar, showhide-toolbar, menu-bar-toggle-auto-compression)
(toggle-highlight-paren-mode, toggle-global-lazy-font-lock-mode):
Remove.  Use the minor mode function directly instead.
(menu-bar-mode): Add message and customize-mark-as-set and return
the new value as do other minor modes.
This commit is contained in:
Stefan Monnier 2002-09-06 20:27:59 +00:00
parent 22eaea41fa
commit 09bfa5cafb

View File

@ -551,6 +551,18 @@ Do the same for the keys of the same name."
;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences")) ;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
(defmacro menu-bar-make-mm-toggle (fname doc help &optional props)
"Make a menu-item for a global minor mode toggle.
FNAME is the minor mode's name (variable and function).
DOC is the text to use the menu entry.
HELP is the text to use for the tooltip.
PROPS are additional properties."
`'(menu-item ,doc ',fname
,@(if props props)
:help ,help
:button (:toggle . (and (default-boundp ',fname)
(default-value ',fname)))))
(defmacro menu-bar-make-toggle (name variable doc message help &optional props &rest body) (defmacro menu-bar-make-toggle (name variable doc message help &optional props &rest body)
`(progn `(progn
(defun ,name () (defun ,name ()
@ -775,30 +787,13 @@ Do the same for the keys of the same name."
:visible `(display-graphic-p) :visible `(display-graphic-p)
:help "Select scroll-bar mode")) :help "Select scroll-bar mode"))
(defun showhide-menu-bar () (define-key menu-bar-showhide-menu [menu-bar-mode]
"Toggle whether to turn menu-bar on/off." '(menu-item "Menu-bar" menu-bar-mode
(interactive)
(menu-bar-mode)
(if menu-bar-mode
(message "Menu-bar mode enabled.")
(message "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
(customize-mark-as-set 'menu-bar-mode))
(define-key menu-bar-showhide-menu [showhide-menu-bar]
'(menu-item "Menu-bar" showhide-menu-bar
:help "Toggle menu-bar on/off" :help "Toggle menu-bar on/off"
:button (:toggle . menu-bar-mode))) :button (:toggle . menu-bar-mode)))
(defun showhide-toolbar ()
"Toggle whether to turn tool-bar on/off."
(interactive)
(if (tool-bar-mode)
(message "Tool-bar mode enabled.")
(message "Tool-bar mode disabled."))
(customize-mark-as-set 'tool-bar-mode))
(define-key menu-bar-showhide-menu [showhide-tool-bar] (define-key menu-bar-showhide-menu [showhide-tool-bar]
(list 'menu-item "Tool-bar" 'showhide-toolbar (list 'menu-item "Tool-bar" 'tool-bar-mode
:help "Turn tool-bar on/off" :help "Turn tool-bar on/off"
:visible `(display-graphic-p) :visible `(display-graphic-p)
:button `(:toggle . tool-bar-mode))) :button `(:toggle . tool-bar-mode)))
@ -839,19 +834,11 @@ Do the same for the keys of the same name."
'("--")) '("--"))
(define-key menu-bar-options-menu [toggle-auto-compression] (define-key menu-bar-options-menu [toggle-auto-compression]
'(menu-item "Automatic File De/compression" '(menu-item "Automatic File De/compression"
menu-bar-toggle-auto-compression-mode auto-compression-mode
:help "Transparently decompress compressed files" :help "Transparently decompress compressed files"
:button (:toggle . (rassq 'jka-compr-handler :button (:toggle . (rassq 'jka-compr-handler
file-name-handler-alist)))) file-name-handler-alist))))
(defun menu-bar-toggle-auto-compression ()
"Toggle automatic file compression and uncompression.
With prefix argument ARG, turn auto compression on if positive, else off.
Returns the new status of auto compression (non-nil means on)."
(interactive)
(auto-compression-mode)
(customize-mark-as-set 'auto-compression-mode))
(define-key menu-bar-options-menu [save-place] (define-key menu-bar-options-menu [save-place]
(menu-bar-make-toggle toggle-save-place-globally save-place (menu-bar-make-toggle toggle-save-place-globally save-place
"Save Place in Files between Sessions" "Save Place in Files between Sessions"
@ -919,9 +906,8 @@ paste (in addition to the normal Emacs bindings)."
(define-key menu-bar-options-menu [highlight-separator] (define-key menu-bar-options-menu [highlight-separator]
'("--")) '("--"))
(define-key menu-bar-options-menu [highlight-paren-mode] (define-key menu-bar-options-menu [highlight-paren-mode]
(menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode (menu-bar-make-mm-toggle show-paren-mode
"Paren Match Highlighting" "Paren Match Highlighting"
"Show Paren mode %s"
"Highlight matching/mismatched parentheses at cursor (Show Paren mode)")) "Highlight matching/mismatched parentheses at cursor (Show Paren mode)"))
(define-key menu-bar-options-menu [transient-mark-mode] (define-key menu-bar-options-menu [transient-mark-mode]
(menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
@ -930,10 +916,9 @@ paste (in addition to the normal Emacs bindings)."
"Make text in active region stand out in color (Transient Mark mode)" "Make text in active region stand out in color (Transient Mark mode)"
(:enable (not cua-mode)))) (:enable (not cua-mode))))
(define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode] (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
(menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode (menu-bar-make-mm-toggle global-font-lock-mode
"Syntax Highlighting" "Syntax Highlighting"
"Global Font Lock mode %s" "Colorize text based on language syntax (Global Font Lock mode)"))
"Colorize text based on language syntax (Global Font Lock mode)"))
;; The "Tools" menu items ;; The "Tools" menu items
@ -1615,7 +1600,7 @@ This command applies to all frames that exist and frames to be
created in the future. created in the future.
With a numeric argument, if the argument is positive, With a numeric argument, if the argument is positive,
turn on menu bars; otherwise, turn off menu bars." turn on menu bars; otherwise, turn off menu bars."
(interactive "P") (interactive "P")
;; Make menu-bar-mode and default-frame-alist consistent. ;; Make menu-bar-mode and default-frame-alist consistent.
(let ((default (assq 'menu-bar-lines default-frame-alist))) (let ((default (assq 'menu-bar-lines default-frame-alist)))
@ -1626,27 +1611,35 @@ turn on menu bars; otherwise, turn off menu bars."
default-frame-alist)))) default-frame-alist))))
;; Toggle or set the mode, according to FLAG. ;; Toggle or set the mode, according to FLAG.
(setq menu-bar-mode (if (null flag) (not menu-bar-mode) (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
(> (prefix-numeric-value flag) 0))) (> (prefix-numeric-value flag) 0)))
;; Apply it to default-frame-alist. ;; Apply it to default-frame-alist.
(let ((parameter (assq 'menu-bar-lines default-frame-alist))) (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
(if (consp parameter) (if (consp parameter)
(setcdr parameter (if menu-bar-mode 1 0)) (setcdr parameter (if menu-bar-mode 1 0))
(setq default-frame-alist (setq default-frame-alist
(cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
default-frame-alist)))) default-frame-alist))))
;; Apply it to existing frames. ;; Apply it to existing frames.
(let ((frames (frame-list))) (let ((frames (frame-list)))
(while frames (while frames
(let ((height (cdr (assq 'height (frame-parameters (car frames)))))) (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
(modify-frame-parameters (car frames) (modify-frame-parameters (car frames)
(list (cons 'menu-bar-lines (list (cons 'menu-bar-lines
(if menu-bar-mode 1 0)))) (if menu-bar-mode 1 0))))
(modify-frame-parameters (car frames) (modify-frame-parameters (car frames)
(list (cons 'height height)))) (list (cons 'height height))))
(setq frames (cdr frames))))) (setq frames (cdr frames))))
(when (interactive-p)
(if menu-bar-mode
(message "Menu-bar mode enabled.")
(message "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
(customize-mark-as-set 'menu-bar-mode))
menu-bar-mode)
(provide 'menu-bar) (provide 'menu-bar)