+;; The "Options" menu items
+
+(defvar menu-bar-custom-menu (make-sparse-keymap "Customize"))
+
+(define-key menu-bar-custom-menu [customize-apropos-groups]
+ '(menu-item "Groups Matching Regexp..." customize-apropos-groups
+ :help "Browse groups whose names match regexp"))
+(define-key menu-bar-custom-menu [customize-apropos-faces]
+ '(menu-item "Faces Matching Regexp..." customize-apropos-faces
+ :help "Browse faces whose names match regexp"))
+(define-key menu-bar-custom-menu [customize-apropos-options]
+ '(menu-item "Options Matching Regexp..." customize-apropos-options
+ :help "Browse options whose names match regexp"))
+(define-key menu-bar-custom-menu [customize-apropos]
+ '(menu-item "Settings Matching Regexp..." customize-apropos
+ :help "Browse customizable settings whose names match regexp"))
+(define-key menu-bar-custom-menu [separator-2]
+ '("--"))
+(define-key menu-bar-custom-menu [customize-group]
+ '(menu-item "Specific Group..." customize-group
+ :help "Customize settings of specific group"))
+(define-key menu-bar-custom-menu [customize-face]
+ '(menu-item "Specific Face..." customize-face
+ :help "Customize attributes of specific face"))
+(define-key menu-bar-custom-menu [customize-option]
+ '(menu-item "Specific Option..." customize-option
+ :help "Change value of specific option"))
+(define-key menu-bar-custom-menu [customize-changed-options]
+ '(menu-item "Recently Changed Options..." customize-changed-options
+ :help "Customize options changed in recent versions"))
+(define-key menu-bar-custom-menu [separator-3]
+ '("--"))
+(define-key menu-bar-custom-menu [customize-browse]
+ '(menu-item "Browse Customization Groups" customize-browse
+ :help "Browse all customization groups"))
+(define-key menu-bar-custom-menu [customize]
+ '(menu-item "Top-level Customization Group" customize
+ :help "The master group called `Emacs'"))
+
+;(defvar menu-bar-preferences-menu (make-sparse-keymap "Preferences"))
+
+(defmacro menu-bar-make-toggle (name variable doc message help &rest body)
+ `(progn
+ (defun ,name ()
+ ,(concat doc ".")
+ (interactive)
+ (if ,(if body `(progn . ,body)
+ `(setq ,variable (not ,variable)))
+ (message ,message "enabled")
+ (message ,message "disabled")))
+ '(menu-item ,doc ,name
+ :help ,help
+ :button (:toggle . (and (boundp ',variable) ,variable)))))
+
+;;; Assemble all the top-level items of the "Options" menu
+(define-key menu-bar-options-menu [customize]
+ (list 'menu-item "Customize Emacs" menu-bar-custom-menu
+ :help "Full customization of every Emacs feature"))
+
+(defun menu-bar-options-save ()
+ "Save current values of Options menu items using Custom."
+ (interactive)
+ (dolist (elt '(debug-on-quit debug-on-error auto-compression-mode
+ case-fold-search truncate-lines show-paren-mode
+ transient-mark-mode global-font-lock-mode
+ current-language-environment default-input-method))
+ (if (default-value elt)
+ (customize-save-variable elt (default-value elt))))
+ (if (memq 'turn-on-auto-fill text-mode-hook)
+ (customize-save-variable 'text-mode-hook
+ (default-value 'text-mode-hook)))
+ (if (featurep 'saveplace)
+ (customize-save-variable 'save-place (default-value 'save-place)))
+ (if (featurep 'uniquify)
+ (customize-save-variable 'uniquify-buffer-name-style
+ (default-value 'uniquify-buffer-name-style))))
+
+(define-key menu-bar-options-menu [save]
+ '(menu-item "Save Options" menu-bar-options-save
+ :help "Save options set from the menu above"))
+
+(define-key menu-bar-options-menu [custom-separator]
+ '("--"))
+
+(define-key menu-bar-options-menu [mule]
+ ;; It is better not to use backquote here,
+ ;; because that makes a bootstrapping problem
+ ;; if you need to recompile all the Lisp files using interpreted code.
+ (list 'menu-item "Mule (Multilingual Environment)" mule-menu-keymap
+;; Most of the MULE menu actually does make sense in unibyte mode,
+;; e.g. language selection.
+;;; ':visible 'default-enable-multibyte-characters
+ ':help "Default language, encodings, input method"))
+;(setq menu-bar-final-items (cons 'mule menu-bar-final-items))
+;(define-key menu-bar-options-menu [preferences]
+; (list 'menu-item "Preferences" menu-bar-preferences-menu
+; :help "Toggle important global options"))
+
+(define-key menu-bar-options-menu [mule-separator]
+ '("--"))
+
+(define-key menu-bar-options-menu [debug-on-quit]
+ (menu-bar-make-toggle toggle-debug-on-quit debug-on-quit
+ "Enter Debugger on Quit/C-g" "Debug on Quit %s"
+ "Enter Lisp debugger when C-g is pressed"))
+(define-key menu-bar-options-menu [debug-on-error]
+ (menu-bar-make-toggle toggle-debug-on-error debug-on-error
+ "Enter Debugger on Error" "Debug on Error %s"
+ "Enter Lisp debugger when error is signaled"))
+(define-key menu-bar-options-menu [debugger-separator]
+ '("--"))
+(define-key menu-bar-options-menu [toggle-auto-compression]
+ '(menu-item "Automatic File De/compression"
+ auto-compression-mode
+ :help "Transparently decompress compressed files"
+ :button (:toggle . (rassq 'jka-compr-handler
+ file-name-handler-alist))))
+(define-key menu-bar-options-menu [save-place]
+ (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"
+ (require 'saveplace)
+ (setq-default save-place
+ (not (default-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 a buffer name by adding parent directory names until unique"
+ (require 'uniquify)
+ (setq uniquify-buffer-name-style
+ (if (not uniquify-buffer-name-style)
+ 'forward))))
+(define-key menu-bar-options-menu [edit-options-separator]
+ '("--"))
+(define-key menu-bar-options-menu [case-fold-search]
+ (menu-bar-make-toggle toggle-case-fold-search case-fold-search
+ "Case-Insensitive Search"
+ "Case-Insensitive Search %s"
+ "If checked, search ignores letter-case"))
+(define-key menu-bar-options-menu [auto-fill-mode]
+ '(menu-item "Word Wrap in Text Modes (Auto Fill)"
+ toggle-text-mode-auto-fill
+ :help "Automatically fill text between left and right margins"
+ :button (:toggle . (member 'turn-on-auto-fill text-mode-hook))))
+(define-key menu-bar-options-menu [truncate-lines]
+ (menu-bar-make-toggle
+ toggle-truncate-lines truncate-lines
+ "Truncate Long Lines in this Buffer" "Long Line Truncation %s"
+ "If checked, long lines are truncated on the screen"
+ (prog1 (setq truncate-lines (not truncate-lines))
+ (set-buffer-modified-p (buffer-modified-p)))))
+(define-key menu-bar-options-menu [highlight-separator]
+ '("--"))
+(define-key menu-bar-options-menu [highlight-paren-mode]
+ (menu-bar-make-toggle toggle-highlight-paren-mode show-paren-mode
+ "Highlight Matching Parentheses"
+ "Show Paren mode %s"
+ "Highlight matching and mismatched parentheses"))
+(define-key menu-bar-options-menu [transient-mark-mode]
+ (menu-bar-make-toggle toggle-transient-mark-mode transient-mark-mode
+ "Transient Mark Mode (highlights region)"
+ "Transient Mark mode %s"
+ "Highlight the marked region when it's active"))
+(define-key menu-bar-options-menu [toggle-global-lazy-font-lock-mode]
+ (menu-bar-make-toggle toggle-global-lazy-font-lock-mode global-font-lock-mode
+ "Highlight Syntax (Global Font Lock)"
+ "Syntax Highlighting %s"
+ "Highlights text based on language syntax"
+ (global-font-lock-mode)))
+
+\f
+;; The "Tools" menu items
+
+(defun send-mail-item-name ()
+ (let* ((known-send-mail-commands '((sendmail-user-agent . "sendmail")
+ (mh-e-user-agent . "MH")
+ (message-user-agent . "Gnus Message")
+ (gnus-user-agent . "Gnus")))
+ (name (assq mail-user-agent known-send-mail-commands)))
+ (if name
+ (setq name (cdr name))
+ (setq name (symbol-name mail-user-agent))
+ (if (string-match "\\(.+\\)-user-agent" name)
+ (setq name (match-string 1 name))))
+ name))
+
+(defun read-mail-item-name ()
+ (let* ((known-rmail-commands '((rmail . "RMAIL")
+ (mh-rmail . "MH")
+ (gnus . "Gnus")))
+ (known (assq read-mail-command known-rmail-commands)))
+ (if known (cdr known) (symbol-name read-mail-command))))
+
+(defvar menu-bar-games-menu (make-sparse-keymap "Games"))
+
+(define-key menu-bar-tools-menu [games]
+ (list 'menu-item "Games" menu-bar-games-menu))
+
+(define-key menu-bar-tools-menu [separator-games]
+ '("--"))
+
+(define-key menu-bar-games-menu [zone]
+ '(menu-item "Zone Out" zone
+ :help "Play tricks with Emacs display when Emacs is idle"))
+(define-key menu-bar-games-menu [yow]
+ '(menu-item "Random Quotation" yow
+ :help "Display a random Zippy quotation"))
+(define-key menu-bar-games-menu [tetris]
+ '(menu-item "Tetris" tetris))
+(define-key menu-bar-games-menu [solitaire]
+ '(menu-item "Solitaire" solitaire))
+(define-key menu-bar-games-menu [snake]
+ '(menu-item "Snake" snake
+ :help "Move snake around avoiding collisions"))
+(define-key menu-bar-games-menu [mult]
+ '(menu-item "Multiplication Puzzle" mpuz
+ :help "Excercise brain with multiplication"))
+(define-key menu-bar-games-menu [life]
+ '(menu-item "Life" life
+ :help "Watch how John Conway's cellular automaton evolves"))
+(define-key menu-bar-games-menu [hanoi]
+ '(menu-item "Towers of Hanoi" hanoi
+ :help "Watch Towers-of-Hanoi puzzle solved by Emacs"))
+(define-key menu-bar-games-menu [gomoku]
+ '(menu-item "Gomoku" gomoku
+ :help "Mark 5 contiguous squares (like tic-tac-toe)"))
+(define-key menu-bar-games-menu [black-box]
+ '(menu-item "Blackbox" blackbox
+ :help "Find balls in a black box by shooting rays"))
+(define-key menu-bar-games-menu [adventure]
+ '(menu-item "Adventure" dunnet
+ :help "Dunnet, a text Adventure game for Emacs"))
+(define-key menu-bar-games-menu [5x5]
+ '(menu-item "5x5" 5x5
+ :help "Fill in all the squares on a 5x5 board"))
+
+(define-key menu-bar-tools-menu [calendar]
+ '(menu-item "Display Calendar" calendar))
+(define-key menu-bar-tools-menu [speedbar]
+ '(menu-item "Display Speedbar" speedbar-frame-mode))
+(define-key menu-bar-tools-menu [directory-search]
+ '(menu-item "Directory Search" eudc-tools-menu
+ :help "Query directory servers via LDAP, CCSO PH/QI or BBDB"))
+(define-key menu-bar-tools-menu [compose-mail]
+ (list
+ 'menu-item `(format "Send Mail (with %s)" (send-mail-item-name))
+ 'compose-mail
+ :visible `(and mail-user-agent (not (eq mail-user-agent 'ignore)))
+ :help "Send a mail message"))
+(define-key menu-bar-tools-menu [rmail]
+ (list
+ 'menu-item `(format "Read Mail (with %s)" (read-mail-item-name))
+ (lambda ()
+ (interactive)
+ (call-interactively read-mail-command))
+ :visible `(and read-mail-command (not (eq read-mail-command 'ignore)))
+ :help "Read your mail and reply to it"))
+(define-key menu-bar-tools-menu [gnus]
+ '(menu-item "Read Net News (Gnus)" gnus
+ :help "Read network news groups"))
+
+(define-key menu-bar-tools-menu [separator-vc]
+ '("--"))
+
+(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"))
+(define-key menu-bar-tools-menu [vc]
+ (list 'menu-item "Version Control" vc-menu-map
+ :help "Interface to RCS, CVS, SCCS"))
+
+(define-key menu-bar-tools-menu [separator-compare]
+ '("--"))
+
+(define-key menu-bar-tools-menu [ediff-misc]
+ '(menu-item "Ediff Miscellanea" menu-bar-ediff-misc-menu
+ :help "Ediff manual, customization, sessions, etc."))
+(define-key menu-bar-tools-menu [epatch]
+ '(menu-item "Apply Patch" menu-bar-epatch-menu))
+(define-key menu-bar-tools-menu [ediff-merge]
+ '(menu-item "Merge" menu-bar-ediff-merge-menu
+ :help "Merge different revisions of files/directories"))
+(define-key menu-bar-tools-menu [compare]
+ '(menu-item "Compare (Ediff)" menu-bar-ediff-menu
+ :help "Display differences between files/directories"))
+
+
+(define-key menu-bar-tools-menu [separator-spell]
+ '("--"))
+
+(define-key menu-bar-tools-menu [spell]
+ '(menu-item "Spell Checking" ispell-menu-map))
+
+(define-key menu-bar-tools-menu [separator-prog]
+ '("--"))
+
+(define-key menu-bar-tools-menu [gdb]
+ '(menu-item "Debugger (GUD)..." gdb
+ :help "Debug a program from within Emacs"))
+(define-key menu-bar-tools-menu [shell-on-region]
+ '(menu-item "Shell Command on Region..." shell-command-on-region
+ :enable mark-active
+ :help "Pass marked region to a shell command"))
+(define-key menu-bar-tools-menu [shell]
+ '(menu-item "Shell Command..." shell-command
+ :help "Invoke a shell command and catch its output"))
+(define-key menu-bar-tools-menu [compile]
+ '(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)"))
+
+\f
+;; The "Help" menu items
+
+(defvar menu-bar-describe-menu (make-sparse-keymap "Describe"))
+
+(define-key menu-bar-describe-menu [mule-diag]
+ '(menu-item "Show All of Mule Status" mule-diag
+ :visible default-enable-multibyte-characters
+ :help "Display multilingual environment settings"))
+(define-key menu-bar-describe-menu [describe-coding-system]
+ '(menu-item "Describe Coding System..." describe-coding-system
+ :visible default-enable-multibyte-characters))
+(define-key menu-bar-describe-menu [describe-input-method]
+ '(menu-item "Describe Input Method..." describe-input-method
+ :visible default-enable-multibyte-characters
+ :help "Keyboard layout for specific input method"))
+(define-key menu-bar-describe-menu [describe-language-environment]
+ (list 'menu-item "Describe Language Environment"
+ describe-language-environment-map
+ :help "Show multilingual settings for a specific language"))
+
+(define-key menu-bar-describe-menu [separator-desc-mule]
+ '("--"))
+
+(define-key menu-bar-describe-menu [list-keybindings]
+ '(menu-item "List Key Bindings" describe-bindings
+ :help "Display a list of all current keybindings"))
+(define-key menu-bar-describe-menu [list-keybindings]
+ '(menu-item "List Key Bindings" describe-bindings
+ :help "Display a list of all current keybindings"))
+(define-key menu-bar-describe-menu [describe-variable]
+ '(menu-item "Describe Variable..." describe-variable
+ :help "Display documentation of variable/option"))
+(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]
+ '(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 [apropos-variables]
+ '(menu-item "Apropos Variables..." apropos-variable
+ :help "List variables whose names match a regexp"))
+(define-key menu-bar-describe-menu [apropos-commands]
+ '(menu-item "Apropos Commands..." apropos-command
+ :help "List commands whose names match a regexp"))
+(define-key menu-bar-describe-menu [describe-mode]
+ '(menu-item "Describe Buffer Modes" describe-mode
+ :help "Describe this buffer's major and minor mode"))
+
+(defvar menu-bar-manuals-menu (make-sparse-keymap "Manuals"))
+
+(define-key menu-bar-manuals-menu [man]
+ '(menu-item "Read Man Page..." manual-entry
+ :help "Man-page docs for external commands and libraries"))
+(define-key menu-bar-manuals-menu [sep2]
+ '("--"))
+(define-key menu-bar-manuals-menu [info]
+ '(menu-item "Browse Manuals with Info" Info-directory
+ :help "Read any of the installed manuals"))
+(define-key menu-bar-manuals-menu [command]
+ '(menu-item "Find Command in Manual" Info-goto-emacs-command-node
+ :help "Display manual section that describes a command"))
+(define-key menu-bar-manuals-menu [key]
+ '(menu-item "Find Key in Manual" Info-goto-emacs-key-command-node
+ :help "Display manual section that describes a key"))
+
+(define-key menu-bar-help-menu [eliza]
+ '(menu-item "Emacs Psychiatrist" doctor
+ :help "Our doctor will help you feel better"))
+(define-key menu-bar-help-menu [sep3]
+ '("--"))
+(define-key menu-bar-help-menu [describe-no-warranty]
+ '(menu-item "(Non)Warranty" describe-no-warranty
+ :help "Explain that Emacs has NO WARRANTY"))
+(define-key menu-bar-help-menu [describe-copying]
+ '(menu-item "Copying Conditions" describe-copying
+ :help "Show the Emacs license (GPL)"))
+(define-key menu-bar-help-menu [describe-distribution]
+ '(menu-item "Getting New Versions" describe-distribution
+ :help "How to get latest versions of Emacs"))
+(define-key menu-bar-help-menu [more]
+ '(menu-item "Find Extra Packages"
+ (lambda ()
+ (interactive)
+ (let (enable-local-variables)
+ (view-file (expand-file-name "MORE.STUFF"
+ data-directory))
+ (goto-address)))
+ :help "Where to find some extra packages and possible updates"))