Mercurial > emacs
annotate lisp/emacs-lisp/easymenu.el @ 6586:de99006a8b38
(Fcompute_motion): Don't use XFASTINT on possibly-negative coords.
Also another doc fix.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 30 Mar 1994 03:02:02 +0000 |
parents | 1d9da8160357 |
children | f75ac1f3d99c |
rev | line source |
---|---|
6529 | 1 ;;; easymenu.el --- support the easymenu interface for defining a menu. |
2 | |
3 ;; Keywords: emulations | |
4 | |
5 ;; Copyright (C) 1994 Free Software Foundation, Inc. | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; This is compatible with easymenu.el by Per Abrahamsen | |
24 ;;; but it is much simpler as it doesn't try to support other Emacs versions. | |
25 ;;; The code was mostly derived from lmenu.el. | |
26 | |
27 ;;; Code: | |
28 | |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
29 ;;;###autoload |
6529 | 30 (defun easy-menu-define (symbol maps doc menu) |
31 "Define a menu bar submenu in maps MAPS, according to MENU. | |
32 The arguments SYMBOL and DOC are ignored; they are present for | |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
33 compatibility only. In other Emacs versions they may be used |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
34 as a variable to hold the menu data, and a doc string for that variable. |
6529 | 35 |
36 The first element of MENU must be a string. It is the menu bar item name. | |
37 The rest of the elements are menu items. | |
38 | |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
39 A menu item is usually a vector of three elements: [NAME CALLBACK t] |
6529 | 40 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
41 NAME is a string--the menu item name. |
6529 | 42 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
43 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
|
44 or a list to evaluate when the item is chosen. |
6529 | 45 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
46 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
|
47 unselectable text. A string consisting solely of hyphens is displayed |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
48 as a solid horizontal line. |
6529 | 49 |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
50 A menu item can be a list. It is treated as a submenu. |
6529 | 51 The first element should be the submenu name. That's used as the |
52 menu item in the top-level menu. The cdr of the submenu list | |
53 is a list of menu items, as above." | |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
54 (or (keymapp maps) (setq maps (list maps))) |
6529 | 55 (let ((keymap (easy-menu-keymap (car menu) (cdr menu)))) |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
56 (while maps |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
57 (define-key (car maps) (vector 'menu-bar (intern (car menu))) |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
58 (cons (car menu) keymap)) |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
59 (setq maps (cdr maps))))) |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
60 |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
61 (defvar easy-menu-item-count 0) |
6529 | 62 |
63 ;; Return a menu keymap corresponding to a Lucid-style menu list | |
64 ;; MENU-ITEMS, and with name MENU-NAME. | |
65 (defun easy-menu-keymap (menu-name menu-items) | |
66 (let ((menu (make-sparse-keymap menu-name))) | |
67 ;; Process items in reverse order, | |
68 ;; since the define-key loop reverses them again. | |
69 (setq menu-items (reverse menu-items)) | |
70 (while menu-items | |
71 (let* ((item (car menu-items)) | |
72 (callback (if (vectorp item) (aref item 1))) | |
73 command enabler name) | |
74 (cond ((stringp item) | |
75 (setq command nil) | |
76 (setq name (if (string-match "^-+$" item) "" item))) | |
77 ((consp item) | |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
78 (setq command (easy-menu-keymap (car item) (cdr item))) |
6529 | 79 (setq name (car item))) |
80 ((vectorp item) | |
81 (setq command (make-symbol (format "menu-function-%d" | |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
82 easy-menu-item-count))) |
6529 | 83 (setq enabler (make-symbol (format "menu-function-%d-enabler" |
6542
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
84 easy-menu-item-count))) |
1d9da8160357
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6529
diff
changeset
|
85 (setq easy-menu-item-count (1+ easy-menu-item-count)) |
6529 | 86 (put command 'menu-enable enabler) |
87 (set enabler (aref item 2)) | |
88 (setq name (aref item 0)) | |
89 (if (symbolp callback) | |
90 (fset command callback) | |
91 (fset command (list 'lambda () '(interactive) callback))))) | |
92 (if (null command) | |
93 ;; Handle inactive strings specially--allow any number | |
94 ;; of identical ones. | |
95 (setcdr menu (cons (list nil name) (cdr menu))) | |
96 (if name | |
97 (define-key menu (vector (intern name)) (cons name command))))) | |
98 (setq menu-items (cdr menu-items))) | |
99 menu)) | |
100 | |
101 (provide 'easymenu) | |
102 | |
103 ;;; easymenu.el ends here |