Subject: bug#4528: list/term/ns-win.el should not fiddle with the standard menus

From: Dan Nicolaescu <[email-masked]>
Date: Tue, 22 Sep 2009 14:48:55 -0700 (PDT)

The code below in list/term/ns-win.el is better put in menu-bar.el where
the menus are defined, just make it conditional there.

That would avoid having to preload easymenu.el on this platform (no
other platform does that) and would simplify the code (no need to play
games with removing menu items).

;; Add a couple of menus and rearrange some others; easiest just to redo toplvl
;; Note keymap defns must be given last-to-first
(define-key global-map [menu-bar] (make-sparse-keymap "menu-bar"))

(setq menu-bar-final-items
      (cond ((eq system-type 'darwin)
             '(buffer windows services help-menu))
            ;; Otherwise, GNUstep.
            (t
             '(buffer windows services hide-app quit))))

;; Add standard top-level items to GNUstep menu.
(unless (eq system-type 'darwin)
  (define-key global-map [menu-bar quit] '("Quit" . save-buffers-kill-emacs))
  (define-key global-map [menu-bar hide-app] '("Hide" . ns-do-hide-emacs)))

(define-key global-map [menu-bar services]
  (cons "Services" (make-sparse-keymap "Services")))
(define-key global-map [menu-bar buffer]
  (cons "Buffers" global-buffers-menu-map))
;;  (cons "Buffers" (make-sparse-keymap "Buffers")))
(define-key global-map [menu-bar tools] (cons "Tools" menu-bar-tools-menu))
(define-key global-map [menu-bar options] (cons "Options" menu-bar-options-menu))
(define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
(define-key global-map [menu-bar file] (cons "File" menu-bar-file-menu))

;; If running under GNUstep, rename "Help" to "Info"
(cond ((eq system-type 'darwin)
       (define-key global-map [menu-bar help-menu]
        (cons "Help" menu-bar-help-menu)))
      (t
       (let ((contents (reverse (cdr menu-bar-help-menu))))
        (setq menu-bar-help-menu
               (append (list 'keymap) (cdr contents) (list "Info"))))
       (define-key global-map [menu-bar help-menu]
        (cons "Info" menu-bar-help-menu))))

(if (not (eq system-type 'darwin))
    ;; in OS X it's in the app menu already
    (define-key menu-bar-help-menu [info-panel]
      '("About Emacs..." . ns-do-emacs-info-panel)))

;;;; Edit menu: Modify slightly

;; Substitute a Copy function that works better under X (for GNUstep).
(easy-menu-remove-item global-map '("menu-bar" "edit") 'copy)
(define-key-after menu-bar-edit-menu [copy]
  '(menu-item "Copy" ns-copy-including-secondary
    :enable mark-active
    :help "Copy text in region between mark and current position")
  'cut)

;; Change to same precondition as select-and-paste, as we don't have
;; `x-selection-exists-p'.
(easy-menu-remove-item global-map '("menu-bar" "edit") 'paste)
(define-key-after menu-bar-edit-menu [paste]
  '(menu-item "Paste" yank
    :enable (and (cdr yank-menu) (not buffer-read-only))
    :help "Paste (yank) text most recently cut/copied")
  'copy)

;; Change text to be more consistent with surrounding menu items `paste', etc.
(easy-menu-remove-item global-map '("menu-bar" "edit") 'paste-from-menu)
(define-key-after menu-bar-edit-menu [select-paste]
  '(menu-item "Select and Paste" yank-menu
    :enable (and (cdr yank-menu) (not buffer-read-only))
    :help "Choose a string from the kill ring and paste it")
  'paste)