annotate lisp/menu-bar.el @ 3026:f66e648dfd03

(NO_MATHERR): Defined.
author Richard M. Stallman <rms@gnu.org>
date Mon, 24 May 1993 17:44:37 +0000
parents e41b3dc686bb
children 7d9b10bea55f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2488
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
1 ;;; menu-bar.el --- define a default menu bar.
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
2
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
3 ;; Author: RMS
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
4 ;; Keywords: internals
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
5
2485
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
6 ;; Copyright (C) 1993 Free Software Foundation, Inc.
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
7
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
8 ;; This file is part of GNU Emacs.
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
9
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
13 ;; any later version.
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
14
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
18 ;; GNU General Public License for more details.
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
19
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
20 ;; You should have received a copy of the GNU General Public License
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
23
2488
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
24 ;;; Code:
2485
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
25
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 (define-key global-map [menu-bar] (make-sparse-keymap "menu-bar"))
2181
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
27 (setq menu-bar-help-menu (make-sparse-keymap "Help"))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
28 (define-key global-map [menu-bar help] (cons "Help" menu-bar-help-menu))
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (setq menu-bar-edit-menu (make-sparse-keymap "Edit"))
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
30 (define-key global-map [menu-bar edit] (cons "Edit" menu-bar-edit-menu))
2181
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
31 (setq menu-bar-file-menu (make-sparse-keymap "File"))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
32 (define-key global-map [menu-bar file] (cons "File" menu-bar-file-menu))
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
2177
942a63709e37 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2175
diff changeset
34 (define-key menu-bar-file-menu [exit-emacs]
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 '("Exit Emacs" . save-buffers-kill-emacs))
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
36 (define-key menu-bar-file-menu [kill-buffer]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
37 '("Kill Buffer" . kill-this-buffer))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
38 (define-key menu-bar-file-menu [delete-frame] '("Delete Frame" . delete-frame))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
39 (define-key menu-bar-file-menu [print-buffer] '("Print Buffer" . print-buffer))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
40 (define-key menu-bar-file-menu [revert-buffer]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
41 '("Revert Buffer" . revert-buffer))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
42 (define-key menu-bar-file-menu [write-file]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
43 '("Save Buffer As..." . write-file))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
44 (define-key menu-bar-file-menu [save-buffer] '("Save Buffer" . save-buffer))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
45 (define-key menu-bar-file-menu [open-file] '("Open File..." . find-file))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
46 (define-key menu-bar-file-menu [new-frame] '("New Frame" . new-frame))
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
2847
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
48 (define-key menu-bar-edit-menu [fill] '("Fill" . fill-region))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
49 (define-key menu-bar-edit-menu [clear] '("Clear" . delete-region))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
50 (define-key menu-bar-edit-menu [paste] '("Paste" . yank))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
51 (define-key menu-bar-edit-menu [copy] '("Copy" . kill-ring-save))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
52 (define-key menu-bar-edit-menu [cut] '("Cut" . kill-region))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
53 (define-key menu-bar-edit-menu [undo] '("Undo" . undo))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
54
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
55 (put 'fill-region 'menu-enable 'mark-active)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
56 (put 'kill-region 'menu-enable 'mark-active)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
57 (put 'kill-ring-save 'menu-enable 'mark-active)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
58 (put 'yank 'menu-enable '(x-selection-exists-p))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
59 (put 'delete-region 'menu-enable 'mark-active)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
60 (put 'undo 'menu-enable '(if (eq last-command 'undo)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
61 pending-undo-list
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
62 (consp buffer-undo-list)))
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
64 (define-key menu-bar-help-menu [emacs-tutorial]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
65 '("Emacs Tutorial" . help-with-tutorial))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
66 (define-key menu-bar-help-menu [man] '("Man..." . manual-entry))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
67 (define-key menu-bar-help-menu [describe-variable]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
68 '("Describe Variable..." . describe-variable))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
69 (define-key menu-bar-help-menu [describe-function]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
70 '("Describe Function..." . describe-function))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
71 (define-key menu-bar-help-menu [describe-key]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
72 '("Describe Key..." . describe-key))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
73 (define-key menu-bar-help-menu [list-keybindings]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
74 '("List Keybindings" . describe-bindings))
2177
942a63709e37 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2175
diff changeset
75 (define-key menu-bar-help-menu [command-apropos]
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 '("Command Apropos..." . command-apropos))
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
77 (define-key menu-bar-help-menu [describe-mode]
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
78 '("Describe Mode" . describe-mode))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
79 (define-key menu-bar-help-menu [info] '("Info" . info))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
80
2177
942a63709e37 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2175
diff changeset
81 (define-key menu-bar-help-menu [emacs-news] '("Emacs News" . view-emacs-news))
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (defun kill-this-buffer () ; for the menubar
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 "Kills the current buffer."
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (interactive)
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (kill-buffer (current-buffer)))
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
87 (defun kill-this-buffer-enabled-p ()
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
88 (let ((count 0)
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
89 (buffers (buffer-list)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
90 (while buffers
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
91 (or (string-match "^ " (buffer-name (car buffers)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
92 (setq count (1+ count)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
93 (setq buffers (cdr buffers)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
94 (> count 1)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
95
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (put 'save-buffer 'menu-enable '(buffer-modified-p))
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
97 (put 'revert-buffer 'menu-enable '(and (buffer-modified-p) (buffer-file-name)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
98 (put 'delete-frame 'menu-enable '(cdr (visible-frame-list)))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
99 (put 'kill-this-buffer 'menu-enable '(kill-this-buffer-enabled-p))
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
100
2175
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (put 'advertised-undo 'menu-enable
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 '(and (not (eq t buffer-undo-list))
61d3483521d7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (if (eq last-command 'undo)
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
104 (and (boundp 'pending-undo-list)
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
105 pending-undo-list)
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
106 buffer-undo-list)))
2181
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
107
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
108 (define-key global-map [menu-bar buffer] '("Buffers" . mouse-buffer-menu))
2178
76da020d14f8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2177
diff changeset
109
2181
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
110 (defvar complex-buffers-menu-p nil
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
111 "*Non-nil says, offer a choice of actions after you pick a buffer.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
112 This applies to the Buffers menu from the menu bar.")
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
113
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
114 (defvar buffers-menu-max-size 10
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
115 "*Maximum number of entries which may appear on the Buffers menu.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
116 If this is 10, then only the ten most-recently-selected buffers are shown.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
117 If this is nil, then all buffers are shown.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
118 A large number or nil slows down menu responsiveness.")
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
119
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
120 (defun mouse-buffer-menu (event)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
121 "Pop up a menu of buffers for selection with the mouse.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
122 This switches buffers in the window that you clicked on,
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
123 and selects that window."
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
124 (interactive "e")
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
125 (let ((buffers (buffer-list))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
126 menu)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
127 ;; If requested, list only the N most recently selected buffers.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
128 (if (and (integerp buffers-menu-max-size)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
129 (> buffers-menu-max-size 1))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
130 (if (> (length buffers) buffers-menu-max-size)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
131 (setcdr (nthcdr buffers-menu-max-size buffers) nil)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
132 (setq menu
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
133 (list "Buffer Menu"
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
134 (cons "Select Buffer"
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
135 (let ((tail buffers)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
136 (maxlen 0)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
137 head)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
138 (while tail
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
139 (let ((elt (car tail)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
140 (if (not (string-match "^ "
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
141 (buffer-name elt)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
142 (setq head (cons
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
143 (cons
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
144 (format
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
145 "%14s %s"
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
146 (buffer-name elt)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
147 (or (buffer-file-name elt) ""))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
148 elt)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
149 head)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
150 (and head (> (length (car (car head))) maxlen)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
151 (setq maxlen (length (car (car head))))))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
152 (setq tail (cdr tail)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
153 (nconc (reverse head)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
154 (list (cons (concat (make-string (- (/ maxlen 2) 8) ?\ )
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
155 "List All Buffers")
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
156 'list-buffers)))))))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
157
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
158
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
159 (let ((buf (x-popup-menu (if (listp event) event
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
160 (cons '(0 0) (selected-frame)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
161 menu))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
162 (window (and (listp event) (posn-window (event-start event)))))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
163 (if (eq buf 'list-buffers)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
164 (list-buffers)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
165 (if buf
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
166 (if complex-buffers-menu-p
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
167 (let ((action (x-popup-menu (if (listp event) event
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
168 (cons '(0 0) (selected-frame)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
169 '("Buffer Action"
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
170 (""
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
171 ("Save Buffer" . save-buffer)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
172 ("Kill Buffer" . kill-buffer)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
173 ("Select Buffer" . switch-to-buffer))))))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
174 (if (eq action 'save-buffer)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
175 (save-excursion
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
176 (set-buffer buf)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
177 (save-buffer))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
178 (funcall action buf)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
179 (and (windowp window)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
180 (select-window window))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
181 (switch-to-buffer buf)))))))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
182
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
183 ;; this version is too slow
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
184 ;;;(defun format-buffers-menu-line (buffer)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
185 ;;; "Returns a string to represent the given buffer in the Buffer menu.
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
186 ;;;nil means the buffer shouldn't be listed. You can redefine this."
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
187 ;;; (if (string-match "\\` " (buffer-name buffer))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
188 ;;; nil
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
189 ;;; (save-excursion
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
190 ;;; (set-buffer buffer)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
191 ;;; (let ((size (buffer-size)))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
192 ;;; (format "%s%s %-19s %6s %-15s %s"
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
193 ;;; (if (buffer-modified-p) "*" " ")
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
194 ;;; (if buffer-read-only "%" " ")
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
195 ;;; (buffer-name)
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
196 ;;; size
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
197 ;;; mode-name
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
198 ;;; (or (buffer-file-name) ""))))))
5a9d9dcc4750 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2178
diff changeset
199
2847
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
200 (defvar menu-bar-mode nil)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
201
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
202 (defun menu-bar-mode (flag)
3007
e41b3dc686bb (menu-bar-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2847
diff changeset
203 "Toggle display of a menu bar on each frame.
2847
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
204 This command applies to all frames that exist and frames to be
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
205 created in the future.
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
206 With a numeric argument, if the argument is negative,
3007
e41b3dc686bb (menu-bar-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2847
diff changeset
207 turn off menu bars; otherwise, turn on menu bars."
2847
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
208 (interactive "P")
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
209 (setq menu-bar-mode (if (null flag) (not menu-bar-mode)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
210 (or (not (numberp flag)) (>= flag 0))))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
211 (let ((parameter (assq 'menu-bar-lines default-frame-alist)))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
212 (if (consp parameter)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
213 (setcdr parameter (if menu-bar-mode 1 0))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
214 (setq default-frame-alist
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
215 (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
216 default-frame-alist))))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
217 (let ((frames (frame-list)))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
218 (while frames
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
219 ;; Turn menu bar on or off in existing frames.
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
220 ;; (Except for minibuffer-only frames.)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
221 (or (eq 'only (cdr (assq 'minibuffer (frame-parameters (car frames)))))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
222 (modify-frame-parameters
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
223 (car frames)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
224 (list (if menu-bar-mode
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
225 '(menu-bar-lines . 1)
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
226 '(menu-bar-lines . 0)))))
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
227 (setq frames (cdr frames)))))
2485
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
228
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
229 ;; Make frames created from now on have a menu bar.
2847
01a46a8f1e1b (fill-region, kill-region, delete-region)
Richard M. Stallman <rms@gnu.org>
parents: 2765
diff changeset
230 (menu-bar-mode t)
2485
c34bbe650160 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2181
diff changeset
231
2765
0eb1a195f56e Provide 'menu-bar.
Richard M. Stallman <rms@gnu.org>
parents: 2695
diff changeset
232 (provide 'menu-bar)
0eb1a195f56e Provide 'menu-bar.
Richard M. Stallman <rms@gnu.org>
parents: 2695
diff changeset
233
2488
278580be9b4a Added and corrected library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2485
diff changeset
234 ;;; menu-bar.el ends here