]> code.delx.au - gnu-emacs/blobdiff - lisp/menu-bar.el
(sit_for): New arg initial_display.
[gnu-emacs] / lisp / menu-bar.el
index 079de741c852e8fed00f5b7f080838dc3f2b9c1b..41bc628c895ef8c0927cb1017e6fccf3f5ccd59f 100644 (file)
@@ -1,10 +1,10 @@
 ;;; menu-bar.el --- define a default menu bar.
 
+;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
+
 ;; Author: RMS
 ;; Keywords: internal
 
-;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
-
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;; Avishai Yacobi suggested some menu rearrangements.
 
 ;;; Code:
 
+;;; User options:
+
+(defcustom buffers-menu-max-size 10
+  "*Maximum number of entries which may appear on the Buffers menu.
+If this is 10, then only the ten most-recently-selected buffers are shown.
+If this is nil, then all buffers are shown.
+A large number or nil slows down menu responsiveness."
+  :type '(choice integer
+                (const :tag "All" nil))
+  :group 'mouse)
+
 ;; Don't clobber an existing menu-bar keymap, to preserve any menu-bar key
 ;; definitions made in loaddefs.el.
 (or (lookup-key global-map [menu-bar])
 \f
 (defvar vc-menu-map (make-sparse-keymap "Version Control"))
 
+(define-key menu-bar-tools-menu [gdb] '("Debugger..." . gdb))
+(define-key menu-bar-tools-menu [compile] '("Compile..." . compile))
+(define-key menu-bar-tools-menu [grep] '("Search Files..." . grep))
+
+(define-key menu-bar-tools-menu [separator-1]
+  '("--"))
+
 (define-key menu-bar-tools-menu [calendar] '("Display Calendar" . calendar))
+(define-key menu-bar-tools-menu [compose-mail] '("Send Mail" . compose-mail))
 (define-key menu-bar-tools-menu [rmail] '("Read Mail" . rmail))
 (define-key menu-bar-tools-menu [gnus] '("Read Net News" . gnus))
 
 (define-key menu-bar-tools-menu [separator-vc]
   '("--"))
 
-(define-key menu-bar-tools-menu [vc-menu]
+(define-key menu-bar-tools-menu [vc]
   (cons "Version Control" vc-menu-map))
 
 (define-key menu-bar-tools-menu [separator-compare]
 
 (if (fboundp 'delete-frame)
     (progn
-      (define-key menu-bar-files-menu [delete-frame]
+      ;; Don't use delete-frame as event name
+      ;; because that is a special event.
+      (define-key menu-bar-files-menu [delete-this-frame]
        '("Delete Frame" . delete-frame))
       (define-key menu-bar-files-menu [make-frame-on-display]
        '("Open New Display..." . make-frame-on-display))
 (define-key menu-bar-files-menu [dired] '("Open Directory..." . dired))
 (define-key menu-bar-files-menu [open-file] '("Open File..." . find-file))
 
-;; This is just one element of the ediff menu--the first.
-(define-key menu-bar-ediff-menu [window]
-  '("This Window And Next Window" . compare-windows))
 \f
 (defun nonincremental-search-forward (string)
   "Read a string and search for it nonincrementally."
   '("Query Replace..." . query-replace))
 (define-key menu-bar-search-menu [find-tag]
   '("Find Tag..." . find-tag))
-(put 'find-tag 'menu-enable 'tags-table-list)
 (define-key menu-bar-search-menu [bookmark]
   '("Bookmarks" . menu-bar-bookmark-map))
 
 (define-key menu-bar-search-menu [separator-search]
   '("--"))
 
-(define-key menu-bar-search-menu [nonincremental-repeat-re-search-back]
+(define-key menu-bar-search-menu [repeat-regexp-back]
   '("Repeat Regexp Backwards" . nonincremental-repeat-re-search-backward))
-(define-key menu-bar-search-menu [nonincremental-repeat-search-back]
+(define-key menu-bar-search-menu [repeat-search-back]
   '("Repeat Backwards" . nonincremental-repeat-search-backward))
-(define-key menu-bar-search-menu [nonincremental-repeat-re-search-fwd]
+(define-key menu-bar-search-menu [repeat-regexp-fwd]
   '("Repeat Regexp" . nonincremental-repeat-re-search-forward))
-(define-key menu-bar-search-menu [nonincremental-repeat-search-fwd]
+(define-key menu-bar-search-menu [repeat-search-fwd]
   '("Repeat Search" . nonincremental-repeat-search-forward))
 
 (define-key menu-bar-search-menu [separator-repeat]
   '("--"))
 
-(define-key menu-bar-search-menu [re-search-back]
+(define-key menu-bar-search-menu [re-search-backward]
   '("Regexp Search Backwards..." . nonincremental-re-search-backward))
-(define-key menu-bar-search-menu [search-back]
+(define-key menu-bar-search-menu [search-backward]
   '("Search Backwards..." . nonincremental-search-backward))
-(define-key menu-bar-search-menu [re-search-fwd]
+(define-key menu-bar-search-menu [re-search-forward]
   '("Regexp Search..." . nonincremental-re-search-forward))
-(define-key menu-bar-search-menu [search-fwd]
+(define-key menu-bar-search-menu [search-forward]
   '("Search..." . nonincremental-search-forward))
 \f
 (if (fboundp 'start-process)
@@ -299,13 +319,34 @@ Do the same for the keys of the same name."
   (define-key global-map [copy] 'clipboard-kill-ring-save)
   (define-key global-map [paste] 'clipboard-yank))
 \f
+
+;;; Menu support
+
+(defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
+
+(define-key menu-bar-custom-menu [custom-menu-update]
+  '("Update This Menu" . custom-menu-update))
+(define-key menu-bar-custom-menu [customize-apropos]
+  '("Apropos..." . customize-apropos))
+(define-key menu-bar-custom-menu [customize-group]
+  '("Specific Group..." . customize-group))
+(define-key menu-bar-custom-menu [customize-face]
+  '("Specific Face..." . customize-face))
+(define-key menu-bar-custom-menu [customize-variable]
+  '("Specific Variable..." . customize-variable))
+(define-key menu-bar-custom-menu [customize]
+  '("Browse Hierarchy of User Options" . customize))
+
 (define-key menu-bar-help-menu [emacs-version]
   '("Show Version" . emacs-version))
 (define-key menu-bar-help-menu [report-emacs-bug]
   '("Send Bug Report..." . report-emacs-bug))
+(define-key menu-bar-help-menu [finder-by-keyword]
+  '("Find Lisp Packages..." . finder-by-keyword))
 (define-key menu-bar-help-menu [emacs-tutorial]
   '("Emacs Tutorial" . help-with-tutorial))
-(define-key menu-bar-help-menu [man] '("Man..." . manual-entry))
+(define-key menu-bar-help-menu [man]
+  '("Man..." . manual-entry))
 (define-key menu-bar-help-menu [describe-variable]
   '("Describe Variable..." . describe-variable))
 (define-key menu-bar-help-menu [describe-function]
@@ -321,6 +362,8 @@ Do the same for the keys of the same name."
 (define-key menu-bar-help-menu [info] '("Browse Manuals" . info))
 (define-key menu-bar-help-menu [emacs-faq] '("Emacs FAQ" . view-emacs-FAQ))
 (define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
+(define-key menu-bar-help-menu [customize-menu]
+  (cons "Customize" menu-bar-custom-menu))
 
 (defun kill-this-buffer ()     ; for the menubar
   "Kills the current buffer."
@@ -334,26 +377,26 @@ Do the same for the keys of the same name."
       (or (string-match "^ " (buffer-name (car buffers)))
          (setq count (1+ count)))
       (setq buffers (cdr buffers)))
-    (and (not (window-minibuffer-p (selected-window)))
+    (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
         (> count 1))))
 
 (put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
 
 (put 'save-buffer 'menu-enable
      '(and (buffer-modified-p)
-          (not (window-minibuffer-p (selected-window)))))
+          (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
 
 (put 'write-file 'menu-enable
-     '(not (window-minibuffer-p (selected-window))))
+     '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
 
 (put 'find-file 'menu-enable
-     '(not (window-minibuffer-p (selected-window))))
+     '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
 
 (put 'dired 'menu-enable
-     '(not (window-minibuffer-p (selected-window))))
+     '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
 
 (put 'insert-file 'menu-enable
-     '(not (window-minibuffer-p (selected-window))))
+     '(not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
 
 (put 'revert-buffer 'menu-enable
      '(or revert-buffer-function revert-buffer-insert-file-contents-function
@@ -368,12 +411,12 @@ Do the same for the keys of the same name."
 (defun delete-frame-enabled-p ()
   "Return non-nil if `delete-frame' should be enabled in the menu bar."
   (let ((frames (frame-list))
-             (count 0))
-         (while frames
-           (if (frame-visible-p (car frames))
-               (setq count (1+ count)))
-           (setq frames (cdr frames)))
-         (> count 1)))
+       (count 0))
+    (while frames
+      (if (frame-visible-p (car frames))
+         (setq count (1+ count)))
+      (setq frames (cdr frames)))
+    (> count 1)))
 
 (put 'advertised-undo 'menu-enable
      '(and (not (eq t buffer-undo-list))
@@ -382,8 +425,10 @@ Do the same for the keys of the same name."
                    pending-undo-list)
             buffer-undo-list)))
 
-(defvar yank-menu-length 20
-  "*Maximum length to display in the yank-menu.")
+(defcustom yank-menu-length 20
+  "*Maximum length to display in the yank-menu."
+  :type 'integer
+  :group 'mouse)
 
 (defun menu-bar-update-yank-menu (string old)
   (let ((front (car (cdr yank-menu)))
@@ -393,6 +438,10 @@ Do the same for the keys of the same name."
                        (substring string 0 (/ yank-menu-length 2))
                        "..."
                        (substring string (- (/ yank-menu-length 2)))))))
+    ;; Don't let the menu string be all dashes
+    ;; because that has a special meaning in a menu.
+    (if (string-match "\\`-+\\'" menu-string)
+       (setq menu-string (concat menu-string " ")))
     ;; If we're supposed to be extending an existing string, and that
     ;; string really is at the front of the menu, then update it in place.
     (if (and old (or (eq old (car front))
@@ -412,15 +461,10 @@ Do the same for the keys of the same name."
   (push-mark (point))
   (insert last-command-event))
 \f
-(define-key global-map [menu-bar buffer] '("Buffers" . menu-bar-buffers))
-
-(defalias 'menu-bar-buffers (make-sparse-keymap "Buffers"))
-
-(defvar buffers-menu-max-size 10
-  "*Maximum number of entries which may appear on the Buffers menu.
-If this is 10, then only the ten most-recently-selected buffers are shown.
-If this is nil, then all buffers are shown.
-A large number or nil slows down menu responsiveness.")
+;; This definition is just to show what this looks like.
+;; It gets overridden below when menu-bar-update-buffers is called.
+(define-key global-map [menu-bar buffer]
+  (cons "Buffers" (make-sparse-keymap "Buffers")))
 
 (defvar list-buffers-directory nil)
 
@@ -466,6 +510,7 @@ A large number or nil slows down menu responsiveness.")
        (frame-or-buffer-changed-p)
        (let ((buffers (buffer-list))
             (frames (frame-list))
+            (maxlen 0)
             buffers-menu frames-menu)
         ;; If requested, list only the N most recently selected buffers.
         (if (and (integerp buffers-menu-max-size)
@@ -480,7 +525,6 @@ A large number or nil slows down menu responsiveness.")
                             (mapcar 'list buffers))
                            tail
                            (menu-bar-update-buffers-maxbuf 0)
-                           (maxlen 0)
                            alist
                            head)
                       ;; Put into each element of buffer-list
@@ -553,29 +597,31 @@ A large number or nil slows down menu responsiveness.")
 
         ;; Make a Frames menu if we have more than one frame.
         (if (cdr frames)
-            (setq frames-menu
-                  (cons "Select Frame"
-                        (mapcar '(lambda (frame)
-                                   (nconc (list frame
-                                                (cdr (assq 'name
-                                                           (frame-parameters frame)))
-                                                (cons nil nil))
-                                          'menu-bar-select-frame))
-                                frames))))
+            (let ((name (concat (make-string (max (- (/ maxlen 2) 3) 0)
+                                             ?\ )
+                                "Frames"))
+                  (frames-menu
+                   (cons 'keymap
+                         (cons "Select Frame"
+                               (mapcar '(lambda (frame)
+                                          (nconc (list frame
+                                                       (cdr (assq 'name
+                                                                  (frame-parameters frame)))
+                                                       (cons nil nil))
+                                                 'menu-bar-select-frame))
+                                       frames)))))
+              ;; Put it underneath the Buffers menu.
+              (setq buffers-menu (cons (cons 'frames (cons name frames-menu))
+                                       buffers-menu))))
         (if buffers-menu
             (setq buffers-menu (cons 'keymap buffers-menu)))
-        (if frames-menu
-            (setq frames-menu (cons 'keymap frames-menu)))
         (define-key (current-global-map) [menu-bar buffer]
-          (cons "Buffers"
-                (if (and buffers-menu frames-menu)
-                    (list 'keymap "Buffers and Frames"
-                          (cons 'buffers (cons "Buffers" buffers-menu))
-                          (cons 'frames (cons "Frames" frames-menu)))
-                  (or buffers-menu frames-menu 'undefined)))))))
+          (cons "Buffers" buffers-menu)))))
 
 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
 
+(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.
@@ -614,7 +660,7 @@ A large number or nil slows down menu responsiveness.")
     (define-key map [menu-bar minibuf space]
       '("Complete Word" . minibuffer-complete-word))
     (define-key map [menu-bar minibuf tab]
-      '("Complete" . 'minibuffer-complete))
+      '("Complete" . minibuffer-complete))
     ))
  (list minibuffer-local-must-match-map
        minibuffer-local-completion-map))