Sync to HEAD
[bpt/emacs.git] / lisp / menu-bar.el
index 19be989..7db5f96 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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
@@ -152,7 +152,7 @@ A large number or nil slows down menu responsiveness."
   '(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))))))
@@ -193,9 +193,41 @@ A large number or nil slows down menu responsiveness."
 
 \f
 ;; The "Edit" menu items
+
+;; The "Edit->Search" submenu
+(defvar menu-bar-last-search-type nil
+  "Type of last non-incremental search command called from the menu.")
+
+(defun nonincremental-repeat-search-forward ()
+  "Search forward for the previous search string or regexp."
+  (interactive)
+  (cond
+   ((and (eq menu-bar-last-search-type 'string)
+        search-ring)
+    (search-forward (car search-ring)))
+   ((and (eq menu-bar-last-search-type 'regexp)
+        regexp-search-ring)
+    (re-search-forward (car regexp-search-ring)))
+   (t
+    (error "No previous search"))))
+
+(defun nonincremental-repeat-search-backward ()
+  "Search backward for the previous search string or regexp."
+  (interactive)
+  (cond
+   ((and (eq menu-bar-last-search-type 'string)
+        search-ring)
+    (search-backward (car search-ring)))
+   ((and (eq menu-bar-last-search-type 'regexp)
+        regexp-search-ring)
+    (re-search-backward (car regexp-search-ring)))
+   (t
+    (error "No previous search"))))
+
 (defun nonincremental-search-forward (string)
   "Read a string and search for it nonincrementally."
   (interactive "sSearch for string: ")
+  (setq menu-bar-last-search-type 'string)
   (if (equal string "")
       (search-forward (car search-ring))
     (isearch-update-ring string nil)
@@ -204,6 +236,7 @@ A large number or nil slows down menu responsiveness."
 (defun nonincremental-search-backward (string)
   "Read a string and search backward for it nonincrementally."
   (interactive "sSearch for string: ")
+  (setq menu-bar-last-search-type 'string)
   (if (equal string "")
       (search-backward (car search-ring))
     (isearch-update-ring string nil)
@@ -212,6 +245,7 @@ A large number or nil slows down menu responsiveness."
 (defun nonincremental-re-search-forward (string)
   "Read a regular expression and search for it nonincrementally."
   (interactive "sSearch for regexp: ")
+  (setq menu-bar-last-search-type 'regexp)
   (if (equal string "")
       (re-search-forward (car regexp-search-ring))
     (isearch-update-ring string t)
@@ -220,106 +254,100 @@ A large number or nil slows down menu responsiveness."
 (defun nonincremental-re-search-backward (string)
   "Read a regular expression and search backward for it nonincrementally."
   (interactive "sSearch for regexp: ")
+  (setq menu-bar-last-search-type 'regexp)
   (if (equal string "")
       (re-search-backward (car regexp-search-ring))
     (isearch-update-ring string t)
     (re-search-backward string)))
 
-(defun nonincremental-repeat-search-forward ()
-  "Search forward for the previous search string."
-  (interactive)
-  (if (null search-ring)
-      (error "No previous search"))
-  (search-forward (car search-ring)))
-
-(defun nonincremental-repeat-search-backward ()
-  "Search backward for the previous search string."
-  (interactive)
-  (if (null search-ring)
-      (error "No previous search"))
-  (search-backward (car search-ring)))
-
-(defun nonincremental-repeat-re-search-forward ()
-  "Search forward for the previous regular expression."
-  (interactive)
-  (if (null regexp-search-ring)
-      (error "No previous search"))
-  (re-search-forward (car regexp-search-ring)))
+(defvar menu-bar-search-menu (make-sparse-keymap "Search"))
 
-(defun nonincremental-repeat-re-search-backward ()
-  "Search backward for the previous regular expression."
-  (interactive)
-  (if (null regexp-search-ring)
-      (error "No previous search"))
-  (re-search-backward (car regexp-search-ring)))
+;; The Edit->Search->Incremental Search menu
+(defvar menu-bar-i-search-menu
+  (make-sparse-keymap "Incremental Search"))
+
+(define-key menu-bar-i-search-menu [isearch-backward-regexp]
+  '(menu-item "Backward Regexp..." isearch-backward-regexp
+             :help "Search backwards for a regular expression as you type it"))
+(define-key menu-bar-i-search-menu [isearch-forward-regexp]
+  '(menu-item "Forward Regexp..." isearch-forward-regexp
+             :help "Search forward for a regular expression as you type it"))
+(define-key menu-bar-i-search-menu [isearch-backward]
+  '(menu-item "Backward String..." isearch-backward
+             :help "Search backwards for a string as you type it"))
+(define-key menu-bar-i-search-menu [isearch-forward]
+  '(menu-item "Forward String..." isearch-forward
+             :help "Search forward for a string as you type it"))
 
-(defvar menu-bar-search-menu (make-sparse-keymap "Search"))
-(defvar menu-bar-adv-search-menu
-  (make-sparse-keymap "Advanced Search/Replace"))
-
-(define-key menu-bar-adv-search-menu [tags-continue]
-  '(menu-item "Continue Tags Search/Replace" tags-loop-continue
-             :help "Continue last tags search/replace operation"))
-(define-key menu-bar-adv-search-menu [tags-repl]
-  '(menu-item "Replace in all tagged files" tags-query-replace
-             :help "Interactively replace a regexp in all tagged files"))
-(define-key menu-bar-adv-search-menu [tags-srch]
-  '(menu-item "Search in all tagged files" tags-search
-             :help "Search for a regexp in all tagged files"))
 
-(define-key menu-bar-adv-search-menu [separator-tag-search]
+(define-key menu-bar-search-menu [i-search]
+  (list 'menu-item "Incremental Search" menu-bar-i-search-menu
+             :help "Incremental Search finds partial matches while you type the search string.\nIt is most convenient from the keyboard.  Try it!"))
+(define-key menu-bar-search-menu [separator-tag-isearch]
   '(menu-item "--"))
 
-(define-key menu-bar-adv-search-menu [query-replace-regexp]
-  '(menu-item "Replace Regexp..." query-replace-regexp
-             :enable (not buffer-read-only)
-             :help "Replace regular expression, ask about each occurrence"))
-(define-key menu-bar-adv-search-menu [repeat-regexp-back]
-  '(menu-item "Repeat Regexp Backwards"
-             nonincremental-repeat-re-search-backward
-             :enable regexp-search-ring
-             :help "Repeat last regular expression search backwards"))
-(define-key menu-bar-adv-search-menu [repeat-regexp-fwd]
-  '(menu-item "Repeat Regexp" nonincremental-repeat-re-search-forward
-             :enable regexp-search-ring
-             :help "Repeat last regular expression search forward"))
-(define-key menu-bar-adv-search-menu [re-search-backward]
-  '(menu-item "Search Regexp Backwards..." nonincremental-re-search-backward
-             :help "Search backwards for a regular expression"))
-(define-key menu-bar-adv-search-menu [re-search-forward]
-  '(menu-item "Search Regexp..." nonincremental-re-search-forward
-             :help "Search forward for a regular expression"))
-(define-key menu-bar-adv-search-menu [separator-tag-isearch]
+(define-key menu-bar-search-menu [tags-continue]
+  '(menu-item "Continue Tags Search" tags-loop-continue
+             :help "Continue last tags search operation"))
+(define-key menu-bar-search-menu [tags-srch]
+  '(menu-item "Search tagged files" tags-search
+             :help "Search for a regexp in all tagged files"))
+(define-key menu-bar-search-menu [separator-tag-search]
   '(menu-item "--"))
-(define-key menu-bar-adv-search-menu [isearch-backward]
-  '(menu-item "Incremental Search Backwards..." isearch-backward
-             :help "Search backwards for a string as you type it"))
-(define-key menu-bar-adv-search-menu [isearch-forward]
-  '(menu-item "Incremental Search..." isearch-forward
-             :help "Search forward for a string as you type it"))
-(define-key menu-bar-search-menu [re-search]
-  (list 'menu-item "Advanced Search/Replace" menu-bar-adv-search-menu
-             :help "Regexp and Tags search and replace"))
 
-(define-key menu-bar-search-menu [query-replace]
-  '(menu-item "Replace..." query-replace
-             :enable (not buffer-read-only)
-             :help "Replace string interactively, ask about each occurrence"))
 (define-key menu-bar-search-menu [repeat-search-back]
   '(menu-item "Repeat Backwards" nonincremental-repeat-search-backward
-             :enable search-ring
+             :enable (or (and (eq menu-bar-last-search-type 'string)
+                              search-ring)
+                         (and (eq menu-bar-last-search-type 'regexp)
+                              regexp-search-ring))
              :help "Repeat last search backwards"))
 (define-key menu-bar-search-menu [repeat-search-fwd]
-  '(menu-item "Repeat Search" nonincremental-repeat-search-forward
-             :enable search-ring
+  '(menu-item "Repeat Forward" nonincremental-repeat-search-forward
+             :enable (or (and (eq menu-bar-last-search-type 'string)
+                              search-ring)
+                         (and (eq menu-bar-last-search-type 'regexp)
+                              regexp-search-ring))
              :help "Repeat last search forward"))
+(define-key menu-bar-search-menu [separator-repeat-search]
+  '(menu-item "--"))
+
+(define-key menu-bar-search-menu [re-search-backward]
+  '(menu-item "Regexp Backwards..." nonincremental-re-search-backward
+             :help "Search backwards for a regular expression"))
+(define-key menu-bar-search-menu [re-search-forward]
+  '(menu-item "Regexp Forward..." nonincremental-re-search-forward
+             :help "Search forward for a regular expression"))
+
 (define-key menu-bar-search-menu [search-backward]
-  '(menu-item "Search Backwards..." nonincremental-search-backward
+  '(menu-item "String Backwards..." nonincremental-search-backward
              :help "Search backwards for a string"))
 (define-key menu-bar-search-menu [search-forward]
-  '(menu-item "Search..." nonincremental-search-forward
+  '(menu-item "String Forward..." nonincremental-search-forward
              :help "Search forward for a string"))
 
