Mercurial > emacs
annotate lisp/emacs-lisp/easymenu.el @ 112402:a102f5772eaa
Merge from mainline.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 21 Jan 2011 12:27:07 -0800 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
38431
853c3674f20a
Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34541
diff
changeset
|
1 ;;; easymenu.el --- support the easymenu interface for defining a menu |
6529 | 2 |
74466 | 3 ;; Copyright (C) 1994, 1996, 1998, 1999, 2000, 2001, 2002, 2003, |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
6600
f75ac1f3d99c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6542
diff
changeset
|
5 |
6529 | 6 ;; Keywords: emulations |
38431
853c3674f20a
Fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34541
diff
changeset
|
7 ;; Author: Richard Stallman <rms@gnu.org> |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
8 ;; Package: emacs |
6529 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94305
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
6529 | 13 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94305
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94305
diff
changeset
|
15 ;; (at your option) any later version. |
6529 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94305
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
6529 | 24 |
14169 | 25 ;;; Commentary: |
26 | |
27 ;; This is compatible with easymenu.el by Per Abrahamsen | |
28 ;; but it is much simpler as it doesn't try to support other Emacs versions. | |
29 ;; The code was mostly derived from lmenu.el. | |
6529 | 30 |
31 ;;; Code: | |
32 | |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
33 (eval-when-compile (require 'cl)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
34 |
97459
84cc2bc95fba
(easy-menu-add): Don't precompute keybindings
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95371
diff
changeset
|
35 (defvar easy-menu-precalculate-equivalent-keybindings nil |
22196
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
36 "Determine when equivalent key bindings are computed for easy-menu menus. |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
37 It can take some time to calculate the equivalent key bindings that are shown |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
38 in a menu. If the variable is on, then this calculation gives a (maybe |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
39 noticeable) delay when a mode is first entered. If the variable is off, then |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
40 this delay will come when a menu is displayed the first time. If you never use |
97459
84cc2bc95fba
(easy-menu-add): Don't precompute keybindings
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95371
diff
changeset
|
41 menus, turn this variable off, otherwise it is probably better to keep it on.") |
84cc2bc95fba
(easy-menu-add): Don't precompute keybindings
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95371
diff
changeset
|
42 (make-obsolete-variable |
84cc2bc95fba
(easy-menu-add): Don't precompute keybindings
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95371
diff
changeset
|
43 'easy-menu-precalculate-equivalent-keybindings nil "23.1") |
22196
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
44 |
42014
198c1186dee3
(easy-menu-intern): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38431
diff
changeset
|
45 (defsubst easy-menu-intern (s) |
58097
21dc9bd90575
(easy-menu-intern): Revert to no-downcasing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57978
diff
changeset
|
46 (if (stringp s) (intern s) s)) |
42014
198c1186dee3
(easy-menu-intern): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38431
diff
changeset
|
47 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
48 ;;;###autoload |
6600
f75ac1f3d99c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6542
diff
changeset
|
49 (defmacro easy-menu-define (symbol maps doc menu) |
6529 | 50 "Define a menu bar submenu in maps MAPS, according to MENU. |
48942
86ecd875b9c5
(easy-menu-do-define): Handle nil for SYMBOL.
Richard M. Stallman <rms@gnu.org>
parents:
47550
diff
changeset
|
51 |
86ecd875b9c5
(easy-menu-do-define): Handle nil for SYMBOL.
Richard M. Stallman <rms@gnu.org>
parents:
47550
diff
changeset
|
52 If SYMBOL is non-nil, store the menu keymap in the value of SYMBOL, |
86ecd875b9c5
(easy-menu-do-define): Handle nil for SYMBOL.
Richard M. Stallman <rms@gnu.org>
parents:
47550
diff
changeset
|
53 and define SYMBOL as a function to pop up the menu, with DOC as its doc string. |
86ecd875b9c5
(easy-menu-do-define): Handle nil for SYMBOL.
Richard M. Stallman <rms@gnu.org>
parents:
47550
diff
changeset
|
54 If SYMBOL is nil, just store the menu keymap into MAPS. |
6529 | 55 |
56 The first element of MENU must be a string. It is the menu bar item name. | |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
57 It may be followed by the following keyword argument pairs |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
58 |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
59 :filter FUNCTION |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
60 |
53373
98e63f90453a
(easy-menu-define): Doc fix.
Eli Zaretskii <eliz@is.elta.co.il>
parents:
52401
diff
changeset
|
61 FUNCTION is a function with one argument, the rest of menu items. |
98e63f90453a
(easy-menu-define): Doc fix.
Eli Zaretskii <eliz@is.elta.co.il>
parents:
52401
diff
changeset
|
62 It returns the remaining items of the displayed menu. |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
63 |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
64 :visible INCLUDE |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
65 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
66 INCLUDE is an expression; this menu is only visible if this |
62301
2acfd9cf6713
(easy-menu-define): Doc fixes.
Nick Roberts <nickrob@snap.net.nz>
parents:
61763
diff
changeset
|
67 expression has a non-nil value. `:included' is an alias for `:visible'. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
68 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
69 :active ENABLE |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
70 |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
71 ENABLE is an expression; the menu is enabled for selection whenever |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
72 this expression's value is non-nil. `:enable' is an alias for `:active'. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
73 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
74 The rest of the elements in MENU, are menu items. |
6529 | 75 |
6600
f75ac1f3d99c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6542
diff
changeset
|
76 A menu item is usually a vector of three elements: [NAME CALLBACK ENABLE] |
6529 | 77 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
78 NAME is a string--the menu item name. |
6529 | 79 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
80 CALLBACK is a command to run when the item is chosen, |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
81 or a list to evaluate when the item is chosen. |
6529 | 82 |
8541
39e8d792604f
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8085
diff
changeset
|
83 ENABLE is an expression; the item is enabled for selection |
39e8d792604f
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8085
diff
changeset
|
84 whenever this expression's value is non-nil. |
6600
f75ac1f3d99c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6542
diff
changeset
|
85 |
26428
f572944ca41f
* emacs-lisp/debug.el (debugger-env-macro):
Sam Steingold <sds@gnu.org>
parents:
25224
diff
changeset
|
86 Alternatively, a menu item may have the form: |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
87 |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
88 [ NAME CALLBACK [ KEYWORD ARG ] ... ] |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
89 |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
90 Where KEYWORD is one of the symbols defined below. |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
91 |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
92 :keys KEYS |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
93 |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
94 KEYS is a string; a complex keyboard equivalent to this menu item. |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
95 This is normally not needed because keyboard equivalents are usually |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
96 computed automatically. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
97 KEYS is expanded with `substitute-command-keys' before it is used. |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
98 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
99 :key-sequence KEYS |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
100 |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
101 KEYS is nil, a string or a vector; nil or a keyboard equivalent to this |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
102 menu item. |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
103 This is a hint that will considerably speed up Emacs' first display of |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
104 a menu. Use `:key-sequence nil' when you know that this menu item has no |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
105 keyboard equivalent. |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
106 |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
107 :active ENABLE |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
108 |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
109 ENABLE is an expression; the item is enabled for selection whenever |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
110 this expression's value is non-nil. `:enable' is an alias for `:active'. |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
111 |
62301
2acfd9cf6713
(easy-menu-define): Doc fixes.
Nick Roberts <nickrob@snap.net.nz>
parents:
61763
diff
changeset
|
112 :visible INCLUDE |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
113 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
114 INCLUDE is an expression; this item is only visible if this |
62301
2acfd9cf6713
(easy-menu-define): Doc fixes.
Nick Roberts <nickrob@snap.net.nz>
parents:
61763
diff
changeset
|
115 expression has a non-nil value. `:included' is an alias for `:visible'. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
116 |
86443 | 117 :label FORM |
118 | |
119 FORM is an expression that will be dynamically evaluated and whose | |
120 value will be used for the menu entry's text label (the default is NAME). | |
121 | |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
122 :suffix FORM |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
123 |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
124 FORM is an expression that will be dynamically evaluated and whose |
86443 | 125 value will be concatenated to the menu entry's label. |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
126 |
14108 | 127 :style STYLE |
26428
f572944ca41f
* emacs-lisp/debug.el (debugger-env-macro):
Sam Steingold <sds@gnu.org>
parents:
25224
diff
changeset
|
128 |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
129 STYLE is a symbol describing the type of menu item. The following are |
26428
f572944ca41f
* emacs-lisp/debug.el (debugger-env-macro):
Sam Steingold <sds@gnu.org>
parents:
25224
diff
changeset
|
130 defined: |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
131 |
16812
af96712b7f5d
(easy-menu-create-keymaps): Menu item STYLE toggle (checkbox)
Richard M. Stallman <rms@gnu.org>
parents:
16160
diff
changeset
|
132 toggle: A checkbox. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
133 Prepend the name with `(*) ' or `( ) ' depending on if selected or not. |
16812
af96712b7f5d
(easy-menu-create-keymaps): Menu item STYLE toggle (checkbox)
Richard M. Stallman <rms@gnu.org>
parents:
16160
diff
changeset
|
134 radio: A radio button. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
135 Prepend the name with `[X] ' or `[ ] ' depending on if selected or not. |
30194 | 136 button: Surround the name with `[' and `]'. Use this for an item in the |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
137 menu bar itself. |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
138 anything else means an ordinary menu item. |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
139 |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
140 :selected SELECTED |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
141 |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
142 SELECTED is an expression; the checkbox or radio button is selected |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
143 whenever this expression's value is non-nil. |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
144 |
28522
7fcfdde7365a
(easy-menu-create-menu): Process menu
Gerd Moellmann <gerd@gnu.org>
parents:
26428
diff
changeset
|
145 :help HELP |
7fcfdde7365a
(easy-menu-create-menu): Process menu
Gerd Moellmann <gerd@gnu.org>
parents:
26428
diff
changeset
|
146 |
7fcfdde7365a
(easy-menu-create-menu): Process menu
Gerd Moellmann <gerd@gnu.org>
parents:
26428
diff
changeset
|
147 HELP is a string, the help to display for the menu item. |
7fcfdde7365a
(easy-menu-create-menu): Process menu
Gerd Moellmann <gerd@gnu.org>
parents:
26428
diff
changeset
|
148 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
149 A menu item can be a string. Then that string appears in the menu as |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
150 unselectable text. A string consisting solely of hyphens is displayed |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
151 as a solid horizontal line. |
6529 | 152 |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
153 A menu item can be a list with the same format as MENU. This is a submenu." |
110034
c87f89486bb7
Use `declare' in defmacros.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110015
diff
changeset
|
154 (declare (indent defun)) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
155 `(progn |
50428
8636083efe8b
(easy-menu-define): Don't make a defvar for nil.
Richard M. Stallman <rms@gnu.org>
parents:
50298
diff
changeset
|
156 ,(if symbol `(defvar ,symbol nil ,doc)) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
157 (easy-menu-do-define (quote ,symbol) ,maps ,doc ,menu))) |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
158 |
81796
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
159 (defun easy-menu-binding (menu &optional item-name) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
160 "Return a binding suitable to pass to `define-key'. |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
161 This is expected to be bound to a mouse event." |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
162 ;; Under Emacs this is almost trivial, whereas under XEmacs this may |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
163 ;; involve defining a function that calls popup-menu. |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
164 (let ((props (if (symbolp menu) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
165 (prog1 (get menu 'menu-prop) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
166 (setq menu (symbol-function menu)))))) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
167 (cons 'menu-item |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
168 (cons (if (eq :label (car props)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
169 (prog1 (cadr props) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
170 (setq props (cddr props))) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
171 (or item-name |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
172 (if (keymapp menu) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
173 (keymap-prompt menu)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
174 "")) |
81796
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
175 (cons menu props))))) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
176 |
11860
0c39d1945e5e
(easy-menu-do-define): Add autoload cookie.
Karl Heuer <kwzh@gnu.org>
parents:
11833
diff
changeset
|
177 ;;;###autoload |
9733
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
178 (defun easy-menu-do-define (symbol maps doc menu) |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
179 ;; We can't do anything that might differ between Emacs dialects in |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
180 ;; `easy-menu-define' in order to make byte compiled files |
a721dbc48e10
(easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents:
9586
diff
changeset
|
181 ;; compatible. Therefore everything interesting is done in this |
26428
f572944ca41f
* emacs-lisp/debug.el (debugger-env-macro):
Sam Steingold <sds@gnu.org>
parents:
25224
diff
changeset
|
182 ;; function. |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
183 (let ((keymap (easy-menu-create-menu (car menu) (cdr menu)))) |
48942
86ecd875b9c5
(easy-menu-do-define): Handle nil for SYMBOL.
Richard M. Stallman <rms@gnu.org>
parents:
47550
diff
changeset
|
184 (when symbol |
86ecd875b9c5
(easy-menu-do-define): Handle nil for SYMBOL.
Richard M. Stallman <rms@gnu.org>
parents:
47550
diff
changeset
|
185 (set symbol keymap) |
61763
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
186 (defalias symbol |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
187 `(lambda (event) ,doc (interactive "@e") |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
188 ;; FIXME: XEmacs uses popup-menu which calls the binding |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
189 ;; while x-popup-menu only returns the selection. |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
190 (x-popup-menu event |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
191 (or (and (symbolp ,symbol) |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
192 (funcall |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
193 (or (plist-get (get ,symbol 'menu-prop) |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
194 :filter) |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
195 'identity) |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
196 (symbol-function ,symbol))) |
ce71dc9ea46f
(easy-menu-do-define): Use defalias, not fset.
Richard M. Stallman <rms@gnu.org>
parents:
58124
diff
changeset
|
197 ,symbol))))) |
81796
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
198 (dolist (map (if (keymapp maps) (list maps) maps)) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
199 (define-key map |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
200 (vector 'menu-bar (easy-menu-intern (car menu))) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
201 (easy-menu-binding keymap (car menu)))))) |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
202 |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
203 (defun easy-menu-filter-return (menu &optional name) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
204 "Convert MENU to the right thing to return from a menu filter. |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
205 MENU is a menu as computed by `easy-menu-define' or `easy-menu-create-menu' or |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
206 a symbol whose value is such a menu. |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
207 In Emacs a menu filter must return a menu (a keymap), in XEmacs a filter must |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
208 return a menu items list (without menu name and keywords). |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
209 This function returns the right thing in the two cases. |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
210 If NAME is provided, it is used for the keymap." |
47169
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
211 (cond |
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
212 ((and (not (keymapp menu)) (consp menu)) |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
213 ;; If it's a cons but not a keymap, then it can't be right |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
214 ;; unless it's an XEmacs menu. |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
215 (setq menu (easy-menu-create-menu (or name "") menu))) |
47169
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
216 ((vectorp menu) |
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
217 ;; It's just a menu entry. |
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
218 (setq menu (cdr (easy-menu-convert-item menu))))) |
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
219 menu) |
6529 | 220 |
87768
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
221 (defvar easy-menu-avoid-duplicate-keys t |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
222 "Dynamically scoped var to register already used keys in a menu. |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
223 If it holds a list, this is expected to be a list of keys already seen in the |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
224 menu we're processing. Else it means we're not processing a menu.") |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
225 |
9586
bada2dc32adc
(easy-menu-create-keymaps): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
8541
diff
changeset
|
226 ;;;###autoload |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
227 (defun easy-menu-create-menu (menu-name menu-items) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
228 "Create a menu called MENU-NAME with items described in MENU-ITEMS. |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
229 MENU-NAME is a string, the name of the menu. MENU-ITEMS is a list of items |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
230 possibly preceded by keyword pairs as described in `easy-menu-define'." |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
231 (let ((menu (make-sparse-keymap menu-name)) |
87768
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
232 (easy-menu-avoid-duplicate-keys nil) |
28522
7fcfdde7365a
(easy-menu-create-menu): Process menu
Gerd Moellmann <gerd@gnu.org>
parents:
26428
diff
changeset
|
233 prop keyword arg label enable filter visible help) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
234 ;; Look for keywords. |
29054
25099b559af9
(easy-menu-create-menu, easy-menu-do-add-item): Use keywordp.
Dave Love <fx@gnu.org>
parents:
28522
diff
changeset
|
235 (while (and menu-items |
25099b559af9
(easy-menu-create-menu, easy-menu-do-add-item): Use keywordp.
Dave Love <fx@gnu.org>
parents:
28522
diff
changeset
|
236 (cdr menu-items) |
25099b559af9
(easy-menu-create-menu, easy-menu-do-add-item): Use keywordp.
Dave Love <fx@gnu.org>
parents:
28522
diff
changeset
|
237 (keywordp (setq keyword (car menu-items)))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
238 (setq arg (cadr menu-items)) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
239 (setq menu-items (cddr menu-items)) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
240 (case keyword |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
241 (:filter |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
242 (setq filter `(lambda (menu) |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
243 (easy-menu-filter-return (,arg menu) ,menu-name)))) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
244 ((:enable :active) (setq enable (or arg ''nil))) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
245 (:label (setq label arg)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
246 (:help (setq help arg)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
247 ((:included :visible) (setq visible (or arg ''nil))))) |
30194 | 248 (if (equal visible ''nil) |
249 nil ; Invisible menu entry, return nil. | |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
250 (if (and visible (not (easy-menu-always-true-p visible))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
251 (setq prop (cons :visible (cons visible prop)))) |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
252 (if (and enable (not (easy-menu-always-true-p enable))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
253 (setq prop (cons :enable (cons enable prop)))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
254 (if filter (setq prop (cons :filter (cons filter prop)))) |
28522
7fcfdde7365a
(easy-menu-create-menu): Process menu
Gerd Moellmann <gerd@gnu.org>
parents:
26428
diff
changeset
|
255 (if help (setq prop (cons :help (cons help prop)))) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
256 (if label (setq prop (cons :label (cons label prop)))) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
257 (setq menu (if filter |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
258 ;; The filter expects the menu in its XEmacs form and the |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
259 ;; pre-filter form will only be passed to the filter |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
260 ;; anyway, so we'd better not convert it at all (it will |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
261 ;; be converted on the fly by easy-menu-filter-return). |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
262 menu-items |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
263 (append menu (mapcar 'easy-menu-convert-item menu-items)))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
264 (when prop |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
265 (setq menu (easy-menu-make-symbol menu 'noexp)) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
266 (put menu 'menu-prop prop)) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
267 menu))) |
6529 | 268 |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
269 |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
270 ;; Known button types. |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
271 (defvar easy-menu-button-prefix |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
272 '((radio . :radio) (toggle . :toggle))) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
273 |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
274 (defvar easy-menu-converted-items-table (make-hash-table :test 'equal)) |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
275 |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
276 (defun easy-menu-convert-item (item) |
30194 | 277 "Memoize the value returned by `easy-menu-convert-item-1' called on ITEM. |
278 This makes key-shortcut-caching work a *lot* better when this | |
279 conversion is done from within a filter. | |
280 This also helps when the NAME of the entry is recreated each time: | |
281 since the menu is built and traversed separately, the lookup | |
282 would always fail because the key is `equal' but not `eq'." | |
95371
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
283 (let* ((cache (gethash item easy-menu-converted-items-table)) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
284 (result (or cache (easy-menu-convert-item-1 item))) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
285 (key (car-safe result))) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
286 (when (and (listp easy-menu-avoid-duplicate-keys) (symbolp key)) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
287 ;; Merging multiple entries with the same name is sometimes what we |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
288 ;; want, but not when the entries are actually different (e.g. same |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
289 ;; name but different :suffix as seen in cal-menu.el) and appear in |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
290 ;; the same menu. So we try to detect and resolve conflicts. |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
291 (while (memq key easy-menu-avoid-duplicate-keys) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
292 ;; We need to use some distinct object, ideally a symbol, ideally |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
293 ;; related to the `name'. Uninterned symbols do not work (they |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
294 ;; are apparently turned into strings and re-interned later on). |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
295 (setq key (intern (format "%s-%d" (symbol-name key) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
296 (length easy-menu-avoid-duplicate-keys)))) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
297 (setq result (cons key (cdr result)))) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
298 (push key easy-menu-avoid-duplicate-keys)) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
299 |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
300 (unless cache (puthash item result easy-menu-converted-items-table)) |
eba56dbc7193
(easy-menu-convert-item, easy-menu-convert-item-1):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94655
diff
changeset
|
301 result)) |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
302 |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
303 (defun easy-menu-convert-item-1 (item) |
50428
8636083efe8b
(easy-menu-define): Don't make a defvar for nil.
Richard M. Stallman <rms@gnu.org>
parents:
50298
diff
changeset
|
304 "Parse an item description and convert it to a menu keymap element. |
8636083efe8b
(easy-menu-define): Don't make a defvar for nil.
Richard M. Stallman <rms@gnu.org>
parents:
50298
diff
changeset
|
305 ITEM defines an item as in `easy-menu-define'." |
81796
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
306 (let (name command label prop remove) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
307 (cond |
24987
aee690417f63
(easy-menu-do-add-item): Support for new seperator types.
Gerd Moellmann <gerd@gnu.org>
parents:
24341
diff
changeset
|
308 ((stringp item) ; An item or separator. |
aee690417f63
(easy-menu-do-add-item): Support for new seperator types.
Gerd Moellmann <gerd@gnu.org>
parents:
24341
diff
changeset
|
309 (setq label item)) |
aee690417f63
(easy-menu-do-add-item): Support for new seperator types.
Gerd Moellmann <gerd@gnu.org>
parents:
24341
diff
changeset
|
310 ((consp item) ; A sub-menu |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
311 (setq label (setq name (car item))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
312 (setq command (cdr item)) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
313 (if (not (keymapp command)) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
314 (setq command (easy-menu-create-menu name command))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
315 (if (null command) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
316 ;; Invisible menu item. Don't insert into keymap. |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
317 (setq remove t) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
318 (when (and (symbolp command) (setq prop (get command 'menu-prop))) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
319 (when (eq :label (car prop)) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
320 (setq label (cadr prop)) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
321 (setq prop (cddr prop))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
322 (setq command (symbol-function command))))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
323 ((vectorp item) ; An item. |
22196
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
324 (let* ((ilen (length item)) |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
325 (active (if (> ilen 2) (or (aref item 2) ''nil) t)) |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
326 (no-name (not (symbolp (setq command (aref item 1))))) |
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
327 cache cache-specified) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
328 (setq label (setq name (aref item 0))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
329 (if no-name (setq command (easy-menu-make-symbol command))) |
29054
25099b559af9
(easy-menu-create-menu, easy-menu-do-add-item): Use keywordp.
Dave Love <fx@gnu.org>
parents:
28522
diff
changeset
|
330 (if (keywordp active) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
331 (let ((count 2) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
332 keyword arg suffix visible style selected keys) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
333 (setq active nil) |
22196
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
334 (while (> ilen count) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
335 (setq keyword (aref item count)) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
336 (setq arg (aref item (1+ count))) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
337 (setq count (+ 2 count)) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
338 (case keyword |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
339 ((:included :visible) (setq visible (or arg ''nil))) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
340 (:key-sequence (setq cache arg cache-specified t)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
341 (:keys (setq keys arg no-name nil)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
342 (:label (setq label arg)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
343 ((:active :enable) (setq active (or arg ''nil))) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
344 (:help (setq prop (cons :help (cons arg prop)))) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
345 (:suffix (setq suffix arg)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
346 (:style (setq style arg)) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
347 (:selected (setq selected (or arg ''nil))))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
348 (if suffix |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
349 (setq label |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
350 (if (stringp suffix) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
351 (if (stringp label) (concat label " " suffix) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
352 `(concat ,label ,(concat " " suffix))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
353 (if (stringp label) |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
354 `(concat ,(concat label " ") ,suffix) |
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
355 `(concat ,label " " ,suffix))))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
356 (cond |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
357 ((eq style 'button) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
358 (setq label (if (stringp label) (concat "[" label "]") |
112214
40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110034
diff
changeset
|
359 `(concat "[" ,label "]")))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
360 ((and selected |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
361 (setq style (assq style easy-menu-button-prefix))) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
362 (setq prop (cons :button |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
363 (cons (cons (cdr style) selected) prop))))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
364 (when (stringp keys) |
87768
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
365 (if (string-match "^[^\\]*\\(\\\\\\[\\([^]]+\\)]\\)[^\\]*$" |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
366 keys) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
367 (let ((prefix |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
368 (if (< (match-beginning 0) (match-beginning 1)) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
369 (substring keys 0 (match-beginning 1)))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
370 (postfix |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
371 (if (< (match-end 1) (match-end 0)) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
372 (substring keys (match-end 1)))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
373 (cmd (intern (match-string 2 keys)))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
374 (setq keys (and (or prefix postfix) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
375 (cons prefix postfix))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
376 (setq keys |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
377 (and (or keys (not (eq command cmd))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
378 (cons cmd keys)))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
379 (setq cache-specified nil)) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
380 (if keys (setq prop (cons :keys (cons keys prop))))) |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
381 (if (and visible (not (easy-menu-always-true-p visible))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
382 (if (equal visible ''nil) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
383 ;; Invisible menu item. Don't insert into keymap. |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
384 (setq remove t) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
385 (setq prop (cons :visible (cons visible prop))))))) |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
386 (if (and active (not (easy-menu-always-true-p active))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
387 (setq prop (cons :enable (cons active prop)))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
388 (if (and (or no-name cache-specified) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
389 (or (null cache) (stringp cache) (vectorp cache))) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
390 (setq prop (cons :key-sequence (cons cache prop)))))) |
23955
9f9e1b450ff5
(easy-menu-get-map): Change global map only if this menu exists in the
Richard M. Stallman <rms@gnu.org>
parents:
23939
diff
changeset
|
391 (t (error "Invalid menu item in easymenu"))) |
30207
584fa6f665f1
(easy-menu-convert-item-1): Intern the label.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30194
diff
changeset
|
392 ;; `intern' the name so as to merge multiple entries with the same name. |
584fa6f665f1
(easy-menu-convert-item-1): Intern the label.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30194
diff
changeset
|
393 ;; It also makes it easier/possible to lookup/change menu bindings |
584fa6f665f1
(easy-menu-convert-item-1): Intern the label.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30194
diff
changeset
|
394 ;; via keymap functions. |
87768
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
395 (let ((key (easy-menu-intern name))) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
396 (cons key |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
397 (and (not remove) |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
398 (cons 'menu-item |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
399 (cons label |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
400 (and name |
2dfbe4c86ab7
(easy-menu-avoid-duplicate-keys): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
401 (cons command prop))))))))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
402 |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
403 (defun easy-menu-define-key (menu key item &optional before) |
30194 | 404 "Add binding in MENU for KEY => ITEM. Similar to `define-key-after'. |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
405 If KEY is not nil then delete any duplications. |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
406 If ITEM is nil, then delete the definition of KEY. |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
407 |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
408 Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil, |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
409 put binding before the item in MENU named BEFORE; otherwise, |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
410 if a binding for KEY is already present in MENU, just change it; |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
411 otherwise put the new binding last in MENU. |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
412 BEFORE can be either a string (menu item name) or a symbol |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
413 \(the fake function key for the menu item). |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
414 KEY does not have to be a symbol, and comparison is done with equal." |
58123
b7ee8419031b
(easy-menu-define-key): Understand the case where the keymap is a symbol.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58097
diff
changeset
|
415 (if (symbolp menu) (setq menu (indirect-function menu))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
416 (let ((inserted (null item)) ; Fake already inserted. |
21807
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
417 tail done) |
20801
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
418 (while (not done) |
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
419 (cond |
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
420 ((or (setq done (or (null (cdr menu)) (keymapp (cdr menu)))) |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
421 (and before (easy-menu-name-match before (cadr menu)))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
422 ;; If key is nil, stop here, otherwise keep going past the |
20801
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
423 ;; inserted element so we can delete any duplications that come |
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
424 ;; later. |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
425 (if (null key) (setq done t)) |
20801
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
426 (unless inserted ; Don't insert more than once. |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
427 (setcdr menu (cons (cons key item) (cdr menu))) |
20801
8aeddd528f57
(easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents:
20791
diff
changeset
|
428 (setq inserted t) |
21807
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
429 (setq menu (cdr menu))) |
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
430 (setq menu (cdr menu))) |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
431 ((and key (equal (car-safe (cadr menu)) key)) |
21807
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
432 (if (or inserted ; Already inserted or |
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
433 (and before ; wanted elsewhere and |
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
434 (setq tail (cddr menu)) ; not last item and not |
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
435 (not (keymapp tail)) |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
436 (not (easy-menu-name-match |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
437 before (car tail))))) ; in position |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
438 (setcdr menu (cddr menu)) ; Remove item. |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
439 (setcdr (cadr menu) item) ; Change item. |
21807
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
440 (setq inserted t) |
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
441 (setq menu (cdr menu)))) |
c62197b13ece
(easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents:
21745
diff
changeset
|
442 (t (setq menu (cdr menu))))))) |
26428
f572944ca41f
* emacs-lisp/debug.el (debugger-env-macro):
Sam Steingold <sds@gnu.org>
parents:
25224
diff
changeset
|
443 |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
444 (defun easy-menu-name-match (name item) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
445 "Return t if NAME is the name of menu item ITEM. |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
446 NAME can be either a string, or a symbol. |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
447 ITEM should be a keymap binding of the form (KEY . MENU-ITEM)." |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
448 (if (consp item) |
45309
105aeedf106c
(easy-menu-make-symbol): Don't treat (lambda () ...) as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45304
diff
changeset
|
449 (if (symbolp name) |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
450 (eq (car-safe item) name) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
451 (if (stringp name) |
45299
948bb97d1e60
(easy-menu-name-match): Match both
Jason Rumney <jasonr@gnu.org>
parents:
44826
diff
changeset
|
452 ;; Match against the text that is displayed to the user. |
50142
c61cd948bb26
(easy-menu-name-match): Catch any error that member-ignore-case might signal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48942
diff
changeset
|
453 (or (condition-case nil (member-ignore-case name item) |
c61cd948bb26
(easy-menu-name-match): Catch any error that member-ignore-case might signal.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48942
diff
changeset
|
454 (error nil)) ;`item' might not be a proper list. |
45299
948bb97d1e60
(easy-menu-name-match): Match both
Jason Rumney <jasonr@gnu.org>
parents:
44826
diff
changeset
|
455 ;; Also check the string version of the symbol name, |
948bb97d1e60
(easy-menu-name-match): Match both
Jason Rumney <jasonr@gnu.org>
parents:
44826
diff
changeset
|
456 ;; for backwards compatibility. |
58097
21dc9bd90575
(easy-menu-intern): Revert to no-downcasing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57978
diff
changeset
|
457 (eq (car-safe item) (intern name))))))) |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
458 |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
459 (defun easy-menu-always-true-p (x) |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
460 "Return true if form X never evaluates to nil." |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
461 (if (consp x) (and (eq (car x) 'quote) (cadr x)) |
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
462 (or (eq x t) (not (symbolp x))))) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
463 |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
464 (defvar easy-menu-item-count 0) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
465 |
30057
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
466 (defun easy-menu-make-symbol (callback &optional noexp) |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
467 "Return a unique symbol with CALLBACK as function value. |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
468 When non-nil, NOEXP indicates that CALLBACK cannot be an expression |
6413c7b9a6c3
(easy-menu-define): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29054
diff
changeset
|
469 \(i.e. does not need to be turned into a function)." |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
470 (let ((command |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
471 (make-symbol (format "menu-function-%d" easy-menu-item-count)))) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
472 (setq easy-menu-item-count (1+ easy-menu-item-count)) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
473 (fset command |
94305
67bb48862873
(easy-menu-make-symbol): Don't wrap keyboard macros within lambdas.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87768
diff
changeset
|
474 (if (or (keymapp callback) (commandp callback) |
67bb48862873
(easy-menu-make-symbol): Don't wrap keyboard macros within lambdas.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87768
diff
changeset
|
475 ;; `functionp' is probably not needed. |
67bb48862873
(easy-menu-make-symbol): Don't wrap keyboard macros within lambdas.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87768
diff
changeset
|
476 (functionp callback) noexp) |
67bb48862873
(easy-menu-make-symbol): Don't wrap keyboard macros within lambdas.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87768
diff
changeset
|
477 callback |
21745
38a6d62cddb9
Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents:
21689
diff
changeset
|
478 `(lambda () (interactive) ,callback))) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
479 command)) |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
480 |
22033
aa1d105f0d67
(easy-menu-change): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
21807
diff
changeset
|
481 ;;;###autoload |
74910
776a7e3c21a0
easy-menu-change patch
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
74466
diff
changeset
|
482 (defun easy-menu-change (path name items &optional before map) |
8085
c7eb887a1e78
(easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7614
diff
changeset
|
483 "Change menu found at PATH as item NAME to contain ITEMS. |
25224
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
484 PATH is a list of strings for locating the menu that |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
485 should contain a submenu named NAME. |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
486 ITEMS is a list of menu items, as in `easy-menu-define'. |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
487 These items entirely replace the previous items in that submenu. |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
488 |
74910
776a7e3c21a0
easy-menu-change patch
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
74466
diff
changeset
|
489 If MAP is specified, it should normally be a keymap; nil stands for the local |
776a7e3c21a0
easy-menu-change patch
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
74466
diff
changeset
|
490 menu-bar keymap. It can also be a symbol, which has earlier been used as the |
776a7e3c21a0
easy-menu-change patch
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
74466
diff
changeset
|
491 first argument in a call to `easy-menu-define', or the value of such a symbol. |
776a7e3c21a0
easy-menu-change patch
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
74466
diff
changeset
|
492 |
25224
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
493 If the menu located by PATH has no submenu named NAME, add one. |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
494 If the optional argument BEFORE is present, add it just before |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
495 the submenu named BEFORE, otherwise add it at the end of the menu. |
8085
c7eb887a1e78
(easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7614
diff
changeset
|
496 |
66495
9bc148ee2fda
(easy-menu-change): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
64751
diff
changeset
|
497 To implement dynamic menus, either call this from |
9bc148ee2fda
(easy-menu-change): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
64751
diff
changeset
|
498 `menu-bar-update-hook' or use a menu filter." |
74910
776a7e3c21a0
easy-menu-change patch
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
74466
diff
changeset
|
499 (easy-menu-add-item map path (easy-menu-create-menu name items) before)) |
8085
c7eb887a1e78
(easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents:
7614
diff
changeset
|
500 |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
501 ;; XEmacs needs the following two functions to add and remove menus. |
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
502 ;; In Emacs this is done automatically when switching keymaps, so |
97459
84cc2bc95fba
(easy-menu-add): Don't precompute keybindings
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95371
diff
changeset
|
503 ;; here easy-menu-remove is a noop. |
47550
df31632ef1db
(easy-menu-remove): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47254
diff
changeset
|
504 (defalias 'easy-menu-remove 'ignore |
df31632ef1db
(easy-menu-remove): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47254
diff
changeset
|
505 "Remove MENU from the current menu bar. |
df31632ef1db
(easy-menu-remove): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47254
diff
changeset
|
506 Contrary to XEmacs, this is a nop on Emacs since menus are automatically |
df31632ef1db
(easy-menu-remove): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47254
diff
changeset
|
507 \(de)activated when the corresponding keymap is (de)activated. |
df31632ef1db
(easy-menu-remove): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47254
diff
changeset
|
508 |
df31632ef1db
(easy-menu-remove): Add docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47254
diff
changeset
|
509 \(fn MENU)") |
6600
f75ac1f3d99c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6542
diff
changeset
|
510 |
22196
4f4d9c92ae33
(easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents:
22033
diff
changeset
|
511 (defun easy-menu-add (menu &optional map) |
47169
bed718560d06
(easy-menu-filter-return):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46197
diff
changeset
|
512 "Add the menu to the menubar. |
62557
efeaec0ce9c4
(easy-menu-add): Correct docstring since
David Kastrup <dak@gnu.org>
parents:
62301
diff
changeset
|
513 On Emacs, menus are already automatically activated when the |
efeaec0ce9c4
(easy-menu-add): Correct docstring since
David Kastrup <dak@gnu.org>
parents:
62301
diff
changeset
|
514 corresponding keymap is activated. On XEmacs this is needed to |
efeaec0ce9c4
(easy-menu-add): Correct docstring since
David Kastrup <dak@gnu.org>
parents:
62301
diff
changeset
|
515 actually add the menu to the current menubar. |
efeaec0ce9c4
(easy-menu-add): Correct docstring since
David Kastrup <dak@gnu.org>
parents:
62301
diff
changeset
|
516 |
efeaec0ce9c4
(easy-menu-add): Correct docstring since
David Kastrup <dak@gnu.org>
parents:
62301
diff
changeset
|
517 You should call this once the menu and keybindings are set up |
efeaec0ce9c4
(easy-menu-add): Correct docstring since
David Kastrup <dak@gnu.org>
parents:
62301
diff
changeset
|
518 completely and menu filter functions can be expected to work." |
97459
84cc2bc95fba
(easy-menu-add): Don't precompute keybindings
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95371
diff
changeset
|
519 ) |
6600
f75ac1f3d99c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6542
diff
changeset
|
520 |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
521 (defun add-submenu (menu-path submenu &optional before in-menu) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
522 "Add submenu SUBMENU in the menu at MENU-PATH. |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
523 If BEFORE is non-nil, add before the item named BEFORE. |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
524 If IN-MENU is non-nil, follow MENU-PATH in IN-MENU. |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
525 This is a compatibility function; use `easy-menu-add-item'." |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
526 (easy-menu-add-item (or in-menu (current-global-map)) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
527 (cons "menu-bar" menu-path) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
528 submenu before)) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
529 |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
530 (defun easy-menu-add-item (map path item &optional before) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
531 "To the submenu of MAP with path PATH, add ITEM. |
25224
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
532 |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
533 If an item with the same name is already present in this submenu, |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
534 then ITEM replaces it. Otherwise, ITEM is added to this submenu. |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
535 In the latter case, ITEM is normally added at the end of the submenu. |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
536 However, if BEFORE is a string and there is an item in the submenu |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
537 with that name, then ITEM is added before that item. |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
538 |
50298
9c1195ddde1a
(easy-menu-add-item): Align the docstring with the code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50296
diff
changeset
|
539 MAP should normally be a keymap; nil stands for the local menu-bar keymap. |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
540 It can also be a symbol, which has earlier been used as the first |
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
541 argument in a call to `easy-menu-define', or the value of such a symbol. |
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
542 |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
543 PATH is a list of strings for locating the submenu where ITEM is to be |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
544 added. If PATH is nil, MAP itself is used. Otherwise, the first |
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
545 element should be the name of a submenu directly under MAP. This |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
546 submenu is then traversed recursively with the remaining elements of PATH. |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
547 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
548 ITEM is either defined as in `easy-menu-define' or a non-nil value returned |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
549 by `easy-menu-item-present-p' or `easy-menu-remove-item' or a menu defined |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
550 earlier by `easy-menu-define' or `easy-menu-create-menu'." |
25224
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
551 (setq map (easy-menu-get-map map path |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
552 (and (null map) (null path) |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
553 (stringp (car-safe item)) |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
554 (car item)))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
555 (if (and (consp item) (consp (cdr item)) (eq (cadr item) 'menu-item)) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
556 ;; This is a value returned by `easy-menu-item-present-p' or |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
557 ;; `easy-menu-remove-item'. |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
558 (easy-menu-define-key map (easy-menu-intern (car item)) |
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
559 (cdr item) before) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
560 (if (or (keymapp item) |
58124
28acd37455bb
(easy-menu-add-item): Use keymap-prompt. Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58123
diff
changeset
|
561 (and (symbolp item) (keymapp (symbol-value item)) |
28acd37455bb
(easy-menu-add-item): Use keymap-prompt. Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58123
diff
changeset
|
562 (setq item (symbol-value item)))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
563 ;; Item is a keymap, find the prompt string and use as item name. |
58124
28acd37455bb
(easy-menu-add-item): Use keymap-prompt. Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58123
diff
changeset
|
564 (setq item (cons (keymap-prompt item) item))) |
81796
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
565 (setq item (easy-menu-convert-item item)) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
566 (easy-menu-define-key map (easy-menu-intern (car item)) (cdr item) before))) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
567 |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
568 (defun easy-menu-item-present-p (map path name) |
78474
88c9f4e4160e
Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents:
78217
diff
changeset
|
569 "In submenu of MAP with path PATH, return non-nil if item NAME is present. |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
570 MAP and PATH are defined as in `easy-menu-add-item'. |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
571 NAME should be a string, the name of the element to be looked for." |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
572 (easy-menu-return-item (easy-menu-get-map map path) name)) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
573 |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
574 (defun easy-menu-remove-item (map path name) |
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
575 "From submenu of MAP with path PATH remove item NAME. |
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
576 MAP and PATH are defined as in `easy-menu-add-item'. |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
577 NAME should be a string, the name of the element to be removed." |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
578 (setq map (easy-menu-get-map map path)) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
579 (let ((ret (easy-menu-return-item map name))) |
44826
af8676236636
(easy-menu-intern): Downcase before interning.
Richard M. Stallman <rms@gnu.org>
parents:
42014
diff
changeset
|
580 (if ret (easy-menu-define-key map (easy-menu-intern name) nil)) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
581 ret)) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
582 |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
583 (defun easy-menu-return-item (menu name) |
30194 | 584 "In menu MENU try to look for menu item with name NAME. |
585 If a menu item is found, return (NAME . item), otherwise return nil. | |
586 If item is an old format item, a new format item is returned." | |
62953
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
587 ;; The call to `lookup-key' also calls the C function `get_keyelt' which |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
588 ;; looks inside a menu-item to only return the actual command. This is |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
589 ;; not what we want here. We should either add an arg to lookup-key to be |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
590 ;; able to turn off this "feature", or else we could use map-keymap here. |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
591 ;; In the mean time, I just use `assq' which is an OK approximation since |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
592 ;; menus are rarely built from vectors or char-tables. |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
593 (let ((item (or (cdr (assq name menu)) |
925395d813a9
(easy-menu-return-item): Find menu items with a nil command binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62557
diff
changeset
|
594 (lookup-key menu (vector (easy-menu-intern name))))) |
23991
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
595 ret enable cache label) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
596 (cond |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
597 ((stringp (car-safe item)) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
598 ;; This is the old menu format. Convert it to new format. |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
599 (setq label (car item)) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
600 (when (stringp (car (setq item (cdr item)))) ; Got help string |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
601 (setq ret (list :help (car item))) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
602 (setq item (cdr item))) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
603 (when (and (consp item) (consp (car item)) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
604 (or (null (caar item)) (numberp (caar item)))) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
605 (setq cache (car item)) ; Got cache |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
606 (setq item (cdr item))) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
607 (and (symbolp item) (setq enable (get item 'menu-enable)) ; Got enable |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
608 (setq ret (cons :enable (cons enable ret)))) |
3dee93390da0
(easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23955
diff
changeset
|
609 (if cache (setq ret (cons cache ret))) |
42014
198c1186dee3
(easy-menu-intern): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38431
diff
changeset
|
610 (cons name (cons 'menu-enable (cons label (cons item ret))))) |
198c1186dee3
(easy-menu-intern): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38431
diff
changeset
|
611 (item ; (or (symbolp item) (keymapp item) (eq (car-safe item) 'menu-item)) |
198c1186dee3
(easy-menu-intern): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38431
diff
changeset
|
612 (cons name item)) ; Keymap or new menu format |
198c1186dee3
(easy-menu-intern): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38431
diff
changeset
|
613 ))) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
614 |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
615 (defun easy-menu-lookup-name (map name) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
616 "Lookup menu item NAME in keymap MAP. |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
617 Like `lookup-key' except that NAME is not an array but just a single key |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
618 and that NAME can be a string representing the menu item's name." |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
619 (or (lookup-key map (vector (easy-menu-intern name))) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
620 (when (stringp name) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
621 ;; `lookup-key' failed and we have a menu item name: look at the |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
622 ;; actual menu entries's names. |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
623 (catch 'found |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
624 (map-keymap (lambda (key item) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
625 (if (condition-case nil (member name item) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
626 (error nil)) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
627 ;; Found it!! Look for it again with |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
628 ;; `lookup-key' so as to handle inheritance and |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
629 ;; to extract the actual command/keymap bound to |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
630 ;; `name' from the item (via get_keyelt). |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
631 (throw 'found (lookup-key map (vector key))))) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
632 map))))) |
25224
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
633 |
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
634 (defun easy-menu-get-map (map path &optional to-modify) |
30194 | 635 "Return a sparse keymap in which to add or remove an item. |
636 MAP and PATH are as defined in `easy-menu-add-item'. | |
25224
31847deec8cb
(easy-menu-get-map-look-for-name): New fn.
Karl Heuer <kwzh@gnu.org>
parents:
24987
diff
changeset
|
637 |
30194 | 638 TO-MODIFY, if non-nil, is the name of the item the caller |
639 wants to modify in the map that we return. | |
640 In some cases we use that to select between the local and global maps." | |
34520
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
641 (setq map |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
642 (catch 'found |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
643 (if (and map (symbolp map) (not (keymapp map))) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
644 (setq map (symbol-value map))) |
81796
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
645 (let ((maps (if map (if (keymapp map) (list map) map) |
6c2d34aea93f
(easy-menu-binding): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
646 (current-active-maps)))) |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
647 ;; Look for PATH in each map. |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
648 (unless map (push 'menu-bar path)) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
649 (dolist (name path) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
650 (setq maps |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
651 (delq nil (mapcar (lambda (map) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
652 (setq map (easy-menu-lookup-name |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
653 map name)) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
654 (and (keymapp map) map)) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
655 maps)))) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
656 |
34520
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
657 ;; Prefer a map that already contains the to-be-modified entry. |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
658 (when to-modify |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
659 (dolist (map maps) |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
660 (when (easy-menu-lookup-name map to-modify) |
34520
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
661 (throw 'found map)))) |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
662 ;; Use the first valid map. |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
663 (when maps (throw 'found (car maps))) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
664 |
34520
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
665 ;; Otherwise, make one up. |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
666 ;; Hardcoding current-local-map is lame, but it's difficult |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
667 ;; to know what the caller intended for us to do ;-( |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
668 (let* ((name (if path (format "%s" (car (reverse path))))) |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
669 (newmap (make-sparse-keymap name))) |
57966
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
670 (define-key (or map (current-local-map)) |
13661731eef0
(easy-menu-get-map-look-for-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57883
diff
changeset
|
671 (apply 'vector (mapcar 'easy-menu-intern path)) |
34520
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
672 (if name (cons name newmap) newmap)) |
bea29075080b
(easy-menu-define): Setup indentation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30209
diff
changeset
|
673 newmap)))) |
23939
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
674 (or (keymapp map) (error "Malformed menu in easy-menu: (%s)" map)) |
8d7a5687c803
(easy-menu-get-map): If MENU is nil, use global menu-bar map.
Richard M. Stallman <rms@gnu.org>
parents:
22196
diff
changeset
|
675 map) |
20791
0c51c56d0a4f
easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents:
19761
diff
changeset
|
676 |
6529 | 677 (provide 'easymenu) |
678 | |
679 ;;; easymenu.el ends here |