Mercurial > emacs
annotate lisp/wid-browse.el @ 41056:d1554875b932
(prin1, print): Doc fix.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Wed, 14 Nov 2001 19:18:35 +0000 |
parents | b174db545cfd |
children | ce2590f06ba0 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32905
diff
changeset
|
1 ;;; wid-browse.el --- functions for browsing widgets |
17334 | 2 ;; |
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
6 ;; Keywords: extensions | |
18244
909a0f9169b8
Synched with 1.9914.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
18090
diff
changeset
|
7 ;; Version: 1.9914 |
17334 | 8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ |
9 | |
17799 | 10 ;; This file is part of GNU Emacs. |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
17334 | 27 ;;; Commentary: |
28 ;; | |
29 ;; Widget browser. See `widget.el'. | |
30 | |
31 ;;; Code: | |
32 | |
33 (require 'easymenu) | |
34 (require 'custom) | |
35 (require 'wid-edit) | |
17550
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
36 (eval-when-compile (require 'cl)) |
17334 | 37 |
38 (defgroup widget-browse nil | |
39 "Customization support for browsing widgets." | |
40 :group 'widgets) | |
41 | |
42 ;;; The Mode. | |
43 | |
44 (defvar widget-browse-mode-map nil | |
45 "Keymap for `widget-browse-mode'.") | |
46 | |
47 (unless widget-browse-mode-map | |
48 (setq widget-browse-mode-map (make-sparse-keymap)) | |
17415 | 49 (set-keymap-parent widget-browse-mode-map widget-keymap) |
50 (define-key widget-browse-mode-map "q" 'bury-buffer)) | |
51 | |
52 (easy-menu-define widget-browse-mode-customize-menu | |
53 widget-browse-mode-map | |
54 "Menu used in widget browser buffers." | |
55 (customize-menu-create 'widgets)) | |
17334 | 56 |
57 (easy-menu-define widget-browse-mode-menu | |
58 widget-browse-mode-map | |
59 "Menu used in widget browser buffers." | |
60 '("Widget" | |
61 ["Browse" widget-browse t] | |
62 ["Browse At" widget-browse-at t])) | |
63 | |
64 (defcustom widget-browse-mode-hook nil | |
65 "Hook called when entering widget-browse-mode." | |
66 :type 'hook | |
67 :group 'widget-browse) | |
68 | |
69 (defun widget-browse-mode () | |
70 "Major mode for widget browser buffers. | |
71 | |
72 The following commands are available: | |
73 | |
74 \\[widget-forward] Move to next button or editable field. | |
75 \\[widget-backward] Move to previous button or editable field. | |
76 \\[widget-button-click] Activate button under the mouse pointer. | |
77 \\[widget-button-press] Activate button under point. | |
78 | |
79 Entry to this mode calls the value of `widget-browse-mode-hook' | |
80 if that value is non-nil." | |
81 (kill-all-local-variables) | |
82 (setq major-mode 'widget-browse-mode | |
83 mode-name "Widget") | |
84 (use-local-map widget-browse-mode-map) | |
17415 | 85 (easy-menu-add widget-browse-mode-customize-menu) |
17334 | 86 (easy-menu-add widget-browse-mode-menu) |
87 (run-hooks 'widget-browse-mode-hook)) | |
88 | |
32905
c197a16ba190
(widget-browse-mode): Add `special' mode-class property.
Dave Love <fx@gnu.org>
parents:
18244
diff
changeset
|
89 (put 'widget-browse-mode 'mode-class 'special) |
c197a16ba190
(widget-browse-mode): Add `special' mode-class property.
Dave Love <fx@gnu.org>
parents:
18244
diff
changeset
|
90 |
17334 | 91 ;;; Commands. |
92 | |
93 ;;;###autoload | |
94 (defun widget-browse-at (pos) | |
95 "Browse the widget under point." | |
96 (interactive "d") | |
18090 | 97 (let* ((field (get-char-property pos 'field)) |
98 (button (get-char-property pos 'button)) | |
99 (doc (get-char-property pos 'widget-doc)) | |
17334 | 100 (text (cond (field "This is an editable text area.") |
101 (button "This is an active area.") | |
102 (doc "This is documentation text.") | |
103 (t "This is unidentified text."))) | |
104 (widget (or field button doc))) | |
105 (when widget | |
106 (widget-browse widget)) | |
107 (message text))) | |
108 | |
109 (defvar widget-browse-history nil) | |
110 | |
17415 | 111 ;;;###autoload |
17334 | 112 (defun widget-browse (widget) |
113 "Create a widget browser for WIDGET." | |
114 (interactive (list (completing-read "Widget: " | |
115 obarray | |
116 (lambda (symbol) | |
117 (get symbol 'widget-type)) | |
118 t nil 'widget-browse-history))) | |
119 (if (stringp widget) | |
120 (setq widget (intern widget))) | |
121 (unless (if (symbolp widget) | |
122 (get widget 'widget-type) | |
123 (and (consp widget) | |
124 (get (widget-type widget) 'widget-type))) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32905
diff
changeset
|
125 (error "Not a widget")) |
17334 | 126 ;; Create the buffer. |
127 (if (symbolp widget) | |
128 (let ((buffer (format "*Browse %s Widget*" widget))) | |
129 (kill-buffer (get-buffer-create buffer)) | |
130 (switch-to-buffer (get-buffer-create buffer))) | |
131 (kill-buffer (get-buffer-create "*Browse Widget*")) | |
132 (switch-to-buffer (get-buffer-create "*Browse Widget*"))) | |
133 (widget-browse-mode) | |
134 | |
135 ;; Quick way to get out. | |
17415 | 136 ;; (widget-create 'push-button |
137 ;; :action (lambda (widget &optional event) | |
138 ;; (bury-buffer)) | |
139 ;; "Quit") | |
140 ;; (widget-insert "\n") | |
17334 | 141 |
142 ;; Top text indicating whether it is a class or object browser. | |
143 (if (listp widget) | |
144 (widget-insert "Widget object browser.\n\nClass: ") | |
145 (widget-insert "Widget class browser.\n\n") | |
146 (widget-create 'widget-browse | |
147 :format "%[%v%]\n%d" | |
148 :doc (get widget 'widget-documentation) | |
149 widget) | |
150 (unless (eq (preceding-char) ?\n) | |
151 (widget-insert "\n")) | |
152 (widget-insert "\nSuper: ") | |
153 (setq widget (get widget 'widget-type))) | |
154 | |
155 ;; Now show the attributes. | |
156 (let ((name (car widget)) | |
157 (items (cdr widget)) | |
158 key value printer) | |
159 (widget-create 'widget-browse | |
160 :format "%[%v%]" | |
161 name) | |
162 (widget-insert "\n") | |
163 (while items | |
164 (setq key (nth 0 items) | |
165 value (nth 1 items) | |
166 printer (or (get key 'widget-keyword-printer) | |
167 'widget-browse-sexp) | |
168 items (cdr (cdr items))) | |
169 (widget-insert "\n" (symbol-name key) "\n\t") | |
170 (funcall printer widget key value) | |
171 (widget-insert "\n"))) | |
172 (widget-setup) | |
173 (goto-char (point-min))) | |
174 | |
17415 | 175 ;;;###autoload |
176 (defun widget-browse-other-window (&optional widget) | |
177 "Show widget browser for WIDGET in other window." | |
178 (interactive) | |
179 (let ((window (selected-window))) | |
180 (switch-to-buffer-other-window "*Browse Widget*") | |
181 (if widget | |
182 (widget-browse widget) | |
183 (call-interactively 'widget-browse)) | |
184 (select-window window))) | |
185 | |
186 | |
17334 | 187 ;;; The `widget-browse' Widget. |
188 | |
189 (define-widget 'widget-browse 'push-button | |
190 "Button for creating a widget browser. | |
191 The :value of the widget shuld be the widget to be browsed." | |
192 :format "%[[%v]%]" | |
193 :value-create 'widget-browse-value-create | |
194 :action 'widget-browse-action) | |
195 | |
196 (defun widget-browse-action (widget &optional event) | |
197 ;; Create widget browser for WIDGET's :value. | |
198 (widget-browse (widget-get widget :value))) | |
199 | |
200 (defun widget-browse-value-create (widget) | |
201 ;; Insert type name. | |
202 (let ((value (widget-get widget :value))) | |
203 (cond ((symbolp value) | |
204 (insert (symbol-name value))) | |
205 ((consp value) | |
206 (insert (symbol-name (widget-type value)))) | |
207 (t | |
208 (insert "strange"))))) | |
209 | |
210 ;;; Keyword Printer Functions. | |
211 | |
212 (defun widget-browse-widget (widget key value) | |
213 "Insert description of WIDGET's KEY VALUE. | |
214 VALUE is assumed to be a widget." | |
215 (widget-create 'widget-browse value)) | |
216 | |
217 (defun widget-browse-widgets (widget key value) | |
218 "Insert description of WIDGET's KEY VALUE. | |
219 VALUE is assumed to be a list of widgets." | |
220 (while value | |
221 (widget-create 'widget-browse | |
222 (car value)) | |
223 (setq value (cdr value)) | |
224 (when value | |
225 (widget-insert " ")))) | |
226 | |
227 (defun widget-browse-sexp (widget key value) | |
228 "Insert description of WIDGET's KEY VALUE. | |
229 Nothing is assumed about value." | |
230 (let ((pp (condition-case signal | |
231 (pp-to-string value) | |
232 (error (prin1-to-string signal))))) | |
233 (when (string-match "\n\\'" pp) | |
234 (setq pp (substring pp 0 (1- (length pp))))) | |
235 (if (cond ((string-match "\n" pp) | |
236 nil) | |
237 ((> (length pp) (- (window-width) (current-column))) | |
238 nil) | |
239 (t t)) | |
240 (widget-insert pp) | |
241 (widget-create 'push-button | |
242 :tag "show" | |
243 :action (lambda (widget &optional event) | |
244 (with-output-to-temp-buffer | |
245 "*Pp Eval Output*" | |
246 (princ (widget-get widget :value)))) | |
247 pp)))) | |
248 | |
249 (defun widget-browse-sexps (widget key value) | |
250 "Insert description of WIDGET's KEY VALUE. | |
251 VALUE is assumed to be a list of widgets." | |
252 (let ((target (current-column))) | |
253 (while value | |
254 (widget-browse-sexp widget key (car value)) | |
255 (setq value (cdr value)) | |
256 (when value | |
257 (widget-insert "\n" (make-string target ?\ )))))) | |
258 | |
259 ;;; Keyword Printers. | |
260 | |
261 (put :parent 'widget-keyword-printer 'widget-browse-widget) | |
262 (put :children 'widget-keyword-printer 'widget-browse-widgets) | |
263 (put :buttons 'widget-keyword-printer 'widget-browse-widgets) | |
264 (put :button 'widget-keyword-printer 'widget-browse-widget) | |
265 (put :args 'widget-keyword-printer 'widget-browse-sexps) | |
266 | |
17550
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
267 ;;; Widget Minor Mode. |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
268 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
269 (defvar widget-minor-mode nil |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
270 "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
|
271 (make-variable-buffer-local 'widget-minor-mode) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
272 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
273 (defvar widget-minor-mode-map nil |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
274 "Keymap used in Widget Minor Mode.") |
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 (unless widget-minor-mode-map |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
277 (setq widget-minor-mode-map (make-sparse-keymap)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
278 (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
|
279 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
280 ;;;###autoload |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
281 (defun widget-minor-mode (&optional arg) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
282 "Togle minor mode for traversing widgets. |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
283 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
|
284 (interactive "P") |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
285 (cond ((null arg) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
286 (setq widget-minor-mode (not widget-minor-mode))) |
18244
909a0f9169b8
Synched with 1.9914.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
18090
diff
changeset
|
287 ((<= arg 0) |
17550
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
288 (setq widget-minor-mode nil)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
289 (t |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
290 (setq widget-minor-mode t))) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
291 (force-mode-line-update)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
292 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
293 (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
|
294 |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
295 (add-to-list 'minor-mode-map-alist |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
296 (cons 'widget-minor-mode widget-minor-mode-map)) |
d6545cfb6c5a
Synched with custom 1.90.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17415
diff
changeset
|
297 |
17334 | 298 ;;; The End: |
299 | |
300 (provide 'wid-browse) | |
301 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32905
diff
changeset
|
302 ;;; wid-browse.el ends here |