diff options
| author | Richard M. Stallman | 1994-03-25 07:38:29 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-03-25 07:38:29 +0000 |
| commit | 029b623a7e3bcad33d2f97250f962ae4f5ca0add (patch) | |
| tree | 39aee6fea6bdf09dc3cacb413fd5f1bbba36e74a | |
| parent | b22e7ecc3f041dfe12c6bda14a8b2b5f7e8173c3 (diff) | |
| download | emacs-029b623a7e3bcad33d2f97250f962ae4f5ca0add.tar.gz emacs-029b623a7e3bcad33d2f97250f962ae4f5ca0add.zip | |
Initial revision
| -rw-r--r-- | lisp/emacs-lisp/easymenu.el | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el new file mode 100644 index 00000000000..d87f134e9b0 --- /dev/null +++ b/lisp/emacs-lisp/easymenu.el | |||
| @@ -0,0 +1,104 @@ | |||
| 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 | |||
| 29 | ;;;###autoload. | ||
| 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 | ||
| 33 | compatibility only. | ||
| 34 | |||
| 35 | The first element of MENU must be a string. It is the menu bar item name. | ||
| 36 | The rest of the elements are menu items. | ||
| 37 | |||
| 38 | A menu item is a vector of three elements: | ||
| 39 | |||
| 40 | - the name of the menu item (a string); | ||
| 41 | - the `callback' of that item; | ||
| 42 | - t. | ||
| 43 | |||
| 44 | If the `callback' of a menu item is a symbol, then it must name a | ||
| 45 | command. It will be invoked with `call-interactively'. If it is a | ||
| 46 | list, then it is evaluated with `eval'. | ||
| 47 | |||
| 48 | If an element of a menu is a string, then that string appears in the | ||
| 49 | menu as unselectable text. | ||
| 50 | |||
| 51 | If an element of a menu is a string consisting solely of hyphens, then that | ||
| 52 | item is displayed as a solid horizontal line. | ||
| 53 | |||
| 54 | If an element of a menu is a list, it is treated as a submenu. | ||
| 55 | The first element should be the submenu name. That's used as the | ||
| 56 | menu item in the top-level menu. The cdr of the submenu list | ||
| 57 | is a list of menu items, as above." | ||
| 58 | (let ((keymap (easy-menu-keymap (car menu) (cdr menu)))) | ||
| 59 | (mapcar (function (lambda (map) | ||
| 60 | (define-key map (vector 'menu-bar (intern (car menu))) | ||
| 61 | (cons (car menu) keymap)))) | ||
| 62 | (if (keymapp maps) (list maps) maps)))) | ||
| 63 | |||
| 64 | ;; Return a menu keymap corresponding to a Lucid-style menu list | ||
| 65 | ;; MENU-ITEMS, and with name MENU-NAME. | ||
| 66 | (defun easy-menu-keymap (menu-name menu-items) | ||
| 67 | (let ((menu (make-sparse-keymap menu-name))) | ||
| 68 | ;; Process items in reverse order, | ||
| 69 | ;; since the define-key loop reverses them again. | ||
| 70 | (setq menu-items (reverse menu-items)) | ||
| 71 | (while menu-items | ||
| 72 | (let* ((item (car menu-items)) | ||
| 73 | (callback (if (vectorp item) (aref item 1))) | ||
| 74 | command enabler name) | ||
| 75 | (cond ((stringp item) | ||
| 76 | (setq command nil) | ||
| 77 | (setq name (if (string-match "^-+$" item) "" item))) | ||
| 78 | ((consp item) | ||
| 79 | (setq command (make-lucid-menu-keymap (car item) (cdr item))) | ||
| 80 | (setq name (car item))) | ||
| 81 | ((vectorp item) | ||
| 82 | (setq command (make-symbol (format "menu-function-%d" | ||
| 83 | add-menu-item-count))) | ||
| 84 | (setq enabler (make-symbol (format "menu-function-%d-enabler" | ||
| 85 | add-menu-item-count))) | ||
| 86 | (setq add-menu-item-count (1+ add-menu-item-count)) | ||
| 87 | (put command 'menu-enable enabler) | ||
| 88 | (set enabler (aref item 2)) | ||
| 89 | (setq name (aref item 0)) | ||
| 90 | (if (symbolp callback) | ||
| 91 | (fset command callback) | ||
| 92 | (fset command (list 'lambda () '(interactive) callback))))) | ||
| 93 | (if (null command) | ||
| 94 | ;; Handle inactive strings specially--allow any number | ||
| 95 | ;; of identical ones. | ||
| 96 | (setcdr menu (cons (list nil name) (cdr menu))) | ||
| 97 | (if name | ||
| 98 | (define-key menu (vector (intern name)) (cons name command))))) | ||
| 99 | (setq menu-items (cdr menu-items))) | ||
| 100 | menu)) | ||
| 101 | |||
| 102 | (provide 'easymenu) | ||
| 103 | |||
| 104 | ;;; easymenu.el ends here | ||