aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-10-24 11:48:50 +0800
committerChong Yidong2012-10-24 11:48:50 +0800
commit75e8f9d2decbbebf7ffc20d17ff8676077071255 (patch)
tree7f70f1b78780777c9417a4498be0892402599272
parent5c78877693213f57d4d0a079fd9554c46eb35c6f (diff)
downloademacs-75e8f9d2decbbebf7ffc20d17ff8676077071255.tar.gz
emacs-75e8f9d2decbbebf7ffc20d17ff8676077071255.zip
Improve documentation of easy-menu-define.
* lisp/emacs-lisp/easymenu.el (easy-menu-define): Doc fix. * doc/lispref/keymaps.texi (Toolkit Differences): Node deleted. (Easy Menu): New node. Fixes: debbugs:12628
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/elisp.texi9
-rw-r--r--doc/lispref/keymaps.texi168
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/easymenu.el147
5 files changed, 213 insertions, 120 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 26765e7a384..9142ef49b12 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
12012-10-24 Chong Yidong <cyd@gnu.org>
2
3 * keymaps.texi (Toolkit Differences): Node deleted.
4 (Easy Menu): New node.
5
12012-10-23 Stefan Monnier <monnier@iro.umontreal.ca> 62012-10-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 7
3 * hooks.texi (Standard Hooks): Clarify that -hooks is deprecated. 8 * hooks.texi (Standard Hooks): Clarify that -hooks is deprecated.
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index d46cb071bf7..1d1dab8faac 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -800,17 +800,14 @@ Menu Keymaps
800* Menu Bar:: How to customize the menu bar. 800* Menu Bar:: How to customize the menu bar.
801* Tool Bar:: A tool bar is a row of images. 801* Tool Bar:: A tool bar is a row of images.
802* Modifying Menus:: How to add new items to a menu. 802* Modifying Menus:: How to add new items to a menu.
803* Easy Menu:: A convenience macro for defining menus.
803 804
804Defining Menus 805Defining Menus
805 806
806* Simple Menu Items:: A simple kind of menu key binding, 807* Simple Menu Items:: A simple kind of menu key binding.
807 limited in capabilities. 808* Extended Menu Items:: More complex menu item definitions.
808* Extended Menu Items:: More powerful menu item definitions
809 let you specify keywords to enable
810 various features.
811* Menu Separators:: Drawing a horizontal line through a menu. 809* Menu Separators:: Drawing a horizontal line through a menu.
812* Alias Menu Items:: Using command aliases in menu items. 810* Alias Menu Items:: Using command aliases in menu items.
813* Toolkit Differences:: Not all toolkits provide the same features.
814 811
815Major and Minor Modes 812Major and Minor Modes
816 813
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi
index 9fa6193a804..8fe729d50f2 100644
--- a/doc/lispref/keymaps.texi
+++ b/doc/lispref/keymaps.texi
@@ -1963,13 +1963,14 @@ is active for the next input event, that activates the keyboard menu
1963feature. 1963feature.
1964 1964
1965@menu 1965@menu
1966* Defining Menus:: How to make a keymap that defines a menu. 1966* Defining Menus:: How to make a keymap that defines a menu.
1967* Mouse Menus:: How users actuate the menu with the mouse. 1967* Mouse Menus:: How users actuate the menu with the mouse.
1968* Keyboard Menus:: How users actuate the menu with the keyboard. 1968* Keyboard Menus:: How users actuate the menu with the keyboard.
1969* Menu Example:: Making a simple menu. 1969* Menu Example:: Making a simple menu.
1970* Menu Bar:: How to customize the menu bar. 1970* Menu Bar:: How to customize the menu bar.
1971* Tool Bar:: A tool bar is a row of images. 1971* Tool Bar:: A tool bar is a row of images.
1972* Modifying Menus:: How to add new items to a menu. 1972* Modifying Menus:: How to add new items to a menu.
1973* Easy Menu:: A convenience macro for making menus.
1973@end menu 1974@end menu
1974 1975
1975@node Defining Menus 1976@node Defining Menus
@@ -2015,17 +2016,12 @@ an existing menu, you can specify its position in the menu using
2015@code{define-key-after} (@pxref{Modifying Menus}). 2016@code{define-key-after} (@pxref{Modifying Menus}).
2016 2017
2017@menu 2018@menu
2018* Simple Menu Items:: A simple kind of menu key binding, 2019* Simple Menu Items:: A simple kind of menu key binding.
2019 limited in capabilities. 2020* Extended Menu Items:: More complex menu item definitions.
2020* Extended Menu Items:: More powerful menu item definitions
2021 let you specify keywords to enable
2022 various features.
2023* Menu Separators:: Drawing a horizontal line through a menu. 2021* Menu Separators:: Drawing a horizontal line through a menu.
2024* Alias Menu Items:: Using command aliases in menu items. 2022* Alias Menu Items:: Using command aliases in menu items.
2025* Toolkit Differences:: Not all toolkits provide the same features.
2026@end menu 2023@end menu
2027 2024
2028
2029@node Simple Menu Items 2025@node Simple Menu Items
2030@subsubsection Simple Menu Items 2026@subsubsection Simple Menu Items
2031 2027
@@ -2312,28 +2308,6 @@ itself). To request this, give the alias symbol a non-@code{nil}
2312causes menu items for @code{make-read-only} and @code{make-writable} to 2308causes menu items for @code{make-read-only} and @code{make-writable} to
2313show the keyboard bindings for @code{read-only-mode}. 2309show the keyboard bindings for @code{read-only-mode}.
2314 2310
2315@node Toolkit Differences
2316@subsubsection Toolkit Differences
2317
2318The various toolkits with which you can build Emacs do not all support
2319the same set of features for menus. Some code works as expected with
2320one toolkit, but not under another.
2321
2322One example is menu actions or buttons in a top-level menu bar. The
2323following works with the Lucid toolkit or on MS Windows, but not with
2324GTK or Nextstep, where clicking on the item has no effect.
2325
2326@example
2327(defun menu-action-greet ()
2328 (interactive)
2329 (message "Hello Emacs User!"))
2330
2331(defun top-level-menu ()
2332 (interactive)
2333 (define-key lisp-interaction-mode-map [menu-bar m]
2334 '(menu-item "Action Button" menu-action-greet)))
2335@end example
2336
2337@node Mouse Menus 2311@node Mouse Menus
2338@subsection Menus and the Mouse 2312@subsection Menus and the Mouse
2339 2313
@@ -2813,3 +2787,125 @@ menu of Shell mode, after the item @code{break}:
2813 [work] '("Work" . work-command) 'break) 2787 [work] '("Work" . work-command) 'break)
2814@end example 2788@end example
2815@end defun 2789@end defun
2790
2791@node Easy Menu
2792@subsection Easy Menu
2793
2794 The following macro provides a convenient way to define pop-up menus
2795and/or menu bar menus.
2796
2797@defmac easy-menu-define symbol maps doc menu
2798This macro defines a pop-up menu and/or menu bar submenu, whose
2799contents are given by @var{menu}.
2800
2801If @var{symbol} is non-@code{nil}, it should be a symbol; then this
2802macro defines @var{symbol} as a function for popping up the menu
2803(@pxref{Pop-Up Menus}), with @var{doc} as its documentation string.
2804@var{symbol} should not be quoted.
2805
2806Regardless of the value of @var{symbol}, if @var{maps} is a keymap,
2807the menu is added to that keymap, as a top-level menu for the menu bar
2808(@pxref{Menu Bar}). It can also be a list of keymaps, in which case
2809the menu is added separately to each of those keymaps.
2810
2811The first element of @var{menu} must be a string, which serves as the
2812menu label. It may be followed by any number of the following
2813keyword-argument pairs:
2814
2815@table @code
2816@item :filter @var{function}
2817@var{function} must be a function which, if called with one
2818argument---the list of the other menu items---returns the actual items
2819to be displayed in the menu.
2820
2821@item :visible @var{include}
2822@var{include} is an expression; if it evaluates to @code{nil}, the
2823menu is made invisible. @code{:included} is an alias for
2824@code{:visible}.
2825
2826@item :active @var{enable}
2827@var{enable} is an expression; if it evaluates to @code{nil}, the menu
2828is not selectable. @code{:enable} is an alias for @code{:active}.
2829@end table
2830
2831The remaining elements in @var{menu} are menu items.
2832
2833A menu item can be a vector of three elements, @code{[@var{name}
2834@var{callback} @var{enable}]}. @var{name} is the menu item name (a
2835string). @var{callback} is a command to run, or an expression to
2836evaluate, when the item is chosen. @var{enable} is an expression; if
2837it evaluates to @code{nil}, the item is disabled for selection.
2838
2839Alternatively, a menu item may have the form:
2840
2841@smallexample
2842 [ @var{name} @var{callback} [ @var{keyword} @var{arg} ]... ]
2843@end smallexample
2844
2845@noindent
2846where @var{name} and @var{callback} have the same meanings as above,
2847and each optional @var{keyword} and @var{arg} pair should be one of
2848the following:
2849
2850@table @code
2851@item :keys @var{keys}
2852@var{keys} is a keyboard equivalent to the menu item (a string). This
2853is normally not needed, as keyboard equivalents are computed
2854automatically. @var{keys} is expanded with
2855@code{substitute-command-keys} before it is displayed (@pxref{Keys in
2856Documentation}).
2857
2858@item :key-sequence @var{keys}
2859@var{keys} is a hint for speeding up Emacs's first display of the
2860menu. It should be nil if you know that the menu item has no keyboard
2861equivalent; otherwise it should be a string or vector specifying a
2862keyboard equivalent for the menu item.
2863
2864@item :active @var{enable}
2865@var{enable} is an expression; if it evaluates to @code{nil}, the item
2866is make unselectable.. @code{:enable} is an alias for @code{:active}.
2867
2868@item :visible @var{include}
2869@var{include} is an expression; if it evaluates to @code{nil}, the
2870item is made invisible. @code{:included} is an alias for
2871@code{:visible}.
2872
2873@item :label @var{form}
2874@var{form} is an expression that is evaluated to obtain a value which
2875serves as the menu item's label (the default is @var{name}).
2876
2877@item :suffix @var{form}
2878@var{form} is an expression that is dynamically evaluated and whose
2879value is concatenated with the menu entry's label.
2880
2881@item :style @var{style}
2882@var{style} is a symbol describing the type of menu item; it should be
2883@code{toggle} (a checkbox), or @code{radio} (a radio button), or
2884anything else (meaning an ordinary menu item).
2885
2886@item :selected @var{selected}
2887@var{selected} is an expression; the checkbox or radio button is
2888selected whenever the expression's value is non-nil.
2889
2890@item :help @var{help}
2891@var{help} is a string describing the menu item.
2892@end table
2893
2894Alternatively, a menu item can be a string. Then that string appears
2895in the menu as unselectable text. A string consisting of dashes is
2896displayed as a separator (@pxref{Menu Separators}).
2897
2898Alternatively, a menu item can be a list with the same format as
2899@var{menu}. This is a submenu.
2900@end defmac
2901
2902Here is an example of using @code{easy-menu-define} to define a menu
2903similar to the one defined in the example in @ref{Menu Bar}:
2904
2905@example
2906(easy-menu-define words-menu global-map
2907 "Menu for word navigation commands."
2908 '("Words"
2909 ["Forward word" forward-word]
2910 ["Backward word" backward-word]))
2911@end example
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c84d0110fc7..5b709c76c74 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12012-10-24 Chong Yidong <cyd@gnu.org>
2
3 * emacs-lisp/easymenu.el (easy-menu-define): Doc fix (Bug#12628).
4
12012-10-24 Stefan Monnier <monnier@iro.umontreal.ca> 52012-10-24 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 * minibuffer.el (completion--all-sorted-completions-location): New var. 7 * minibuffer.el (completion--all-sorted-completions-location): New var.
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el
index 939fab78942..26a1fce2309 100644
--- a/lisp/emacs-lisp/easymenu.el
+++ b/lisp/emacs-lisp/easymenu.el
@@ -44,110 +44,101 @@ menus, turn this variable off, otherwise it is probably better to keep it on.")
44 44
45;;;###autoload 45;;;###autoload
46(defmacro easy-menu-define (symbol maps doc menu) 46(defmacro easy-menu-define (symbol maps doc menu)
47 "Define a menu bar submenu in maps MAPS, according to MENU. 47 "Define a pop-up menu and/or menu bar menu specified by MENU.
48If SYMBOL is non-nil, define SYMBOL as a function to pop up the
49submenu defined by MENU, with DOC as its doc string.
48 50
49If SYMBOL is non-nil, store the menu keymap in the value of SYMBOL, 51MAPS, if non-nil, should be a keymap or a list of keymaps; add
50and define SYMBOL as a function to pop up the menu, with DOC as its doc string. 52the submenu defined by MENU to the keymap or each of the keymaps,
51If SYMBOL is nil, just store the menu keymap into MAPS. 53as a top-level menu bar item.
52 54
53The first element of MENU must be a string. It is the menu bar item name. 55The first element of MENU must be a string. It is the menu bar
54It may be followed by the following keyword argument pairs 56item name. It may be followed by the following keyword argument
57pairs:
55 58
56 :filter FUNCTION 59 :filter FUNCTION
60 FUNCTION must be a function which, if called with one
61 argument---the list of the other menu items---returns the
62 items to actually display.
57 63
58FUNCTION is a function with one argument, the rest of menu items. 64 :visible INCLUDE
59It returns the remaining items of the displayed menu. 65 INCLUDE is an expression. The menu is visible if the
66 expression evaluates to a non-nil value. `:included' is an
67 alias for `:visible'.
60 68
61 :visible INCLUDE 69 :active ENABLE
70 ENABLE is an expression. The menu is enabled for selection
71 if the expression evaluates to a non-nil value. `:enable' is
72 an alias for `:active'.
62 73
63INCLUDE is an expression; this menu is only visible if this 74The rest of the elements in MENU are menu items.
64expression has a non-nil value. `:included' is an alias for `:visible'. 75A menu item can be a vector of three elements:
65 76
66 :active ENABLE 77 [NAME CALLBACK ENABLE]
67
68ENABLE is an expression; the menu is enabled for selection whenever
69this expression's value is non-nil. `:enable' is an alias for `:active'.
70
71The rest of the elements in MENU, are menu items.
72
73A menu item is usually a vector of three elements: [NAME CALLBACK ENABLE]
74 78
75NAME is a string--the menu item name. 79NAME is a string--the menu item name.
76 80
77CALLBACK is a command to run when the item is chosen, 81CALLBACK is a command to run when the item is chosen, or an
78or a list to evaluate when the item is chosen. 82expression to evaluate when the item is chosen.
79 83
80ENABLE is an expression; the item is enabled for selection 84ENABLE is an expression; the item is enabled for selection if the
81whenever this expression's value is non-nil. 85expression evaluates to a non-nil value.
82 86
83Alternatively, a menu item may have the form: 87Alternatively, a menu item may have the form:
84 88
85 [ NAME CALLBACK [ KEYWORD ARG ] ... ] 89 [ NAME CALLBACK [ KEYWORD ARG ]... ]
86
87Where KEYWORD is one of the symbols defined below.
88
89 :keys KEYS
90
91KEYS is a string; a complex keyboard equivalent to this menu item.
92This is normally not needed because keyboard equivalents are usually
93computed automatically.
94KEYS is expanded with `substitute-command-keys' before it is used.
95
96 :key-sequence KEYS
97
98KEYS is nil, a string or a vector; nil or a keyboard equivalent to this
99menu item.
100This is a hint that will considerably speed up Emacs's first display of
101a menu. Use `:key-sequence nil' when you know that this menu item has no
102keyboard equivalent.
103
104 :active ENABLE
105
106ENABLE is an expression; the item is enabled for selection whenever
107this expression's value is non-nil. `:enable' is an alias for `:active'.
108
109 :visible INCLUDE
110
111INCLUDE is an expression; this item is only visible if this
112expression has a non-nil value. `:included' is an alias for `:visible'.
113
114 :label FORM
115 90
116FORM is an expression that will be dynamically evaluated and whose 91where NAME and CALLBACK have the same meanings as above, and each
117value will be used for the menu entry's text label (the default is NAME). 92optional KEYWORD and ARG pair should be one of the following:
118 93
119 :suffix FORM 94 :keys KEYS
95 KEYS is a string; a keyboard equivalent to the menu item.
96 This is normally not needed because keyboard equivalents are
97 usually computed automatically. KEYS is expanded with
98 `substitute-command-keys' before it is used.
120 99
121FORM is an expression that will be dynamically evaluated and whose 100 :key-sequence KEYS
122value will be concatenated to the menu entry's label. 101 KEYS is a hint for speeding up Emacs's first display of the
102 menu. It should be nil if you know that the menu item has no
103 keyboard equivalent; otherwise it should be a string or
104 vector specifying a keyboard equivalent for the menu item.
123 105
124 :style STYLE 106 :active ENABLE
107 ENABLE is an expression; the item is enabled for selection
108 whenever this expression's value is non-nil. `:enable' is an
109 alias for `:active'.
125 110
126STYLE is a symbol describing the type of menu item. The following are 111 :visible INCLUDE
127defined: 112 INCLUDE is an expression; this item is only visible if this
113 expression has a non-nil value. `:included' is an alias for
114 `:visible'.
128 115
129toggle: A checkbox. 116 :label FORM
130 Prepend the name with `(*) ' or `( ) ' depending on if selected or not. 117 FORM is an expression that is dynamically evaluated and whose
131radio: A radio button. 118 value serves as the menu item's label (the default is NAME).
132 Prepend the name with `[X] ' or `[ ] ' depending on if selected or not.
133button: Surround the name with `[' and `]'. Use this for an item in the
134 menu bar itself.
135anything else means an ordinary menu item.
136 119
137 :selected SELECTED 120 :suffix FORM
121 FORM is an expression that is dynamically evaluated and whose
122 value is concatenated with the menu entry's label.
138 123
139SELECTED is an expression; the checkbox or radio button is selected 124 :style STYLE
140whenever this expression's value is non-nil. 125 STYLE is a symbol describing the type of menu item; it should
126 be `toggle' (a checkbox), or `radio' (a radio button), or any
127 other value (meaning an ordinary menu item).
141 128
142 :help HELP 129 :selected SELECTED
130 SELECTED is an expression; the checkbox or radio button is
131 selected whenever the expression's value is non-nil.
143 132
144HELP is a string, the help to display for the menu item. 133 :help HELP
134 HELP is a string, the help to display for the menu item.
145 135
146A menu item can be a string. Then that string appears in the menu as 136Alternatively, a menu item can be a string. Then that string
147unselectable text. A string consisting solely of hyphens is displayed 137appears in the menu as unselectable text. A string consisting
148as a solid horizontal line. 138solely of dashes is displayed as a menu separator.
149 139
150A menu item can be a list with the same format as MENU. This is a submenu." 140Alternatively, a menu item can be a list with the same format as
141MENU. This is a submenu."
151 (declare (indent defun) (debug (symbolp body))) 142 (declare (indent defun) (debug (symbolp body)))
152 `(progn 143 `(progn
153 ,(if symbol `(defvar ,symbol nil ,doc)) 144 ,(if symbol `(defvar ,symbol nil ,doc))