Move ns-win.el's rather wacky menu adjustments to menu-bar.el.
[bpt/emacs.git] / lisp / menu-bar.el
index d740cfc..9d8e474 100644 (file)
@@ -6,6 +6,7 @@
 ;; Author: RMS
 ;; Maintainer: FSF
 ;; Keywords: internal, mouse
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
 (define-key menu-bar-edit-menu [props]
   `(menu-item ,(purecopy "Text Properties") facemenu-menu))
 
+;; ns-win.el said: Add spell for platorm consistency.
+(if (featurep 'ns)
+    (define-key menu-bar-edit-menu [spell]
+      `(menu-item ,(purecopy "Spell") ispell-menu-map)))
+
 (define-key menu-bar-edit-menu [fill]
   `(menu-item ,(purecopy "Fill") fill-region
              :enable (and mark-active (not buffer-read-only))
              ,(purecopy "Delete the text in region between mark and current position")))
 (defvar yank-menu (cons (purecopy "Select Yank") nil))
 (fset 'yank-menu (cons 'keymap yank-menu))
-(define-key menu-bar-edit-menu [paste-from-menu]
-  `(menu-item ,(purecopy "Paste from Kill Menu") yank-menu
+;; The ns differences here seem silly.
+(define-key menu-bar-edit-menu (if (featurep 'ns) [select-paste]
+                                 [paste-from-menu])
+  ;; ns-win.el said: Change text to be more consistent with
+  ;; surrounding menu items `paste', etc."
+  `(menu-item ,(purecopy (if (featurep 'ns) "Select and Paste"
+                           "Paste from Kill Menu")) yank-menu
              :enable (and (cdr yank-menu) (not buffer-read-only))
              :help ,(purecopy "Choose a string from the kill ring and paste it")))
 (define-key menu-bar-edit-menu [paste]
   `(menu-item ,(purecopy "Paste") yank
              :enable (and (or
-                           ;; Emacs compiled --without-x doesn't have
-                           ;; x-selection-exists-p.
+                           ;; Emacs compiled --without-x (or --with-ns)
+                           ;; doesn't have x-selection-exists-p.
                            (and (fboundp 'x-selection-exists-p)
-                                (x-selection-exists-p))
-                           kill-ring)
+                                (x-selection-exists-p 'CLIPBOARD))
+                           (if (featurep 'ns) ; like paste-from-menu
+                               (cdr yank-menu)
+                             kill-ring))
                           (not buffer-read-only))
              :help ,(purecopy "Paste (yank) text most recently cut/copied")))
 (define-key menu-bar-edit-menu [copy]
-  `(menu-item ,(purecopy "Copy") menu-bar-kill-ring-save
-             :enable mark-active
-             :help ,(purecopy "Copy text in region between mark and current position")
-             :keys ,(purecopy "\\[kill-ring-save]")))
+  ;; ns-win.el said: Substitute a Copy function that works better
+  ;; under X (for GNUstep).
+  `(menu-item ,(purecopy "Copy") ,(if (featurep 'ns)
+                                      'ns-copy-including-secondary
+                                    'menu-bar-kill-ring-save)
+              :enable mark-active
+              :help ,(purecopy "Copy text in region between mark and current position")
+              :keys ,(purecopy (if (featurep 'ns)
+                                   "\\[ns-copy-including-secondary]"
+                                 "\\[kill-ring-save]"))))
 (define-key menu-bar-edit-menu [cut]
   `(menu-item ,(purecopy "Cut") kill-region
              :enable (and mark-active (not buffer-read-only))
              :help
              ,(purecopy "Cut (kill) text in region between mark and current position")))
+;; ns-win.el said: Separate undo from cut/paste section.
+(if (featurep 'ns)
+    (define-key menu-bar-edit-menu [separator-undo] `(,(purecopy "--"))))
 (define-key menu-bar-edit-menu [undo]
   `(menu-item ,(purecopy "Undo") undo
              :enable (and (not buffer-read-only)
                             (consp buffer-undo-list)))
              :help ,(purecopy "Undo last operation")))
 
-
 (defun menu-bar-kill-ring-save (beg end)
   (interactive "r")
   (if (mouse-region-match)
   "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
 Do the same for the keys of the same name."
   (interactive)
-  ;; We can't use constant list structure here because it becomes pure,
-  ;; and because it gets modified with cache data.
-  (define-key menu-bar-edit-menu [paste]
-    (cons "Paste" (cons "Paste text from clipboard" 'clipboard-yank)))
-  (define-key menu-bar-edit-menu [copy]
-    (cons "Copy" (cons "Copy text in region to the clipboard"
-                      'clipboard-kill-ring-save)))
-  (define-key menu-bar-edit-menu [cut]
-    (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)
@@ -674,13 +684,23 @@ by \"Save Options\" in Custom buffers.")
     ;; put on a customized-value property.
     (dolist (elt '(line-number-mode column-number-mode size-indication-mode
                   cua-mode show-paren-mode transient-mark-mode
-                  blink-cursor-mode display-time-mode display-battery-mode))
+                  blink-cursor-mode display-time-mode display-battery-mode
+                  ;; These are set by other functions that don't set
+                  ;; the customized state.  Having them here has the
+                  ;; side-effect that turning them off via X
+                  ;; resources acts like having customized them, but
+                  ;; that seems harmless.
+                  menu-bar-mode tool-bar-mode))
+      ;; FIXME ? It's a little annoying that running this command
+      ;; always loads cua-base, paren, time, and battery, even if they
+      ;; have not been customized in any way.  (Due to custom-load-symbol.)
       (and (customize-mark-to-save elt)
           (setq need-save t)))
     ;; These are set with `customize-set-variable'.
     (dolist (elt '(scroll-bar-mode
                   debug-on-quit debug-on-error
-                  tooltip-mode menu-bar-mode tool-bar-mode
+                  ;; Somehow this works, when tool-bar and menu-bar don't.
+                  tooltip-mode
                   save-place uniquify-buffer-name-style fringe-mode
                   indicate-empty-lines indicate-buffer-boundaries
                   case-fold-search font-use-system-font
@@ -691,7 +711,7 @@ by \"Save Options\" in Custom buffers.")
                   ;; Nonetheless, not saving it would like be confuse
                   ;; more often.
                   ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2002-02-11.
-                  text-mode-hook))
+                  text-mode-hook tool-bar-position))
       (and (get elt 'customized-value)
           (customize-mark-to-save elt)
           (setq need-save t)))
@@ -703,6 +723,10 @@ by \"Save Options\" in Custom buffers.")
     (when need-save
       (custom-save-all))))
 
+(define-key menu-bar-options-menu [package]
+  '(menu-item "Manage Emacs Packages" package-list-packages
+             :help "Install or uninstall additional Emacs packages"))
+
 (define-key menu-bar-options-menu [save]
   `(menu-item ,(purecopy "Save Options") menu-bar-options-save
              :help ,(purecopy "Save options set from the menu above")))
@@ -975,11 +999,93 @@ mail status in mode line"))
              :help ,(purecopy "Turn menu-bar on/off")
              :button (:toggle . (> (frame-parameter nil 'menu-bar-lines) 0))))
 
-(define-key menu-bar-showhide-menu [showhide-tool-bar]
-  `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
-             :help ,(purecopy "Turn tool-bar on/off")
-             :visible (display-graphic-p)
-             :button (:toggle . (> (frame-parameter nil 'tool-bar-lines) 0))))
+(defun menu-bar-set-tool-bar-position (position)
+  (customize-set-variable 'tool-bar-mode t)
+  (customize-set-variable 'tool-bar-position position))
+(defun menu-bar-showhide-tool-bar-menu-customize-disable ()
+  "Do not display tool bars."
+  (interactive)
+  (customize-set-variable 'tool-bar-mode nil))
+(defun menu-bar-showhide-tool-bar-menu-customize-enable-left ()
+  "Display tool bars on the left side."
+  (interactive)
+  (menu-bar-set-tool-bar-position 'left))
+(defun menu-bar-showhide-tool-bar-menu-customize-enable-right ()
+  "Display tool bars on the right side."
+  (interactive)
+  (menu-bar-set-tool-bar-position 'right))
+(defun menu-bar-showhide-tool-bar-menu-customize-enable-top ()
+  "Display tool bars on the top side."
+  (interactive)
+  (menu-bar-set-tool-bar-position 'top))
+(defun menu-bar-showhide-tool-bar-menu-customize-enable-bottom ()
+  "Display tool bars on the bottom side."
+  (interactive)
+  (menu-bar-set-tool-bar-position 'bottom))
+
+(if (featurep 'move-toolbar)
+    (progn
+      (defvar menu-bar-showhide-tool-bar-menu (make-sparse-keymap "Tool-bar"))
+
+      (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-left]
+       `(menu-item ,(purecopy "On the left") 
+                   menu-bar-showhide-tool-bar-menu-customize-enable-left
+                   :help ,(purecopy "Tool-bar at the left side")
+                   :visible (display-graphic-p)
+                   :button 
+                   (:radio . (and tool-bar-mode 
+                                  (eq (frame-parameter nil 'tool-bar-position)
+                                      'left)))))
+
+      (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-right]
+       `(menu-item ,(purecopy "On the right") 
+                   menu-bar-showhide-tool-bar-menu-customize-enable-right
+                   :help ,(purecopy "Tool-bar at the right side")
+                   :visible (display-graphic-p)
+                   :button
+                   (:radio . (and tool-bar-mode 
+                                  (eq (frame-parameter nil 'tool-bar-position)
+                                      'right)))))
+
+      (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-bottom]
+       `(menu-item ,(purecopy "On the bottom") 
+                   menu-bar-showhide-tool-bar-menu-customize-enable-bottom
+                   :help ,(purecopy "Tool-bar at the bottom")
+                   :visible (display-graphic-p)
+                   :button
+                   (:radio . (and tool-bar-mode 
+                                  (eq (frame-parameter nil 'tool-bar-position)
+                                      'bottom)))))
+
+      (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-top]
+       `(menu-item ,(purecopy "On the top") 
+                   menu-bar-showhide-tool-bar-menu-customize-enable-top
+                   :help ,(purecopy "Tool-bar at the top")
+                   :visible (display-graphic-p)
+                   :button
+                   (:radio . (and tool-bar-mode 
+                                  (eq (frame-parameter nil 'tool-bar-position)
+                                      'top)))))
+
+      (define-key menu-bar-showhide-tool-bar-menu [showhide-tool-bar-none]
+       `(menu-item ,(purecopy "None") 
+                   menu-bar-showhide-tool-bar-menu-customize-disable
+                   :help ,(purecopy "Turn tool-bar off")
+                   :visible (display-graphic-p)
+                   :button (:radio . (eq tool-bar-mode nil))))
+
+      (define-key menu-bar-showhide-menu [showhide-tool-bar]
+       `(menu-item ,(purecopy "Tool-bar") ,menu-bar-showhide-tool-bar-menu
+                   :visible (display-graphic-p)))
+
+      )
+  ;; else not tool bar that can move.
+  (define-key menu-bar-showhide-menu [showhide-tool-bar]
+    `(menu-item ,(purecopy "Tool-bar") toggle-tool-bar-mode-from-frame
+               :help ,(purecopy "Turn tool-bar on/off")
+               :visible (display-graphic-p)
+               :button (:toggle . (> (frame-parameter nil 'tool-bar-lines) 0))))
+)
 
 (define-key menu-bar-options-menu [showhide]
   `(menu-item ,(purecopy "Show/Hide") ,menu-bar-showhide-menu))
@@ -1055,7 +1161,7 @@ mail status in mode line"))
 (define-key menu-bar-options-menu [cua-emulation-mode]
   (menu-bar-make-mm-toggle cua-mode
                           "Shift movement mark region (CUA)"
-                          "Use shifted movement keys to set and extend the region."
+                          "Use shifted movement keys to set and extend the region"
                           (:visible (and (boundp 'cua-enable-cua-keys)
                                          (not cua-enable-cua-keys)))))
 
@@ -1191,6 +1297,9 @@ mail status in mode line"))
 (define-key menu-bar-games-menu [life]
   `(menu-item ,(purecopy "Life")  life
              :help ,(purecopy "Watch how John Conway's cellular automaton evolves")))
+(define-key menu-bar-games-menu [land]
+  `(menu-item ,(purecopy "Landmark") landmark
+             :help ,(purecopy "Watch a neural-network robot learn landmarks")))
 (define-key menu-bar-games-menu [hanoi]
   `(menu-item ,(purecopy "Towers of Hanoi") hanoi
              :help ,(purecopy "Watch Towers-of-Hanoi puzzle solved by Emacs")))
@@ -1400,6 +1509,9 @@ mail status in mode line"))
 (define-key menu-bar-describe-menu [describe-current-display-table]
   `(menu-item ,(purecopy "Describe Display Table") describe-current-display-table
              :help ,(purecopy "Describe the current display table")))
+(define-key menu-bar-describe-menu [describe-package]
+  `(menu-item ,(purecopy "Describe Package...") describe-package
+              :help ,(purecopy "Display documentation of a Lisp package")))
 (define-key menu-bar-describe-menu [describe-face]
   `(menu-item ,(purecopy "Describe Face...") describe-face
               :help ,(purecopy "Display the properties of a face")))
@@ -1500,7 +1612,7 @@ key, a click, or a menu-item")))
 (define-key menu-bar-manuals-menu [emacs-lisp-reference]
   `(menu-item ,(purecopy "Emacs Lisp Reference") menu-bar-read-lispref
              :help ,(purecopy "Read the Emacs Lisp Reference manual")))
-(define-key menu-bar-manuals-menu [emac-lisp-intro]
+(define-key menu-bar-manuals-menu [emacs-lisp-intro]
   `(menu-item ,(purecopy "Introduction to Emacs Lisp") menu-bar-read-lispintro
              :help ,(purecopy "Read the Introduction to Emacs Lisp Programming")))
 
@@ -1531,11 +1643,11 @@ key, a click, or a menu-item")))
 (define-key menu-bar-help-menu [sep2]
   menu-bar-separator)
 (define-key menu-bar-help-menu [external-packages]
-  `(menu-item ,(purecopy "External Packages") menu-bar-help-extra-packages
+  `(menu-item ,(purecopy "Finding Extra Packages") menu-bar-help-extra-packages
              :help ,(purecopy "Lisp packages distributed separately for use in Emacs")))
 (define-key menu-bar-help-menu [find-emacs-packages]
-  `(menu-item ,(purecopy "Find Emacs Packages") finder-by-keyword
-             :help ,(purecopy "Find packages and features by keyword")))
+  `(menu-item ,(purecopy "Search Built-in Packages") finder-by-keyword
+             :help ,(purecopy "Find built-in packages and features by keyword")))
 (define-key menu-bar-help-menu [more-manuals]
   `(menu-item ,(purecopy "More Manuals") ,menu-bar-manuals-menu))
 (define-key menu-bar-help-menu [emacs-manual]
@@ -1920,36 +2032,43 @@ Buffers menu is regenerated."
     `(menu-item ,(purecopy "Previous History Item") previous-history-element
                :help ,(purecopy "Put previous minibuffer history element in the minibuffer"))))
 \f
-;;;###autoload
-;; This comment is taken from 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))
-
 (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."
-  :init-value nil
+  :init-value t
   :global t
   :group 'frames
 
-  ;; Make menu-bar-mode and default-frame-alist consistent.
-  (modify-all-frames-parameters (list (cons 'menu-bar-lines
-                                           (if menu-bar-mode 1 0))))
-
+  ;; Turn the menu-bars on all frames on or off.
+  (let ((val (if menu-bar-mode 1 0)))
+    (dolist (frame (frame-list))
+      (set-frame-parameter frame 'menu-bar-lines val))
+    ;; If the user has given `default-frame-alist' a `menu-bar-lines'
+    ;; parameter, replace it.
+    (if (assq 'menu-bar-lines default-frame-alist)
+       (setq default-frame-alist
+             (cons (cons 'menu-bar-lines val)
+                   (assq-delete-all 'menu-bar-lines
+                                    default-frame-alist)))))
   ;; 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 (called-interactively-p 'interactive) (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)
+                        "Menu-bar mode disabled.  Use M-x menu-bar-mode to make the menu bar appear.")))
+
+;;;###autoload
+;; (This does not work right unless it comes after the above definition.)
+;; This comment is taken from 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 above, but
+;; that would overwrite disabling the menu bar from X resources.
+(put 'menu-bar-mode 'standard-value '(t))
 
 (defun toggle-menu-bar-mode-from-frame (&optional arg)
   "Toggle menu bar on or off, based on the status of the current frame.
@@ -1983,5 +2102,4 @@ If FRAME is nil or not given, use the selected frame."
 
 (provide 'menu-bar)
 
-;; arch-tag: 6e6a3c22-4ec4-4d3d-8190-583f8ef94ced
 ;;; menu-bar.el ends here