annotate lisp/emacs-lisp/easymenu.el @ 22267:dfac7398266b

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Wed, 27 May 1998 23:47:15 +0000
parents 4f4d9c92ae33
children 8d7a5687c803
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; easymenu.el --- support the easymenu interface for defining a menu.
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
3 ;; Copyright (C) 1994, 1996, 1998 Free Software Foundation, Inc.
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
4
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Keywords: emulations
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
6 ;; Author: rms
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
23 ;; Boston, MA 02111-1307, USA.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
25 ;;; Commentary:
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
26
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
27 ;; This is compatible with easymenu.el by Per Abrahamsen
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
28 ;; but it is much simpler as it doesn't try to support other Emacs versions.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14108
diff changeset
29 ;; The code was mostly derived from lmenu.el.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; Code:
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
33 (defcustom easy-menu-precalculate-equivalent-keybindings t
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
34 "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
35 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
36 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
37 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
38 this delay will come when a menu is displayed the first time. If you never use
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
39 menus, turn this variable off, otherwise it is probably better to keep it on."
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
40 :type 'boolean
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
41 :group 'menu
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
42 :version "20.3")
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
43
6542
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
44 ;;;###autoload
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
45 (defmacro easy-menu-define (symbol maps doc menu)
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 "Define a menu bar submenu in maps MAPS, according to MENU.
11512
a196f05240a9 (easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10415
diff changeset
47 The menu keymap is stored in symbol SYMBOL, both as its value
a196f05240a9 (easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10415
diff changeset
48 and as its function definition. DOC is used as the doc string for SYMBOL.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 The first element of MENU must be a string. It is the menu bar item name.
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
51 It may be followed by the keyword argument pair
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
52 :filter FUNCTION
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
53 FUNCTION is a function with one argument, the menu. It returns the actual
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
54 menu displayed.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
55
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 The rest of the elements are menu items.
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
58 A menu item is usually a vector of three elements: [NAME CALLBACK ENABLE]
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
6542
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
60 NAME is a string--the menu item name.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
6542
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
62 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
63 or a list to evaluate when the item is chosen.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
8541
39e8d792604f (easy-menu-define): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 8085
diff changeset
65 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
66 whenever this expression's value is non-nil.
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
67
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
68 Alternatively, a menu item may have the form:
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
69
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
70 [ 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
71
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
72 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
73
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
74 :keys KEYS
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
75
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
76 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
77 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
78 computed automatically.
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
79
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
80 :active ENABLE
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
81
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
82 ENABLE is an expression; the item is enabled for selection
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
83 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
84
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
85 :suffix NAME
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
86
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
87 NAME is a string; the name of an argument to CALLBACK.
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
88
14108
cab8d383f10d (easy-menu-define): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 11860
diff changeset
89 :style STYLE
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
90
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
91 STYLE is a symbol describing the type of menu item. The following are
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
92 defined:
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
93
16812
af96712b7f5d (easy-menu-create-keymaps): Menu item STYLE toggle (checkbox)
Richard M. Stallman <rms@gnu.org>
parents: 16160
diff changeset
94 toggle: A checkbox.
af96712b7f5d (easy-menu-create-keymaps): Menu item STYLE toggle (checkbox)
Richard M. Stallman <rms@gnu.org>
parents: 16160
diff changeset
95 Prepend the name with '(*) ' or '( ) ' depending on if selected or not.
af96712b7f5d (easy-menu-create-keymaps): Menu item STYLE toggle (checkbox)
Richard M. Stallman <rms@gnu.org>
parents: 16160
diff changeset
96 radio: A radio button.
af96712b7f5d (easy-menu-create-keymaps): Menu item STYLE toggle (checkbox)
Richard M. Stallman <rms@gnu.org>
parents: 16160
diff changeset
97 Prepend the name with '[X] ' or '[ ] ' depending on if selected or not.
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
98 nil: An ordinary menu item.
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
99
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
100 :selected SELECTED
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
101
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
102 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
103 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
104
6542
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
105 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
106 unselectable text. A string consisting solely of hyphens is displayed
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
107 as a solid horizontal line.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
6542
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
109 A menu item can be a list. It is treated as a submenu.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 The first element should be the submenu name. That's used as the
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
111 menu item name in the top-level menu. It may be followed by the :filter
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
112 FUNCTION keyword argument pair. The rest of the submenu list are menu items,
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
113 as above."
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
114 `(progn
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
115 (defvar ,symbol nil ,doc)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
116 (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
117
11860
0c39d1945e5e (easy-menu-do-define): Add autoload cookie.
Karl Heuer <kwzh@gnu.org>
parents: 11833
diff changeset
118 ;;;###autoload
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
119 (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
120 ;; 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
121 ;; `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
122 ;; compatible. Therefore everything interesting is done in this
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
123 ;; function.
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
124 (set symbol (easy-menu-create-menu (car menu) (cdr menu)))
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
125 (fset symbol (` (lambda (event) (, doc) (interactive "@e")
16160
9acae440fe98 (easy-menu-do-define): Use `x-popup-menu' instead of
Richard M. Stallman <rms@gnu.org>
parents: 15429
diff changeset
126 (x-popup-menu event (, symbol)))))
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
127 (mapcar (function (lambda (map)
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
128 (define-key map (vector 'menu-bar (intern (car menu)))
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
129 (cons (car menu) (symbol-value symbol)))))
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
130 (if (keymapp maps) (list maps) maps)))
6542
1d9da8160357 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6529
diff changeset
131
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
132 (defun easy-menu-filter-return (menu)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
133 "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
134 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
135 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
136 In Emacs a menu filter must return a menu (a keymap), in XEmacs a filter must
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
137 return a menu items list (without menu name and keywords). This function
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
138 returns the right thing in the two cases."
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
139 (easy-menu-get-map menu nil)) ; Get past indirections.
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
9586
bada2dc32adc (easy-menu-create-keymaps): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 8541
diff changeset
141 ;;;###autoload
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
142 (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
143 "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
144 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
145 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
146 (let ((menu (make-sparse-keymap menu-name))
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
147 prop keyword arg label enable filter visible)
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
148 ;; Look for keywords.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
149 (while (and menu-items (cdr menu-items)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
150 (symbolp (setq keyword (car menu-items)))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
151 (= ?: (aref (symbol-name keyword) 0)))
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
152 (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
153 (setq menu-items (cddr menu-items))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
154 (cond
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
155 ((eq keyword ':filter) (setq filter arg))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
156 ((eq keyword ':active) (setq enable (or arg ''nil)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
157 ((eq keyword ':label) (setq label arg))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
158 ((eq keyword ':visible) (setq visible (or arg ''nil)))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
159 (if (equal visible ''nil) nil ; Invisible menu entry, return nil.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
160 (if (and visible (not (easy-menu-always-true visible)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
161 (setq prop (cons :visible (cons visible prop))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
162 (if (and enable (not (easy-menu-always-true enable)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
163 (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
164 (if filter (setq prop (cons :filter (cons filter prop))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
165 (if label (setq prop (cons nil (cons label prop))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
166 (while menu-items
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
167 (easy-menu-do-add-item menu (car menu-items))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
168 (setq menu-items (cdr menu-items)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
169 (when prop
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
170 (setq menu (easy-menu-make-symbol menu))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
171 (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
172 menu)))
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
174
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
175 ;; Button prefixes.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
176 (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
177 '((radio . :radio) (toggle . :toggle)))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
178
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
179 (defun easy-menu-do-add-item (menu item &optional before)
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
180 ;; Parse an item description and add the item to a keymap. This is
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
181 ;; the function that is used for item definition by the other easy-menu
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
182 ;; functions.
20801
8aeddd528f57 (easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents: 20791
diff changeset
183 ;; MENU is a sparse keymap i.e. a list starting with the symbol `keymap'.
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
184 ;; ITEM defines an item as in `easy-menu-define'.
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
185 ;; Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
186 ;; put item before BEFORE in MENU, otherwise if item is already present in
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
187 ;; MENU, just change it, otherwise put it last in MENU.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
188 (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
189 (cond
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
190 ((stringp item)
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
191 (setq label
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
192 (if (string-match ; If an XEmacs separator
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
193 "^\\(-+\\|\
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
194 --:\\(\\(no\\|\\(sing\\|doub\\)le\\(Dashed\\)?\\)Line\\|\
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
195 shadow\\(Double\\)?Etched\\(In\\|Out\\)\\(Dash\\)?\\)\\)$"
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
196 item) "" ; use a single line separator.
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
197 item)))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
198 ((consp item)
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
199 (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
200 (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
201 (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
202 (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
203 (if (null command)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
204 ;; 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
205 (setq remove t)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
206 (when (and (symbolp command) (setq prop (get command 'menu-prop)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
207 (when (null (car prop))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
208 (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
209 (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
210 (setq command (symbol-function command)))))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
211 ((vectorp item)
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
212 (let* ((ilen (length item))
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
213 (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
214 (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
215 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
216 (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
217 (if no-name (setq command (easy-menu-make-symbol command)))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
218 (if (and (symbolp active) (= ?: (aref (symbol-name active) 0)))
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
219 (let ((count 2)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
220 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
221 (setq active nil)
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
222 (while (> ilen count)
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
223 (setq keyword (aref item count))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
224 (setq arg (aref item (1+ count)))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
225 (setq count (+ 2 count))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
226 (cond
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
227 ((eq keyword :visible) (setq visible (or arg ''nil)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
228 ((eq keyword :key-sequence)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
229 (setq cache arg cache-specified t))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
230 ((eq keyword :keys) (setq keys arg no-name nil))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
231 ((eq keyword :label) (setq label arg))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
232 ((eq keyword :active) (setq active (or arg ''nil)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
233 ((eq keyword :suffix) (setq suffix arg))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
234 ((eq keyword :style) (setq style arg))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
235 ((eq keyword :selected) (setq selected (or arg ''nil)))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
236 (if (stringp suffix)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
237 (setq label (if (stringp label) (concat label " " suffix)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
238 (list 'concat label (concat " " suffix)))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
239 (if (and selected
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
240 (setq style (assq style easy-menu-button-prefix)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
241 (setq prop (cons :button
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
242 (cons (cons (cdr style) (or selected ''nil))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
243 prop))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
244 (when (stringp keys)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
245 (if (string-match "^[^\\]*\\(\\\\\\[\\([^]]+\\)]\\)[^\\]*$"
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
246 keys)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
247 (let ((prefix
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
248 (if (< (match-beginning 0) (match-beginning 1))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
249 (substring keys 0 (match-beginning 1))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
250 (postfix
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
251 (if (< (match-end 1) (match-end 0))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
252 (substring keys (match-end 1))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
253 (cmd (intern (substring keys (match-beginning 2)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
254 (match-end 2)))))
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
255 (setq keys (and (or prefix postfix)
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
256 (cons prefix postfix)))
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
257 (setq keys
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
258 (and (or keys (not (eq command cmd)))
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
259 (cons cmd keys))))
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
260 (setq cache-specified nil))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
261 (if keys (setq prop (cons :keys (cons keys prop)))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
262 (if (and visible (not (easy-menu-always-true visible)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
263 (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
264 ;; 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
265 (setq remove t)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
266 (setq prop (cons :visible (cons visible prop)))))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
267 (if (and active (not (easy-menu-always-true active)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
268 (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
269 (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
270 (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
271 (setq prop (cons :key-sequence (cons cache prop))))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
272 (t (error "Invalid menu item in easymenu.")))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
273 (easy-menu-define-key menu (if (stringp name) (intern name) name)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
274 (and (not remove)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
275 (cons 'menu-item
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
276 (cons label
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
277 (and name (cons command prop)))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
278 (if (stringp before) (intern before) before))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
279
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
280 (defun easy-menu-define-key (menu key item &optional before)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
281 ;; Add binding in MENU for KEY => ITEM. Similar to `define-key-after'.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
282 ;; If KEY is not nil then delete any duplications. If ITEM is nil, then
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
283 ;; don't insert, only delete.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
284 ;; Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
285 ;; put binding before BEFORE in MENU, otherwise if binding is already
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
286 ;; present in MENU, just change it, otherwise put it last in MENU.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
287 (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
288 tail done)
20801
8aeddd528f57 (easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents: 20791
diff changeset
289 (while (not done)
8aeddd528f57 (easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents: 20791
diff changeset
290 (cond
8aeddd528f57 (easy-menu-add-item); The BEFORE argument works
Richard M. Stallman <rms@gnu.org>
parents: 20791
diff changeset
291 ((or (setq done (or (null (cdr menu)) (keymapp (cdr menu))))
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
292 (and before (equal (car-safe (cadr menu)) before)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
293 ;; 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
294 ;; 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
295 ;; later.
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
296 (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
297 (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
298 (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
299 (setq inserted t)
21807
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
300 (setq menu (cdr menu)))
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
301 (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
302 ((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
303 (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
304 (and before ; wanted elsewhere and
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
305 (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
306 (not (keymapp tail))
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
307 (not (equal (car-safe (car tail)) before)))) ; in position
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
308 (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
309 (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
310 (setq inserted t)
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
311 (setq menu (cdr menu))))
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
312 (t (setq menu (cdr menu)))))))
c62197b13ece (easy-menu-define-key): Fixed bug with BEFORE
Richard M. Stallman <rms@gnu.org>
parents: 21745
diff changeset
313
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
314 (defun easy-menu-always-true (x)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
315 ;; Return true if X never evaluates to nil.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
316 (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
317 (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
318
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
319 (defvar easy-menu-item-count 0)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
320
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
321 (defun easy-menu-make-symbol (callback)
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
322 ;; Return a unique symbol with CALLBACK as function value.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
323 (let ((command
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
324 (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
325 (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
326 (fset command
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
327 (if (keymapp callback) callback
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
328 `(lambda () (interactive) ,callback)))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
329 command))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
330
22033
aa1d105f0d67 (easy-menu-change): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 21807
diff changeset
331 ;;;###autoload
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
332 (defun easy-menu-change (path name items &optional before)
8085
c7eb887a1e78 (easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7614
diff changeset
333 "Change menu found at PATH as item NAME to contain ITEMS.
c7eb887a1e78 (easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7614
diff changeset
334 PATH is a list of strings for locating the menu containing NAME in the
c7eb887a1e78 (easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7614
diff changeset
335 menu bar. ITEMS is a list of menu items, as in `easy-menu-define'.
c7eb887a1e78 (easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7614
diff changeset
336 These items entirely replace the previous items in that map.
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
337 If NAME is not present in the menu located by PATH, then add item NAME to
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
338 that menu. If the optional argument BEFORE is present add NAME in menu
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
339 just before BEFORE, otherwise add at end of menu.
8085
c7eb887a1e78 (easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7614
diff changeset
340
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
341 Either call this from `menu-bar-update-hook' or use a menu filter,
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
342 to implement dynamic menus."
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
343 (easy-menu-add-item nil path (cons name items) before))
8085
c7eb887a1e78 (easy-menu-change): New function.
Richard M. Stallman <rms@gnu.org>
parents: 7614
diff changeset
344
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
345 ;; 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
346 ;; In Emacs this is done automatically when switching keymaps, so
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
347 ;; here easy-menu-remove is a noop and easy-menu-add only precalculates
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
348 ;; equivalent keybindings (if easy-menu-precalculate-equivalent-keybindings
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
349 ;; is on).
9733
a721dbc48e10 (easy-menu-define): Call `easy-menu-do-define' to do
Richard M. Stallman <rms@gnu.org>
parents: 9586
diff changeset
350 (defun easy-menu-remove (menu))
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
351
22196
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
352 (defun easy-menu-add (menu &optional map)
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
353 "Maybe precalculate equivalent key bindings.
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
354 Do it if `easy-menu-precalculate-equivalent-keybindings' is on,"
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
355 (when easy-menu-precalculate-equivalent-keybindings
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
356 (if (and (symbolp menu) (not (keymapp menu)) (boundp menu))
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
357 (setq menu (symbol-value menu)))
4f4d9c92ae33 (easy-menu-do-add-item): Small simplifications.
Richard M. Stallman <rms@gnu.org>
parents: 22033
diff changeset
358 (if (keymapp menu) (x-popup-menu nil menu))))
6600
f75ac1f3d99c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 6542
diff changeset
359
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
360 (defun easy-menu-add-item (menu path item &optional before)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
361 "At the end of the submenu of MENU with path PATH add ITEM.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
362 If ITEM is already present in this submenu, then this item will be changed.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
363 otherwise ITEM will be added at the end of the submenu, unless the optional
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
364 argument BEFORE is present, in which case ITEM will instead be added
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
365 before the item named BEFORE.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
366 MENU is either a symbol, which have earlier been used as the first
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
367 argument in a call to `easy-menu-define', or the value of such a symbol
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
368 i.e. a menu, or nil which stands for the menu-bar itself.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
369 PATH is a list of strings for locating the submenu where ITEM is to be
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
370 added. If PATH is nil, MENU itself is used. Otherwise, the first
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
371 element should be the name of a submenu directly under MENU. This
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
372 submenu is then traversed recursively with the remaining elements of PATH.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
373 ITEM is either defined as in `easy-menu-define' or a menu defined earlier
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
374 by `easy-menu-define' or `easy-menu-create-menu'."
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
375 (setq menu (easy-menu-get-map menu path))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
376 (if (or (keymapp item)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
377 (and (symbolp item) (keymapp (symbol-value item))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
378 ;; Item is a keymap, find the prompt string and use as item name.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
379 (let ((tail (easy-menu-get-map item nil)) name)
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
380 (if (not (keymapp item)) (setq item tail))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
381 (while (and (null name) (consp (setq tail (cdr tail)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
382 (not (keymapp tail)))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
383 (if (stringp (car tail)) (setq name (car tail)) ; Got a name.
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
384 (setq tail (cdr tail))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
385 (setq item (cons name item))))
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
386 (easy-menu-do-add-item menu item before))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
387
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
388 (defun easy-menu-item-present-p (menu path name)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
389 "In submenu of MENU with path PATH, return true iff item NAME is present.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
390 MENU and PATH are defined as in `easy-menu-add-item'.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
391 NAME should be a string, the name of the element to be looked for."
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
392 (lookup-key (easy-menu-get-map menu path) (vector (intern name))))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
393
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
394 (defun easy-menu-remove-item (menu path name)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
395 "From submenu of MENU with path PATH remove item NAME.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
396 MENU and PATH are defined as in `easy-menu-add-item'.
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
397 NAME should be a string, the name of the element to be removed."
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
398 (easy-menu-define-key (easy-menu-get-map menu path) (intern name) nil))
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
399
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
400 (defun easy-menu-get-map (menu path)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
401 ;; Return a sparse keymap in which to add or remove an item.
21745
38a6d62cddb9 Use new menu item format. Don't simulate button prefix.
Richard M. Stallman <rms@gnu.org>
parents: 21689
diff changeset
402 ;; MENU and PATH are as defined in `easy-menu-add-item'.
20791
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
403 (if (null menu)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
404 (setq menu (key-binding (vconcat '(menu-bar) (mapcar 'intern path))))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
405 (if (and (symbolp menu) (not (keymapp menu)))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
406 (setq menu (symbol-value menu)))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
407 (if path (setq menu (lookup-key menu (vconcat (mapcar 'intern path))))))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
408 (while (and (symbolp menu) (keymapp menu))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
409 (setq menu (symbol-function menu)))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
410 (or (keymapp menu) (error "Malformed menu in easy-menu: (%s)" menu))
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
411 menu)
0c51c56d0a4f easy-menu-define): Use ` and , read-macros
Richard M. Stallman <rms@gnu.org>
parents: 19761
diff changeset
412
6529
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (provide 'easymenu)
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
79c305d1edcb Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 ;;; easymenu.el ends here