comparison man/lispref/menus.texi @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 @c -*-texinfo-*-
2 @c This is part of the XEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 @c Copyright (C) 1995 Sun Microsystems.
5 @c See the file lispref.texi for copying conditions.
6 @setfilename ../../info/menu.info
7 @node Menus, Dialog Boxes, Keymaps, Top
8 @chapter Menus
9 @cindex menu
10
11 @menu
12 * Menu Format:: Format of a menu description.
13 * Menubar Format:: How to specify a menubar.
14 * Menubar:: Functions for controlling the menubar.
15 * Modifying Menus:: Modifying a menu description.
16 * Pop-Up Menus:: Functions for specifying pop-up menus.
17 * Menu Filters:: Filter functions for the default menubar.
18 * Buffers Menu:: The menu that displays the list of buffers.
19 @end menu
20
21 @node Menu Format
22 @section Format of Menus
23 @cindex menu format
24 @cindex format of menus
25
26 A menu is described using a @dfn{menu description}, which is a list of
27 menu items, keyword-value pairs, strings, and submenus. The menu
28 description specifies which items are present in the menu, what function
29 each item invokes, and whether the item is selectable or not. Pop-up
30 menus are directly described with a menu description, while menubars are
31 described slightly differently (see below).
32
33 The first element of a menu must be a string, which is the name of the
34 menu. This is the string that will be displayed in the parent menu or
35 menubar, if any. This string is not displayed in the menu itself,
36 except in the case of the top level pop-up menu, where there is no
37 parent. In this case, the string will be displayed at the top of the
38 menu if @code{popup-menu-titles} is non-@code{nil}.
39
40 Immediately following the first element there may optionally be up
41 to three keyword-value pairs, as follows:
42
43 @table @code
44 @item :included @var{form}
45 This can be used to control the visibility of a menu. The form is
46 evaluated and the menu will be omitted if the result is @code{nil}.
47
48 @item :config @var{symbol}
49 This is an efficient shorthand for @code{:included (memq @var{symbol}
50 menubar-configuration)}. See the variable @code{menubar-configuration}.
51
52 @item :filter @var{function}
53 A menu filter is used to sensitize or incrementally create a submenu
54 only when it is selected by the user and not every time the menubar is
55 activated. The filter function is passed the list of menu items in the
56 submenu and must return a list of menu items to be used for the menu.
57 It is called only when the menu is about to be displayed, so other menus
58 may already be displayed. Vile and terrible things will happen if a
59 menu filter function changes the current buffer, window, or frame. It
60 also should not raise, lower, or iconify any frames. Basically, the
61 filter function should have no side-effects.
62 @end table
63
64 The rest of the menu consists of elements as follows:
65
66 @itemize @bullet
67 @item
68 A @dfn{menu item}, which is a vector in the following form:
69
70 @example
71 @code{[ @var{name} @var{callback} @var{:keyword} @var{value} @var{:keyword} @var{value} ... ]}
72 @end example
73
74 @var{name} is a string, the name of the menu item; it is the string to
75 display on the menu. It is filtered through the resource database, so
76 it is possible for resources to override what string is actually
77 displayed.
78
79 @var{callback} is a form that will be invoked when the menu item is
80 selected. If the callback of a menu item is a symbol, then it must name
81 a command. It will be invoked with @code{call-interactively}. If it is
82 a list, then it is evaluated with @code{eval}.
83
84 The valid keywords and their meanings are described below.
85
86 Note that for compatibility purposes, the form
87
88 @example
89 @code{[ @var{name} @var{callback} @var{active-p} ]}
90 @end example
91
92 is also accepted and is equivalent to
93
94 @example
95 @code{[ @var{name} @var{callback} :active @var{active-p} ]}
96 @end example
97
98 and the form
99
100 @example
101 @code{[ @var{name} @var{callback} @var{active-p} @var{suffix}]}
102 @end example
103
104 is accepted and is equivalent to
105
106 @example
107 @code{[ @var{name} @var{callback} :active @var{active-p} :suffix @var{suffix}]}
108 @end example
109
110 However, these older forms are deprecated and should generally not be used.
111
112 @item
113 If an element of a menu is a string, then that string will be presented
114 in the menu as unselectable text.
115
116 @item
117 If an element of a menu is a string consisting solely of hyphens, then
118 that item will be presented as a solid horizontal line.
119
120 @item
121 If an element of a menu is a string beginning with @samp{--:}, then
122 a particular sort of horizontal line will be displayed, as follows:
123
124 @table @samp
125 @item "--:singleLine"
126 A solid horizontal line. This is equivalent to a string consisting
127 solely of hyphens.
128 @item "--:doubleLine"
129 A solid double horizontal line.
130 @item "--:singleDashedLine"
131 A dashed horizontal line.
132 @item "--:doubleDashedLine"
133 A dashed double horizontal line.
134 @item "--:noLine"
135 No line (but a small space is left).
136 @item "--:shadowEtchedIn"
137 A solid horizontal line with a 3-d recessed appearance.
138 @item "--:shadowEtchedOut"
139 A solid horizontal line with a 3-d pushed-out appearance.
140 @item "--:shadowDoubleEtchedIn"
141 A solid double horizontal line with a 3-d recessed appearance.
142 @item "--:shadowDoubleEtchedOut"
143 A solid double horizontal line with a 3-d pushed-out appearance.
144 @item "--:shadowEtchedInDash"
145 A dashed horizontal line with a 3-d recessed appearance.
146 @item "--:shadowEtchedOutDash"
147 A dashed horizontal line with a 3-d pushed-out appearance.
148 @item "--:shadowDoubleEtchedInDash"
149 A dashed double horizontal line with a 3-d recessed appearance.
150 @item "--:shadowDoubleEtchedOutDash"
151 A dashed double horizontal line with a 3-d pushed-out appearance.
152 @end table
153
154 @item
155 If an element of a menu is a list, it is treated as a submenu. The name
156 of that submenu (the first element in the list) will be used as the name
157 of the item representing this menu on the parent.
158 @end itemize
159
160 The possible keywords are as follows:
161
162 @table @asis
163 @item :active @var{form}
164 @var{form} will be evaluated when the menu that this item is a part of
165 is about to be displayed, and the item will be selectable only if the
166 result is non-@code{nil}. If the item is unselectable, it will
167 usually be displayed grayed-out to indicate this.
168
169 @item :suffix @var{string}
170 The string is appended to the displayed name. This provides a
171 convenient way of adding the name of a command's ``argument'' to the
172 menu, like like @samp{Kill Buffer NAME}.
173
174 @item :keys @var{string}
175 Normally, the keyboard equivalents of commands in menus are displayed
176 when the ``callback'' is a symbol. This can be used to specify keys for
177 more complex menu items. It is passed through
178 @code{substitute-command-keys} first.
179
180 @item :style @var{style}
181 Specifies what kind of object this menu item is. @var{style} be one
182 of the symbols
183
184 @table @code
185 @item nil
186 A normal menu item.
187 @item toggle
188 A toggle button.
189 @item radio
190 A radio button.
191 @item button
192 A menubar button.
193 @end table
194
195 The only difference between toggle and radio buttons is how they are
196 displayed. But for consistency, a toggle button should be used when
197 there is one option whose value can be turned on or off, and radio
198 buttons should be used when there is a set of mutually exclusive options.
199 When using a group of radio buttons, you should arrange for no more than
200 one to be marked as selected at a time.
201
202 @item :selected @var{form}
203 Meaningful only when @var{style} is @code{toggle}, @code{radio} or
204 @code{button}. This specifies whether the button will be in the
205 selected or unselected state. @var{form} is evaluated, as for
206 @code{:active}.
207
208 @item :included @var{form}
209 This can be used to control the visibility of a menu item. The form is
210 evaluated and the menu item is only displayed if the result is
211 non-@code{nil}. Note that this is different from @code{:active}: If
212 @code{:active} evaluates to @code{nil}, the item will be displayed
213 grayed out, while if @code{:included} evaluates to @code{nil}, the item
214 will be omitted entirely.
215
216 @item :config @var{symbol}
217 This is an efficient shorthand for @code{:included (memq @var{symbol}
218 menubar-configuration)}. See the variable @code{menubar-configuration}.
219 @end table
220
221 @defvar menubar-configuration
222 This variable holds a list of symbols, against which the value of the
223 @code{:config} tag for each menubar item will be compared. If a menubar
224 item has a @code{:config} tag, then it is omitted from the menubar if
225 that tag is not a member of the @code{menubar-configuration} list.
226 @end defvar
227
228 For example:
229
230 @example
231 ("File"
232 :filter file-menu-filter ; file-menu-filter is a function that takes
233 ; one argument (a list of menu items) and
234 ; returns a list of menu items
235 [ "Save As..." write-file t ]
236 [ "Revert Buffer" revert-buffer (buffer-modified-p) ]
237 [ "Read Only" toggle-read-only :style toggle :selected buffer-read-only ]
238 )
239 @end example
240
241 @node Menubar Format
242 @section Format of the Menubar
243 @cindex menubar format
244 @cindex format of the menubar
245
246 A menubar is a list of menus, menu items, and strings. The format is
247 similar to that of a menu, except:
248
249 @itemize @bullet
250 @item
251 The first item need not be a string, and is not treated specially.
252
253 @item
254 A string consisting solely of hyphens is not treated specially.
255
256 @item
257 If an element of a menubar is @code{nil}, then it is used to represent
258 the division between the set of menubar items which are flush-left and
259 those which are flush-right. (Note: this isn't completely implemented
260 yet.)
261 @end itemize
262
263 @node Menubar
264 @section Menubar
265 @cindex menubar
266
267 @defvar current-menubar
268 This variable holds the description of the current menubar. This may be
269 buffer-local. When the menubar is changed, the function
270 @code{set-menubar-dirty-flag} has to be called in order for the menubar
271 to be updated on the screen.
272 @end defvar
273
274 @defvr Constant default-menubar
275 This variable holds the menubar description of the menubar that is
276 visible at startup. This is the value that @code{current-menubar}
277 has at startup.
278 @end defvr
279
280 @defun set-menubar-dirty-flag
281 This function tells XEmacs that the menubar widget has to be updated.
282 Changes to the menubar will generally not be visible until this function
283 is called.
284 @end defun
285
286 The following convenience functions are provided for setting the
287 menubar. They are equivalent to doing the appropriate action to change
288 @code{current-menubar}, and then calling @code{set-menubar-dirty-flag}.
289 Note that these functions copy their argument using
290 @code{copy-sequence}.
291
292 @defun set-menubar menubar
293 This function sets the default menubar to be @var{menubar} (@pxref{Menu
294 Format}). This is the menubar that will be visible in buffers that
295 have not defined their own, buffer-local menubar.
296 @end defun
297
298 @defun set-buffer-menubar menubar
299 This function sets the buffer-local menubar to be @var{menubar}. This
300 does not change the menubar in any buffers other than the current one.
301 @end defun
302
303 Miscellaneous:
304
305 @defvar menubar-show-keybindings
306 If true, the menubar will display keyboard equivalents. If false, only
307 the command names will be displayed.
308 @end defvar
309
310 @defvar activate-menubar-hook
311 Function or functions called before a menubar menu is pulled down.
312 These functions are called with no arguments, and should interrogate and
313 modify the value of @code{current-menubar} as desired.
314
315 The functions on this hook are invoked after the mouse goes down, but
316 before the menu is mapped, and may be used to activate, deactivate, add,
317 or delete items from the menus. However, using a filter (with the
318 @code{:filter} keyword in a menu description) is generally a more
319 efficient way of accomplishing the same thing, because the filter is
320 invoked only when the actual menu goes down. With a complex menu,
321 there can be a quite noticeable and sometimes aggravating delay if
322 all menu modification is implemented using the @code{activate-menubar-hook}.
323 See above.
324
325 These functions may return the symbol @code{t} to assert that they have
326 made no changes to the menubar. If any other value is returned, the
327 menubar is recomputed. If @code{t} is returned but the menubar has been
328 changed, then the changes may not show up right away. Returning
329 @code{nil} when the menubar has not changed is not so bad; more
330 computation will be done, but redisplay of the menubar will still be
331 performed optimally.
332 @end defvar
333
334 @defvar menu-no-selection-hook
335 Function or functions to call when a menu or dialog box is dismissed
336 without a selection having been made.
337 @end defvar
338
339 @node Modifying Menus
340 @section Modifying Menus
341
342 The following functions are provided to modify the menubar of one of its
343 submenus. Note that these functions modify the menu in-place, rather
344 than copying it and making a new menu.
345
346 Some of these functions take a @dfn{menu path}, which is a list of
347 strings identifying the menu to be modified. For example,
348 @code{("File")} names the top-level ``File'' menu. @code{("File"
349 "Foo")} names a hypothetical submenu of ``File''.
350
351 Others take a @dfn{menu item path}, which is similar to a menu path but
352 also specifies a particular item to be modified. For example,
353 @code{("File" "Save")} means the menu item called ``Save'' under the
354 top-level ``File'' menu. @code{("Menu" "Foo" "Item")} means the menu
355 item called ``Item'' under the ``Foo'' submenu of ``Menu''.
356
357 @defun add-submenu menu-path submenu &optional before
358 This function adds a menu to the menubar or one of its submenus. If the
359 named menu exists already, it is changed.
360
361 @var{menu-path} identifies the menu under which the new menu should be
362 inserted. If @var{menu-path} is @code{nil}, then the menu will be added
363 to the menubar itself.
364
365 @var{submenu} is the new menu to add (@pxref{Menu Format}).
366
367 @var{before}, if provided, is the name of a menu before which this menu
368 should be added, if this menu is not on its parent already. If the menu
369 is already present, it will not be moved.
370 @end defun
371
372 @defun add-menu-button menu-path menu-leaf &optional before
373 This function adds a menu item to some menu, creating the menu first if
374 necessary. If the named item exists already, it is changed.
375
376 @var{menu-path} identifies the menu under which the new menu item should
377 be inserted.
378
379 @var{menu-leaf} is a menubar leaf node (@pxref{Menu Format}).
380
381 @var{before}, if provided, is the name of a menu before which this item
382 should be added, if this item is not on the menu already. If the item
383 is already present, it will not be moved.
384 @end defun
385
386 @defun delete-menu-item menu-item-path
387 This function removes the menu item specified by @var{menu-item-path}
388 from the menu hierarchy.
389 @end defun
390
391 @defun enable-menu-item menu-item-path
392 This function makes the menu item specified by @var{menu-item-path} be
393 selectable.
394 @end defun
395
396 @defun disable-menu-item menu-item-path
397 This function makes the menu item specified by @var{menu-item-path} be
398 unselectable.
399 @end defun
400
401 @defun relabel-menu-item menu-item-path new-name
402 This function changes the string of the menu item specified by
403 @var{menu-item-path}. @var{new-name} is the string that the menu item
404 will be printed as from now on.
405 @end defun
406
407 The following function can be used to search for a particular item in
408 a menubar specification, given a path to the item.
409
410 @defun find-menu-item menubar menu-item-path &optional parent
411 This function searches @var{menubar} for the item given by
412 @var{menu-item-path} starting from @var{parent} (@code{nil} means start
413 at the top of @var{menubar}). This function returns @code{(@var{item}
414 . @var{parent})}, where @var{parent} is the immediate parent of the item
415 found (a menu description), and @var{item} is either a vector, list, or
416 string, depending on the nature of the menu item.
417
418 This function signals an error if the item is not found.
419 @end defun
420
421 The following deprecated functions are also documented, so that
422 existing code can be understood. You should not use these functions
423 in new code.
424
425 @defun add-menu menu-path menu-name menu-items &optional before
426 This function adds a menu to the menubar or one of its submenus. If the
427 named menu exists already, it is changed. This is obsolete; use
428 @code{add-submenu} instead.
429
430 @var{menu-path} identifies the menu under which the new menu should be
431 inserted. If @var{menu-path} is @code{nil}, then the menu will be added
432 to the menubar itself.
433
434 @var{menu-name} is the string naming the menu to be added;
435 @var{menu-items} is a list of menu items, strings, and submenus. These
436 two arguments are the same as the first and following elements of a menu
437 description (@pxref{Menu Format}).
438
439 @var{before}, if provided, is the name of a menu before which this
440 menu should be added, if this menu is not on its parent already. If the
441 menu is already present, it will not be moved.
442 @end defun
443
444 @defun add-menu-item menu-path item-name function enabled-p &optional before
445 This function adds a menu item to some menu, creating the menu first if
446 necessary. If the named item exists already, it is changed. This is
447 obsolete; use @code{add-menu-button} instead.
448
449 @var{menu-path} identifies the menu under which the new menu item should
450 be inserted. @var{item-name}, @var{function}, and @var{enabled-p} are
451 the first, second, and third elements of a menu item vector (@pxref{Menu
452 Format}).
453
454 @var{before}, if provided, is the name of a menu item before which this
455 item should be added, if this item is not on the menu already. If the
456 item is already present, it will not be moved.
457 @end defun
458
459 @node Menu Filters
460 @section Menu Filters
461 @cindex menu filters
462
463 The following filter functions are provided for use in
464 @code{default-menubar}. You may want to use them in your own menubar
465 description.
466
467 @defun file-menu-filter menu-items
468 This function changes the arguments and sensitivity of these File menu items:
469
470 @table @samp
471 @item Delete Buffer
472 Has the name of the current buffer appended to it.
473 @item Print Buffer
474 Has the name of the current buffer appended to it.
475 @item Pretty-Print Buffer
476 Has the name of the current buffer appended to it.
477 @item Save Buffer
478 Has the name of the current buffer appended to it, and is sensitive only
479 when the current buffer is modified.
480 @item Revert Buffer
481 Has the name of the current buffer appended to it, and is sensitive only
482 when the current buffer has a file.
483 @item Delete Frame
484 Sensitive only when there is more than one visible frame.
485 @end table
486 @end defun
487
488 @defun edit-menu-filter menu-items
489 This function changes the arguments and sensitivity of these Edit menu items:
490
491 @table @samp
492 @item Cut
493 Sensitive only when XEmacs owns the primary X Selection (if
494 @code{zmacs-regions} is @code{t}, this is equivalent to saying that
495 there is a region selected).
496 @item Copy
497 Sensitive only when XEmacs owns the primary X Selection.
498 @item Clear
499 Sensitive only when XEmacs owns the primary X Selection.
500 @item Paste
501 Sensitive only when there is an owner for the X Clipboard Selection.
502 @item Undo
503 Sensitive only when there is undo information. While in the midst of an
504 undo, this is changed to @samp{Undo More}.
505 @end table
506 @end defun
507
508 @defun buffers-menu-filter menu-items
509 This function sets up the Buffers menu. @xref{Buffers Menu} for
510 more information.
511 @end defun
512
513 @node Pop-Up Menus
514 @section Pop-Up Menus
515 @cindex pop-up menu
516
517 @defun popup-menu menu-desc
518 This function pops up a menu specified by @var{menu-desc}, which is a
519 menu description (@pxref{Menu Format}). The menu is displayed at the
520 current mouse position.
521 @end defun
522
523 @defun popup-menu-up-p
524 This function returns @code{t} if a pop-up menu is up, @code{nil}
525 otherwise.
526 @end defun
527
528 @defvar popup-menu-titles
529 If true (the default), pop-up menus will have title bars at the top.
530 @end defvar
531
532 Some machinery is provided that attempts to provide a higher-level
533 mechanism onto pop-up menus. This only works if you do not redefine
534 the binding for button3.
535
536 @deffn Command popup-mode-menu
537 This function pops up a menu of global and mode-specific commands. The
538 menu is computed by combining @code{global-popup-menu} and
539 @code{mode-popup-menu}. This is the default binding for button3.
540 You should generally not change this binding.
541 @end deffn
542
543 @defvar global-popup-menu
544 This holds the global popup menu. This is present in all modes.
545 (This is @code{nil} by default.)
546 @end defvar
547
548 @defvar mode-popup-menu
549 The mode-specific popup menu. Automatically buffer local.
550 This is appended to the default items in @code{global-popup-menu}.
551 @end defvar
552
553 @defvr Constant default-popup-menu
554 This holds the default value of @code{mode-popup-menu}.
555 @end defvr
556
557 @defvar activate-popup-menu-hook
558 Function or functions run before a mode-specific popup menu is made
559 visible. These functions are called with no arguments, and should
560 interrogate and modify the value of @code{global-popup-menu} or
561 @code{mode-popup-menu} as desired. Note: this hook is only run if you
562 use @code{popup-mode-menu} for activating the global and mode-specific
563 commands; if you have your own binding for button3, this hook won't be
564 run.
565 @end defvar
566
567 The following convenience functions are provided for displaying
568 pop-up menus.
569
570 @defun popup-buffer-menu event
571 This function pops up a copy of the @samp{Buffers} menu (from the menubar)
572 where the mouse is clicked.
573 @end defun
574
575 @defun popup-menubar-menu event
576 This function pops up a copy of menu that also appears in the menubar.
577 @end defun
578
579 @node Buffers Menu
580 @section Buffers Menu
581 @cindex buffers menu
582
583 The following options control how the @samp{Buffers} menu is displayed.
584 This is a list of all (or a subset of) the buffers currently in existence,
585 and is updated dynamically.
586
587 @defopt buffers-menu-max-size
588 This user option holds the maximum number of entries which may appear on
589 the @samp{Buffers} menu. If this is 10, then only the ten
590 most-recently-selected buffers will be shown. If this is @code{nil},
591 then all buffers will be shown. Setting this to a large number or
592 @code{nil} will slow down menu responsiveness.
593 @end defopt
594
595 @defun format-buffers-menu-line buffer
596 This function returns a string to represent @var{buffer} in the
597 @samp{Buffers} menu. @code{nil} means the buffer shouldn't be listed.
598 You can redefine this.
599 @end defun
600
601 @defopt complex-buffers-menu-p
602 If true, the @samp{Buffers} menu will contain several commands, as submenus
603 of each buffer line. If this is false, then there will be only one command:
604 select that buffer.
605 @end defopt
606
607 @defopt buffers-menu-switch-to-buffer-function
608 This user option holds the function to call to select a buffer from the
609 @samp{Buffers} menu. @code{switch-to-buffer} is a good choice, as is
610 @code{pop-to-buffer}.
611 @end defopt
612