Mercurial > emacs
annotate lisp/obsolete/x-menu.el @ 94010:eb51ce38e226
(__MINGW_NOTHROW): If not defined, define to nothing.
Add copyright notice.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 11 Apr 2008 19:23:32 +0000 |
parents | ee22366f2a68 |
children | 43d30a1ea764 |
rev | line source |
---|---|
39022 | 1 ;;; x-menu.el --- menu support for X |
2 | |
74509 | 3 ;; Copyright (C) 1986, 2001, 2002, 2003, 2004, 2005, |
79715 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
39022 | 5 |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
78228
1e016d63f292
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
10 ;; the Free Software Foundation; either version 3, or (at your option) |
39022 | 11 ;; any later version. |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 ;; Boston, MA 02110-1301, USA. | |
39022 | 22 |
23 ;;; Commentary: | |
24 | |
94000
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
25 ;; This file has been obsolete since Emacs 21.1. |
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
26 |
39022 | 27 ;;; Code: |
28 | |
65190
ba16937f9b3f
(x-process-mouse-hook): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
29 (defvar x-process-mouse-hook) |
ba16937f9b3f
(x-process-mouse-hook): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
30 |
39022 | 31 (defun x-menu-mode () |
32 "Major mode for creating permanent menus for use with X. | |
33 These menus are implemented entirely in Lisp; popup menus, implemented | |
34 with x-popup-menu, are implemented using XMenu primitives." | |
35 (make-local-variable 'x-menu-items-per-line) | |
36 (make-local-variable 'x-menu-item-width) | |
37 (make-local-variable 'x-menu-items-alist) | |
38 (make-local-variable 'x-process-mouse-hook) | |
39 (make-local-variable 'x-menu-assoc-buffer) | |
40 (setq buffer-read-only t) | |
41 (setq truncate-lines t) | |
42 (setq x-process-mouse-hook 'x-menu-pick-entry) | |
43 (setq mode-line-buffer-identification '("MENU: %32b"))) | |
44 | |
45 (defvar x-menu-max-width 0) | |
46 (defvar x-menu-items-per-line 0) | |
47 (defvar x-menu-item-width 0) | |
48 (defvar x-menu-items-alist nil) | |
49 (defvar x-menu-assoc-buffer nil) | |
50 | |
51 (defvar x-menu-item-spacing 1 | |
52 "*Minimum horizontal spacing between objects in a permanent X menu.") | |
53 | |
54 (defun x-menu-create-menu (name) | |
55 "Create a permanent X menu. | |
56 Returns an item which should be used as a | |
57 menu object whenever referring to the menu." | |
58 (let ((old (current-buffer)) | |
59 (buf (get-buffer-create name))) | |
60 (set-buffer buf) | |
61 (x-menu-mode) | |
62 (setq x-menu-assoc-buffer old) | |
63 (set-buffer old) | |
64 buf)) | |
65 | |
66 (defun x-menu-change-associated-buffer (menu buffer) | |
67 "Change associated buffer of MENU to BUFFER. | |
68 BUFFER should be a buffer object." | |
69 (let ((old (current-buffer))) | |
70 (set-buffer menu) | |
71 (setq x-menu-assoc-buffer buffer) | |
72 (set-buffer old))) | |
73 | |
74 (defun x-menu-add-item (menu item binding) | |
75 "Add to MENU an item with name ITEM, associated with BINDING. | |
76 Following a sequence of calls to x-menu-add-item, a call to x-menu-compute | |
77 should be performed before the menu will be made available to the user. | |
78 | |
79 BINDING should be a function of one argument, which is the numerical | |
80 button/key code as defined in x-menu.el." | |
81 (let ((old (current-buffer)) | |
82 elt) | |
83 (set-buffer menu) | |
84 (if (setq elt (assoc item x-menu-items-alist)) | |
85 (rplacd elt binding) | |
86 (setq x-menu-items-alist (append x-menu-items-alist | |
87 (list (cons item binding))))) | |
88 (set-buffer old) | |
89 item)) | |
90 | |
91 (defun x-menu-delete-item (menu item) | |
92 "Delete from MENU the item named ITEM. | |
93 Call `x-menu-compute' before making the menu available to the user." | |
94 (let ((old (current-buffer)) | |
95 elt) | |
96 (set-buffer menu) | |
97 (if (setq elt (assoc item x-menu-items-alist)) | |
98 (rplaca elt nil)) | |
99 (set-buffer old) | |
100 item)) | |
101 | |
102 (defun x-menu-activate (menu) | |
103 "Compute all necessary parameters for MENU. | |
104 This must be called whenever a menu is modified before it is made | |
105 available to the user. This also creates the menu itself." | |
106 (let ((buf (current-buffer))) | |
107 (pop-to-buffer menu) | |
108 (let (buffer-read-only) | |
109 (setq x-menu-max-width (1- (frame-width))) | |
110 (setq x-menu-item-width 0) | |
111 (let (items-head | |
112 (items-tail x-menu-items-alist)) | |
113 (while items-tail | |
114 (if (car (car items-tail)) | |
115 (progn (setq items-head (cons (car items-tail) items-head)) | |
116 (setq x-menu-item-width | |
117 (max x-menu-item-width | |
118 (length (car (car items-tail))))))) | |
119 (setq items-tail (cdr items-tail))) | |
120 (setq x-menu-items-alist (reverse items-head))) | |
121 (setq x-menu-item-width (+ x-menu-item-spacing x-menu-item-width)) | |
122 (setq x-menu-items-per-line | |
123 (max 1 (/ x-menu-max-width x-menu-item-width))) | |
124 (erase-buffer) | |
125 (let ((items-head x-menu-items-alist)) | |
126 (while items-head | |
127 (let ((items 0)) | |
128 (while (and items-head | |
129 (<= (setq items (1+ items)) x-menu-items-per-line)) | |
130 (insert (format (concat "%" | |
131 (int-to-string x-menu-item-width) "s") | |
132 (car (car items-head)))) | |
133 (setq items-head (cdr items-head)))) | |
134 (insert ?\n))) | |
135 (shrink-window (max 0 | |
136 (- (window-height) | |
137 (1+ (count-lines (point-min) (point-max)))))) | |
138 (goto-char (point-min))) | |
139 (pop-to-buffer buf))) | |
140 | |
141 (defun x-menu-pick-entry (position event) | |
142 "Internal function for dispatching on mouse/menu events" | |
143 (let* ((x (min (1- x-menu-items-per-line) | |
144 (/ (current-column) x-menu-item-width))) | |
145 (y (- (count-lines (point-min) (point)) | |
146 (if (zerop (current-column)) 0 1))) | |
147 (item (+ x (* y x-menu-items-per-line))) | |
148 (litem (cdr (nth item x-menu-items-alist)))) | |
149 (and litem (funcall litem event))) | |
150 (pop-to-buffer x-menu-assoc-buffer)) | |
151 | |
152 (provide 'x-menu) | |
153 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79715
diff
changeset
|
154 ;; arch-tag: 889f6d49-c01b-49e7-aaef-b0c6966c2961 |
39022 | 155 ;;; x-menu.el ends here |