Mercurial > emacs
annotate lisp/wid-browse.el @ 17752:2687f3d7c191
(x-make-font-bold-italic): New function.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 12 May 1997 05:26:35 +0000 |
parents | d6545cfb6c5a |
children | 0df9495348e7 |
rev | line source |
---|---|
17334 | 1 ;;; wid-browse.el --- Functions for browsing widgets. |
2 ;; | |
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
6 ;; Keywords: extensions | |
17550
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
7 ;; Version: 1.90 |
17334 | 8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ |
9 | |
10 ;;; Commentary: | |
11 ;; | |
12 ;; Widget browser. See `widget.el'. | |
13 | |
14 ;;; Code: | |
15 | |
16 (require 'easymenu) | |
17 (require 'custom) | |
18 (require 'wid-edit) | |
17550
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
19 (eval-when-compile (require 'cl)) |
17334 | 20 |
21 (defgroup widget-browse nil | |
22 "Customization support for browsing widgets." | |
23 :group 'widgets) | |
24 | |
25 ;;; The Mode. | |
26 | |
27 (defvar widget-browse-mode-map nil | |
28 "Keymap for `widget-browse-mode'.") | |
29 | |
30 (unless widget-browse-mode-map | |
31 (setq widget-browse-mode-map (make-sparse-keymap)) | |
17415 | 32 (set-keymap-parent widget-browse-mode-map widget-keymap) |
33 (define-key widget-browse-mode-map "q" 'bury-buffer)) | |
34 | |
35 (easy-menu-define widget-browse-mode-customize-menu | |
36 widget-browse-mode-map | |
37 "Menu used in widget browser buffers." | |
38 (customize-menu-create 'widgets)) | |
17334 | 39 |
40 (easy-menu-define widget-browse-mode-menu | |
41 widget-browse-mode-map | |
42 "Menu used in widget browser buffers." | |
43 '("Widget" | |
44 ["Browse" widget-browse t] | |
45 ["Browse At" widget-browse-at t])) | |
46 | |
47 (defcustom widget-browse-mode-hook nil | |
48 "Hook called when entering widget-browse-mode." | |
49 :type 'hook | |
50 :group 'widget-browse) | |
51 | |
52 (defun widget-browse-mode () | |
53 "Major mode for widget browser buffers. | |
54 | |
55 The following commands are available: | |
56 | |
57 \\[widget-forward] Move to next button or editable field. | |
58 \\[widget-backward] Move to previous button or editable field. | |
59 \\[widget-button-click] Activate button under the mouse pointer. | |
60 \\[widget-button-press] Activate button under point. | |
61 | |
62 Entry to this mode calls the value of `widget-browse-mode-hook' | |
63 if that value is non-nil." | |
64 (kill-all-local-variables) | |
65 (setq major-mode 'widget-browse-mode | |
66 mode-name "Widget") | |
67 (use-local-map widget-browse-mode-map) | |
17415 | 68 (easy-menu-add widget-browse-mode-customize-menu) |
17334 | 69 (easy-menu-add widget-browse-mode-menu) |
70 (run-hooks 'widget-browse-mode-hook)) | |
71 | |
72 ;;; Commands. | |
73 | |
74 ;;;###autoload | |
75 (defun widget-browse-at (pos) | |
76 "Browse the widget under point." | |
77 (interactive "d") | |
78 (let* ((field (get-text-property pos 'field)) | |
79 (button (get-text-property pos 'button)) | |
80 (doc (get-text-property pos 'widget-doc)) | |
81 (text (cond (field "This is an editable text area.") | |
82 (button "This is an active area.") | |
83 (doc "This is documentation text.") | |
84 (t "This is unidentified text."))) | |
85 (widget (or field button doc))) | |
86 (when widget | |
87 (widget-browse widget)) | |
88 (message text))) | |
89 | |
90 (defvar widget-browse-history nil) | |
91 | |
17415 | 92 ;;;###autoload |
17334 | 93 (defun widget-browse (widget) |
94 "Create a widget browser for WIDGET." | |
95 (interactive (list (completing-read "Widget: " | |
96 obarray | |
97 (lambda (symbol) | |
98 (get symbol 'widget-type)) | |
99 t nil 'widget-browse-history))) | |
100 (if (stringp widget) | |
101 (setq widget (intern widget))) | |
102 (unless (if (symbolp widget) | |
103 (get widget 'widget-type) | |
104 (and (consp widget) | |
105 (get (widget-type widget) 'widget-type))) | |
106 (error "Not a widget.")) | |
107 ;; Create the buffer. | |
108 (if (symbolp widget) | |
109 (let ((buffer (format "*Browse %s Widget*" widget))) | |
110 (kill-buffer (get-buffer-create buffer)) | |
111 (switch-to-buffer (get-buffer-create buffer))) | |
112 (kill-buffer (get-buffer-create "*Browse Widget*")) | |
113 (switch-to-buffer (get-buffer-create "*Browse Widget*"))) | |
114 (widget-browse-mode) | |
115 | |
116 ;; Quick way to get out. | |
17415 | 117 ;; (widget-create 'push-button |
118 ;; :action (lambda (widget &optional event) | |
119 ;; (bury-buffer)) | |
120 ;; "Quit") | |
121 ;; (widget-insert "\n") | |
17334 | 122 |
123 ;; Top text indicating whether it is a class or object browser. | |
124 (if (listp widget) | |
125 (widget-insert "Widget object browser.\n\nClass: ") | |
126 (widget-insert "Widget class browser.\n\n") | |
127 (widget-create 'widget-browse | |
128 :format "%[%v%]\n%d" | |
129 :doc (get widget 'widget-documentation) | |
130 widget) | |
131 (unless (eq (preceding-char) ?\n) | |
132 (widget-insert "\n")) | |
133 (widget-insert "\nSuper: ") | |
134 (setq widget (get widget 'widget-type))) | |
135 | |
136 ;; Now show the attributes. | |
137 (let ((name (car widget)) | |
138 (items (cdr widget)) | |
139 key value printer) | |
140 (widget-create 'widget-browse | |
141 :format "%[%v%]" | |
142 name) | |
143 (widget-insert "\n") | |
144 (while items | |
145 (setq key (nth 0 items) | |
146 value (nth 1 items) | |
147 printer (or (get key 'widget-keyword-printer) | |
148 'widget-browse-sexp) | |
149 items (cdr (cdr items))) | |
150 (widget-insert "\n" (symbol-name key) "\n\t") | |
151 (funcall printer widget key value) | |
152 (widget-insert "\n"))) | |
153 (widget-setup) | |
154 (goto-char (point-min))) | |
155 | |
17415 | 156 ;;;###autoload |
157 (defun widget-browse-other-window (&optional widget) | |
158 "Show widget browser for WIDGET in other window." | |
159 (interactive) | |
160 (let ((window (selected-window))) | |
161 (switch-to-buffer-other-window "*Browse Widget*") | |
162 (if widget | |
163 (widget-browse widget) | |
164 (call-interactively 'widget-browse)) | |
165 (select-window window))) | |
166 | |
167 | |
17334 | 168 ;;; The `widget-browse' Widget. |
169 | |
170 (define-widget 'widget-browse 'push-button | |
171 "Button for creating a widget browser. | |
172 The :value of the widget shuld be the widget to be browsed." | |
173 :format "%[[%v]%]" | |
174 :value-create 'widget-browse-value-create | |
175 :action 'widget-browse-action) | |
176 | |
177 (defun widget-browse-action (widget &optional event) | |
178 ;; Create widget browser for WIDGET's :value. | |
179 (widget-browse (widget-get widget :value))) | |
180 | |
181 (defun widget-browse-value-create (widget) | |
182 ;; Insert type name. | |
183 (let ((value (widget-get widget :value))) | |
184 (cond ((symbolp value) | |
185 (insert (symbol-name value))) | |
186 ((consp value) | |
187 (insert (symbol-name (widget-type value)))) | |
188 (t | |
189 (insert "strange"))))) | |
190 | |
191 ;;; Keyword Printer Functions. | |
192 | |
193 (defun widget-browse-widget (widget key value) | |
194 "Insert description of WIDGET's KEY VALUE. | |
195 VALUE is assumed to be a widget." | |
196 (widget-create 'widget-browse value)) | |
197 | |
198 (defun widget-browse-widgets (widget key value) | |
199 "Insert description of WIDGET's KEY VALUE. | |
200 VALUE is assumed to be a list of widgets." | |
201 (while value | |
202 (widget-create 'widget-browse | |
203 (car value)) | |
204 (setq value (cdr value)) | |
205 (when value | |
206 (widget-insert " ")))) | |
207 | |
208 (defun widget-browse-sexp (widget key value) | |
209 "Insert description of WIDGET's KEY VALUE. | |
210 Nothing is assumed about value." | |
211 (let ((pp (condition-case signal | |
212 (pp-to-string value) | |
213 (error (prin1-to-string signal))))) | |
214 (when (string-match "\n\\'" pp) | |
215 (setq pp (substring pp 0 (1- (length pp))))) | |
216 (if (cond ((string-match "\n" pp) | |
217 nil) | |
218 ((> (length pp) (- (window-width) (current-column))) | |
219 nil) | |
220 (t t)) | |
221 (widget-insert pp) | |
222 (widget-create 'push-button | |
223 :tag "show" | |
224 :action (lambda (widget &optional event) | |
225 (with-output-to-temp-buffer | |
226 "*Pp Eval Output*" | |
227 (princ (widget-get widget :value)))) | |
228 pp)))) | |
229 | |
230 (defun widget-browse-sexps (widget key value) | |
231 "Insert description of WIDGET's KEY VALUE. | |
232 VALUE is assumed to be a list of widgets." | |
233 (let ((target (current-column))) | |
234 (while value | |
235 (widget-browse-sexp widget key (car value)) | |
236 (setq value (cdr value)) | |
237 (when value | |
238 (widget-insert "\n" (make-string target ?\ )))))) | |
239 | |
240 ;;; Keyword Printers. | |
241 | |
242 (put :parent 'widget-keyword-printer 'widget-browse-widget) | |
243 (put :children 'widget-keyword-printer 'widget-browse-widgets) | |
244 (put :buttons 'widget-keyword-printer 'widget-browse-widgets) | |
245 (put :button 'widget-keyword-printer 'widget-browse-widget) | |
246 (put :args 'widget-keyword-printer 'widget-browse-sexps) | |
247 | |
17550
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
248 ;;; Widget Minor Mode. |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
249 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
250 (defvar widget-minor-mode nil |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
251 "I non-nil, we are in Widget Minor Mode.") |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
252 (make-variable-buffer-local 'widget-minor-mode) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
253 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
254 (defvar widget-minor-mode-map nil |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
255 "Keymap used in Widget Minor Mode.") |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
256 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
257 (unless widget-minor-mode-map |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
258 (setq widget-minor-mode-map (make-sparse-keymap)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
259 (set-keymap-parent widget-minor-mode-map widget-keymap)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
260 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
261 ;;;###autoload |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
262 (defun widget-minor-mode (&optional arg) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
263 "Togle minor mode for traversing widgets. |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
264 With arg, turn widget mode on if and only if arg is positive." |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
265 (interactive "P") |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
266 (cond ((null arg) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
267 (setq widget-minor-mode (not widget-minor-mode))) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
268 ((<= 0 arg) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
269 (setq widget-minor-mode nil)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
270 (t |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
271 (setq widget-minor-mode t))) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
272 (force-mode-line-update)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
273 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
274 (add-to-list 'minor-mode-alist '(widget-minor-mode " Widget")) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
275 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
276 (add-to-list 'minor-mode-map-alist |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
277 (cons 'widget-minor-mode widget-minor-mode-map)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
278 |
17334 | 279 ;;; The End: |
280 | |
281 (provide 'wid-browse) | |
282 | |
283 ;; wid-browse.el ends here |