1 ;;; @(#) defmenu.el -- A GNU Emacs extension which helps building menus
2 ;;; @(#) $Keywords: X, menu $
4 ;; Copyright (C) 1995 Mikael Djurfeldt
7 ;; defmenu|djurfeldt@nada.kth.se|
8 ;; A GNU Emacs extension which helps building menus|
9 ;; $Date: 2003-08-20 19:00:44 $|$Revision: 1.1 $|~/misc/defmenu.el.Z|
11 ;; Author: Mikael Djurfeldt <djurfeldt@nada.kth.se>
14 ;; This program is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by the Free
16 ;; Software Foundation; either version 2 of the License, or (at your option)
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 ;; You should have received a copy of the GNU General Public License along
25 ;; with GNU Emacs. If you did not, write to the Free Software Foundation,
26 ;; Inc., 675 Mass Ave., Cambridge, MA 02139, USA.
38 (defun define-menu (keymap key name entries
)
39 "Define a menu in KEYMAP on fake function key KEY with label NAME.
40 Every entry in the list ENTRIES defines a menu item and looks like this:
42 (LABEL DEFINITION [ENABLE-EXP])
44 LABEL is a string which will appear in the menu.
45 DEFINITION is either a symbol, in which case it will be used both as
46 fake function key and binding, or a pair, where the car is the fake
47 function key and the cdr is the binding.
48 The optional ENABLE-EXP is an expression which will be evaluated every
49 time the menu is displayed. If it returns nil the menu item will
52 You can get a separator by including nil in the ENTRIES list."
54 (vector 'menu-bar key
)
55 (cons name
(make-menu name entries
))))
57 (defun make-menu (name entries
)
58 "Make a menu with label NAME.
59 Every entry in the list ENTRIES defines a menu item and looks like this:
61 (LABEL DEFINITION [ENABLE-EXP])
63 LABEL is a string which will appear in the menu.
64 DEFINITION is either a symbol, in which case it will be used both as
65 fake function key and binding, or a pair, where the car is the fake
66 function key and the cdr is the binding.
67 The optional ENABLE-EXP is an expression which will be evaluated every
68 time the menu is displayed. If it returns nil the menu item will
71 You can get a separator by including nil in the ENTRIES list."
72 (let ((menu (make-sparse-keymap name
))
73 (entries (reverse entries
)))
75 (let ((entry (car entries
)))
77 (define-key menu
(vector (defmenu-gensym "separator")) '("--"))
78 (if (symbolp (nth 1 entry
))
79 (define-key menu
(vector (nth 1 entry
))
80 (cons (car entry
) (nth 1 entry
)))
81 (define-key menu
(vector (car (nth 1 entry
)))
82 (cons (car entry
) (cdr (nth 1 entry
)))))
83 (if (not (null (nthcdr 2 entry
)))
84 (put (nth 1 entry
) 'menu-enable
(nth 2 entry
)))))
85 (setq entries
(cdr entries
)))
88 (defun defmenu-gensym (prefix)
89 (let ((counter (intern (concat "defmenu-" prefix
"count"))))
90 (if (boundp counter
) (set counter
(1+ (symbol-value counter
)))
92 (intern (concat prefix
(int-to-string (symbol-value counter
))))))