aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorChong Yidong2012-10-24 11:48:50 +0800
committerChong Yidong2012-10-24 11:48:50 +0800
commit75e8f9d2decbbebf7ffc20d17ff8676077071255 (patch)
tree7f70f1b78780777c9417a4498be0892402599272 /doc
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
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/elisp.texi9
-rw-r--r--doc/lispref/keymaps.texi168
3 files changed, 140 insertions, 42 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