;;; menu-bar.el --- define a default menu bar
-;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1993,94,1995,2000,01,02,2003 Free Software Foundation, Inc.
;; Author: RMS
;; Maintainer: FSF
(cons "Options" menu-bar-options-menu))
(defvar menu-bar-edit-menu (make-sparse-keymap "Edit"))
(define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
-(defvar menu-bar-files-menu (make-sparse-keymap "File"))
-(define-key global-map [menu-bar files] (cons "File" menu-bar-files-menu))
+(defvar menu-bar-file-menu (make-sparse-keymap "File"))
+(define-key global-map [menu-bar file] (cons "File" menu-bar-file-menu))
;; This alias is for compatibility with 19.28 and before.
-(defvar menu-bar-file-menu menu-bar-files-menu)
+(defvar menu-bar-files-menu menu-bar-file-menu)
;; This is referenced by some code below; it is defined in uniquify.el
(defvar uniquify-buffer-name-style)
\f
;; The "File" menu items
-(define-key menu-bar-files-menu [exit-emacs]
+(define-key menu-bar-file-menu [exit-emacs]
'(menu-item "Exit Emacs" save-buffers-kill-emacs
:help "Save unsaved buffers, then exit"))
-(define-key menu-bar-files-menu [separator-exit]
+(define-key menu-bar-file-menu [separator-exit]
'("--"))
;; Don't use delete-frame as event name because that is a special
;; event.
-(define-key menu-bar-files-menu [delete-this-frame]
+(define-key menu-bar-file-menu [delete-this-frame]
'(menu-item "Delete Frame" delete-frame
:visible (fboundp 'delete-frame)
:enable (delete-frame-enabled-p)
:help "Delete currently selected frame"))
-(define-key menu-bar-files-menu [make-frame-on-display]
+(define-key menu-bar-file-menu [make-frame-on-display]
'(menu-item "New Frame on Display..." make-frame-on-display
:visible (fboundp 'make-frame-on-display)
:help "Open a new frame on another display"))
-(define-key menu-bar-files-menu [make-frame]
+(define-key menu-bar-file-menu [make-frame]
'(menu-item "New Frame" make-frame-command
:visible (fboundp 'make-frame-command)
:help "Open a new frame"))
-(define-key menu-bar-files-menu [one-window]
+(define-key menu-bar-file-menu [one-window]
'(menu-item "Unsplit Windows" delete-other-windows
:enable (not (one-window-p t nil))
:help "Make selected window fill its frame"))
-(define-key menu-bar-files-menu [split-window]
+(define-key menu-bar-file-menu [split-window]
'(menu-item "Split Window" split-window-vertically
:help "Split selected window in two"))
-(define-key menu-bar-files-menu [separator-window]
+(define-key menu-bar-file-menu [separator-window]
'(menu-item "--"))
-(define-key menu-bar-files-menu [ps-print-region]
+(define-key menu-bar-file-menu [ps-print-region]
'(menu-item "Postscript Print Region (B+W)" ps-print-region
:enable mark-active
:help "Pretty-print marked region in black and white to PostScript printer"))
-(define-key menu-bar-files-menu [ps-print-buffer]
+(define-key menu-bar-file-menu [ps-print-buffer]
'(menu-item "Postscript Print Buffer (B+W)" ps-print-buffer
:help "Pretty-print current buffer in black and white to PostScript printer"))
-(define-key menu-bar-files-menu [ps-print-region-faces]
+(define-key menu-bar-file-menu [ps-print-region-faces]
'(menu-item "Postscript Print Region" ps-print-region-with-faces
:enable mark-active
:help "Pretty-print marked region to PostScript printer"))
-(define-key menu-bar-files-menu [ps-print-buffer-faces]
+(define-key menu-bar-file-menu [ps-print-buffer-faces]
'(menu-item "Postscript Print Buffer" ps-print-buffer-with-faces
:help "Pretty-print current buffer to PostScript printer"))
-(define-key menu-bar-files-menu [print-region]
+(define-key menu-bar-file-menu [print-region]
'(menu-item "Print Region" print-region
:enable mark-active
:help "Print region between mark and current position"))
-(define-key menu-bar-files-menu [print-buffer]
+(define-key menu-bar-file-menu [print-buffer]
'(menu-item "Print Buffer" print-buffer
:help "Print current buffer with page headings"))
-(define-key menu-bar-files-menu [separator-print]
+(define-key menu-bar-file-menu [separator-print]
'(menu-item "--"))
-(define-key menu-bar-files-menu [recover-session]
+(define-key menu-bar-file-menu [recover-session]
'(menu-item "Recover Crashed Session..." recover-session
:enable (and auto-save-list-file-prefix
(file-directory-p
auto-save-list-file-prefix)))
t))
:help "Recover edits from a crashed session"))
-(define-key menu-bar-files-menu [revert-buffer]
+(define-key menu-bar-file-menu [revert-buffer]
'(menu-item "Revert Buffer" revert-buffer
:enable (or revert-buffer-function
revert-buffer-insert-file-contents-function
- (and (buffer-file-name)
+ (and buffer-file-number
(or (buffer-modified-p)
(not (verify-visited-file-modtime
(current-buffer))))))
:help "Re-read current buffer from its file"))
-(define-key menu-bar-files-menu [write-file]
+(define-key menu-bar-file-menu [write-file]
'(menu-item "Save Buffer As..." write-file
:enable (not (window-minibuffer-p
(frame-selected-window menu-updating-frame)))
:help "Write current buffer to another file"))
-(define-key menu-bar-files-menu [save-buffer]
+(define-key menu-bar-file-menu [save-buffer]
'(menu-item "Save (current buffer)" save-buffer
:enable (and (buffer-modified-p)
(buffer-file-name)
(frame-selected-window menu-updating-frame))))
:help "Save current buffer to its file"))
-(define-key menu-bar-files-menu [separator-save]
+(define-key menu-bar-file-menu [separator-save]
'(menu-item "--"))
-(define-key menu-bar-files-menu [kill-buffer]
+(define-key menu-bar-file-menu [kill-buffer]
'(menu-item "Close (current buffer)" kill-this-buffer
:enable (kill-this-buffer-enabled-p)
:help "Discard current buffer"))
-(define-key menu-bar-files-menu [insert-file]
+(define-key menu-bar-file-menu [insert-file]
'(menu-item "Insert File..." insert-file
:enable (not (window-minibuffer-p
(frame-selected-window menu-updating-frame)))
:help "Insert another file into current buffer"))
-(define-key menu-bar-files-menu [dired]
+(define-key menu-bar-file-menu [dired]
'(menu-item "Open Directory..." dired
:help "Read a directory, operate on its files"))
-(define-key menu-bar-files-menu [open-file]
- '(menu-item "Open File..." find-file
+(define-key menu-bar-file-menu [open-file]
+ '(menu-item "Open File..." find-file-existing
:enable (not (window-minibuffer-p
(frame-selected-window menu-updating-frame)))
- :help "Read a file into an Emacs buffer"))
+ :help "Read an existing file into an Emacs buffer"))
+(define-key menu-bar-file-menu [new-file]
+ '(menu-item "New File..." find-file
+ :enable (not (window-minibuffer-p
+ (frame-selected-window menu-updating-frame)))
+ :help "Read or create a file and edit it"))
\f
;; The "Edit" menu items
(message "Selecting a region with the mouse does `copy' automatically")
(kill-ring-save beg end)))
-(autoload 'ispell-menu-map "ispell" nil t 'keymap)
-
;; These are alternative definitions for the cut, paste and copy
;; menu items. Use them if your system expects these to use the clipboard.
(cons "Cut" (cons "Delete text in region and copy it to the clipboard"
'clipboard-kill-region)))
+ ;; These are Sun server keysyms for the Cut, Copy and Paste keys
+ ;; (also for XFree86 on Sun keyboard):
(define-key global-map [f20] 'clipboard-kill-region)
(define-key global-map [f16] 'clipboard-kill-ring-save)
(define-key global-map [f18] 'clipboard-yank)
- ;; X11R6 versions
+ ;; X11R6 versions:
(define-key global-map [cut] 'clipboard-kill-region)
(define-key global-map [copy] 'clipboard-kill-ring-save)
(define-key global-map [paste] 'clipboard-yank))
(defmacro menu-bar-make-toggle (name variable doc message help &rest body)
`(progn
- (defun ,name ()
+ (defun ,name (&optional interactively)
,(concat "Toggle whether to " (downcase (substring help 0 1))
- (substring help 1) ".")
- (interactive)
+ (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
(custom-load-symbol ',variable)
;; 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 (interactive-p) (customize-mark-as-set ',variable)))
+ (if interactively (customize-mark-as-set ',variable)))
'(menu-item ,doc ,name
:help ,help
:button (:toggle . (and (default-boundp ',variable)
"Save current values of Options menu items using Custom."
(interactive)
(let ((need-save nil))
+ ;; These are set with menu-bar-make-mm-toggle, which does not
+ ;; put on a customized-value property.
+ (dolist (elt '(line-number-mode column-number-mode cua-mode show-paren-mode
+ transient-mark-mode global-font-lock-mode))
+ (and (customize-mark-to-save elt)
+ (setq need-save t)))
;; These are set with `customize-set-variable'.
- (dolist (elt '(line-number-mode column-number-mode scroll-bar-mode
+ (dolist (elt '(scroll-bar-mode
debug-on-quit debug-on-error menu-bar-mode tool-bar-mode
save-place uniquify-buffer-name-style fringe-mode
- case-fold-search cua-mode show-paren-mode
- transient-mark-mode global-font-lock-mode
+ fringe-indicators case-fold-search
display-time-mode auto-compression-mode
current-language-environment default-input-method
;; Saving `text-mode-hook' is somewhat questionable,
(define-key menu-bar-options-menu [custom-separator]
'("--"))
+(define-key menu-bar-options-menu [mouse-set-font]
+ '(menu-item "Set Font/Fontset" mouse-set-font
+ :visible (display-multi-font-p)
+ :help "Select a font from list of known fonts/fontsets"))
+
;; The "Show/Hide" submenu of menu "Options"
(defvar menu-bar-showhide-menu (make-sparse-keymap "Show/Hide"))
(define-key menu-bar-showhide-menu [column-number-mode]
(menu-bar-make-mm-toggle column-number-mode
- "Show Column Numbers"
+ "Column Numbers"
"Show the current column number in the mode line"))
(define-key menu-bar-showhide-menu [line-number-mode]
(menu-bar-make-mm-toggle line-number-mode
- "Show Line Numbers"
+ "Line Numbers"
"Show the current line number in the mode line"))
(define-key menu-bar-showhide-menu [linecolumn-separator]
(customize-mark-as-set 'display-time-mode))
(define-key menu-bar-showhide-menu [showhide-date-time]
- '(menu-item "Date and Time" showhide-date-time
- :help "Display date and time in the mode line"
+ '(menu-item "Date, Time and Mail" showhide-date-time
+ :help "Display date, time, mail status in mode line"
:button (:toggle . display-time-mode)))
(define-key menu-bar-showhide-menu [datetime-separator]
(frame-visible-p
(symbol-value 'speedbar-frame))))))
+
+(defvar menu-bar-showhide-fringe-ind-menu (make-sparse-keymap "Indicators"))
+
+;; The real definition is in fringe.el.
+;; This is to prevent errors in the :radio conditions below.
+(setq fringe-indicators nil)
+
+(defun menu-bar-showhide-fringe-ind-empty ()
+ "Display empty line indicators in the left or right fringe."
+ (interactive)
+ (require 'fringe)
+ (customize-set-variable 'fringe-indicators 'empty))
+
+(define-key menu-bar-showhide-fringe-ind-menu [empty]
+ '(menu-item "Empty lines only" menu-bar-showhide-fringe-ind-empty
+ :help "Show empty line indicators in fringe"
+ :visible (display-graphic-p)
+ :button (:radio . (eq fringe-indicators 'empty))))
+
+(defun menu-bar-showhide-fringe-ind-mixed ()
+ "Display top and bottom indicators in opposite fringes, arrow in right."
+ (interactive)
+ (require 'fringe)
+ (customize-set-variable 'fringe-indicators 'mixed))
+
+(define-key menu-bar-showhide-fringe-ind-menu [mixed]
+ '(menu-item "Opposite, arrows right" menu-bar-showhide-fringe-ind-mixed
+ :help "Show top/bottom indicators in opposite fringes, arrows in right"
+ :visible (display-graphic-p)
+ :button (:radio . (eq fringe-indicators 'mixed))))
+
+(defun menu-bar-showhide-fringe-ind-box ()
+ "Display top and bottom indicators in opposite fringes."
+ (interactive)
+ (require 'fringe)
+ (customize-set-variable 'fringe-indicators 'box))
+
+(define-key menu-bar-showhide-fringe-ind-menu [box]
+ '(menu-item "Opposite, no arrows" menu-bar-showhide-fringe-ind-box
+ :help "Show top/bottom indicators in opposite fringes, no arrows"
+ :visible (display-graphic-p)
+ :button (:radio . (eq fringe-indicators 'box))))
+
+(defun menu-bar-showhide-fringe-ind-right ()
+ "Display fringe indicators in the right fringe."
+ (interactive)
+ (require 'fringe)
+ (customize-set-variable 'fringe-indicators 'right))
+
+(define-key menu-bar-showhide-fringe-ind-menu [right]
+ '(menu-item "In right fringe" menu-bar-showhide-fringe-ind-right
+ :help "Show indicators in right fringe"
+ :visible (display-graphic-p)
+ :button (:radio . (eq fringe-indicators 'right))))
+
+(defun menu-bar-showhide-fringe-ind-left ()
+ "Display fringe indicators in the left fringe."
+ (interactive)
+ (require 'fringe)
+ (customize-set-variable 'fringe-indicators 'left))
+
+(define-key menu-bar-showhide-fringe-ind-menu [left]
+ '(menu-item "In left fringe" menu-bar-showhide-fringe-ind-left
+ :help "Show indicators in left fringe"
+ :visible (display-graphic-p)
+ :button (:radio . (eq fringe-indicators 'left))))
+
+(defun menu-bar-showhide-fringe-ind-none ()
+ "Do not display any fringe indicators."
+ (interactive)
+ (require 'fringe)
+ (customize-set-variable 'fringe-indicators nil))
+
+(define-key menu-bar-showhide-fringe-ind-menu [none]
+ '(menu-item "No indicators" menu-bar-showhide-fringe-ind-none
+ :help "Hide all fringe indicators"
+ :visible (display-graphic-p)
+ :button (:radio . (eq fringe-indicators nil))))
+
+
+
(defvar menu-bar-showhide-fringe-menu (make-sparse-keymap "Fringe"))
(defun menu-bar-showhide-fringe-menu-customize ()
(interactive)
(customize-set-variable 'fringe-mode nil))
+(define-key menu-bar-showhide-fringe-menu [showhide-fringe-ind]
+ (list 'menu-item "Indicators" menu-bar-showhide-fringe-ind-menu
+ :visible `(display-graphic-p)
+ :help "Select fringe mode"))
+
;; The real definition is in fringe.el.
;; This is to prevent errors in the :radio conditions below.
(setq fringe-mode nil)
(menu-bar-make-toggle toggle-save-place-globally save-place
"Save Place in Files between Sessions"
"Saving place in files %s"
- "Visit files of previous session when restarting Emacs"))
+ "Visit files of previous session when restarting Emacs"
+ (require 'saveplace)
+ ;; Do it by name, to avoid a free-variable
+ ;; warning during byte compilation.
+ (set-default
+ 'save-place (not (symbol-value 'save-place)))))
(define-key menu-bar-options-menu [uniquify]
(menu-bar-make-toggle toggle-uniquify-buffer-names uniquify-buffer-name-style
(define-key menu-bar-options-menu [edit-options-separator]
'("--"))
(define-key menu-bar-options-menu [cua-mode]
- '(menu-item "CUA-style cut and paste"
- menu-bar-toggle-cua-mode
- :help "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"
- :button (:toggle . cua-mode)))
-
-(defun menu-bar-toggle-cua-mode ()
- "Toggle CUA key-binding mode.
-When enabled, using shifted movement keys will activate the region (and
-highlight the region using `transient-mark-mode'), and typed text replaces
-the active selection. C-z, C-x, C-c, and C-v will undo, cut, copy, and
-paste (in addition to the normal Emacs bindings)."
- (interactive)
- (cua-mode nil)
- (customize-mark-as-set 'cua-mode)
- (message "CUA-style cut and paste %s"
- (if cua-mode "enabled" "disabled")))
+ (menu-bar-make-mm-toggle cua-mode
+ "C-x/C-c/C-v cut and paste (CUA)"
+ "Use C-z/C-x/C-c/C-v keys for undo/cut/copy/paste"))
(define-key menu-bar-options-menu [case-fold-search]
(menu-bar-make-toggle toggle-case-fold-search case-fold-search
(defvar vc-menu-map (make-sparse-keymap "Version Control"))
(define-key menu-bar-tools-menu [pcl-cvs]
- `(menu-item "PCL-CVS" ,cvs-global-menu
- :help "Module-level interface to CVS"))
+ '(menu-item "PCL-CVS" cvs-global-menu
+ :help "Module-level interface to CVS"))
(define-key menu-bar-tools-menu [vc]
(list 'menu-item "Version Control" vc-menu-map
:help "Interface to RCS, CVS, SCCS"))
'(menu-item "Compile..." compile
:help "Invoke compiler or Make, view compilation errors"))
(define-key menu-bar-tools-menu [grep]
- '(menu-item "Search Files (Grep)..." grep
- :help "Search files for strings or regexps (with Grep)"))
+ '(menu-item "Search Files (with grep)..." grep
+ :help "Search files for strings or regexps (with grep)"))
\f
;; The "Help" menu items
(defun help-with-tutorial-spec-language ()
"Use the Emacs tutorial, specifying which language you want."
- (interactive)
+ (interactive)
(help-with-tutorial t))
(define-key menu-bar-help-menu [emacs-tutorial-language-specific]
(setq buffers-menu (cons 'keymap (cons "Select Buffer" buffers-menu)))
(define-key (current-global-map) [menu-bar buffer]
- (cons "Buffers" buffers-menu)))))
+ ;; Call copy-sequence so the string is not pure.
+ (cons (copy-sequence "Buffers") buffers-menu)))))
(add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
(list 'menu-item "Enter" 'exit-minibuffer
:help "Terminate input and exit minibuffer")))
\f
-(defcustom menu-bar-mode t
- "Toggle display of a menu bar on each frame.
-Setting this variable directly does not take effect;
-use either \\[customize] or the function `menu-bar-mode'."
- :set (lambda (symbol value)
- (menu-bar-mode (or value 0)))
- :initialize 'custom-initialize-default
- :type 'boolean
- :group 'frames)
-
-(defun menu-bar-mode (&optional flag)
+;;;###autoload
+;; This comment is taken from toolbar/tool-bar.el near
+;; (put 'tool-bar-mode ...)
+;; We want to pretend the menu bar by standard is on, as this will make
+;; customize consider disabling the menu bar a customization, and save
+;; that. We could do this for real by setting :init-value below, but
+;; that would overwrite disabling the tool bar from X resources.
+(put 'menu-bar-mode 'standard-value '(t))
+
+;;;###autoload
+(define-minor-mode menu-bar-mode
"Toggle display of a menu bar on each frame.
This command applies to all frames that exist and frames to be
created in the future.
With a numeric argument, if the argument is positive,
turn on menu bars; otherwise, turn off menu bars."
- (interactive "P")
-
+ :init-value nil
+ :global t
+ :group 'frames
;; Make menu-bar-mode and default-frame-alist consistent.
- (let ((default (assq 'menu-bar-lines default-frame-alist)))
- (if default
- (setq menu-bar-mode (not (eq (cdr default) 0)))
- (setq default-frame-alist
- (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
- default-frame-alist))))
-
- ;; Toggle or set the mode, according to FLAG.
- (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
- (> (prefix-numeric-value flag) 0)))
-
- ;; Apply it to default-frame-alist.
- (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
- (if (consp parameter)
- (setcdr parameter (if menu-bar-mode 1 0))
- (setq default-frame-alist
- (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
- default-frame-alist))))
-
- ;; Apply it to existing frames.
- (let ((frames (frame-list)))
- (while frames
- (let ((height (cdr (assq 'height (frame-parameters (car frames))))))
- (modify-frame-parameters (car frames)
- (list (cons 'menu-bar-lines
- (if menu-bar-mode 1 0))))
- (modify-frame-parameters (car frames)
- (list (cons 'height height))))
- (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))
-
+ (let ((lines (if menu-bar-mode 1 0)))
+ ;; Alter existing frames...
+ (mapc (lambda (frame)
+ (modify-frame-parameters frame
+ (list (cons 'menu-bar-lines lines))))
+ (frame-list))
+ ;; ...and future ones.
+ (let ((elt (assq 'menu-bar-lines default-frame-alist)))
+ (if elt
+ (setcdr elt lines)
+ (add-to-list 'default-frame-alist (cons 'menu-bar-lines lines)))))
+
+ ;; Make the message appear when Emacs is idle. We can not call message
+ ;; directly. The minor-mode message "Menu-bar mode disabled" comes
+ ;; after this function returns, overwriting any message we do here.
+ (when (and (interactive-p) (not menu-bar-mode))
+ (run-with-idle-timer 0 nil 'message
+ "Menu-bar mode disabled. Use M-x menu-bar-mode to make the menu bar appear."))
menu-bar-mode)
(provide 'menu-bar)
+;;; arch-tag: 6e6a3c22-4ec4-4d3d-8190-583f8ef94ced
;;; menu-bar.el ends here