Fix crash when using ffmpeg to play mp3 and ogg
[sxemacs] / lisp / menubar-items.el
1 ;;; menubar-items.el --- Menubar and popup-menu content for SXEmacs.
2
3 ;; Copyright (C) 1991-1995, 1997-1998 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
5 ;; Copyright (C) 1995 Sun Microsystems.
6 ;; Copyright (C) 1995, 1996, 2000 Ben Wing.
7 ;; Copyright (C) 1997 MORIOKA Tomohiko.
8
9 ;; Maintainer: SXEmacs Development Team
10 ;; Keywords: frames, extensions, internal, dumped
11
12 ;; This file is part of SXEmacs.
13
14 ;; SXEmacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
18
19 ;; SXEmacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27 ;;; Authorship:
28
29 ;; Created c. 1991 for Lucid Emacs.  Originally called x-menubar.el.
30 ;;   Contained four menus -- File, Edit, Buffers, Help.
31 ;;   Dynamic menu changes possible only through activate-menubar-hook.
32 ;;   Also contained menu manipulation funs, e.g. find-menu-item, add-menu.
33 ;; Options menu added for 19.9 by Jamie Zawinski, late 1993.
34 ;; Major reorganization c. 1994 by Ben Wing; added many items and moved
35 ;;   some items to two new menus, Apps and Tools. (for 19.10?)
36 ;; Generic menubar functions moved to new file, menubar.el, by Ben Wing,
37 ;;   1995, for 19.12; also, creation of current buffers menu options,
38 ;;   and buffers menu changed from purely most-recent to sorted alphabetical,
39 ;;   by mode.  Also added mode-popup-menu support.
40 ;; New API (add-submenu, add-menu-button) and menu filter support added
41 ;;   late summer 1995 by Stig, for 19.13.  Also popup-menubar-menu.
42 ;; Renamed to menubar-items.el c. 1998, with MS Win support.
43 ;; Options menu rewritten to use custom c. 1999 by ? (Jan Vroonhof?).
44 ;; Major reorganization Mar. 2000 by Ben Wing; added many items and changed
45 ;;   top-level menus to File, Edit, View, Cmds, Tools, Options, Buffers.
46 ;; Accelerator spec functionality added Mar. 2000 by Ben Wing.
47
48 ;;; Commentary:
49
50 ;; This file is dumped with SXEmacs (when window system and menubar support is
51 ;; compiled in).
52
53 ;;; Code:
54
55 (defun Menubar-items-truncate-history (list count label-length)
56   "Truncate a history LIST to first COUNT items.
57 Return a list of (label value) lists with labels truncated to last
58 LABEL-LENGTH characters of value."
59   (mapcar #'(lambda (x)
60               (if (<= (length x) label-length)
61                   (list x x)
62                 (list
63                  (concat "..." (substring x (- label-length))) x)))
64           (if (<= (length list) count)
65               list
66             (butlast list (- (length list) count)))))
67
68 (defun submenu-generate-accelerator-spec (list &optional omit-chars-list)
69   "Add auto-generated accelerator specifications to a submenu.
70 This can be used to add accelerators to the return value of a menu filter
71 function.  It correctly ignores unselectable items.  It will destructively
72 modify the list passed to it.  If an item already has an auto-generated
73 accelerator spec, this will be removed before the new one is added, making
74 this function idempotent.
75
76 If OMIT-CHARS-LIST is given, it should be a list of lowercase characters,
77 which will not be used as accelerators."
78   (let ((n 0))
79     (dolist (item list list)
80       (cond
81        ((vectorp item)
82         (setq n (1+ n))
83         (aset item 0
84               (concat
85                (menu-item-generate-accelerator-spec n omit-chars-list)
86                (menu-item-strip-accelerator-spec (aref item 0)))))
87        ((consp item)
88         (setq n (1+ n))
89         (setcar item
90                 (concat
91                  (menu-item-generate-accelerator-spec n omit-chars-list)
92                  (menu-item-strip-accelerator-spec (car item)))))))))
93
94 (defun menu-item-strip-accelerator-spec (item)
95   "Strip an auto-generated accelerator spec off of ITEM.
96 ITEM should be a string.  This removes specs added by
97 `menu-item-generate-accelerator-spec' and `submenu-generate-accelerator-spec'."
98   (if (string-match "%_. " item)
99       (substring item 4)
100     item))
101
102 (defun menu-item-generate-accelerator-spec (n &optional omit-chars-list)
103   "Return an accelerator specification for use with auto-generated menus.
104 This should be concat'd onto the beginning of each menu line.  The spec
105 allows the Nth line to be selected by the number N.  '0' is used for the
106 10th line, and 'a' through 'z' are used for the following 26 lines.
107
108 If OMIT-CHARS-LIST is given, it should be a list of lowercase characters,
109 which will not be used as accelerators."
110   (cond ((< n 10) (concat "%_" (int-to-string n) " "))
111         ((= n 10) "%_0 ")
112         ((<= n 36)
113          (setq n (- n 10))
114          (let ((m 0))
115            (while (> n 0)
116              (setq m (1+ m))
117              (while (memq (int-to-char (+ m (- (char-to-int ?a) 1)))
118                           omit-chars-list)
119                (setq m (1+ m)))
120              (setq n (1- n)))
121            (if (<= m 26)
122                (concat
123                 "%_"
124                 (char-to-string (int-to-char (+ m (- (char-to-int ?a) 1))))
125                 " ")
126              "")))
127         (t "")))
128
129 (defcustom menu-max-items 25
130   "*Maximum number of items in generated menus.
131 If number of entries in such a menu is larger than this value, split menu
132 into submenus of nearly equal length (see `menu-submenu-max-items').  If
133 nil, never split menu into submenus."
134   :group 'menu
135   :type '(choice (const :tag "no submenus" nil)
136                  (integer)))
137
138 (defcustom menu-submenu-max-items 20
139   "*Maximum number of items in submenus when splitting menus.
140 We split large menus into submenus of this many items, and then balance
141 them out as much as possible (otherwise the last submenu may have very few
142 items)."
143   :group 'menu
144   :type 'integer)
145
146 (defcustom menu-submenu-name-format "%-12.12s ... %.12s"
147   "*Format specification of the submenu name when splitting menus.
148 Used by `menu-split-long-menu' if the number of entries in a menu is
149 larger than `menu-menu-max-items'.
150 This string should contain one %s for the name of the first entry and
151 one %s for the name of the last entry in the submenu.
152 If the value is a function, it should return the submenu name.  The
153 function is be called with two arguments, the names of the first and
154 the last entry in the menu."
155   :group 'menu
156   :type '(choice (string :tag "Format string")
157                  (function)))
158
159 (defun menu-split-long-menu (menu)
160   "Split MENU according to `menu-max-items' and add accelerator specs.
161
162 You should normally use the idiom
163
164 \(menu-split-long-menu (menu-sort-menu menu))
165
166 See also `menu-sort-menu'."
167   (let ((len (length menu)))
168     (if (or (null menu-max-items)
169             (<= len menu-max-items))
170         (submenu-generate-accelerator-spec menu)
171       (let* ((outer (/ (+ len (1- menu-submenu-max-items))
172                        menu-submenu-max-items))
173              (inner (/ (+ len (1- outer)) outer))
174              (result nil))
175         (while menu
176           (let ((sub nil)
177                 (from (car menu)))
178             (dotimes (foo (min inner len))
179               (setq sub  (cons (car menu) sub)
180                     menu (cdr menu)))
181             (setq len (- len inner))
182             (let ((to (car sub)))
183               (setq sub (nreverse sub))
184               (setq result
185                     (cons (cons (if (stringp menu-submenu-name-format)
186                                     (format menu-submenu-name-format
187                                             (menu-item-strip-accelerator-spec
188                                              (aref from 0))
189                                             (menu-item-strip-accelerator-spec
190                                              (aref to 0)))
191                                   (funcall menu-submenu-name-format
192                                            (menu-item-strip-accelerator-spec
193                                             (aref from 0))
194                                            (menu-item-strip-accelerator-spec
195                                             (aref to 0))))
196                                 (submenu-generate-accelerator-spec sub))
197                           result)))))
198         (submenu-generate-accelerator-spec (nreverse result))))))
199
200 (defun menu-sort-menu (menu)
201   "Sort MENU alphabetically.
202
203 You should normally use the idiom
204
205 \(menu-split-long-menu (menu-sort-menu menu))
206
207 See also `menu-split-long-menu'."
208   (sort menu
209         #'(lambda (a b) (string-lessp (aref a 0) (aref b 0)))))
210
211 (defun menu-item-search ()
212   "Bring up a search dialog if possible and desired, else do interactive search"
213   (interactive)
214   (if (should-use-dialog-box-p)
215       (make-search-dialog)
216     (isearch-forward)))
217
218 (defconst default-menubar
219 ; (purecopy-menubar ;purespace is dead
220    ;; note backquote.
221    `(
222      ("%_File"
223       ["%_Open..." find-file]
224       ["Open in Other %_Window..." find-file-other-window]
225       ["Open in New %_Frame..." find-file-other-frame]
226       ["%_Hex Edit File..." hexl-find-file
227        :active (fboundp 'hexl-find-file)]
228       ["%_Insert File..." insert-file]
229       ["%_View File..." view-file]
230       "------"
231       ["%_Save" save-buffer
232        :active (buffer-modified-p)
233        :suffix (if put-buffer-names-in-file-menu (buffer-name) "")]
234       ["Save %_As..." write-file]
235       ["Save So%_me Buffers" save-some-buffers]
236       "-----"
237       ,@(if (valid-specifier-tag-p 'msprinter)
238           '(["Page Set%_up..." generic-page-setup]))
239       ["%_Print" generic-print-buffer
240        :active (or (valid-specifier-tag-p 'msprinter)
241                    (and (not (eq system-type 'windows-nt))
242                         (fboundp 'lpr-region)))
243        :suffix (if (region-active-p) "Selection..."
244                  (if put-buffer-names-in-file-menu (concat (buffer-name) "...")
245                    "..."))]
246       ,@(unless (valid-specifier-tag-p 'msprinter)
247           '(["Prett%_y-Print" ps-print-buffer-with-faces
248              :active (fboundp 'ps-print-buffer-with-faces)
249              :suffix (if put-buffer-names-in-file-menu (buffer-name) "")]))
250       "-----"
251       ["%_Revert Buffer" revert-buffer
252        :active (or buffer-file-name revert-buffer-function)
253        :suffix (if put-buffer-names-in-file-menu (buffer-name) "")]
254       ["Re%_cover File..." recover-file]
255       ["Recover S%_ession..." recover-session]
256       "-----"
257       ["E%_xit SXEmacs" save-buffers-kill-emacs]
258       )
259
260      ("%_Edit"
261       ["%_Undo" advertised-undo
262        :active (and (not (eq buffer-undo-list t))
263                     (or buffer-undo-list pending-undo-list))
264        :suffix (if (or (eq last-command 'undo)
265                        (eq last-command 'advertised-undo))
266                    "More" "")]
267       ["%_Redo" redo
268        :included (fboundp 'redo)
269        :active (not (or (eq buffer-undo-list t)
270                         (eq last-buffer-undo-list nil)
271                         (not (or (eq last-buffer-undo-list buffer-undo-list)
272                                  (and (null (car-safe buffer-undo-list))
273                                       (eq last-buffer-undo-list
274                                           (cdr-safe buffer-undo-list)))))
275                         (or (eq buffer-undo-list pending-undo-list)
276                             (eq (cdr buffer-undo-list) pending-undo-list))))
277        :suffix (if (eq last-command 'redo) "More" "")]
278       "----"
279       ["Cu%_t" kill-primary-selection
280        :active (selection-owner-p)]
281       ["%_Copy" copy-primary-selection
282        :active (selection-owner-p)]
283       ["%_Paste" yank-clipboard-selection
284        :active (selection-exists-p 'CLIPBOARD)]
285       ["%_Delete" delete-primary-selection
286        :active (selection-owner-p)]
287       "----"
288       ["Select %_All" mark-whole-buffer]
289       ["Select Pa%_ge" mark-page]
290       "----"
291       ["%_Find..." menu-item-search]
292       ["R%_eplace..." query-replace]
293       ["Replace (Rege%_xp)..." query-replace-regexp]
294       ["%_List Matching Lines..." list-matching-lines]
295       ,@(when (featurep 'mule)
296          '("----"
297            ("%_Multilingual (\"Mule\")"
298             ("%_Describe Language Support")
299             ("%_Set Language Environment")
300             "--"
301             ["T%_oggle Input Method" toggle-input-method]
302             ["Select %_Input Method" set-input-method]
303             ["D%_escribe Input Method" describe-input-method]
304             "--"
305             ["Describe Current %_Coding Systems"
306              describe-current-coding-system]
307             ["Set Coding System of %_Buffer File..."
308              set-buffer-file-coding-system]
309             ;; not implemented yet
310             ["Set Coding System of %_Terminal..."
311              set-terminal-coding-system :active nil]
312             ;; not implemented yet
313             ["Set Coding System of %_Keyboard..."
314              set-keyboard-coding-system :active nil]
315             ["Set Coding System of %_Process..."
316              set-buffer-process-coding-system
317              :active (get-buffer-process (current-buffer))]
318             "--"
319             ["Show Cha%_racter Table" view-charset-by-menu]
320             ;; not implemented yet
321             ["Show Dia%_gnosis for MULE" mule-diag :active nil]
322             ["Show \"%_hello\" in Many Languages" view-hello-file]))
323          )
324       )
325
326      ("%_View"
327       ["%_New Frame" make-frame]
328       ["Frame on Other Displa%_y..." make-frame-on-display
329        :active (fboundp 'make-frame-on-display)]
330       ["%_Delete Frame" delete-frame
331        :active (not (eq (next-frame (selected-frame) 'nomini 'window-system)
332                         (selected-frame)))]
333       "-----"
334       ["%_Split Window" split-window-vertically]
335       ["S%_plit Window (Side by Side)" split-window-horizontally]
336       ["%_Un-Split (Keep This)" delete-other-windows
337        :active (not (one-window-p t))]
338       ["Un-Split (Keep %_Others)" delete-window
339        :active (not (one-window-p t))]
340       "----"
341       ("N%_arrow"
342        ["%_Narrow to Region" narrow-to-region :active (region-exists-p)]
343        ["Narrow to %_Page" narrow-to-page]
344        ["Narrow to %_Defun" narrow-to-defun]
345       "----"
346        ["%_Widen" widen :active (or (/= (point-min) 1)
347                                     (/= (point-max) (1+ (buffer-size))))]
348        )
349       "----"
350       ["Show Message %_Log" show-message-log]
351       "----"
352       ["%_Goto Line..." goto-line]
353       ["%_What Line" what-line]
354       ("%_Bookmarks"
355        :filter bookmark-menu-filter)
356       "----"
357       ["%_Jump to Previous Mark" (set-mark-command t)
358        :active (mark t)]
359       )
360
361      ("C%_mds"
362       ["Repeat %_Last Complex Command..." repeat-complex-command]
363       ["E%_valuate Lisp Expression..." eval-expression]
364       ["Execute %_Named Command..." execute-extended-command]
365       "----"
366       ["Start %_Macro Recording" start-kbd-macro
367        :included (not defining-kbd-macro)]
368       ["End %_Macro Recording" end-kbd-macro
369        :included defining-kbd-macro]
370       ["E%_xecute Last Macro" call-last-kbd-macro
371        :active last-kbd-macro]
372       ("%_Other Macro"
373        ["%_Append to Last Macro" (start-kbd-macro t)
374         :active (and (not defining-kbd-macro) last-kbd-macro)]
375        ["%_Query User During Macro" kbd-macro-query
376         :active defining-kbd-macro]
377        ["Enter %_Recursive Edit During Macro" (kbd-macro-query t)
378         :active defining-kbd-macro]
379        "---"
380        ["E%_xecute Last Macro on Region Lines"
381         :active (and last-kbd-macro (region-exists-p))]
382        "---"
383        ["%_Name Last Macro..." name-last-kbd-macro
384         :active last-kbd-macro]
385        ["Assign Last Macro to %_Key..." assign-last-kbd-macro-to-key
386         :active (and last-kbd-macro
387                      (fboundp 'assign-last-kbd-macro-to-key))]
388        "---"
389        ["%_Edit Macro..." edit-kbd-macro]
390        ["Edit %_Last Macro" edit-last-kbd-macro
391         :active last-kbd-macro]
392        "---"
393        ["%_Insert Named Macro into Buffer..." insert-kbd-macro]
394        ["Read Macro from Re%_gion" read-kbd-macro
395         :active (region-exists-p)]
396        )
397       "----"
398       ("%_Abbrev"
399        ["D%_ynamic Abbrev Expand" dabbrev-expand]
400        ["Dynamic Abbrev %_Complete" dabbrev-completion]
401        ["Dynamic Abbrev Complete in %_All Buffers" (dabbrev-completion 16)]
402        "----"
403        "----"
404        ["%_Define Global Abbrev for " add-global-abbrev
405         :suffix (abbrev-string-to-be-defined nil)
406         :active abbrev-mode]
407        ["Define %_Mode-Specific Abbrev for " add-mode-abbrev
408         :suffix (abbrev-string-to-be-defined nil)
409         :active abbrev-mode]
410        ["Define Global Ex%_pansion for " inverse-add-global-abbrev
411         :suffix (inverse-abbrev-string-to-be-defined 1)
412         :active abbrev-mode]
413        ["Define Mode-Specific Expa%_nsion for " inverse-add-mode-abbrev
414         :suffix (inverse-abbrev-string-to-be-defined 1)
415         :active abbrev-mode]
416        "---"
417        ["E%_xpand Abbrev" expand-abbrev]
418        ["Expand Abbrevs in Re%_gion" expand-region-abbrevs
419         :active (region-exists-p)]
420        ["%_Unexpand Last Abbrev" unexpand-abbrev
421         :active (and (stringp last-abbrev-text)
422                      (> last-abbrev-location 0))]
423        "---"
424        ["%_Kill All Abbrevs" kill-all-abbrevs]
425        ["%_Insert All Abbrevs into Buffer" insert-abbrevs]
426        ["%_List Abbrevs" list-abbrevs]
427        "---"
428        ["%_Edit Abbrevs" edit-abbrevs]
429        ["%_Redefine Abbrevs from Buffer" edit-abbrevs-redefine
430         :active (eq major-mode 'edit-abbrevs-mode)]
431        "---"
432        ["%_Save Abbrevs As..." write-abbrev-file]
433        ["L%_oad Abbrevs..." read-abbrev-file]
434        )
435       ("%_Register"
436        ["%_Copy to Register..." copy-to-register :active (region-exists-p)]
437        ["%_Paste Register..." insert-register]
438        "---"
439        ["%_Save Point to Register" point-to-register]
440        ["%_Jump to Register"  register-to-point]
441        )
442       ("R%_ectangles"
443        ["%_Kill Rectangle" kill-rectangle]
444        ["%_Yank Rectangle" yank-rectangle]
445        ["Rectangle %_to Register" copy-rectangle-to-register]
446        ["Rectangle %_from Register" insert-register]
447        ["%_Clear Rectangle" clear-rectangle]
448        ["%_Open Rectangle" open-rectangle]
449        ["%_Prefix Rectangle..." string-rectangle]
450        ["Rectangle %_Mousing"
451         (customize-set-variable 'mouse-track-rectangle-p
452                                 (not mouse-track-rectangle-p))
453         :style toggle :selected mouse-track-rectangle-p]
454        )
455       ("%_Sort"
456        ["%_Lines in Region" sort-lines :active (region-exists-p)]
457        ["%_Paragraphs in Region" sort-paragraphs :active (region-exists-p)]
458        ["P%_ages in Region" sort-pages :active (region-exists-p)]
459        ["%_Columns in Region" sort-columns :active (region-exists-p)]
460        ["%_Regexp..." sort-regexp-fields :active (region-exists-p)]
461        )
462       ("%_Change Case"
463        ["%_Upcase Region" upcase-region :active (region-exists-p)]
464        ["%_Downcase Region" downcase-region :active (region-exists-p)]
465        ["%_Capitalize Region" capitalize-region :active (region-exists-p)]
466        ["%_Title-Case Region" capitalize-region-as-title
467         :active (region-exists-p)]
468        )
469       ("Ce%_nter"
470        ["%_Line" center-line]
471        ["%_Paragraph" center-paragraph]
472        ["%_Region" center-region :active (region-exists-p)]
473        )
474       ("%_Indent"
475        ["%_As Previous Line" indent-relative]
476        ["%_To Column..." indent-to-column]
477        "---"
478        ["%_Region" indent-region :active (region-exists-p)]
479        ["%_Balanced Expression" indent-sexp]
480        ["%_C Expression" indent-c-exp]
481        )
482       ("S%_pell-Check"
483        ["%_Buffer" ispell-buffer
484         :active (fboundp 'ispell-buffer)]
485        "---"
486        ["%_Word" ispell-word]
487        ["%_Complete Word" ispell-complete-word]
488        ["%_Region" ispell-region]
489        )
490       )
491
492      ("%_Tools"
493       ("%_Packages"
494        ("%_Set Download Site"
495         ("%_Official Releases"
496          :filter (lambda (&rest junk)
497                    (menu-split-long-menu
498                     (submenu-generate-accelerator-spec
499                      (package-ui-download-menu)))))
500         ("%_Pre-Releases"
501          :filter (lambda (&rest junk)
502                    (menu-split-long-menu
503                     (submenu-generate-accelerator-spec
504                      (package-ui-pre-release-download-menu)))))
505         ("%_Site Releases"
506          :filter (lambda (&rest junk)
507                    (menu-split-long-menu
508                     (submenu-generate-accelerator-spec
509                      (package-ui-site-release-download-menu))))))
510        "--:shadowEtchedIn"
511        ["%_Update Package Index" package-get-update-base]
512        ["%_List and Install" pui-list-packages]
513        ["U%_pdate Installed Packages" package-get-update-all]
514        ["%_Help" (Info-goto-node "(xemacs)Packages")])
515       ("%_Internet"
516        ["Read Mail %_1 (VM)..." vm
517         :active (fboundp 'vm)]
518        ["Read Mail %_2 (MH)..." (mh-rmail t)
519         :active (fboundp 'mh-rmail)]
520        ["Send %_Mail..." compose-mail
521         :active (fboundp 'compose-mail)]
522        ["Usenet %_News" gnus
523         :active (fboundp 'gnus)]
524        ["Browse the %_Web" w3
525         :active (fboundp 'w3)])
526       "---"
527       ("%_Grep"
528        :filter
529        (lambda (menu)
530          (if (or (not (boundp 'grep-history)) (null grep-history))
531              menu
532            (let ((items
533                   (submenu-generate-accelerator-spec
534                    (mapcar #'(lambda (label-value)
535                                (vector (first label-value)
536                                        (list 'grep (second label-value))))
537                            (Menubar-items-truncate-history
538                             grep-history 10 50)))))
539              (append menu '("---") items))))
540        ["%_Grep..." grep :active (fboundp 'grep)]
541        ["%_Kill Grep" kill-compilation
542         :active (and (fboundp 'kill-compilation)
543                      (fboundp 'compilation-find-buffer)
544                      (let ((buffer (condition-case nil
545                                        (compilation-find-buffer)
546                                      (error nil))))
547                        (and buffer (get-buffer-process buffer))))]
548        "---"
549        ["Grep %_All Files in Current Directory..."
550         (progn
551           (require 'compile)
552           (let ((grep-command
553                  (cons (concat grep-command " *")
554                        (length grep-command))))
555             (call-interactively 'grep)))
556         :active (fboundp 'grep)]
557        ["Grep %_C and C Header Files in Current Directory..."
558         (progn
559           (require 'compile)
560           (let ((grep-command
561                  (cons (concat grep-command " *.[chCH]"
562                                         ; i wanted to also use *.cc and *.hh.
563                                         ; see long comment below under Perl.
564                                )
565                        (length grep-command))))
566             (call-interactively 'grep)))
567         :active (fboundp 'grep)]
568        ["Grep C Hea%_der Files in Current Directory..."
569         (progn
570           (require 'compile)
571           (let ((grep-command
572                  (cons (concat grep-command " *.[hH]"
573                                         ; i wanted to also use *.hh.
574                                         ; see long comment below under Perl.
575                                )
576                        (length grep-command))))
577             (call-interactively 'grep)))
578         :active (fboundp 'grep)]
579        ["Grep %_E-Lisp Files in Current Directory..."
580         (progn
581           (require 'compile)
582           (let ((grep-command
583                  (cons (concat grep-command " *.el")
584                        (length grep-command))))
585             (call-interactively 'grep)))
586         :active (fboundp 'grep)]
587        ["Grep %_Perl Files in Current Directory..."
588         (progn
589           (require 'compile)
590           (let ((grep-command
591                  (cons (concat grep-command " *.pl"
592                                         ; i wanted to use this:
593                                         ; " *.pl *.pm *.am"
594                                         ; but grep complains if it can't
595                                         ; match anything in a glob, and
596                                         ; that screws other things up.
597                                         ; perhaps we need to first scan
598                                         ; each separate glob in the directory
599                                         ; to see if there are any files in
600                                         ; that glob, and if not, omit it.
601                                )
602                        (length grep-command))))
603             (call-interactively 'grep)))
604         :active (fboundp 'grep)]
605        ["Grep %_HTML Files in Current Directory..."
606         (progn
607           (require 'compile)
608           (let ((grep-command
609                  (cons (concat grep-command " *.*htm*")
610                        (length grep-command))))
611             (call-interactively 'grep)))
612         :active (fboundp 'grep)]
613        "---"
614        ["%_Next Match" next-error
615         :active (and (fboundp 'compilation-errors-exist-p)
616                      (compilation-errors-exist-p))]
617        ["Pre%_vious Match" previous-error
618         :active (and (fboundp 'compilation-errors-exist-p)
619                      (compilation-errors-exist-p))]
620        ["%_First Match" first-error
621         :active (and (fboundp 'compilation-errors-exist-p)
622                      (compilation-errors-exist-p))]
623        ["G%_oto Match" compile-goto-error
624         :active (and (fboundp 'compilation-errors-exist-p)
625                      (compilation-errors-exist-p))]
626        "---"
627        ["%_Set Grep Command..."
628         (progn
629           (require 'compile)
630           (customize-set-variable
631            'grep-command
632            (read-shell-command "Default Grep Command: " grep-command)))
633         :active (fboundp 'grep)
634         ]
635        )
636       ("%_Compile"
637        :filter
638        (lambda (menu)
639          (if (or (not (boundp 'compile-history)) (null compile-history))
640              menu
641            (let ((items
642                   (submenu-generate-accelerator-spec
643                    (mapcar #'(lambda (label-value)
644                                (vector (first label-value)
645                                        (list 'compile (second label-value))))
646                            (Menubar-items-truncate-history
647                             compile-history 10 50)))))
648              (append menu '("---") items))))
649        ["%_Compile..." compile :active (fboundp 'compile)]
650        ["%_Repeat Compilation" recompile :active (fboundp 'recompile)]
651        ["%_Kill Compilation" kill-compilation
652         :active (and (fboundp 'kill-compilation)
653                      (fboundp 'compilation-find-buffer)
654                      (let ((buffer (condition-case nil
655                                        (compilation-find-buffer)
656                                      (error nil))))
657                        (and buffer (get-buffer-process buffer))))]
658        "---"
659        ["%_Next Error" next-error
660         :active (and (fboundp 'compilation-errors-exist-p)
661                      (compilation-errors-exist-p))]
662        ["Pre%_vious Error" previous-error
663         :active (and (fboundp 'compilation-errors-exist-p)
664                      (compilation-errors-exist-p))]
665        ["%_First Error" first-error
666         :active (and (fboundp 'compilation-errors-exist-p)
667                      (compilation-errors-exist-p))]
668        ["G%_oto Error" compile-goto-error
669         :active (and (fboundp 'compilation-errors-exist-p)
670                      (compilation-errors-exist-p))]
671        )
672       ("%_Debug"
673        ["%_GDB..." gdb
674         :active (fboundp 'gdb)]
675        ["%_DBX..." dbx
676         :active (fboundp 'dbx)])
677       ("%_Shell"
678        ["%_Shell" shell
679         :active (fboundp 'shell)]
680        ["S%_hell Command..." shell-command
681         :active (fboundp 'shell-command)]
682        ["Shell Command on %_Region..." shell-command-on-region
683        :active (and (fboundp 'shell-command-on-region) (region-exists-p))])
684
685       ("%_Tags"
686        ["%_Find Tag..." find-tag]
687        ["Find %_Other Window..." find-tag-other-window]
688        ["%_Next Tag..." (find-tag nil)]
689        ["N%_ext Other Window..." (find-tag-other-window nil)]
690        ["Next %_File" next-file]
691        "-----"
692        ["Tags %_Search..." tags-search]
693        ["Tags %_Replace..." tags-query-replace]
694        ["%_Continue Search/Replace" tags-loop-continue]
695        "-----"
696        ["%_Pop stack" pop-tag-mark]
697        ["%_Apropos..." tags-apropos]
698        "-----"
699        ["%_Set Tags Table File..." visit-tags-table]
700        )
701
702       "----"
703
704       ("Ca%_lendar"
705        ["%_3-Month Calendar" calendar
706         :active (fboundp 'calendar)]
707        ["%_Diary" diary
708         :active (fboundp 'diary)]
709        ["%_Holidays" holidays
710         :active (fboundp 'holidays)]
711        ;; we're all pagans at heart ...
712        ["%_Phases of the Moon" phases-of-moon
713         :active (fboundp 'phases-of-moon)]
714        ["%_Sunrise/Sunset" sunrise-sunset
715         :active (fboundp 'sunrise-sunset)])
716
717       ("Ga%_mes"
718        ["%_Mine Game" xmine
719         :active (fboundp 'xmine)]
720        ["%_Tetris" tetris
721         :active (fboundp 'tetris)]
722        ["%_Sokoban" sokoban
723         :active (fboundp 'sokoban)]
724        ["Quote from %_Zippy" yow
725         :active (fboundp 'yow)]
726        ["%_Psychoanalyst" doctor
727         :active (fboundp 'doctor)]
728        ["Ps%_ychoanalyze Zippy!" psychoanalyze-pinhead
729         :active (fboundp 'psychoanalyze-pinhead)]
730        ["%_Random Flames" flame
731         :active (fboundp 'flame)]
732        ["%_Dunnet (Adventure)" dunnet
733         :active (fboundp 'dunnet)]
734        ["Towers of %_Hanoi" hanoi
735         :active (fboundp 'hanoi)]
736        ["Game of %_Life" life
737         :active (fboundp 'life)]
738        ["M%_ultiplication Puzzle" mpuz
739         :active (fboundp 'mpuz)])
740
741       "----"
742       )
743
744      ("%_Options"
745       ("%_Advanced (Customize)"
746        ("%_Emacs" :filter (lambda (&rest junk)
747                             (cdr (custom-menu-create 'emacs))))
748        ["%_Group..." customize-group]
749        ["%_Variable..." customize-variable]
750        ["%_Face..." customize-face]
751        ["%_Saved..." customize-saved]
752        ["Se%_t..." customize-customized]
753        ["%_Apropos..." customize-apropos]
754        ["%_Browse..." customize-browse])
755       "---"
756       ("%_Editing"
757        ["This Buffer %_Read Only" (toggle-read-only)
758         :style toggle :selected buffer-read-only]
759        ["%_Yank/Kill Interact With Clipboard"
760         (if (eq interprogram-cut-function 'own-clipboard)
761             (progn
762               (customize-set-variable 'interprogram-cut-function nil)
763               (customize-set-variable 'interprogram-paste-function nil))
764           (customize-set-variable 'interprogram-cut-function 'own-clipboard)
765           (customize-set-variable 'interprogram-paste-function 'get-clipboard))
766         :style toggle
767         :selected (eq interprogram-cut-function 'own-clipboard)]
768        ["%_Overstrike"
769         (progn
770           (setq overwrite-mode (if overwrite-mode nil 'overwrite-mode-textual))
771           (customize-set-variable 'overwrite-mode overwrite-mode))
772         :style toggle :selected overwrite-mode]
773        ["%_Abbrev Mode"
774         (customize-set-variable 'abbrev-mode
775                                 (not (default-value 'abbrev-mode)))
776         :style toggle
777         :selected (default-value 'abbrev-mode)]
778        ["Active Re%_gions"
779         (customize-set-variable 'zmacs-regions (not zmacs-regions))
780         :style toggle :selected zmacs-regions]
781        "---"
782        ["%_Case Sensitive Search"
783         (customize-set-variable 'case-fold-search
784                                 (setq case-fold-search (not case-fold-search)))
785         :style toggle :selected (not case-fold-search)]
786        ["Case %_Matching Replace"
787         (customize-set-variable 'case-replace (not case-replace))
788         :style toggle :selected case-replace]
789        "---"
790        ("%_Newline at End of File..."
791         ["%_Don't Require"
792          (customize-set-variable 'require-final-newline nil)
793          :style radio :selected (not require-final-newline)]
794         ["%_Require"
795          (customize-set-variable 'require-final-newline t)
796          :style radio :selected (eq require-final-newline t)]
797         ["%_Ask"
798          (customize-set-variable 'require-final-newline 'ask)
799          :style radio :selected (and require-final-newline
800                                      (not (eq require-final-newline t)))])
801        ["Add Newline When Moving Past %_End"
802         (customize-set-variable 'next-line-add-newlines
803                                 (not next-line-add-newlines))
804         :style toggle :selected next-line-add-newlines])
805       ("%_Keyboard and Mouse"
806        ["%_Delete Key Deletes Selection"
807         (customize-set-variable 'pending-delete-mode (not pending-delete-mode))
808         :style toggle
809         :selected (and (boundp 'pending-delete-mode) pending-delete-mode)
810         :active (boundp 'pending-delete-mode)]
811        ["`%_kill-line' Kills Whole Line at %_Beg"
812          (customize-set-variable 'kill-whole-line (not kill-whole-line))
813          :style toggle
814          :selected kill-whole-line]
815        ["Size for %_Block-Movement Commands..."
816         (customize-set-variable 'block-movement-size
817                                 (read-number "Block Movement Size: "
818                                               t block-movement-size))]
819        ["%_VI Emulation"
820         (progn
821           (toggle-viper-mode)
822           (customize-set-variable 'viper-mode viper-mode))
823         :style toggle :selected (and (boundp 'viper-mode) viper-mode)
824         :active (fboundp 'toggle-viper-mode)]
825        "----"
826        ["S%_hifted Motion Keys Select Region"
827          (customize-set-variable 'shifted-motion-keys-select-region
828                                  (not shifted-motion-keys-select-region))
829          :style toggle
830          :selected shifted-motion-keys-select-region]
831        ["%_After Shifted Motion, Unshifted Motion Keys Deselect"
832          (customize-set-variable 'unshifted-motion-keys-deselect-region
833                                  (not unshifted-motion-keys-deselect-region))
834          :style toggle
835          :selected unshifted-motion-keys-deselect-region]
836        "----"
837        ["%_Set Key..." global-set-key]
838        ["%_Unset Key..." global-unset-key]
839        "---"
840        ["%_Mouse Paste at Text Cursor (not Clicked Location)"
841         (customize-set-variable 'mouse-yank-at-point (not mouse-yank-at-point))
842         :style toggle :selected mouse-yank-at-point]
843        "---"
844        ["%_Teach Extended Commands"
845         (customize-set-variable 'teach-extended-commands-p
846                                 (not teach-extended-commands-p))
847         :style toggle :selected teach-extended-commands-p]
848        )
849       ("%_Printing"
850        ["Set Printer %_Name for Generic Print Support..."
851         (customize-set-variable
852          'printer-name
853          (read-string "Set printer name: " printer-name))]
854        "---"
855        ["Command-Line %_Switches for `lpr'/`lp'..."
856         ;; better to directly open a customization buffer, since the value
857         ;; must be a list of strings, which is somewhat complex to prompt for.
858         (customize-variable 'lpr-switches)
859         (boundp 'lpr-switches)]
860        ("%_Pretty-Print Paper Size"
861         ["%_Letter"
862          (customize-set-variable 'ps-paper-type 'letter)
863          :style radio
864          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'letter))
865          :active (boundp 'ps-paper-type)]
866         ["Lette%_r-Small"
867          (customize-set-variable 'ps-paper-type 'letter-small)
868          :style radio
869          :selected (and (boundp 'ps-paper-type)
870                         (eq ps-paper-type 'letter-small))
871          :active (boundp 'ps-paper-type)]
872         ["Le%_gal"
873          (customize-set-variable 'ps-paper-type 'legal)
874          :style radio
875          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'legal))
876          :active (boundp 'ps-paper-type)]
877         ["%_Statement"
878          (customize-set-variable 'ps-paper-type 'statement)
879          :style radio
880          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'statement))
881          :active (boundp 'ps-paper-type)]
882         ["%_Executive"
883          (customize-set-variable 'ps-paper-type 'executive)
884          :style radio
885          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'executive))
886          :active (boundp 'ps-paper-type)]
887         ["%_Tabloid"
888          (customize-set-variable 'ps-paper-type 'tabloid)
889          :style radio
890          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'tabloid))
891          :active (boundp 'ps-paper-type)]
892         ["Le%_dger"
893          (customize-set-variable 'ps-paper-type 'ledger)
894          :style radio
895          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'ledger))
896          :active (boundp 'ps-paper-type)]
897         ["A%_3"
898          (customize-set-variable 'ps-paper-type 'a3)
899          :style radio
900          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'a3))
901          :active (boundp 'ps-paper-type)]
902         ["%_A4"
903          (customize-set-variable 'ps-paper-type 'a4)
904          :style radio
905          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'a4))
906          :active (boundp 'ps-paper-type)]
907         ["A4s%_mall"
908          (customize-set-variable 'ps-paper-type 'a4small)
909          :style radio
910          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'a4small))
911          :active (boundp 'ps-paper-type)]
912         ["B%_4"
913          (customize-set-variable 'ps-paper-type 'b4)
914          :style radio
915          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'b4))
916          :active (boundp 'ps-paper-type)]
917         ["%_B5"
918          (customize-set-variable 'ps-paper-type 'b5)
919          :style radio
920          :selected (and (boundp 'ps-paper-type) (eq ps-paper-type 'b5))
921          :active (boundp 'ps-paper-type)]
922         )
923        ["%_Color Printing"
924         (cond (ps-print-color-p
925                (customize-set-variable 'ps-print-color-p nil)
926                ;; I'm wondering whether all this muck is useful.
927                (and (boundp 'original-face-background)
928                     original-face-background
929                     (set-face-background 'default original-face-background)))
930               (t
931                (customize-set-variable 'ps-print-color-p t)
932                (setq original-face-background
933                      (face-background-instance 'default))
934                (set-face-background 'default "white")))
935         :style toggle
936         :selected (and (boundp 'ps-print-color-p) ps-print-color-p)
937         :active (boundp 'ps-print-color-p)])
938       ("%_Internet"
939        ("%_Compose Mail With"
940         ["Default Emacs Mailer"
941          (customize-set-variable 'mail-user-agent 'sendmail-user-agent)
942          :style radio
943          :selected (eq mail-user-agent 'sendmail-user-agent)]
944         ["MH"
945          (customize-set-variable 'mail-user-agent 'mh-e-user-agent)
946          :style radio
947          :selected (eq mail-user-agent 'mh-e-user-agent)
948          :active (get 'mh-e-user-agent 'composefunc)]
949         ["GNUS"
950          (customize-set-variable 'mail-user-agent 'message-user-agent)
951          :style radio
952          :selected (eq mail-user-agent 'message-user-agent)
953          :active (get 'message-user-agent 'composefunc)]
954         )
955        ["Set My %_Email Address..."
956         (customize-set-variable
957          'user-mail-address
958          (read-string "Set email address: " user-mail-address))]
959        ["Set %_Machine Email Name..."
960         (customize-set-variable
961          'mail-host-address
962          (read-string "Set machine email name: " mail-host-address))]
963        ["Set %_SMTP Server..."
964         (progn
965           (require 'smtpmail)
966           (customize-set-variable
967            'smtpmail-smtp-server
968            (read-string "Set SMTP server: " smtpmail-smtp-server)))
969         :active (and (boundp 'send-mail-function)
970                      (eq send-mail-function 'smtpmail-send-it))]
971        ["SMTP %_Debug Info"
972         (progn
973           (require 'smtpmail)
974           (customize-set-variable 'smtpmail-debug-info
975                                   (not smtpmail-debug-info)))
976         :style toggle
977         :selected (and (boundp 'smtpmail-debug-info) smtpmail-debug-info)
978         :active (and (boundp 'send-mail-function)
979                      (eq send-mail-function 'smtpmail-send-it))]
980        "---"
981        ("%_Open URLs With"
982         ["%_Emacs-W3"
983          (customize-set-variable 'browse-url-browser-function 'browse-url-w3)
984          :style radio
985          :selected (and (boundp 'browse-url-browser-function)
986                         (eq browse-url-browser-function 'browse-url-w3))
987          :active (and (boundp 'browse-url-browser-function)
988                       (fboundp 'browse-url-w3)
989                       (fboundp 'w3-fetch))]
990         ["Emacs-%_W3 (gnuclient)"
991          (customize-set-variable 'browse-url-browser-function 'browse-url-w3-gnudoit)
992          :style radio
993          :selected (and (boundp 'browse-url-browser-function)
994                         (eq browse-url-browser-function
995                             'browse-url-w3-gnudoit))
996          :active (and (boundp 'browse-url-browser-function)
997                       (fboundp 'browse-url-w3-gnudoit))]
998         ["%_Netscape"
999          (customize-set-variable 'browse-url-browser-function
1000                                  'browse-url-netscape)
1001          :style radio
1002          :selected (and (boundp 'browse-url-browser-function)
1003                         (eq browse-url-browser-function 'browse-url-netscape))
1004          :active (and (boundp 'browse-url-browser-function)
1005                       (fboundp 'browse-url-netscape))]
1006         ["%_Mosaic"
1007          (customize-set-variable 'browse-url-browser-function
1008                                  'browse-url-mosaic)
1009          :style radio
1010          :selected (and (boundp 'browse-url-browser-function)
1011                         (eq browse-url-browser-function 'browse-url-mosaic))
1012          :active (and (boundp 'browse-url-browser-function)
1013                       (fboundp 'browse-url-mosaic))]
1014         ["Mosaic (%_CCI)"
1015          (customize-set-variable 'browse-url-browser-function 'browse-url-cci)
1016          :style radio
1017          :selected (and (boundp 'browse-url-browser-function)
1018                         (eq browse-url-browser-function 'browse-url-cci))
1019          :active (and (boundp 'browse-url-browser-function)
1020                       (fboundp 'browse-url-cci))]
1021         ["%_IXI Mosaic"
1022          (customize-set-variable 'browse-url-browser-function
1023                                  'browse-url-iximosaic)
1024          :style radio
1025          :selected (and (boundp 'browse-url-browser-function)
1026                         (eq browse-url-browser-function 'browse-url-iximosaic))
1027          :active (and (boundp 'browse-url-browser-function)
1028                       (fboundp 'browse-url-iximosaic))]
1029         ["%_Lynx (xterm)"
1030          (customize-set-variable 'browse-url-browser-function
1031                                  'browse-url-lynx-xterm)
1032          :style radio
1033          :selected (and (boundp 'browse-url-browser-function)
1034                         (eq browse-url-browser-function 'browse-url-lynx-xterm))
1035          :active (and (boundp 'browse-url-browser-function)
1036                       (fboundp 'browse-url-lynx-xterm))]
1037         ["L%_ynx (sxemacs)"
1038          (customize-set-variable 'browse-url-browser-function
1039                                  'browse-url-lynx-emacs)
1040          :style radio
1041          :selected (and (boundp 'browse-url-browser-function)
1042                         (eq browse-url-browser-function 'browse-url-lynx-emacs))
1043          :active (and (boundp 'browse-url-browser-function)
1044                       (fboundp 'browse-url-lynx-emacs))]
1045         ["%_Grail"
1046          (customize-set-variable 'browse-url-browser-function
1047                                  'browse-url-grail)
1048          :style radio
1049          :selected (and (boundp 'browse-url-browser-function)
1050                         (eq browse-url-browser-function 'browse-url-grail))
1051          :active (and (boundp 'browse-url-browser-function)
1052                       (fboundp 'browse-url-grail))]
1053         ["%_KDE"
1054          (customize-set-variable 'browse-url-browser-function
1055                                  'browse-url-kde)
1056          :style radio
1057          :selected (and (boundp 'browse-url-browser-function)
1058                         (eq browse-url-browser-function 'browse-url-kde))
1059          :active (and (boundp 'browse-url-browser-function)
1060                       (fboundp 'browse-url-kde))]
1061         ["Mo%_zilla"
1062          (customize-set-variable 'browse-url-browser-function
1063                                  'browse-url-mozilla)
1064          :style radio
1065          :selected (and (boundp 'browse-url-browser-function)
1066                         (eq browse-url-browser-function 'browse-url-mozilla))
1067          :active (and (boundp 'browse-url-browser-function)
1068                       (fboundp 'browse-url-mozilla))]
1069         ["G%_aleon"
1070          (customize-set-variable 'browse-url-browser-function
1071                                  'browse-url-galeon)
1072          :style radio
1073          :selected (and (boundp 'browse-url-browser-function)
1074                         (eq browse-url-browser-function 'browse-url-galeon))
1075          :active (and (boundp 'browse-url-browser-function)
1076                       (fboundp 'browse-url-galeon))]
1077         ["%_Opera"
1078          (customize-set-variable 'browse-url-browser-function
1079                                  'browse-url-opera)
1080          :style radio
1081          :selected (and (boundp 'browse-url-browser-function)
1082                         (eq browse-url-browser-function 'browse-url-opera))
1083          :active (and (boundp 'browse-url-browser-function)
1084                       (fboundp 'browse-url-opera))]
1085         ["%_MMM"
1086          (customize-set-variable 'browse-url-browser-function
1087                                  'browse-url-mmm)
1088          :style radio
1089          :selected (and (boundp 'browse-url-browser-function)
1090                         (eq browse-url-browser-function 'browse-url-mmm))
1091          :active (and (boundp 'browse-url-browser-function)
1092                       (fboundp 'browse-url-mmm))]
1093         ["G%_eneric Browser"
1094          (customize-set-variable 'browse-url-browser-function
1095                                  'browse-url-generic)
1096          :style radio
1097          :selected (and (boundp 'browse-url-browser-function)
1098                         (eq browse-url-browser-function 'browse-url-generic))
1099          :active (and (boundp 'browse-url-browser-function)
1100                       (boundp 'browse-url-generic-program)
1101                       browse-url-generic-program
1102                       (fboundp 'browse-url-generic))]
1103         ))
1104       ("%_Troubleshooting"
1105        ["%_Debug on Error"
1106         (customize-set-variable 'debug-on-error (not debug-on-error))
1107         :style toggle :selected debug-on-error]
1108        ["Debug on %_Quit"
1109         (customize-set-variable 'debug-on-quit (not debug-on-quit))
1110         :style toggle :selected debug-on-quit]
1111        ["Debug on S%_ignal"
1112         (customize-set-variable 'debug-on-signal (not debug-on-signal))
1113         :style toggle :selected debug-on-signal]
1114        ["%_Stack Trace on Error"
1115         (customize-set-variable 'stack-trace-on-error
1116                                 (not stack-trace-on-error))
1117         :style toggle :selected stack-trace-on-error]
1118        ["Stack Trace on Si%_gnal"
1119         (customize-set-variable 'stack-trace-on-signal
1120                                 (not stack-trace-on-signal))
1121         :style toggle :selected stack-trace-on-signal]
1122        )
1123       "-----"
1124       ("%_Display"
1125        ,@(if (featurep 'scrollbar)
1126              '(["%_Scrollbars"
1127                 (customize-set-variable 'scrollbars-visible-p
1128                                         (not scrollbars-visible-p))
1129                 :style toggle
1130                 :selected scrollbars-visible-p]))
1131        ["%_Wrap Long Lines"
1132         (progn;; becomes buffer-local
1133           (setq truncate-lines (not truncate-lines))
1134           (customize-set-variable 'truncate-lines truncate-lines))
1135         :style toggle
1136         :selected (not truncate-lines)]
1137        "----"
1138        ["%_3D Modeline"
1139         (customize-set-variable 'modeline-3d-p
1140                                 (not modeline-3d-p))
1141         :style toggle
1142         :selected modeline-3d-p]
1143        ("Modeline %_Horizontal Scrolling"
1144         ["%_None"
1145          (customize-set-variable 'modeline-scrolling-method nil)
1146          :style radio
1147          :selected (not modeline-scrolling-method)]
1148         ["As %_Text"
1149          (customize-set-variable 'modeline-scrolling-method t)
1150          :style radio
1151          :selected (eq modeline-scrolling-method t)]
1152         ["As %_Scrollbar"
1153          (customize-set-variable 'modeline-scrolling-method 'scrollbar)
1154          :style radio
1155          :selected (eq modeline-scrolling-method 'scrollbar)]
1156         )
1157        ,@(if (featurep 'toolbar)
1158              '("---"
1159                ["%_Toolbars Visible"
1160                 (customize-set-variable 'toolbar-visible-p
1161                                         (not toolbar-visible-p))
1162                 :style toggle
1163                 :selected toolbar-visible-p]
1164                ["Toolbars Ca%_ptioned"
1165                 (customize-set-variable 'toolbar-captioned-p
1166                                         (not toolbar-captioned-p))
1167                 :style toggle
1168                 :active toolbar-visible-p
1169                 :selected toolbar-captioned-p]
1170                ("Default Toolba%_r Location"
1171                 ["%_Top"
1172                  (customize-set-variable 'default-toolbar-position 'top)
1173                  :style radio
1174                  :active toolbar-visible-p
1175                  :selected (eq default-toolbar-position 'top)]
1176                 ["%_Bottom"
1177                  (customize-set-variable 'default-toolbar-position 'bottom)
1178                  :style radio
1179                  :active toolbar-visible-p
1180                  :selected (eq default-toolbar-position 'bottom)]
1181                 ["%_Left"
1182                  (customize-set-variable 'default-toolbar-position 'left)
1183                  :style radio
1184                  :active toolbar-visible-p
1185                  :selected (eq default-toolbar-position 'left)]
1186                 ["%_Right"
1187                  (customize-set-variable 'default-toolbar-position 'right)
1188                  :style radio
1189                  :active toolbar-visible-p
1190                  :selected (eq default-toolbar-position 'right)]
1191                 )
1192                ))
1193        ,@(if (featurep 'gutter)
1194              '("---"
1195                ["B%_uffers Tab Visible"
1196                 (customize-set-variable 'gutter-buffers-tab-visible-p
1197                                         (not gutter-buffers-tab-visible-p))
1198                 :style toggle
1199                 :selected gutter-buffers-tab-visible-p]
1200                ("Default %_Gutter Location"
1201                 ["%_Top"
1202                  (customize-set-variable 'default-gutter-position 'top)
1203                  :style radio
1204                  :selected (eq default-gutter-position 'top)]
1205                 ["%_Bottom"
1206                  (customize-set-variable 'default-gutter-position 'bottom)
1207                  :style radio
1208                  :selected (eq default-gutter-position 'bottom)]
1209                 ["%_Left"
1210                  (customize-set-variable 'default-gutter-position 'left)
1211                  :style radio
1212                  :selected (eq default-gutter-position 'left)]
1213                 ["%_Right"
1214                  (customize-set-variable 'default-gutter-position 'right)
1215                  :style radio
1216                  :selected (eq default-gutter-position 'right)]
1217                 )
1218                ))
1219        "-----"
1220        ["%_Blinking Cursor"
1221         (customize-set-variable 'blink-cursor-mode (not blink-cursor-mode))
1222         :style toggle
1223         :selected (and (boundp 'blink-cursor-mode) blink-cursor-mode)
1224         :active (boundp 'blink-cursor-mode)]
1225        ["Bl%_ock Cursor"
1226         (progn
1227           (customize-set-variable 'bar-cursor nil)
1228           (force-cursor-redisplay))
1229         :style radio
1230         :selected (null bar-cursor)]
1231        ["Bar Cursor (%_1 Pixel)"
1232         (progn
1233           (customize-set-variable 'bar-cursor t)
1234           (force-cursor-redisplay))
1235         :style radio
1236         :selected (eq bar-cursor t)]
1237        ["Bar Cursor (%_2 Pixels)"
1238         (progn
1239           (customize-set-variable 'bar-cursor 2)
1240           (force-cursor-redisplay))
1241         :style radio
1242         :selected (and bar-cursor (not (eq bar-cursor t)))]
1243        "----"
1244        ("Pa%_ren Highlighting"
1245        ["%_None"
1246         (customize-set-variable 'paren-mode nil)
1247         :style radio
1248         :selected (and (boundp 'paren-mode) (not paren-mode))
1249         :active (boundp 'paren-mode)]
1250        ["%_Blinking Paren"
1251         (customize-set-variable 'paren-mode 'blink-paren)
1252         :style radio
1253         :selected (and (boundp 'paren-mode) (eq paren-mode 'blink-paren))
1254         :active (boundp 'paren-mode)]
1255        ["%_Steady Paren"
1256         (customize-set-variable 'paren-mode 'paren)
1257         :style radio
1258         :selected (and (boundp 'paren-mode) (eq paren-mode 'paren))
1259         :active (boundp 'paren-mode)]
1260        ["%_Expression"
1261         (customize-set-variable 'paren-mode 'sexp)
1262         :style radio
1263         :selected (and (boundp 'paren-mode) (eq paren-mode 'sexp))
1264         :active (boundp 'paren-mode)]
1265        ;;        ["Nes%_ted Shading"
1266        ;;         (customize-set-variable 'paren-mode 'nested)
1267        ;;         :style radio
1268        ;;         :selected (and (boundp 'paren-mode) (eq paren-mode 'nested))
1269        ;;         :active (boundp 'paren-mode)]
1270        )
1271        "------"
1272        ["%_Line Numbers"
1273         (progn
1274           (customize-set-variable 'line-number-mode (not line-number-mode))
1275           (redraw-modeline))
1276         :style toggle :selected line-number-mode]
1277        ["%_Column Numbers"
1278         (progn
1279           (customize-set-variable 'column-number-mode
1280                                   (not column-number-mode))
1281           (redraw-modeline))
1282         :style toggle :selected column-number-mode]
1283
1284        ("\"Other %_Window\" Location"
1285         ["%_Always in Same Frame"
1286          (customize-set-variable
1287           'get-frame-for-buffer-default-instance-limit nil)
1288          :style radio
1289          :selected (null get-frame-for-buffer-default-instance-limit)]
1290         ["Other Frame (%_2 Frames Max)"
1291          (customize-set-variable 'get-frame-for-buffer-default-instance-limit
1292                                  2)
1293          :style radio
1294          :selected (eq 2 get-frame-for-buffer-default-instance-limit)]
1295         ["Other Frame (%_3 Frames Max)"
1296          (customize-set-variable 'get-frame-for-buffer-default-instance-limit
1297                                  3)
1298          :style radio
1299          :selected (eq 3 get-frame-for-buffer-default-instance-limit)]
1300         ["Other Frame (%_4 Frames Max)"
1301          (customize-set-variable 'get-frame-for-buffer-default-instance-limit
1302                                  4)
1303          :style radio
1304          :selected (eq 4 get-frame-for-buffer-default-instance-limit)]
1305         ["Other Frame (%_5 Frames Max)"
1306          (customize-set-variable 'get-frame-for-buffer-default-instance-limit
1307                                  5)
1308          :style radio
1309          :selected (eq 5 get-frame-for-buffer-default-instance-limit)]
1310         ["Always Create %_New Frame"
1311          (customize-set-variable 'get-frame-for-buffer-default-instance-limit
1312                                  0)
1313          :style radio
1314          :selected (eq 0 get-frame-for-buffer-default-instance-limit)]
1315         "-----"
1316         ["%_Temp Buffers Always in Same Frame"
1317          (customize-set-variable 'temp-buffer-show-function
1318                                  'show-temp-buffer-in-current-frame)
1319          :style radio
1320          :selected (eq temp-buffer-show-function
1321                        'show-temp-buffer-in-current-frame)]
1322         ["Temp Buffers %_Like Other Buffers"
1323          (customize-set-variable 'temp-buffer-show-function nil)
1324          :style radio
1325          :selected (null temp-buffer-show-function)]
1326         "-----"
1327         ["%_Make Current Frame Gnuserv Target"
1328          (customize-set-variable 'gnuserv-frame (if (eq gnuserv-frame t) nil
1329                                                   t))
1330          :style toggle
1331          :selected (and (boundp 'gnuserv-frame) (eq gnuserv-frame t))
1332          :active (boundp 'gnuserv-frame)]
1333         )
1334        )
1335       ("%_Menubars"
1336        ["%_Frame-Local Font Menu"
1337         (customize-set-variable 'font-menu-this-frame-only-p
1338                                 (not font-menu-this-frame-only-p))
1339         :style toggle
1340         :selected (and (boundp 'font-menu-this-frame-only-p)
1341                        font-menu-this-frame-only-p)]
1342        ["%_Alt/Meta Selects Menu Items"
1343         (if (eq menu-accelerator-enabled 'menu-force)
1344             (customize-set-variable 'menu-accelerator-enabled nil)
1345           (customize-set-variable 'menu-accelerator-enabled 'menu-force))
1346         :style toggle
1347         :selected (eq menu-accelerator-enabled 'menu-force)]
1348        "----"
1349        ["Buffers Menu %_Length..."
1350         (customize-set-variable
1351          'buffers-menu-max-size
1352          ;; would it be better to open a customization buffer ?
1353          (let ((val
1354                 (read-number
1355                  "Enter number of buffers to display (or 0 for unlimited): ")))
1356            (if (eq val 0) nil val)))]
1357        ["%_Multi-Operation Buffers Sub-Menus"
1358         (customize-set-variable 'complex-buffers-menu-p
1359                                 (not complex-buffers-menu-p))
1360         :style toggle
1361         :selected complex-buffers-menu-p]
1362        ["S%_ubmenus for Buffer Groups"
1363         (customize-set-variable 'buffers-menu-submenus-for-groups-p
1364                                 (not buffers-menu-submenus-for-groups-p))
1365         :style toggle
1366         :selected buffers-menu-submenus-for-groups-p]
1367        ["%_Verbose Buffer Menu Entries"
1368         (if (eq buffers-menu-format-buffer-line-function
1369                 'slow-format-buffers-menu-line)
1370             (customize-set-variable 'buffers-menu-format-buffer-line-function
1371                                     'format-buffers-menu-line)
1372           (customize-set-variable 'buffers-menu-format-buffer-line-function
1373                                   'slow-format-buffers-menu-line))
1374         :style toggle
1375         :selected (eq buffers-menu-format-buffer-line-function
1376                       'slow-format-buffers-menu-line)]
1377        ("Buffers Menu %_Sorting"
1378         ["%_Most Recently Used"
1379          (progn
1380            (customize-set-variable 'buffers-menu-sort-function nil)
1381            (customize-set-variable 'buffers-menu-grouping-function nil))
1382          :style radio
1383          :selected (null buffers-menu-sort-function)]
1384         ["%_Alphabetically"
1385          (progn
1386            (customize-set-variable 'buffers-menu-sort-function
1387                                    'sort-buffers-menu-alphabetically)
1388            (customize-set-variable 'buffers-menu-grouping-function nil))
1389          :style radio
1390          :selected (eq 'sort-buffers-menu-alphabetically
1391                        buffers-menu-sort-function)]
1392         ["%_By Major Mode, Then Alphabetically"
1393          (progn
1394            (customize-set-variable
1395             'buffers-menu-sort-function
1396             'sort-buffers-menu-by-mode-then-alphabetically)
1397            (customize-set-variable
1398             'buffers-menu-grouping-function
1399             'group-buffers-menu-by-mode-then-alphabetically))
1400          :style radio
1401          :selected (eq 'sort-buffers-menu-by-mode-then-alphabetically
1402                        buffers-menu-sort-function)])
1403        "---"
1404        ["%_Ignore Scaled Fonts"
1405         (customize-set-variable 'font-menu-ignore-scaled-fonts
1406                                 (not font-menu-ignore-scaled-fonts))
1407         :style toggle
1408         :selected (and (boundp 'font-menu-ignore-scaled-fonts)
1409                        font-menu-ignore-scaled-fonts)]
1410        )
1411       ("S%_yntax Highlighting"
1412        ["%_In This Buffer"
1413         (progn;; becomes buffer local
1414           (font-lock-mode)
1415           (customize-set-variable 'font-lock-mode font-lock-mode))
1416         :style toggle
1417         :selected (and (boundp 'font-lock-mode) font-lock-mode)
1418         :active (boundp 'font-lock-mode)]
1419        ["%_Automatic"
1420         (customize-set-variable 'font-lock-auto-fontify
1421                                 (not font-lock-auto-fontify))
1422         :style toggle
1423         :selected (and (boundp 'font-lock-auto-fontify) font-lock-auto-fontify)
1424         :active (fboundp 'font-lock-mode)]
1425        "-----"
1426        ["Force %_Rehighlight in this Buffer"
1427         (customize-set-variable 'font-lock-auto-fontify
1428                                 (not font-lock-auto-fontify))
1429         :style toggle
1430         :selected (and (boundp 'font-lock-auto-fontify) font-lock-auto-fontify)
1431         :active (fboundp 'font-lock-mode)]
1432        "-----"
1433        ["%_Fonts"
1434         (progn
1435           (require 'font-lock)
1436           (font-lock-use-default-fonts)
1437           (customize-set-variable 'font-lock-use-fonts t)
1438           (customize-set-variable 'font-lock-use-colors nil)
1439           (font-lock-mode 1))
1440         :style radio
1441         :selected (and (boundp 'font-lock-use-fonts) font-lock-use-fonts)
1442         :active (fboundp 'font-lock-mode)]
1443        ["%_Colors"
1444         (progn
1445           (require 'font-lock)
1446           (font-lock-use-default-colors)
1447           (customize-set-variable 'font-lock-use-colors t)
1448           (customize-set-variable 'font-lock-use-fonts nil)
1449           (font-lock-mode 1))
1450         :style radio
1451         :selected (and (boundp 'font-lock-use-colors) font-lock-use-colors)
1452         :active (boundp 'font-lock-mode)]
1453        "-----"
1454        ["%_1 Least"
1455         (progn
1456           (require 'font-lock)
1457           (if (or (and (not (integerp font-lock-maximum-decoration))
1458                        (not (eq t font-lock-maximum-decoration)))
1459                   (and (integerp font-lock-maximum-decoration)
1460                        (<= font-lock-maximum-decoration 0)))
1461               nil
1462             (customize-set-variable 'font-lock-maximum-decoration nil)
1463             (font-lock-recompute-variables)))
1464         :style radio
1465         :active (fboundp 'font-lock-mode)
1466         :selected (and (boundp 'font-lock-maximum-decoration)
1467                        (or (and (not (integerp font-lock-maximum-decoration))
1468                                 (not (eq t font-lock-maximum-decoration)))
1469                            (and (integerp font-lock-maximum-decoration)
1470                                 (<= font-lock-maximum-decoration 0))))]
1471        ["%_2 More"
1472         (progn
1473           (require 'font-lock)
1474           (if (and (integerp font-lock-maximum-decoration)
1475                    (= 1 font-lock-maximum-decoration))
1476               nil
1477             (customize-set-variable 'font-lock-maximum-decoration 1)
1478             (font-lock-recompute-variables)))
1479         :style radio
1480         :active (fboundp 'font-lock-mode)
1481         :selected (and (boundp 'font-lock-maximum-decoration)
1482                        (integerp font-lock-maximum-decoration)
1483                        (= 1 font-lock-maximum-decoration))]
1484        ["%_3 Even More"
1485         (progn
1486           (require 'font-lock)
1487           (if (and (integerp font-lock-maximum-decoration)
1488                    (= 2 font-lock-maximum-decoration))
1489               nil
1490             (customize-set-variable 'font-lock-maximum-decoration 2)
1491             (font-lock-recompute-variables)))
1492         :style radio
1493         :active (fboundp 'font-lock-mode)
1494         :selected (and (boundp 'font-lock-maximum-decoration)
1495                        (integerp font-lock-maximum-decoration)
1496                        (= 2 font-lock-maximum-decoration))]
1497        ["%_4 Most"
1498         (progn
1499           (require 'font-lock)
1500           (if (or (eq font-lock-maximum-decoration t)
1501                   (and (integerp font-lock-maximum-decoration)
1502                        (>= font-lock-maximum-decoration 3)))
1503               nil
1504             (customize-set-variable 'font-lock-maximum-decoration t)
1505             (font-lock-recompute-variables)))
1506         :style radio
1507         :active (fboundp 'font-lock-mode)
1508         :selected (and (boundp 'font-lock-maximum-decoration)
1509                        (or (eq font-lock-maximum-decoration t)
1510                            (and (integerp font-lock-maximum-decoration)
1511                                 (>= font-lock-maximum-decoration 3))))]
1512        "-----"
1513        ["Lazy %_Lock"
1514         (progn;; becomes buffer local
1515           (lazy-lock-mode)
1516           (customize-set-variable 'lazy-lock-mode lazy-lock-mode)
1517           ;; this shouldn't be necessary so there has to
1518           ;; be a redisplay bug lurking somewhere (or
1519           ;; possibly another event handler bug)
1520           (redraw-modeline))
1521         :active (and (boundp 'font-lock-mode) (boundp 'lazy-lock-mode)
1522                      font-lock-mode)
1523         :style toggle
1524         :selected (and (boundp 'lazy-lock-mode) lazy-lock-mode)]
1525        ["Lazy %_Shot"
1526         (progn;; becomes buffer local
1527           (lazy-shot-mode)
1528           (customize-set-variable 'lazy-shot-mode lazy-shot-mode)
1529           ;; this shouldn't be necessary so there has to
1530           ;; be a redisplay bug lurking somewhere (or
1531           ;; possibly another event handler bug)
1532           (redraw-modeline))
1533         :active (and (boundp 'font-lock-mode) (boundp 'lazy-shot-mode)
1534                      font-lock-mode)
1535         :style toggle
1536         :selected (and (boundp 'lazy-shot-mode) lazy-shot-mode)]
1537        ["Cac%_hing"
1538         (progn;; becomes buffer local
1539           (fast-lock-mode)
1540           (customize-set-variable 'fast-lock-mode fast-lock-mode)
1541           ;; this shouldn't be necessary so there has to
1542           ;; be a redisplay bug lurking somewhere (or
1543           ;; possibly another event handler bug)
1544           (redraw-modeline))
1545         :active (and (boundp 'font-lock-mode) (boundp 'fast-lock-mode)
1546                      font-lock-mode)
1547         :style toggle
1548         :selected (and (boundp 'fast-lock-mode) fast-lock-mode)]
1549        )
1550       ("%_Font" :filter font-menu-family-constructor)
1551       ("Font Si%_ze" :filter font-menu-size-constructor)
1552       ;;      ("Font Weig%_ht" :filter font-menu-weight-constructor)
1553       ["Edit Fa%_ces..." (customize-face nil)]
1554       "-----"
1555       ["Edit I%_nit File"
1556        ;; #### there should be something that holds the name that the init
1557        ;; file should be created as, when it's not present.
1558        (progn (find-file (or user-init-file
1559                              (expand-file-name "init.el" user-init-directory)))
1560               (or (eq major-mode 'emacs-lisp-mode)
1561                   (emacs-lisp-mode)))]
1562       ["%_Save Options to Custom File" customize-save-customized]
1563       )
1564
1565      ("%_Buffers"
1566       :filter buffers-menu-filter
1567       ["Go To %_Previous Buffer" switch-to-other-buffer]
1568       ["Go To %_Buffer..." switch-to-buffer]
1569       "----"
1570       ["%_List All Buffers" list-buffers]
1571       ["%_Delete Buffer" kill-this-buffer
1572        :suffix (if put-buffer-names-in-file-menu (buffer-name) "")]
1573       "----"
1574       )
1575
1576      nil        ; the partition: menus after this are flushright
1577
1578      ("%_Help"
1579       ["%_About SXEmacs..." about-sxemacs]
1580       "-----"
1581       ["What's %_New in SXEmacs" view-emacs-news]
1582       ["%_Obtaining SXEmacs" describe-distribution]
1583       "-----"
1584       ("%_Info (Online Docs)"
1585        ["%_Info Contents" info]
1586        ["Lookup %_Key Binding..." Info-goto-emacs-key-command-node]
1587        ["Lookup %_Command..." Info-goto-emacs-command-node]
1588        ["Lookup %_Function..." Info-elisp-ref]
1589        ["Lookup %_Topic..." Info-query])
1590       ("SXEmacs %_FAQ"
1591        ["%_FAQ (local)" xemacs-local-faq]
1592        ["FAQ via %_WWW" xemacs-www-faq
1593         :active (fboundp 'browse-url)]
1594        ["%_Home Page" xemacs-www-page
1595         :active (fboundp 'browse-url)])
1596       ("%_Tutorials"
1597        :filter tutorials-menu-filter)
1598       ("%_Samples"
1599        ["Sample %_init.el"
1600         (find-file (locate-data-file "sample.init.el"))
1601         :active (locate-data-file "sample.init.el")]
1602        ["Sample .%_Xdefaults"
1603         (find-file (locate-data-file "sample.Xdefaults"))
1604         :included (featurep 'x)
1605         :active (locate-data-file "sample.Xdefaults")]
1606        ["Sample %_enriched"
1607         (find-file (locate-data-file "enriched.doc"))
1608         :active (locate-data-file "enriched.doc")])
1609       ("%_Commands & Keys"
1610        ["%_Mode" describe-mode]
1611        ["%_Apropos..." hyper-apropos]
1612        ["Apropos %_Docs..." apropos-documentation]
1613        "-----"
1614        ["%_Key..." describe-key]
1615        ["%_Bindings" describe-bindings]
1616        ["%_Mouse Bindings" describe-pointer]
1617        ["%_Recent Keys" view-lossage]
1618        "-----"
1619        ["%_Function..." describe-function]
1620        ["%_Variable..." describe-variable]
1621        ["%_Locate Command..." where-is])
1622       "-----"
1623       ["%_Recent Messages" view-lossage]
1624       ("%_Misc"
1625        ["%_Current Installation Info" describe-installation
1626         :active (boundp 'Installation-string)]
1627        ["%_No Warranty" describe-no-warranty]
1628        ["SXEmacs %_License" describe-copying]
1629        ["Find %_Packages" finder-by-keyword]
1630        ["View %_Splash Screen" sxemacs-splash-buffer]
1631        ["%_Unix Manual..." manual-entry])
1632       ["Send %_Bug Report..." report-sxemacs-bug
1633        :active (fboundp 'report-sxemacs-bug)])))
1634
1635 \f
1636 (defun maybe-add-init-button ()
1637   "Don't call this.
1638 Adds `Load .emacs' button to menubar when starting up with -q."
1639   (when (not load-user-init-file-p)
1640     (add-menu-button
1641      nil
1642      ["%_Load init.el"
1643       (progn
1644         (mapc #'(lambda (buf)
1645                  (with-current-buffer buf
1646                    (delete-menu-item '("Load init.el"))))
1647               (buffer-list))
1648         (load-user-init-file))
1649       ]
1650      "Help")))
1651
1652 (add-hook 'before-init-hook 'maybe-add-init-button)
1653
1654 \f
1655 ;;; The File menu
1656
1657 (defvar put-buffer-names-in-file-menu t)
1658
1659 \f
1660 ;;; The Bookmarks menu
1661
1662 (defun bookmark-menu-filter (&rest ignore)
1663   (declare (special bookmark-alist))
1664   (let ((definedp (and (boundp 'bookmark-alist)
1665                        bookmark-alist
1666                        t)))
1667     `(,(if definedp
1668            '("%_Jump to Bookmark"
1669              :filter (lambda (&rest junk)
1670                        (submenu-generate-accelerator-spec
1671                         (mapcar #'(lambda (bmk)
1672                                     `[,bmk (bookmark-jump ',bmk)])
1673                                 (bookmark-all-names)))))
1674          ["%_Jump to Bookmark" nil nil])
1675       ["Set %_Bookmark" bookmark-set
1676        :active (fboundp 'bookmark-set)]
1677       "---"
1678       ["Insert %_Contents" bookmark-menu-insert
1679        :active (fboundp 'bookmark-menu-insert)]
1680       ["Insert L%_ocation" bookmark-menu-locate
1681        :active (fboundp 'bookmark-menu-locate)]
1682       "---"
1683       ["%_Rename Bookmark" bookmark-menu-rename
1684        :active (fboundp 'bookmark-menu-rename)]
1685       ,(if definedp
1686            '("%_Delete Bookmark"
1687              :filter (lambda (&rest junk)
1688                        (submenu-generate-accelerator-spec
1689                         (mapcar #'(lambda (bmk)
1690                                     `[,bmk (bookmark-delete ',bmk)])
1691                                 (bookmark-all-names)))))
1692          ["%_Delete Bookmark" nil nil])
1693       ["%_Edit Bookmark List" bookmark-bmenu-list       ,definedp]
1694       "---"
1695       ["%_Save Bookmarks"        bookmark-save          ,definedp]
1696       ["Save Bookmarks %_As..."  bookmark-write         ,definedp]
1697       ["%_Load a Bookmark File" bookmark-load
1698        :active (fboundp 'bookmark-load)])))
1699
1700 ;;; The Buffers menu
1701
1702 (defgroup buffers-menu nil
1703   "Customization of `Buffers' menu."
1704   :group 'menu)
1705
1706 (defvar buffers-menu-omit-chars-list '(?b ?p ?l ?d))
1707
1708 (defcustom buffers-menu-max-size 25
1709   "*Maximum number of entries which may appear on the \"Buffers\" menu.
1710 If this is 10, then only the ten most-recently-selected buffers will be
1711 shown.  If this is nil, then all buffers will be shown.  Setting this to
1712 a large number or nil will slow down menu responsiveness."
1713   :type '(choice (const :tag "Show all" nil)
1714                  (integer 10))
1715   :group 'buffers-menu)
1716
1717 (defcustom complex-buffers-menu-p nil
1718   "*If non-nil, the buffers menu will contain several commands.
1719 Commands will be presented as submenus of each buffer line.  If this
1720 is false, then there will be only one command: select that buffer."
1721   :type 'boolean
1722   :group 'buffers-menu)
1723
1724 (defcustom buffers-menu-submenus-for-groups-p nil
1725   "*If non-nil, the buffers menu will contain one submenu per group of buffers.
1726 The grouping function is specified in `buffers-menu-grouping-function'.
1727 If this is an integer, do not build submenus if the number of buffers
1728 is not larger than this value."
1729   :type '(choice (const :tag "No Subgroups" nil)
1730                  (integer :tag "Max. submenus" 10)
1731                  (sexp :format "%t\n" :tag "Allow Subgroups" :value t))
1732   :group 'buffers-menu)
1733
1734 (defcustom buffers-menu-switch-to-buffer-function 'switch-to-buffer
1735   "*The function to call to select a buffer from the buffers menu.
1736 `switch-to-buffer' is a good choice, as is `pop-to-buffer'."
1737   :type '(radio (function-item switch-to-buffer)
1738                 (function-item pop-to-buffer)
1739                 (function :tag "Other"))
1740   :group 'buffers-menu)
1741
1742 (defcustom buffers-menu-omit-function 'buffers-menu-omit-invisible-buffers
1743   "*If non-nil, a function specifying the buffers to omit from the buffers menu.
1744 This is passed a buffer and should return non-nil if the buffer should be
1745 omitted.  The default value `buffers-menu-omit-invisible-buffers' omits
1746 buffers that are normally considered \"invisible\" (those whose name
1747 begins with a space)."
1748   :type '(choice (const :tag "None" nil)
1749                  function)
1750   :group 'buffers-menu)
1751
1752 (defcustom buffers-menu-format-buffer-line-function 'format-buffers-menu-line
1753   "*The function to call to return a string to represent a buffer in
1754 the buffers menu.  The function is passed a buffer and a number
1755 (starting with 1) indicating which buffer line in the menu is being
1756 processed and should return a string containing an accelerator
1757 spec. (Check out `menu-item-generate-accelerator-spec' as a convenient
1758 way of generating the accelerator specs.) The default value
1759 `format-buffers-menu-line' just returns the name of the buffer and
1760 uses the number as the accelerator.  Also check out
1761 `slow-format-buffers-menu-line' which returns a whole bunch of info
1762 about a buffer.
1763
1764 Note: Gross Compatibility Hack: Older versions of this function prototype
1765 only expected one argument, not two.  We deal gracefully with such
1766 functions by simply calling them with one argument and leaving out the
1767 line number.  However, this may go away at any time, so make sure to
1768 update all of your functions of this type."
1769   :type 'function
1770   :group 'buffers-menu)
1771
1772 (defcustom buffers-menu-sort-function
1773   'sort-buffers-menu-by-mode-then-alphabetically
1774   "*If non-nil, a function to sort the list of buffers in the buffers menu.
1775 It will be passed two arguments (two buffers to compare) and should return
1776 t if the first is \"less\" than the second.  One possible value is
1777 `sort-buffers-menu-alphabetically'; another is
1778 `sort-buffers-menu-by-mode-then-alphabetically'."
1779   :type '(choice (const :tag "None" nil)
1780                  function)
1781   :group 'buffers-menu)
1782
1783 (defcustom buffers-menu-grouping-function
1784   'group-buffers-menu-by-mode-then-alphabetically
1785   "*If non-nil, a function to group buffers in the buffers menu together.
1786 It will be passed two arguments, successive members of the sorted buffers
1787 list after being passed through `buffers-menu-sort-function'.  It should
1788 return non-nil if the second buffer begins a new group.  The return value
1789 should be the name of the old group, which may be used in hierarchical
1790 buffers menus.  The last invocation of the function contains nil as the
1791 second argument, so that the name of the last group can be determined.
1792
1793 The sensible values of this function are dependent on the value specified
1794 for `buffers-menu-sort-function'."
1795   :type '(choice (const :tag "None" nil)
1796                  function)
1797   :group 'buffers-menu)
1798
1799 (defun sort-buffers-menu-alphabetically (buf1 buf2)
1800   "For use as a value of `buffers-menu-sort-function'.
1801 Sorts the buffers in alphabetical order by name, but puts buffers beginning
1802 with a star at the end of the list."
1803   (let* ((nam1 (buffer-name buf1))
1804          (nam2 (buffer-name buf2))
1805          (inv1p (not (null (string-match "\\` " nam1))))
1806          (inv2p (not (null (string-match "\\` " nam2))))
1807          (star1p (not (null (string-match "\\`*" nam1))))
1808          (star2p (not (null (string-match "\\`*" nam2)))))
1809     (cond ((not (eq inv1p inv2p))
1810            (not inv1p))
1811           ((not (eq star1p star2p))
1812            (not star1p))
1813           (t
1814            (string-lessp nam1 nam2)))))
1815
1816 (defun sort-buffers-menu-by-mode-then-alphabetically (buf1 buf2)
1817   "For use as a value of `buffers-menu-sort-function'.
1818 Sorts first by major mode and then alphabetically by name, but puts buffers
1819 beginning with a star at the end of the list."
1820   (let* ((nam1 (buffer-name buf1))
1821          (nam2 (buffer-name buf2))
1822          (inv1p (not (null (string-match "\\` " nam1))))
1823          (inv2p (not (null (string-match "\\` " nam2))))
1824          (star1p (not (null (string-match "\\`*" nam1))))
1825          (star2p (not (null (string-match "\\`*" nam2))))
1826          (mode1 (symbol-value-in-buffer 'major-mode buf1))
1827          (mode2 (symbol-value-in-buffer 'major-mode buf2)))
1828     (cond ((not (eq inv1p inv2p))
1829            (not inv1p))
1830           ((not (eq star1p star2p))
1831            (not star1p))
1832           ((and star1p star2p (string-lessp nam1 nam2)))
1833           ((string-lessp mode1 mode2)
1834            t)
1835           ((string-lessp mode2 mode1)
1836            nil)
1837           (t
1838            (string-lessp nam1 nam2)))))
1839
1840 ;; this version is too slow on some machines.
1841 ;; (vintage 1990, that is)
1842 (defun slow-format-buffers-menu-line (buffer n)
1843   "For use as a value of `buffers-menu-format-buffer-line-function'.
1844 This returns a string containing a bunch of info about the buffer."
1845   (concat (menu-item-generate-accelerator-spec n buffers-menu-omit-chars-list)
1846           (format "%s%s %-19s %6s %-15s %s"
1847                   (if (buffer-modified-p buffer) "*" " ")
1848                   (if (symbol-value-in-buffer 'buffer-read-only buffer)
1849                       "%" " ")
1850                   (buffer-name buffer)
1851                   (buffer-size buffer)
1852                   (symbol-value-in-buffer 'mode-name buffer)
1853                   (or (buffer-file-name buffer) ""))))
1854
1855 (defun format-buffers-menu-line (buffer n)
1856   "For use as a value of `buffers-menu-format-buffer-line-function'.
1857 This just returns the buffer's name."
1858   (concat (menu-item-generate-accelerator-spec n buffers-menu-omit-chars-list)
1859           (buffer-name buffer)))
1860
1861 (defun group-buffers-menu-by-mode-then-alphabetically (buf1 buf2)
1862   "For use as a value of `buffers-menu-grouping-function'.
1863 This groups buffers by major mode.  It only really makes sense if
1864 `buffers-menu-sorting-function' is
1865 `sort-buffers-menu-by-mode-then-alphabetically'."
1866   (cond ((string-match "\\`*" (buffer-name buf1))
1867          (and (null buf2) "*Misc*"))
1868         ((or (null buf2)
1869              (string-match "\\`*" (buffer-name buf2))
1870              (not (eq (symbol-value-in-buffer 'major-mode buf1)
1871                       (symbol-value-in-buffer 'major-mode buf2))))
1872          (symbol-value-in-buffer 'mode-name buf1))
1873         (t nil)))
1874
1875 (defun buffer-menu-save-buffer (buffer)
1876   (save-excursion
1877     (set-buffer buffer)
1878     (save-buffer)))
1879
1880 (defun buffer-menu-write-file (buffer)
1881   (save-excursion
1882     (set-buffer buffer)
1883     (write-file (read-file-name
1884                  (format "Write %s to file: "
1885                          (buffer-name (current-buffer)))))))
1886
1887 (defsubst build-buffers-menu-internal (buffers)
1888   (let (name line (n 0))
1889     (mapcar
1890      #'(lambda (buffer)
1891          (if (eq buffer t)
1892              "---"
1893            (setq n (1+ n))
1894            (setq line
1895                  ; #### a truly Kyle-friendly hack.
1896                  (let ((fn buffers-menu-format-buffer-line-function))
1897                    (if (= (function-max-args fn) 1)
1898                        (funcall fn buffer)
1899                      (funcall fn buffer n))))
1900            (if complex-buffers-menu-p
1901                (delq nil
1902                      (list line
1903                            (vector "S%_witch to Buffer"
1904                                    (list buffers-menu-switch-to-buffer-function
1905                                          (setq name (buffer-name buffer)))
1906                                    t)
1907                            (if (eq buffers-menu-switch-to-buffer-function
1908                                    'switch-to-buffer)
1909                                (vector "Switch to Buffer, Other %_Frame"
1910                                        (list 'switch-to-buffer-other-frame
1911                                              (setq name (buffer-name buffer)))
1912                                        t)
1913                              nil)
1914                            (if (and (buffer-modified-p buffer)
1915                                     (buffer-file-name buffer))
1916                                (vector "%_Save Buffer"
1917                                        (list 'buffer-menu-save-buffer name) t)
1918                              ["%_Save Buffer" nil nil]
1919                              )
1920                            (vector "Save %_As..."
1921                                    (list 'buffer-menu-write-file name) t)
1922                            (vector "%_Delete Buffer" (list 'kill-buffer name)
1923                                    t)))
1924              ;; #### We don't want buffer names to be translated,
1925              ;; #### so we put the buffer name in the suffix.
1926              ;; #### Also, avoid losing with non-ASCII buffer names.
1927              ;; #### We still lose, however, if complex-buffers-menu-p. --mrb
1928              (vector ""
1929                      (list buffers-menu-switch-to-buffer-function
1930                            (buffer-name buffer))
1931                      t line))))
1932      buffers)))
1933
1934 (defun buffers-menu-filter (menu)
1935   "This is the menu filter for the top-level buffers \"Buffers\" menu.
1936 It dynamically creates a list of buffers to use as the contents of the menu.
1937 Only the most-recently-used few buffers will be listed on the menu, for
1938 efficiency reasons.  You can control how many buffers will be shown by
1939 setting `buffers-menu-max-size'.  You can control the text of the menu
1940 items by redefining the function `format-buffers-menu-line'."
1941   (let ((buffers (delete-if buffers-menu-omit-function (buffer-list))))
1942     (and (integerp buffers-menu-max-size)
1943          (> buffers-menu-max-size 1)
1944          (> (length buffers) buffers-menu-max-size)
1945          ;; shorten list of buffers (not with submenus!)
1946          (not (and buffers-menu-grouping-function
1947                    buffers-menu-submenus-for-groups-p))
1948          (setcdr (nthcdr buffers-menu-max-size buffers) nil))
1949     (if buffers-menu-sort-function
1950         (setq buffers (sort buffers buffers-menu-sort-function)))
1951     (if (and buffers-menu-grouping-function
1952              buffers-menu-submenus-for-groups-p
1953              (or (not (integerp buffers-menu-submenus-for-groups-p))
1954                  (> (length buffers) buffers-menu-submenus-for-groups-p)))
1955         (let (groups groupnames current-group)
1956           (mapl
1957            #'(lambda (sublist)
1958                (let ((groupname (funcall buffers-menu-grouping-function
1959                                          (car sublist) (cadr sublist))))
1960                  (setq current-group (cons (car sublist) current-group))
1961                  (if groupname
1962                      (progn
1963                        (setq groups (cons (nreverse current-group)
1964                                           groups))
1965                        (setq groupnames (cons groupname groupnames))
1966                        (setq current-group nil)))))
1967            buffers)
1968           (setq buffers
1969                 (mapcar*
1970                  #'(lambda (groupname group)
1971                      (cons groupname (build-buffers-menu-internal group)))
1972                  (nreverse groupnames)
1973                  (nreverse groups))))
1974       (if buffers-menu-grouping-function
1975           (progn
1976             (setq buffers
1977                   (mapcon
1978                    #'(lambda (sublist)
1979                        (cond ((funcall buffers-menu-grouping-function
1980                                        (car sublist) (cadr sublist))
1981                               (list (car sublist) t))
1982                              (t (list (car sublist)))))
1983                    buffers))
1984             ;; remove a trailing separator.
1985             (and (>= (length buffers) 2)
1986                  (let ((lastcdr (nthcdr (- (length buffers) 2) buffers)))
1987                    (if (eq t (cadr lastcdr))
1988                        (setcdr lastcdr nil))))))
1989       (setq buffers (build-buffers-menu-internal buffers)))
1990     (append menu buffers)
1991     ))
1992
1993 (defun language-environment-menu-filter (menu)
1994   "This is the menu filter for the \"Language Environment\" submenu."
1995   (declare (special language-environment-list))
1996   (let ((n 0))
1997     (mapcar (lambda (env-sym)
1998               (setq n (1+ n))
1999               `[ ,(concat (menu-item-generate-accelerator-spec n)
2000                           (capitalize (symbol-name env-sym)))
2001                  (set-language-environment ',env-sym)])
2002             language-environment-list)))
2003
2004 \f
2005 ;;; The Options menu
2006
2007 ;; We'll keep those variables here for a while, in order to provide a
2008 ;; function for porting the old options file that a user may own to Custom.
2009
2010 (defvar options-save-faces nil
2011   "*Non-nil value means save-options will save information about faces.
2012 A nil value means save-options will not save face information.
2013 Set this non-nil only if you use M-x edit-faces to change face
2014 settings.  If you use M-x customize-face or the \"Browse Faces...\"
2015 menu entry, you will see a button in the Customize Face buffer that you
2016 can use to permanently save your face changes.
2017
2018 M-x edit-faces is deprecated.  Support for it and this variable will
2019 be discontinued in a future release.")
2020
2021 (defvar save-options-init-file nil
2022   "File into which to save forms to load the options file (nil for .emacs).
2023 Normally this is nil, which means save into your .emacs file (the value
2024 of `user-init-file'.")
2025
2026 (defvar save-options-file ".xemacs-options"
2027   "File to save options into.
2028 This file is loaded from your .emacs file.
2029 If this is a relative filename, it is put into the same directory as your
2030 .emacs file.")
2031
2032
2033 \f
2034 ;;; The Help menu
2035
2036 (defun tutorials-menu-filter (menu-items)
2037   (declare (special language-info-alist
2038                     current-language-environment
2039                     tutorial-supported-languages))
2040   (append
2041    (if (featurep 'mule)
2042        (if (assq 'tutorial
2043                  (assoc current-language-environment language-info-alist))
2044            `([,(concat "%_Default (" current-language-environment ")")
2045               help-with-tutorial]))
2046      '(["%_English" help-with-tutorial]))
2047    (submenu-generate-accelerator-spec
2048     (if (featurep 'mule)
2049         ;; Mule tutorials.
2050         (mapcan #'(lambda (lang)
2051                     (let ((tut (assq 'tutorial lang)))
2052                       (and tut
2053                            (not (string= (car lang) "ASCII"))
2054                            ;; skip current language, since we already
2055                            ;; included it first
2056                            (not (string= (car lang)
2057                                          current-language-environment))
2058                            `([,(car lang)
2059                               (help-with-tutorial nil ,(cdr tut))]))))
2060                 language-info-alist)
2061       ;; Non mule tutorials.
2062       (mapcar #'(lambda (lang)
2063                   `[,(car lang)
2064                     (help-with-tutorial ,(format "TUTORIAL.%s"
2065                                                  (cadr lang)))])
2066               tutorial-supported-languages)))))
2067
2068 (set-menubar default-menubar)
2069
2070 \f
2071 ;;; Popup menus.
2072
2073 (defconst default-popup-menu
2074   '("SXEmacs Commands"
2075     ["%_Undo" advertised-undo
2076      :active (and (not (eq buffer-undo-list t))
2077                   (or buffer-undo-list pending-undo-list))
2078      :suffix (if (or (eq last-command 'undo)
2079                      (eq last-command 'advertised-undo))
2080                  "More" "")]
2081     ["Cu%_t" kill-primary-selection
2082      :active (selection-owner-p)]
2083     ["%_Copy" copy-primary-selection
2084      :active (selection-owner-p)]
2085     ["%_Paste" yank-clipboard-selection
2086      :active (selection-exists-p 'CLIPBOARD)]
2087     ["%_Delete" delete-primary-selection
2088      :active (selection-owner-p)]
2089     "-----"
2090     ["Select %_Block" mark-paragraph]
2091     ["Sp%_lit Window" split-window-vertically]
2092     ["U%_nsplit Window" delete-other-windows]
2093     ))
2094
2095 ;; In an effort to avoid massive menu clutter, this mostly worthless menu is
2096 ;; superseded by any local popup menu...
2097 (setq-default mode-popup-menu default-popup-menu)
2098
2099 \f
2100 ;; misc
2101
2102 (defun sxemacs-splash-buffer ()
2103   "Redisplay SXEmacs splash screen in a buffer."
2104   (interactive)
2105   (let ((buffer (get-buffer-create "*Splash*"))
2106         tmout)
2107     (set-buffer buffer)
2108     (setq buffer-read-only t)
2109     (erase-buffer buffer)
2110     (setq tmout (display-splash-frame))
2111     (when tmout
2112       (make-local-hook 'kill-buffer-hook)
2113       (add-hook 'kill-buffer-hook
2114                 `(lambda ()
2115                    (disable-timeout ,tmout))
2116                 nil t))
2117     (pop-to-buffer buffer)
2118     (delete-other-windows)))
2119
2120 \f
2121 ;;; backwards compatibility
2122 (provide 'x-menubar)
2123 (provide 'menubar-items)
2124
2125 ;;; menubar-items.el ends here.