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
|
|
7 ;; Version: 1.71
|
|
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)
|
|
19 (require 'cl)
|
|
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))
|
|
32 (set-keymap-parent widget-browse-mode-map widget-keymap))
|
|
33
|
|
34 (easy-menu-define widget-browse-mode-menu
|
|
35 widget-browse-mode-map
|
|
36 "Menu used in widget browser buffers."
|
|
37 '("Widget"
|
|
38 ["Browse" widget-browse t]
|
|
39 ["Browse At" widget-browse-at t]))
|
|
40
|
|
41 (defcustom widget-browse-mode-hook nil
|
|
42 "Hook called when entering widget-browse-mode."
|
|
43 :type 'hook
|
|
44 :group 'widget-browse)
|
|
45
|
|
46 (defun widget-browse-mode ()
|
|
47 "Major mode for widget browser buffers.
|
|
48
|
|
49 The following commands are available:
|
|
50
|
|
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.
|
|
55
|
|
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
|
|
60 mode-name "Widget")
|
|
61 (use-local-map widget-browse-mode-map)
|
|
62 (easy-menu-add widget-browse-mode-menu)
|
|
63 (run-hooks 'widget-browse-mode-hook))
|
|
64
|
|
65 ;;; Commands.
|
|
66
|
|
67 ;;;###autoload
|
|
68 (defun widget-browse-at (pos)
|
|
69 "Browse the widget under point."
|
|
70 (interactive "d")
|
|
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)))
|
|
79 (when widget
|
|
80 (widget-browse widget))
|
|
81 (message text)))
|
|
82
|
|
83 (defvar widget-browse-history nil)
|
|
84
|
|
85 (defun widget-browse (widget)
|
|
86 "Create a widget browser for WIDGET."
|
|
87 (interactive (list (completing-read "Widget: "
|
|
88 obarray
|
|
89 (lambda (symbol)
|
|
90 (get symbol 'widget-type))
|
|
91 t nil 'widget-browse-history)))
|
|
92 (if (stringp widget)
|
|
93 (setq widget (intern widget)))
|
|
94 (unless (if (symbolp widget)
|
|
95 (get widget 'widget-type)
|
|
96 (and (consp widget)
|
|
97 (get (widget-type widget) 'widget-type)))
|
|
98 (error "Not a widget."))
|
|
99 ;; Create the buffer.
|
|
100 (if (symbolp 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*")))
|
|
106 (widget-browse-mode)
|
|
107
|
|
108 ;; Quick way to get out.
|
|
109 (widget-create 'push-button
|
|
110 :action (lambda (widget &optional event)
|
|
111 (bury-buffer))
|
|
112 "Quit")
|
|
113 (widget-insert "\n")
|
|
114
|
|
115 ;; Top text indicating whether it is a class or object browser.
|
|
116 (if (listp widget)
|
|
117 (widget-insert "Widget object browser.\n\nClass: ")
|
|
118 (widget-insert "Widget class browser.\n\n")
|
|
119 (widget-create 'widget-browse
|
|
120 :format "%[%v%]\n%d"
|
|
121 :doc (get widget 'widget-documentation)
|
|
122 widget)
|
|
123 (unless (eq (preceding-char) ?\n)
|
|
124 (widget-insert "\n"))
|
|
125 (widget-insert "\nSuper: ")
|
|
126 (setq widget (get widget 'widget-type)))
|
|
127
|
|
128 ;; Now show the attributes.
|
|
129 (let ((name (car widget))
|
|
130 (items (cdr widget))
|
|
131 key value printer)
|
|
132 (widget-create 'widget-browse
|
|
133 :format "%[%v%]"
|
|
134 name)
|
|
135 (widget-insert "\n")
|
|
136 (while items
|
|
137 (setq key (nth 0 items)
|
|
138 value (nth 1 items)
|
|
139 printer (or (get key 'widget-keyword-printer)
|
|
140 'widget-browse-sexp)
|
|
141 items (cdr (cdr items)))
|
|
142 (widget-insert "\n" (symbol-name key) "\n\t")
|
|
143 (funcall printer widget key value)
|
|
144 (widget-insert "\n")))
|
|
145 (widget-setup)
|
|
146 (goto-char (point-min)))
|
|
147
|
|
148 ;;; The `widget-browse' Widget.
|
|
149
|
|
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."
|
|
153 :format "%[[%v]%]"
|
|
154 :value-create 'widget-browse-value-create
|
|
155 :action 'widget-browse-action)
|
|
156
|
|
157 (defun widget-browse-action (widget &optional event)
|
|
158 ;; Create widget browser for WIDGET's :value.
|
|
159 (widget-browse (widget-get widget :value)))
|
|
160
|
|
161 (defun widget-browse-value-create (widget)
|
|
162 ;; Insert type name.
|
|
163 (let ((value (widget-get widget :value)))
|
|
164 (cond ((symbolp value)
|
|
165 (insert (symbol-name value)))
|
|
166 ((consp value)
|
|
167 (insert (symbol-name (widget-type value))))
|
|
168 (t
|
|
169 (insert "strange")))))
|
|
170
|
|
171 ;;; Keyword Printer Functions.
|
|
172
|
|
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))
|
|
177
|
|
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."
|
|
181 (while value
|
|
182 (widget-create 'widget-browse
|
|
183 (car value))
|
|
184 (setq value (cdr value))
|
|
185 (when value
|
|
186 (widget-insert " "))))
|
|
187
|
|
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
|
|
192 (pp-to-string value)
|
|
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)
|
|
197 nil)
|
|
198 ((> (length pp) (- (window-width) (current-column)))
|
|
199 nil)
|
|
200 (t t))
|
|
201 (widget-insert pp)
|
|
202 (widget-create 'push-button
|
|
203 :tag "show"
|
|
204 :action (lambda (widget &optional event)
|
|
205 (with-output-to-temp-buffer
|
|
206 "*Pp Eval Output*"
|
|
207 (princ (widget-get widget :value))))
|
|
208 pp))))
|
|
209
|
|
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)))
|
|
214 (while value
|
|
215 (widget-browse-sexp widget key (car value))
|
|
216 (setq value (cdr value))
|
|
217 (when value
|
|
218 (widget-insert "\n" (make-string target ?\ ))))))
|
|
219
|
|
220 ;;; Keyword Printers.
|
|
221
|
|
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)
|
|
227
|
|
228 ;;; The End:
|
|
229
|
|
230 (provide 'wid-browse)
|
|
231
|
|
232 ;; wid-browse.el ends here
|