Mercurial > emacs
annotate lisp/x-menu.el @ 38587:42e75caf68ff
(shift_glyph_matrix, blank_row): Fix computation
of row's visible height.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 27 Jul 2001 15:28:46 +0000 |
parents | 67b464da13ec |
children |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
1 ;;; x-menu.el --- menu support for X |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
2 |
35 | 3 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
806 | 9 ;; the Free Software Foundation; either version 2, or (at your option) |
35 | 10 ;; any later version. |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
14169 | 18 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 ;; Boston, MA 02111-1307, USA. | |
35 | 21 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
22 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
23 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
656
diff
changeset
|
24 ;;; Code: |
35 | 25 |
26 (defun x-menu-mode () | |
27 "Major mode for creating permanent menus for use with X. | |
28 These menus are implemented entirely in Lisp; popup menus, implemented | |
29 with x-popup-menu, are implemented using XMenu primitives." | |
30 (make-local-variable 'x-menu-items-per-line) | |
31 (make-local-variable 'x-menu-item-width) | |
32 (make-local-variable 'x-menu-items-alist) | |
33 (make-local-variable 'x-process-mouse-hook) | |
34 (make-local-variable 'x-menu-assoc-buffer) | |
35 (setq buffer-read-only t) | |
36 (setq truncate-lines t) | |
37 (setq x-process-mouse-hook 'x-menu-pick-entry) | |
38 (setq mode-line-buffer-identification '("MENU: %32b"))) | |
39 | |
40 (defvar x-menu-max-width 0) | |
41 (defvar x-menu-items-per-line 0) | |
42 (defvar x-menu-item-width 0) | |
43 (defvar x-menu-items-alist nil) | |
44 (defvar x-menu-assoc-buffer nil) | |
45 | |
46 (defvar x-menu-item-spacing 1 | |
47 "*Minimum horizontal spacing between objects in a permanent X menu.") | |
48 | |
49 (defun x-menu-create-menu (name) | |
12950 | 50 "Create a permanent X menu. |
51 Returns an item which should be used as a | |
35 | 52 menu object whenever referring to the menu." |
53 (let ((old (current-buffer)) | |
54 (buf (get-buffer-create name))) | |
55 (set-buffer buf) | |
56 (x-menu-mode) | |
57 (setq x-menu-assoc-buffer old) | |
58 (set-buffer old) | |
59 buf)) | |
60 | |
61 (defun x-menu-change-associated-buffer (menu buffer) | |
12950 | 62 "Change associated buffer of MENU to BUFFER. |
63 BUFFER should be a buffer object." | |
35 | 64 (let ((old (current-buffer))) |
65 (set-buffer menu) | |
66 (setq x-menu-assoc-buffer buffer) | |
67 (set-buffer old))) | |
68 | |
69 (defun x-menu-add-item (menu item binding) | |
12950 | 70 "Add to MENU an item with name ITEM, associated with BINDING. |
35 | 71 Following a sequence of calls to x-menu-add-item, a call to x-menu-compute |
72 should be performed before the menu will be made available to the user. | |
73 | |
74 BINDING should be a function of one argument, which is the numerical | |
75 button/key code as defined in x-menu.el." | |
76 (let ((old (current-buffer)) | |
77 elt) | |
78 (set-buffer menu) | |
79 (if (setq elt (assoc item x-menu-items-alist)) | |
80 (rplacd elt binding) | |
81 (setq x-menu-items-alist (append x-menu-items-alist | |
82 (list (cons item binding))))) | |
83 (set-buffer old) | |
84 item)) | |
85 | |
86 (defun x-menu-delete-item (menu item) | |
12950 | 87 "Delete from MENU the item named ITEM. |
88 Call `x-menu-compute' before making the menu available to the user." | |
35 | 89 (let ((old (current-buffer)) |
90 elt) | |
91 (set-buffer menu) | |
92 (if (setq elt (assoc item x-menu-items-alist)) | |
93 (rplaca elt nil)) | |
94 (set-buffer old) | |
95 item)) | |
96 | |
97 (defun x-menu-activate (menu) | |
12950 | 98 "Compute all necessary parameters for MENU. |
99 This must be called whenever a menu is modified before it is made | |
100 available to the user. This also creates the menu itself." | |
35 | 101 (let ((buf (current-buffer))) |
102 (pop-to-buffer menu) | |
103 (let (buffer-read-only) | |
806 | 104 (setq x-menu-max-width (1- (frame-width))) |
35 | 105 (setq x-menu-item-width 0) |
106 (let (items-head | |
107 (items-tail x-menu-items-alist)) | |
108 (while items-tail | |
12950 | 109 (if (car (car items-tail)) |
35 | 110 (progn (setq items-head (cons (car items-tail) items-head)) |
111 (setq x-menu-item-width | |
112 (max x-menu-item-width | |
12950 | 113 (length (car (car items-tail))))))) |
35 | 114 (setq items-tail (cdr items-tail))) |
115 (setq x-menu-items-alist (reverse items-head))) | |
116 (setq x-menu-item-width (+ x-menu-item-spacing x-menu-item-width)) | |
117 (setq x-menu-items-per-line | |
118 (max 1 (/ x-menu-max-width x-menu-item-width))) | |
119 (erase-buffer) | |
120 (let ((items-head x-menu-items-alist)) | |
121 (while items-head | |
122 (let ((items 0)) | |
123 (while (and items-head | |
124 (<= (setq items (1+ items)) x-menu-items-per-line)) | |
125 (insert (format (concat "%" | |
126 (int-to-string x-menu-item-width) "s") | |
12950 | 127 (car (car items-head)))) |
35 | 128 (setq items-head (cdr items-head)))) |
129 (insert ?\n))) | |
130 (shrink-window (max 0 | |
131 (- (window-height) | |
132 (1+ (count-lines (point-min) (point-max)))))) | |
133 (goto-char (point-min))) | |
134 (pop-to-buffer buf))) | |
135 | |
136 (defun x-menu-pick-entry (position event) | |
137 "Internal function for dispatching on mouse/menu events" | |
138 (let* ((x (min (1- x-menu-items-per-line) | |
139 (/ (current-column) x-menu-item-width))) | |
140 (y (- (count-lines (point-min) (point)) | |
141 (if (zerop (current-column)) 0 1))) | |
142 (item (+ x (* y x-menu-items-per-line))) | |
143 (litem (cdr (nth item x-menu-items-alist)))) | |
144 (and litem (funcall litem event))) | |
145 (pop-to-buffer x-menu-assoc-buffer)) | |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
146 |
18383 | 147 (provide 'x-menu) |
148 | |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
149 ;;; x-menu.el ends here |