1 ;;; wid-browse.el --- Functions for browsing widgets.
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: extensions
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
12 ;; Widget browser. See `widget.el'.
21 (defgroup widget-browse nil
22 "Customization support for browsing widgets."
27 (defvar widget-browse-mode-map nil
28 "Keymap for `widget-browse-mode'.")
30 (unless widget-browse-mode-map
31 (setq widget-browse-mode-map
(make-sparse-keymap))
32 (set-keymap-parent widget-browse-mode-map widget-keymap
))
34 (easy-menu-define widget-browse-mode-menu
35 widget-browse-mode-map
36 "Menu used in widget browser buffers."
38 ["Browse" widget-browse t
]
39 ["Browse At" widget-browse-at t
]))
41 (defcustom widget-browse-mode-hook nil
42 "Hook called when entering widget-browse-mode."
44 :group
'widget-browse
)
46 (defun widget-browse-mode ()
47 "Major mode for widget browser buffers.
49 The following commands are available:
51 \\[widget-forward] Move to next button or editable field.
52 \\[widget-backward] Move to previous button or editable field.
53 \\[widget-button-click] Activate button under the mouse pointer.
54 \\[widget-button-press] Activate button under point.
56 Entry to this mode calls the value of `widget-browse-mode-hook'
57 if that value is non-nil."
58 (kill-all-local-variables)
59 (setq major-mode
'widget-browse-mode
61 (use-local-map widget-browse-mode-map
)
62 (easy-menu-add widget-browse-mode-menu
)
63 (run-hooks 'widget-browse-mode-hook
))
68 (defun widget-browse-at (pos)
69 "Browse the widget under point."
71 (let* ((field (get-text-property pos
'field
))
72 (button (get-text-property pos
'button
))
73 (doc (get-text-property pos
'widget-doc
))
74 (text (cond (field "This is an editable text area.")
75 (button "This is an active area.")
76 (doc "This is documentation text.")
77 (t "This is unidentified text.")))
78 (widget (or field button doc
)))
80 (widget-browse widget
))
83 (defvar widget-browse-history nil
)
85 (defun widget-browse (widget)
86 "Create a widget browser for WIDGET."
87 (interactive (list (completing-read "Widget: "
90 (get symbol
'widget-type
))
91 t nil
'widget-browse-history
)))
93 (setq widget
(intern widget
)))
94 (unless (if (symbolp widget
)
95 (get widget
'widget-type
)
97 (get (widget-type widget
) 'widget-type
)))
98 (error "Not a widget."))
101 (let ((buffer (format "*Browse %s Widget*" widget
)))
102 (kill-buffer (get-buffer-create buffer
))
103 (switch-to-buffer (get-buffer-create buffer
)))
104 (kill-buffer (get-buffer-create "*Browse Widget*"))
105 (switch-to-buffer (get-buffer-create "*Browse Widget*")))
108 ;; Quick way to get out.
109 (widget-create 'push-button
110 :action
(lambda (widget &optional event
)
115 ;; Top text indicating whether it is a class or object browser.
117 (widget-insert "Widget object browser.\n\nClass: ")
118 (widget-insert "Widget class browser.\n\n")
119 (widget-create 'widget-browse
121 :doc
(get widget
'widget-documentation
)
123 (unless (eq (preceding-char) ?
\n)
124 (widget-insert "\n"))
125 (widget-insert "\nSuper: ")
126 (setq widget
(get widget
'widget-type
)))
128 ;; Now show the attributes.
129 (let ((name (car widget
))
132 (widget-create 'widget-browse
137 (setq key
(nth 0 items
)
139 printer
(or (get key
'widget-keyword-printer
)
141 items
(cdr (cdr items
)))
142 (widget-insert "\n" (symbol-name key
) "\n\t")
143 (funcall printer widget key value
)
144 (widget-insert "\n")))
146 (goto-char (point-min)))
148 ;;; The `widget-browse' Widget.
150 (define-widget 'widget-browse
'push-button
151 "Button for creating a widget browser.
152 The :value of the widget shuld be the widget to be browsed."
154 :value-create
'widget-browse-value-create
155 :action
'widget-browse-action
)
157 (defun widget-browse-action (widget &optional event
)
158 ;; Create widget browser for WIDGET's :value.
159 (widget-browse (widget-get widget
:value
)))
161 (defun widget-browse-value-create (widget)
163 (let ((value (widget-get widget
:value
)))
164 (cond ((symbolp value
)
165 (insert (symbol-name value
)))
167 (insert (symbol-name (widget-type value
))))
169 (insert "strange")))))
171 ;;; Keyword Printer Functions.
173 (defun widget-browse-widget (widget key value
)
174 "Insert description of WIDGET's KEY VALUE.
175 VALUE is assumed to be a widget."
176 (widget-create 'widget-browse value
))
178 (defun widget-browse-widgets (widget key value
)
179 "Insert description of WIDGET's KEY VALUE.
180 VALUE is assumed to be a list of widgets."
182 (widget-create 'widget-browse
184 (setq value
(cdr value
))
186 (widget-insert " "))))
188 (defun widget-browse-sexp (widget key value
)
189 "Insert description of WIDGET's KEY VALUE.
190 Nothing is assumed about value."
191 (let ((pp (condition-case signal
193 (error (prin1-to-string signal
)))))
194 (when (string-match "\n\\'" pp
)
195 (setq pp
(substring pp
0 (1- (length pp
)))))
196 (if (cond ((string-match "\n" pp
)
198 ((> (length pp
) (- (window-width) (current-column)))
202 (widget-create 'push-button
204 :action
(lambda (widget &optional event
)
205 (with-output-to-temp-buffer
207 (princ (widget-get widget
:value
))))
210 (defun widget-browse-sexps (widget key value
)
211 "Insert description of WIDGET's KEY VALUE.
212 VALUE is assumed to be a list of widgets."
213 (let ((target (current-column)))
215 (widget-browse-sexp widget key
(car value
))
216 (setq value
(cdr value
))
218 (widget-insert "\n" (make-string target ?\
))))))
220 ;;; Keyword Printers.
222 (put :parent
'widget-keyword-printer
'widget-browse-widget
)
223 (put :children
'widget-keyword-printer
'widget-browse-widgets
)
224 (put :buttons
'widget-keyword-printer
'widget-browse-widgets
)
225 (put :button
'widget-keyword-printer
'widget-browse-widget
)
226 (put :args
'widget-keyword-printer
'widget-browse-sexps
)
230 (provide 'wid-browse
)
232 ;; wid-browse.el ends here