+;; The Edit->Replace submenu
+
+(defvar menu-bar-replace-menu (make-sparse-keymap "Replace"))
+
+(define-key menu-bar-replace-menu [tags-repl-continue]
+  '(menu-item "Continue Replace" tags-loop-continue
+             :help "Continue last tags replace operation"))
+(define-key menu-bar-replace-menu [tags-repl]
+  '(menu-item "Replace in tagged files" tags-query-replace
+             :help "Interactively replace a regexp in all tagged files"))
+(define-key menu-bar-replace-menu [separator-replace-tags]
+  '(menu-item "--"))
+
+(define-key menu-bar-replace-menu [query-replace-regexp]
+  '(menu-item "Replace Regexp..." query-replace-regexp
+             :enable (not buffer-read-only)
+             :help "Replace regular expression interactively, ask about each occurrence"))
+(define-key menu-bar-replace-menu [query-replace]
+  '(menu-item "Replace String..." query-replace
+             :enable (not buffer-read-only)
+             :help "Replace string interactively, ask about each occurrence"))
+
 ;;; Assemble the top-level Edit menu items.
 (define-key menu-bar-edit-menu [props]
   '(menu-item "Text Properties" facemenu-menu
@@ -397,6 +425,9 @@ A large number or nil slows down menu responsiveness."
 (define-key menu-bar-edit-menu [goto]
   (list 'menu-item "Go To" menu-bar-goto-menu))
 
+(define-key menu-bar-edit-menu [replace]
+  (list 'menu-item "Replace" menu-bar-replace-menu))
+
 (define-key menu-bar-edit-menu [search]
   (list 'menu-item "Search" menu-bar-search-menu))
 
@@ -453,8 +484,6 @@ A large number or nil slows down menu responsiveness."
       (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.
 
@@ -497,10 +526,12 @@ Do the same for the keys of the same name."
     (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))
@@ -557,13 +588,13 @@ 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
+  `'(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 &rest body)
   `(progn
      (defun ,name ()
        ,(concat "Toggle whether to " (downcase (substring help 0 1))
@@ -576,20 +607,13 @@ PROPS are additional properties."
                       (get (or (get ',variable 'custom-get) 'default-value)))
                   (funcall set ',variable (not (funcall get ',variable))))))
           (message ,message "enabled")
-        (message ,message "disabled")))
-     ;; 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.  Unfortunately, he could very likely call the function
-     ;; defined above there.  So we put `customize-mark-as-set' in a
-     ;; lambda expression.
-     ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
-     '(menu-item ,doc (lambda ()
-                       (interactive)
-                       (,name)
-                       (customize-mark-as-set ',variable))
-                ,@(if props props)
+        (message ,message "disabled"))
+       ;; 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 (interactive-p) (customize-mark-as-set ',variable)))
+     '(menu-item ,doc ,name
                 :help ,help
                  :button (:toggle . (and (default-boundp ',variable)
                                         (default-value ',variable))))))
@@ -632,19 +656,24 @@ PROPS are additional properties."
 (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-toggle toggle-column-number-mode column-number-mode
-                       "Show Column Numbers" "Column number mode %s"
-                       "Show the current column number in the mode line"))
+  (menu-bar-make-mm-toggle column-number-mode
+                          "Column Numbers"
+                          "Show the current column number in the mode line"))
 
 (define-key menu-bar-showhide-menu [line-number-mode]
-  (menu-bar-make-toggle toggle-line-number-mode line-number-mode
-                       "Show Line Numbers" "Line number mode %s"
-                       "Show the current line number in the mode line"))
+  (menu-bar-make-mm-toggle line-number-mode
+                          "Line Numbers"
+                          "Show the current line number in the mode line"))
 
 (define-key menu-bar-showhide-menu [linecolumn-separator]
   '("--"))
@@ -658,8 +687,8 @@ PROPS are additional properties."
   (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]
@@ -767,7 +796,7 @@ PROPS are additional properties."
 (defun menu-bar-left-scroll-bar ()
   "Display scroll bars on the left of each window."
   (interactive)
-  (customize-set-variable 'scroll-bar-mode 'right))
+  (customize-set-variable 'scroll-bar-mode 'left))
 
 (define-key menu-bar-showhide-scroll-bar-menu [none]
   '(menu-item "None"
@@ -843,14 +872,18 @@ PROPS are additional properties."
   (menu-bar-make-toggle toggle-save-place-globally save-place
                        "Save Place in Files between Sessions"
                        "Saving place in files %s"
-                       "Save Emacs state for next session"))
+                       "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
                        "Use Directory Names in Buffer Names"
                        "Directory name in buffer names (uniquify) %s"
                        "Uniquify buffer names by adding parent directory names"
-                       () ; no props
                        (require 'uniquify)
                        (setq uniquify-buffer-name-style
                              (if (not uniquify-buffer-name-style)
@@ -859,22 +892,9 @@ PROPS are additional properties."
 (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
+                          "CUA-style cut and paste"
+                          "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
@@ -908,13 +928,12 @@ paste (in addition to the normal Emacs bindings)."
 (define-key menu-bar-options-menu [highlight-paren-mode]
   (menu-bar-make-mm-toggle show-paren-mode
                           "Paren Match Highlighting"
-                       "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]
-  (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
-                       "Active Region Highlighting"
-                       "Transient Mark mode %s"
-                       "Make text in active region stand out in color (Transient Mark mode)"
-                       (:enable (not cua-mode))))
+  (menu-bar-make-mm-toggle transient-mark-mode
+                          "Active Region Highlighting"
+                          "Make text in active region stand out in color (Transient Mark mode)"
+                          (:enable (not cua-mode))))
 (define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
   (menu-bar-make-mm-toggle global-font-lock-mode
                           "Syntax Highlighting"
@@ -1028,8 +1047,8 @@ paste (in addition to the normal Emacs bindings)."
 
 (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"))
@@ -1073,8 +1092,8 @@ paste (in addition to the normal Emacs bindings)."
   '(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
@@ -1119,11 +1138,16 @@ paste (in addition to the normal Emacs bindings)."
 (define-key menu-bar-describe-menu [describe-function]
   '(menu-item "Describe Function..." describe-function
              :help "Display documentation of function/command"))
-(define-key menu-bar-describe-menu [describe-key]
+(define-key menu-bar-describe-menu [describe-key-1]
   '(menu-item "Describe Key..." describe-key
              ;; Users typically don't identify keys and menu items...
              :help "Display documentation of command bound to a \
 key (or menu-item)"))
+(define-key menu-bar-describe-menu [describe-key]
+  '(menu-item "What's This? " describe-key
+             ;; Users typically don't identify keys and menu items...
+             :help "Display documentation of command bound to a \
+key (or menu-item)"))
 (define-key menu-bar-describe-menu [describe-mode]
   '(menu-item "Describe Buffer Modes" describe-mode
              :help "Describe this buffer's major and minor mode"))
@@ -1272,7 +1296,7 @@ key (or menu-item)"))
 
 (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]
@@ -1540,21 +1564,21 @@ Buffers menu is regenerated."
 (menu-bar-update-buffers)
 
 ;; this version is too slow
-;;;(defun format-buffers-menu-line (buffer)
-;;;  "Returns a string to represent the given buffer in the Buffer menu.
-;;;nil means the buffer shouldn't be listed.  You can redefine this."
-;;;  (if (string-match "\\` " (buffer-name buffer))
-;;;      nil
-;;;    (save-excursion
-;;;     (set-buffer buffer)
-;;;     (let ((size (buffer-size)))
-;;;       (format "%s%s %-19s %6s %-15s %s"
-;;;           (if (buffer-modified-p) "*" " ")
-;;;           (if buffer-read-only "%" " ")
-;;;           (buffer-name)
-;;;           size
-;;;           mode-name
-;;;           (or (buffer-file-name) ""))))))
+;;(defun format-buffers-menu-line (buffer)
+;;  "Returns a string to represent the given buffer in the Buffer menu.
+;;nil means the buffer shouldn't be listed.  You can redefine this."
+;;  (if (string-match "\\` " (buffer-name buffer))
+;;      nil
+;;    (save-excursion
+;;     (set-buffer buffer)
+;;     (let ((size (buffer-size)))
+;;       (format "%s%s %-19s %6s %-15s %s"
+;;            (if (buffer-modified-p) "*" " ")
+;;            (if buffer-read-only "%" " ")
+;;            (buffer-name)
+;;            size
+;;            mode-name
+;;            (or (buffer-file-name) ""))))))
 \f
 ;;; Set up a menu bar menu for the minibuffer.
 
@@ -1584,63 +1608,47 @@ Buffers menu is regenerated."
     (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