*** empty log message ***
[gnus] / lisp / widget-edit.el
1 ;;; widget-edit.el --- Functions for creating and using widgets.
2 ;;
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: extensions
7 ;; Version: 0.992
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
9
10 ;;; Commentary:
11 ;;
12 ;; See `widget.el'.
13
14 ;;; Code:
15
16 (require 'widget)
17 (require 'cl)
18 (autoload 'pp-to-string "pp")
19 (autoload 'Info-goto-node "info")
20
21 ;; The following should go away when bundled with Emacs.
22 (condition-case ()
23     (require 'custom)
24   (error nil))
25
26 (eval-and-compile
27   (unless (and (featurep 'custom) (fboundp 'custom-declare-variable))
28     ;; We have the old custom-library, hack around it!
29     (defmacro defgroup (&rest args) nil)
30     (defmacro defcustom (&rest args) nil)
31     (defmacro defface (&rest args) nil)
32     (when (fboundp 'copy-face)
33       (copy-face 'default 'widget-documentation-face)
34       (copy-face 'bold 'widget-button-face)
35       (copy-face 'italic 'widget-field-face))
36     (defvar widget-mouse-face 'highlight)
37     (defvar widget-menu-max-size 40)))
38
39 ;;; Compatibility.
40
41 (or (fboundp 'event-point)
42     ;; XEmacs function missing in Emacs.
43     (defun event-point (event)
44       "Return the character position of the given mouse-motion, button-press,
45 or button-release event.  If the event did not occur over a window, or did
46 not occur over text, then this returns nil.  Otherwise, it returns an index
47 into the buffer visible in the event's window."
48       (posn-point (event-start event))))
49
50 ;;; Customization.
51
52 (defgroup widgets nil
53   "Customization support for the Widget Library."
54   :group 'emacs)
55
56 (defface widget-documentation-face '((t ()))
57   "Face used for documentation text."
58   :group 'widgets)
59
60 (defface widget-button-face '((t (:bold t)))
61   "Face used for widget buttons."
62   :group 'widgets)
63
64 (defcustom widget-mouse-face 'highlight
65   "Face used for widget buttons when the mouse is above them."
66   :type 'face
67   :group 'widgets)
68
69 (defface widget-field-face '((((type x)
70                                (class grayscale color)
71                                (background light))
72                               (:background "light gray"))
73                              (((type x)
74                                (class grayscale color)
75                                (background dark))
76                               (:background "dark gray"))
77                              (t 
78                               (:italic t)))
79   "Face used for editable fields."
80   :group 'widgets)
81
82 (defcustom widget-menu-max-size 40
83   "Largest number of items allowed in a popup-menu.
84 Larger menus are read through the minibuffer."
85   :type 'integer)
86
87 ;;; Utility functions.
88 ;;
89 ;; These are not really widget specific.
90
91 (defun widget-plist-member (plist prop)
92   ;; Return non-nil if PLIST has the property PROP.
93   ;; PLIST is a property list, which is a list of the form
94   ;; (PROP1 VALUE1 PROP2 VALUE2 ...).  PROP is a symbol.
95   ;; Unlike `plist-get', this allows you to distinguish between a missing
96   ;; property and a property with the value nil.
97   ;; The value is actually the tail of PLIST whose car is PROP.
98   (while (and plist (not (eq (car plist) prop)))
99     (setq plist (cdr (cdr plist))))
100   plist)
101
102 (defun widget-princ-to-string (object)
103   ;; Return string representation of OBJECT, any Lisp object.
104   ;; No quoting characters are used; no delimiters are printed around
105   ;; the contents of strings.
106   (save-excursion
107     (set-buffer (get-buffer-create " *widget-tmp*"))
108     (erase-buffer)
109     (let ((standard-output (current-buffer)))
110       (princ object))
111     (buffer-string)))
112
113 (defun widget-clear-undo ()
114   "Clear all undo information."
115   (buffer-disable-undo (current-buffer))
116   (buffer-enable-undo))
117
118 (defun widget-choose (title items &optional event)
119   "Choose an item from a list.
120
121 First argument TITLE is the name of the list.
122 Second argument ITEMS is an alist (NAME . VALUE).
123 Optional third argument EVENT is an input event.
124
125 The user is asked to choose between each NAME from the items alist,
126 and the VALUE of the chosen element will be returned.  If EVENT is a
127 mouse event, and the number of elements in items is less than
128 `widget-menu-max-size', a popup menu will be used, otherwise the
129 minibuffer."
130   (cond ((and (< (length items) widget-menu-max-size)
131               event (fboundp 'x-popup-menu) window-system)
132          ;; We are in Emacs-19, pressed by the mouse
133          (x-popup-menu event
134                        (list title (cons "" items))))
135         ((and (< (length items) widget-menu-max-size)
136               event (fboundp 'popup-menu) window-system)
137          ;; We are in XEmacs, pressed by the mouse
138          (let ((val (get-popup-menu-response
139                      (cons ""
140                            (mapcar
141                             (function
142                              (lambda (x)
143                                (vector (car x) (list (car x)) t)))
144                             items)))))
145            (setq val (and val
146                           (listp (event-object val))
147                           (stringp (car-safe (event-object val)))
148                           (car (event-object val))))
149            (cdr (assoc val items))))
150         (t
151          (cdr (assoc (completing-read (concat title ": ")
152                                       items nil t)
153                      items)))))
154
155 ;;; Widget text specifications.
156 ;; 
157 ;; These functions are for specifying text properties. 
158
159 (defun widget-specify-none (from to)
160   ;; Clear all text properties between FROM and TO.
161   (set-text-properties from to nil))
162
163 (defun widget-specify-text (from to)
164   ;; Default properties.
165   (add-text-properties from to (list 'read-only t
166                                      'front-sticky t
167                                      'rear-nonsticky nil)))
168
169 (defun widget-specify-field (widget from to)
170   ;; Specify editable button for WIDGET between FROM and TO.
171   (widget-specify-field-update widget from to)
172
173   ;; Make it possible to edit the front end of the field.
174   (add-text-properties (1- from) from (list 'rear-nonsticky t
175                                             'end-open t
176                                             'invisible t))
177   (when (or (string-match "\\(.\\|\n\\)%v" (widget-get widget :format))
178             (widget-get widget :hide-front-space))
179     ;; WARNING: This is going to lose horrible if the character just
180     ;; before the field can be modified (e.g. if it belongs to a
181     ;; choice widget).  We try to compensate by checking the format
182     ;; string, and hope the user hasn't changed the :create method.
183     (put-text-property (- from 2) from 'intangible 'front))
184   
185   ;; Make it possible to edit back end of the field.
186   (add-text-properties to (1+ to) (list 'front-sticky nil
187                                         'start-open t))
188
189   (when (widget-get widget :size)
190     (put-text-property to (1+ to) 'invisible t)
191     (when (or (string-match "%v\\(.\\|\n\\)" (widget-get widget :format))
192               (widget-get widget :hide-rear-space))
193       ;; WARNING: This is going to lose horrible if the character just
194       ;; after the field can be modified (e.g. if it belongs to a
195       ;; choice widget).  We try to compensate by checking the format
196       ;; string, and hope the user hasn't changed the :create method.
197       (put-text-property to (+ to 2) 'intangible 'rear))))
198
199 (defun widget-specify-field-update (widget from to)
200   ;; Specify editable button for WIDGET between FROM and TO.
201   (let ((map (widget-get widget :keymap))
202         (face (or (widget-get widget :value-face)
203                   'widget-field-face)))
204     (set-text-properties from to (list 'field widget
205                                        'read-only nil
206                                        'keymap map
207                                        'local-map map
208                                        'face face))
209     (unless (widget-get widget :size)
210       (put-text-property to (1+ to) 'face face))))
211
212 (defun widget-specify-button (widget from to)
213   ;; Specify button for WIDGET between FROM and TO.
214   (let ((face (widget-apply widget :button-face-get)))
215     (add-text-properties from to (list 'button widget
216                                        'mouse-face widget-mouse-face
217                                        'face face))))
218
219 (defun widget-specify-doc (widget from to)
220   ;; Specify documentation for WIDGET between FROM and TO.
221   (add-text-properties from to (list 'widget-doc widget
222                                      'face 'widget-documentation-face)))
223
224 (defmacro widget-specify-insert (&rest form)
225   ;; Execute FORM without inheriting any text properties.
226   `(save-restriction
227      (let ((inhibit-read-only t)
228            result
229            after-change-functions)
230        (insert "<>")
231        (narrow-to-region (- (point) 2) (point))
232        (widget-specify-none (point-min) (point-max))
233        (goto-char (1+ (point-min)))
234        (setq result (progn ,@form))
235        (delete-region (point-min) (1+ (point-min)))
236        (delete-region (1- (point-max)) (point-max))
237        (goto-char (point-max))
238        result)))
239
240 ;;; Widget Properties.
241
242 (defun widget-put (widget property value)
243   "In WIDGET set PROPERTY to VALUE.
244 The value can later be retrived with `widget-get'."
245   (setcdr widget (plist-put (cdr widget) property value)))
246
247 (defun widget-get (widget property)
248   "In WIDGET, get the value of PROPERTY.
249 The value could either be specified when the widget was created, or
250 later with `widget-put'."
251   (cond ((widget-plist-member (cdr widget) property)
252          (plist-get (cdr widget) property))
253         ((car widget)
254          (widget-get (get (car widget) 'widget-type) property))
255         (t nil)))
256
257 (defun widget-member (widget property)
258   "Non-nil iff there is a definition in WIDGET for PROPERTY."
259   (cond ((widget-plist-member (cdr widget) property)
260          t)
261         ((car widget)
262          (widget-member (get (car widget) 'widget-type) property))
263         (t nil)))
264
265 (defun widget-apply (widget property &rest args)
266   "Apply the value of WIDGET's PROPERTY to the widget itself.
267 ARGS are passed as extra argments to the function."
268   (apply (widget-get widget property) widget args))
269
270 (defun widget-value (widget)
271   "Extract the current value of WIDGET."
272   (widget-apply widget
273                 :value-to-external (widget-apply widget :value-get)))
274
275 (defun widget-value-set (widget value)
276   "Set the current value of WIDGET to VALUE."
277   (widget-apply widget
278                 :value-set (widget-apply widget
279                                          :value-to-internal value)))
280
281 (defun widget-match-inline (widget vals)
282   ;; In WIDGET, match the start of VALS.
283   (cond ((widget-get widget :inline)
284          (widget-apply widget :match-inline vals))
285         ((and vals
286               (widget-apply widget :match (car vals)))
287          (cons (list (car vals)) (cdr vals)))
288         (t nil)))
289
290 ;;; Creating Widgets.
291
292 ;;;###autoload
293 (defun widget-create (type &rest args)
294   "Create widget of TYPE.  
295 The optional ARGS are additional keyword arguments."
296   (let ((widget (apply 'widget-convert type args)))
297     (widget-apply widget :create)
298     widget))
299
300 (defun widget-create-child-and-convert (parent type &rest args)
301   "As part of the widget PARENT, create a child widget TYPE.
302 The child is converted, using the keyword arguments ARGS."
303   (let ((widget (apply 'widget-convert type args)))
304     (widget-put widget :parent parent)
305     (unless (widget-get widget :indent)
306       (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
307                                     (or (widget-get widget :extra-offset) 0)
308                                     (widget-get parent :offset))))
309     (widget-apply widget :create)
310     widget))
311
312 (defun widget-create-child (parent type)
313   "Create widget of TYPE.  "
314   (let ((widget (copy-list type)))
315     (widget-put widget :parent parent)
316     (unless (widget-get widget :indent)
317       (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
318                                     (widget-get parent :offset))))
319     (widget-apply widget :create)
320     widget))
321
322 ;;;###autoload
323 (defun widget-delete (widget)
324   "Delete WIDGET."
325   (widget-apply widget :delete))
326
327 (defun widget-convert (type &rest args)
328   "Convert TYPE to a widget without inserting it in the buffer. 
329 The optional ARGS are additional keyword arguments."
330   ;; Don't touch the type.
331   (let* ((widget (if (symbolp type) 
332                      (list type)
333                    (copy-list type)))
334          (current widget)
335          (keys args))
336     ;; First set the :args keyword.
337     (while (cdr current)                ;Look in the type.
338       (let ((next (car (cdr current))))
339         (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
340             (setq current (cdr (cdr current)))
341           (setcdr current (list :args (cdr current)))
342           (setq current nil))))
343     (while args                         ;Look in the args.
344       (let ((next (nth 0 args)))
345         (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
346             (setq args (nthcdr 2 args))
347           (widget-put widget :args args)
348           (setq args nil))))
349     ;; Then Convert the widget.
350     (setq type widget)
351     (while type
352       (let ((convert-widget (plist-get (cdr type) :convert-widget)))
353         (if convert-widget
354             (setq widget (funcall convert-widget widget))))
355       (setq type (get (car type) 'widget-type)))
356     ;; Finally set the keyword args.
357     (while keys 
358       (let ((next (nth 0 keys)))
359         (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
360             (progn 
361               (widget-put widget next (nth 1 keys))
362               (setq keys (nthcdr 2 keys)))
363           (setq keys nil))))
364     ;; Convert the :value to internal format.
365     (if (widget-member widget :value)
366         (let ((value (widget-get widget :value)))
367           (widget-put widget
368                       :value (widget-apply widget :value-to-internal value))))
369     ;; Return the newly create widget.
370     widget))
371
372 (defun widget-insert (&rest args)
373   "Call `insert' with ARGS and make the text read only."
374   (let ((inhibit-read-only t)
375         after-change-functions
376         (from (point)))
377     (apply 'insert args)
378     (widget-specify-text from (point))))
379
380 ;;; Keymap and Comands.
381
382 (defvar widget-keymap nil
383   "Keymap containing useful binding for buffers containing widgets.
384 Recommended as a parent keymap for modes using widgets.")
385
386 (if widget-keymap 
387     ()
388   (setq widget-keymap (make-sparse-keymap))
389   (set-keymap-parent widget-keymap global-map)
390   (define-key widget-keymap "\t" 'widget-forward)
391   (define-key widget-keymap "\M-\t" 'widget-backward)
392   (define-key widget-keymap [(shift tab)] 'widget-backward)
393   (if (string-match "XEmacs" (emacs-version))
394       (define-key widget-keymap [button2] 'widget-button-click)
395     (define-key widget-keymap [menu-bar] 'nil)
396     (define-key widget-keymap [mouse-2] 'widget-button-click))
397   (define-key widget-keymap "\C-m" 'widget-button-press))
398
399 (defvar widget-global-map global-map
400   "Keymap used for events the widget does not handle themselves.")
401 (make-variable-buffer-local 'widget-global-map)
402
403 (defun widget-button-click (event)
404   "Activate button below mouse pointer."
405   (interactive "@e")
406   (widget-button-press (event-point event) event))
407
408 (defun widget-button-press (pos &optional event)
409   "Activate button at POS."
410   (interactive "@d")
411   (let* ((button (get-text-property pos 'button)))
412     (if button
413         (widget-apply button :action event)
414       (call-interactively
415        (lookup-key widget-global-map (this-command-keys))))))
416
417 (defun widget-forward (arg)
418   "Move point to the next field or button.
419 With optional ARG, move across that many fields."
420   (interactive "p")
421   (while (> arg 0)
422     (setq arg (1- arg))
423     (let ((next (cond ((get-text-property (point) 'button)
424                        (next-single-property-change (point) 'button))
425                       ((get-text-property (point) 'field)
426                        (next-single-property-change (point) 'field))
427                       (t
428                        (point)))))
429       (if (null next)                   ; Widget extends to end. of buffer
430           (setq next (point-min)))
431       (let ((button (next-single-property-change next 'button))
432             (field (next-single-property-change next 'field)))
433         (cond ((or (get-text-property next 'button)
434                    (get-text-property next 'field))
435                (goto-char next))
436               ((and button field)
437                (goto-char (min button field)))
438               (button (goto-char button))
439               (field (goto-char field))
440               (t
441                (let ((button (next-single-property-change (point-min) 'button))
442                      (field (next-single-property-change (point-min) 'field)))
443                  (cond ((and button field) (goto-char (min button field)))
444                        (button (goto-char button))
445                        (field (goto-char field))
446                        (t
447                         (error "No buttons or fields found")))))))))
448   (while (< arg 0)
449     (if (= (point-min) (point))
450         (forward-char 1))
451     (setq arg (1+ arg))
452     (let ((previous (cond ((get-text-property (1- (point)) 'button)
453                            (previous-single-property-change (point) 'button))
454                           ((get-text-property (1- (point)) 'field)
455                            (previous-single-property-change (point) 'field))
456                           (t
457                            (point)))))
458       (if (null previous)               ; Widget extends to beg. of buffer
459           (setq previous (point-max)))
460       (let ((button (previous-single-property-change previous 'button))
461             (field (previous-single-property-change previous 'field)))
462         (cond ((and button field)
463                (goto-char (max button field)))
464               (button (goto-char button))
465               (field (goto-char field))
466               (t
467                (let ((button (previous-single-property-change
468                               (point-max) 'button))
469                      (field (previous-single-property-change
470                              (point-max) 'field)))
471                  (cond ((and button field) (goto-char (max button field)))
472                        (button (goto-char button))
473                        (field (goto-char field))
474                        (t
475                         (error "No buttons or fields found"))))))))
476     (let ((button (previous-single-property-change (point) 'button))
477           (field (previous-single-property-change (point) 'field)))
478       (cond ((and button field)
479              (goto-char (max button field)))
480             (button (goto-char button))
481             (field (goto-char field)))))
482   (widget-echo-help (point)))
483
484 (defun widget-backward (arg)
485   "Move point to the previous field or button.
486 With optional ARG, move across that many fields."
487   (interactive "p")
488   (widget-forward (- arg)))
489
490 ;;; Setting up the buffer.
491
492 (defvar widget-field-new nil)
493 ;; List of all newly created editable fields in the buffer.
494 (make-variable-buffer-local 'widget-field-new)
495
496 (defvar widget-field-list nil)
497 ;; List of all editable fields in the buffer.
498 (make-variable-buffer-local 'widget-field-list)
499
500 (defun widget-setup ()
501   "Setup current buffer so editing string widgets works."
502   (let ((inhibit-read-only t)
503         (after-change-functions nil)
504         field)
505     (while widget-field-new
506       (setq field (car widget-field-new)
507             widget-field-new (cdr widget-field-new)
508             widget-field-list (cons field widget-field-list))
509       (let ((from (widget-get field :value-from))
510             (to (widget-get field :value-to)))
511         (widget-specify-field field from to)
512         (move-marker from (1- from))
513         (move-marker to (1+ to)))))
514   (widget-clear-undo)
515   ;; We need to maintain text properties and size of the editing fields.
516   (make-local-variable 'after-change-functions)
517   (if widget-field-list
518       (setq after-change-functions '(widget-after-change))
519     (setq after-change-functions nil)))
520
521 (defvar widget-field-last nil)
522 ;; Last field containing point.
523 (make-variable-buffer-local 'widget-field-last)
524
525 (defvar widget-field-was nil)
526 ;; The widget data before the change.
527 (make-variable-buffer-local 'widget-field-was)
528
529 (defun widget-field-find (pos)
530   ;; Find widget whose editing field is located at POS.
531   ;; Return nil if POS is not inside and editing field.
532   ;; 
533   ;; This is only used in `widget-field-modified', since ordinarily
534   ;; you would just test the field property.
535   (let ((fields widget-field-list)
536         field found)
537     (while fields
538       (setq field (car fields)
539             fields (cdr fields))
540       (let ((from (widget-get field :value-from))
541             (to (widget-get field :value-to)))
542         (if (and from to (< from pos) (> to  pos))
543             (setq fields nil
544                   found field))))
545     found))
546
547 (defun widget-after-change (from to old)
548   ;; Adjust field size and text properties.
549   (condition-case nil
550       (let ((field (widget-field-find from))
551             (inhibit-read-only t))
552         (cond ((null field))
553               ((not (eq field (widget-field-find to)))
554                (debug)
555                (message "Error: `widget-after-change' called on two fields"))
556               (t
557                (let ((size (widget-get field :size)))
558                  (if size 
559                      (let ((begin (1+ (widget-get field :value-from)))
560                            (end (1- (widget-get field :value-to))))
561                        (widget-specify-field-update field begin end)
562                        (cond ((< (- end begin) size)
563                               ;; Field too small.
564                               (save-excursion
565                                 (goto-char end)
566                                 (insert-char ?\  (- (+ begin size) end))
567                                 (widget-specify-field-update field 
568                                                              begin
569                                                              (+ begin size))))
570                              ((> (- end begin) size)
571                               ;; Field too large and
572                               (if (or (< (point) (+ begin size))
573                                       (> (point) end))
574                                   ;; Point is outside extra space.
575                                   (setq begin (+ begin size))
576                                 ;; Point is within the extra space.
577                                 (setq begin (point)))
578                               (save-excursion
579                                 (goto-char end)
580                                 (while (and (eq (preceding-char) ?\ )
581                                             (> (point) begin))
582                                   (delete-backward-char 1))))))
583                    (widget-specify-field-update field from to)))
584                (widget-apply field :notify field))))
585     (error (debug))))
586
587 ;;; The `default' Widget.
588
589 (define-widget 'default nil
590   "Basic widget other widgets are derived from."
591   :value-to-internal (lambda (widget value) value)
592   :value-to-external (lambda (widget value) value)
593   :create 'widget-default-create
594   :indent nil
595   :offset 0
596   :format-handler 'widget-default-format-handler
597   :button-face-get 'widget-default-button-face-get 
598   :delete 'widget-default-delete
599   :value-set 'widget-default-value-set
600   :value-inline 'widget-default-value-inline
601   :menu-tag-get 'widget-default-menu-tag-get
602   :validate (lambda (widget) nil)
603   :action 'widget-default-action
604   :notify 'widget-default-notify)
605
606 (defun widget-default-create (widget)
607   "Create WIDGET at point in the current buffer."
608   (widget-specify-insert
609    (let ((from (point))
610          (tag (widget-get widget :tag))
611          (doc (widget-get widget :doc))
612          button-begin button-end
613          doc-begin doc-end
614          value-pos)
615      (insert (widget-get widget :format))
616      (goto-char from)
617      ;; Parse % escapes in format.
618      (while (re-search-forward "%\\(.\\)" nil t)
619        (let ((escape (aref (match-string 1) 0)))
620          (replace-match "" t t)
621          (cond ((eq escape ?%)
622                 (insert "%"))
623                ((eq escape ?\[)
624                 (setq button-begin (point)))
625                ((eq escape ?\])
626                 (setq button-end (point)))
627                ((eq escape ?n)
628                 (when (widget-get widget :indent)
629                   (insert "\n")
630                   (insert-char ?  (widget-get widget :indent))))
631                ((eq escape ?t)
632                 (if tag
633                     (insert tag)
634                   (let ((standard-output (current-buffer)))
635                     (princ (widget-get widget :value)))))
636                ((eq escape ?d)
637                 (when doc
638                   (setq doc-begin (point))
639                   (insert doc)
640                   (while (eq (preceding-char) ?\n)
641                     (delete-backward-char 1))
642                   (insert "\n")
643                   (setq doc-end (point))))
644                ((eq escape ?v)
645                 (if (and button-begin (not button-end))
646                     (widget-apply widget :value-create)
647                   (setq value-pos (point))))
648                (t 
649                 (widget-apply widget :format-handler escape)))))
650      ;; Specify button and doc, and insert value.
651      (and button-begin button-end
652           (widget-specify-button widget button-begin button-end))
653      (and doc-begin doc-end
654           (widget-specify-doc widget doc-begin doc-end))
655      (when value-pos
656        (goto-char value-pos)
657        (widget-apply widget :value-create)))
658    (let ((from (copy-marker (point-min)))
659          (to (copy-marker (point-max))))
660      (widget-specify-text from to)
661      (set-marker-insertion-type from t)
662      (set-marker-insertion-type to nil)
663      (widget-put widget :from from)
664      (widget-put widget :to to))))
665
666 (defun widget-default-format-handler (widget escape)
667   ;; We recognize the %h escape by default.
668   (let* ((buttons (widget-get widget :buttons))
669          (doc-property (widget-get widget :documentation-property))
670          (doc-try (cond ((widget-get widget :doc))
671                         ((symbolp doc-property)
672                          (documentation-property (widget-get widget :value)
673                                                  doc-property))
674                         (t
675                          (funcall doc-property (widget-get widget :value)))))
676          (doc-text (and (stringp doc-try)
677                         (> (length doc-try) 1)
678                         doc-try)))
679     (cond ((eq escape ?h)
680            (when doc-text
681              (and (eq (preceding-char) ?\n)
682                   (widget-get widget :indent)
683                   (insert-char ?  (widget-get widget :indent)))
684              ;; The `*' in the beginning is redundant.
685              (when (eq (aref doc-text  0) ?*)
686                (setq doc-text (substring doc-text 1)))
687              ;; Get rid of trailing newlines.
688              (when (string-match "\n+\\'" doc-text)
689                (setq doc-text (substring doc-text 0 (match-beginning 0))))
690              (push (if (string-match "\n." doc-text)
691                        ;; Allow multiline doc to be hiden.
692                        (widget-create-child-and-convert
693                         widget 'widget-help 
694                         :doc (progn
695                                (string-match "\\`.*" doc-text)
696                                (match-string 0 doc-text))
697                         :widget-doc doc-text
698                         "?")
699                      ;; A single line is just inserted.
700                      (widget-create-child-and-convert
701                       widget 'item :format "%d" :doc doc-text nil))
702                    buttons)))
703           (t 
704            (error "Unknown escape `%c'" escape)))
705     (widget-put widget :buttons buttons)))
706
707 (defun widget-default-button-face-get (widget)
708   ;; Use :button-face or widget-button-face
709   (or (widget-get widget :button-face) 'widget-button-face))
710
711 (defun widget-default-delete (widget)
712   ;; Remove widget from the buffer.
713   (let ((from (widget-get widget :from))
714         (to (widget-get widget :to))
715         (inhibit-read-only t)
716         after-change-functions)
717     (widget-apply widget :value-delete)
718     (delete-region from to)
719     (set-marker from nil)
720     (set-marker to nil)))
721
722 (defun widget-default-value-set (widget value)
723   ;; Recreate widget with new value.
724   (save-excursion
725     (goto-char (widget-get widget :from))
726     (widget-apply widget :delete)
727     (widget-put widget :value value)
728     (widget-apply widget :create)))
729
730 (defun widget-default-value-inline (widget)
731   ;; Wrap value in a list unless it is inline.
732   (if (widget-get widget :inline)
733       (widget-value widget)
734     (list (widget-value widget))))
735
736 (defun widget-default-menu-tag-get (widget)
737   ;; Use tag or value for menus.
738   (or (widget-get widget :menu-tag)
739       (widget-get widget :tag)
740       (widget-princ-to-string (widget-get widget :value))))
741
742 (defun widget-default-action (widget &optional event)
743   ;; Notify the parent when a widget change
744   (let ((parent (widget-get widget :parent)))
745     (when parent
746       (widget-apply parent :notify widget event))))
747
748 (defun widget-default-notify (widget child &optional event)
749   ;; Pass notification to parent.
750   (widget-default-action widget event))
751
752 ;;; The `item' Widget.
753
754 (define-widget 'item 'default
755   "Constant items for inclusion in other widgets."
756   :convert-widget 'widget-item-convert-widget
757   :value-create 'widget-item-value-create
758   :value-delete 'ignore
759   :value-get 'widget-item-value-get
760   :match 'widget-item-match
761   :match-inline 'widget-item-match-inline
762   :action 'widget-item-action
763   :format "%t\n")
764
765 (defun widget-item-convert-widget (widget)
766   ;; Initialize :value and :tag from :args in WIDGET.
767   (let ((args (widget-get widget :args)))
768     (when args 
769       (widget-put widget :value (widget-apply widget
770                                               :value-to-internal (car args)))
771       (widget-put widget :args nil)))
772   widget)
773
774 (defun widget-item-value-create (widget)
775   ;; Insert the printed representation of the value.
776   (let ((standard-output (current-buffer)))
777     (princ (widget-get widget :value))))
778
779 (defun widget-item-match (widget value)
780   ;; Match if the value is the same.
781   (equal (widget-get widget :value) value))
782
783 (defun widget-item-match-inline (widget values)
784   ;; Match if the value is the same.
785   (let ((value (widget-get widget :value)))
786     (and (listp value)
787          (<= (length value) (length values))
788          (let ((head (subseq values 0 (length value))))
789            (and (equal head value)
790                 (cons head (subseq values (length value))))))))
791
792 (defun widget-item-action (widget &optional event)
793   ;; Just notify itself.
794   (widget-apply widget :notify widget event))
795
796 (defun widget-item-value-get (widget)
797   ;; Items are simple.
798   (widget-get widget :value))
799
800 ;;; The `push-button' Widget.
801
802 (define-widget 'push-button 'item
803   "A pushable button."
804   :format "%[[%t]%]")
805
806 ;;; The `link' Widget.
807
808 (define-widget 'link 'item
809   "An embedded link."
810   :format "%[_%t_%]")
811
812 ;;; The `info-link' Widget.
813
814 (define-widget 'info-link 'link
815   "A link to an info file."
816   :action 'widget-info-link-action)
817
818 (defun widget-info-link-action (widget &optional event)
819   "Open the info node specified by WIDGET."
820   (Info-goto-node (widget-value widget)))
821
822 ;;; The `url-link' Widget.
823
824 (define-widget 'url-link 'link
825   "A link to an www page."
826   :action 'widget-url-link-action)
827
828 (defun widget-url-link-action (widget &optional event)
829   "Open the url specified by WIDGET."
830   (require 'browse-url)
831   (funcall browse-url-browser-function (widget-value widget)))
832
833 ;;; The `editable-field' Widget.
834
835 (define-widget 'editable-field 'default
836   "An editable text field."
837   :convert-widget 'widget-item-convert-widget
838   :format "%v"
839   :value ""
840   :action 'widget-field-action
841   :value-create 'widget-field-value-create
842   :value-delete 'widget-field-value-delete
843   :value-get 'widget-field-value-get
844   :match 'widget-field-match)
845
846 ;; History of field minibuffer edits.
847 (defvar widget-field-history nil)
848
849 (defun widget-field-action (widget &optional event)
850   ;; Edit the value in the minibuffer.
851   (let ((tag (widget-apply widget :menu-tag-get))
852         (invalid (widget-apply widget :validate)))
853     (when invalid
854       (error (widget-get invalid :error)))
855     (widget-value-set widget 
856                       (widget-apply widget 
857                                     :value-to-external
858                                     (read-string (concat tag ": ") 
859                                                  (widget-apply 
860                                                   widget
861                                                   :value-to-internal
862                                                   (widget-value widget))
863                                                  'widget-field-history)))
864     (widget-apply widget :notify widget event)
865     (widget-setup)))
866
867 (defun widget-field-value-create (widget)
868   ;; Create an editable text field.
869   (insert " ")
870   (let ((size (widget-get widget :size))
871         (value (widget-get widget :value))
872         (from (point)))
873     (if (null size)
874         (if (zerop (length value))
875             (insert "")
876           (insert value))
877       (insert value)
878       (if (< (length value) size)
879           (insert-char ?\  (- size (length value)))))
880     (unless (memq widget widget-field-list)
881       (setq widget-field-new (cons widget widget-field-new)))
882     (widget-put widget :value-to (copy-marker (point)))
883     (set-marker-insertion-type (widget-get widget :value-to) nil)
884     (if (null size)
885         (insert ?\n)
886       (insert ?\ ))
887     (widget-put widget :value-from (copy-marker from))
888     (set-marker-insertion-type (widget-get widget :value-from) t)))
889
890 (defun widget-field-value-delete (widget)
891   ;; Remove the widget from the list of active editing fields.
892   (setq widget-field-list (delq widget widget-field-list))
893   (set-marker (widget-get widget :value-from) nil)
894   (set-marker (widget-get widget :value-to) nil))
895
896 (defun widget-field-value-get (widget)
897   ;; Return current text in editing field.
898   (let ((from (widget-get widget :value-from))
899         (to (widget-get widget :value-to))
900         (size (widget-get widget :size))
901         (old (current-buffer)))
902     (if (and from to)
903         (progn 
904           (set-buffer (marker-buffer from))
905           (setq from (1+ from)
906                 to (1- to))
907           (while (and size
908                       (not (zerop size))
909                       (> to from)
910                       (eq (char-after (1- to)) ?\ ))
911             (setq to (1- to)))
912           (prog1 (buffer-substring-no-properties from to)
913             (set-buffer old)))
914       (widget-get widget :value))))
915
916 (defun widget-field-match (widget value)
917   ;; Match any string.
918   (stringp value))
919
920 ;;; The `text' Widget.
921
922 (define-widget 'text 'editable-field
923   "A multiline text area.")
924
925 ;;; The `menu-choice' Widget.
926
927 (define-widget 'menu-choice 'default
928   "A menu of options."
929   :convert-widget  'widget-choice-convert-widget
930   :format "%[%t%]: %v"
931   :case-fold t
932   :tag "choice"
933   :void '(item :format "invalid (%t)\n")
934   :value-create 'widget-choice-value-create
935   :value-delete 'widget-radio-value-delete
936   :value-get 'widget-choice-value-get
937   :value-inline 'widget-choice-value-inline
938   :action 'widget-choice-action
939   :error "Make a choice"
940   :validate 'widget-choice-validate
941   :match 'widget-choice-match
942   :match-inline 'widget-choice-match-inline)
943
944 (defun widget-choice-convert-widget (widget)
945   ;; Expand type args into widget objects.
946 ;  (widget-put widget :args (mapcar (lambda (child)
947 ;                                    (if (widget-get child ':converted)
948 ;                                        child
949 ;                                      (widget-put child ':converted t)
950 ;                                      (widget-convert child)))
951 ;                                  (widget-get widget :args)))
952   (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
953   widget)
954
955 (defun widget-choice-value-create (widget)
956   ;; Insert the first choice that matches the value.
957   (let ((value (widget-get widget :value))
958         (args (widget-get widget :args))
959         current)
960     (while args
961       (setq current (car args)
962             args (cdr args))
963       (when (widget-apply current :match value)
964         (widget-put widget :children (list (widget-create-child-and-convert
965                                             widget current :value value)))
966         (widget-put widget :choice current)
967         (setq args nil
968               current nil)))
969     (when current
970       (let ((void (widget-get widget :void)))
971         (widget-put widget :children (list (widget-create-child-and-convert
972                                             widget void :value value)))
973         (widget-put widget :choice void)))))
974
975 (defun widget-choice-value-get (widget)
976   ;; Get value of the child widget.
977   (widget-value (car (widget-get widget :children))))
978
979 (defun widget-choice-value-inline (widget)
980   ;; Get value of the child widget.
981   (widget-apply (car (widget-get widget :children)) :value-inline))
982
983 (defun widget-choice-action (widget &optional event)
984   ;; Make a choice.
985   (let ((args (widget-get widget :args))
986         (old (widget-get widget :choice))
987         (tag (widget-apply widget :menu-tag-get))
988         (completion-ignore-case (widget-get widget :case-fold))
989         current choices)
990     ;; Remember old value.
991     (if (and old (not (widget-apply widget :validate)))
992         (let* ((external (widget-value widget))
993                (internal (widget-apply old :value-to-internal external)))
994           (widget-put old :value internal)))
995     ;; Find new choice.
996     (setq current
997           (cond ((= (length args) 0)
998                  nil)
999                 ((= (length args) 1)
1000                  (nth 0 args))
1001                 ((and (= (length args) 2)
1002                       (memq old args))
1003                  (if (eq old (nth 0 args))
1004                      (nth 1 args)
1005                    (nth 0 args)))
1006                 (t
1007                  (while args
1008                    (setq current (car args)
1009                          args (cdr args))
1010                    (setq choices
1011                          (cons (cons (widget-apply current :menu-tag-get)
1012                                      current)
1013                                choices)))
1014                  (widget-choose tag (reverse choices) event))))
1015     (when current
1016       (widget-value-set widget 
1017                         (widget-apply current :value-to-external
1018                                       (widget-get current :value)))
1019     (widget-apply widget :notify widget event)
1020     (widget-setup)))
1021   ;; Notify parent.
1022   (widget-apply widget :notify widget event)
1023   (widget-clear-undo))
1024
1025 (defun widget-choice-validate (widget)
1026   ;; Valid if we have made a valid choice.
1027   (let ((void (widget-get widget :void))
1028         (choice (widget-get widget :choice))
1029         (child (car (widget-get widget :children))))
1030     (if (eq void choice)
1031         widget
1032       (widget-apply child :validate))))
1033
1034 (defun widget-choice-match (widget value)
1035   ;; Matches if one of the choices matches.
1036   (let ((args (widget-get widget :args))
1037         current found)
1038     (while (and args (not found))
1039       (setq current (car args)
1040             args (cdr args)
1041             found (widget-apply current :match value)))
1042     found))
1043
1044 (defun widget-choice-match-inline (widget values)
1045   ;; Matches if one of the choices matches.
1046   (let ((args (widget-get widget :args))
1047         current found)
1048     (while (and args (null found))
1049       (setq current (car args)
1050             args (cdr args)
1051             found (widget-match-inline current values)))
1052     found))
1053
1054 ;;; The `toggle' Widget.
1055
1056 (define-widget 'toggle 'menu-choice
1057   "Toggle between two states."
1058   :convert-widget 'widget-toggle-convert-widget
1059   :format "%v"
1060   :on "on"
1061   :off "off")
1062
1063 (defun widget-toggle-convert-widget (widget)
1064   ;; Create the types representing the `on' and `off' states.
1065   (let ((on-type (widget-get widget :on-type))
1066         (off-type (widget-get widget :off-type)))
1067     (unless on-type
1068       (setq on-type
1069             (list 'choice-item 
1070                   :value t
1071                   :match (lambda (widget value) value)
1072                   :tag (widget-get widget :on))))
1073     (unless off-type
1074       (setq off-type
1075             (list 'choice-item :value nil :tag (widget-get widget :off))))
1076     (widget-put widget :args (list on-type off-type)))
1077   widget)
1078
1079 ;;; The `checkbox' Widget.
1080
1081 (define-widget 'checkbox 'toggle
1082   "A checkbox toggle."
1083   :convert-widget 'widget-item-convert-widget
1084   :on-type '(choice-item :format "%[[X]%]" t)
1085   :off-type  '(choice-item :format "%[[ ]%]" nil))
1086
1087 ;;; The `checklist' Widget.
1088
1089 (define-widget 'checklist 'default
1090   "A multiple choice widget."
1091   :convert-widget 'widget-choice-convert-widget
1092   :format "%v"
1093   :offset 4
1094   :entry-format "%b %v"
1095   :menu-tag "checklist"
1096   :greedy nil
1097   :value-create 'widget-checklist-value-create
1098   :value-delete 'widget-radio-value-delete
1099   :value-get 'widget-checklist-value-get
1100   :validate 'widget-checklist-validate
1101   :match 'widget-checklist-match
1102   :match-inline 'widget-checklist-match-inline)
1103
1104 (defun widget-checklist-value-create (widget)
1105   ;; Insert all values
1106   (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
1107         (args (widget-get widget :args)))
1108     (while args 
1109       (widget-checklist-add-item widget (car args) (assq (car args) alist))
1110       (setq args (cdr args)))
1111     (widget-put widget :children (nreverse (widget-get widget :children)))))
1112
1113 (defun widget-checklist-add-item (widget type chosen)
1114   ;; Create checklist item in WIDGET of type TYPE.
1115   ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
1116   (and (eq (preceding-char) ?\n)
1117        (widget-get widget :indent)
1118        (insert-char ?  (widget-get widget :indent)))
1119   (widget-specify-insert 
1120    (let* ((children (widget-get widget :children))
1121           (buttons (widget-get widget :buttons))
1122           (from (point))
1123           child button)
1124      (insert (widget-get widget :entry-format))
1125      (goto-char from)
1126      ;; Parse % escapes in format.
1127      (while (re-search-forward "%\\([bv%]\\)" nil t)
1128        (let ((escape (aref (match-string 1) 0)))
1129          (replace-match "" t t)
1130          (cond ((eq escape ?%)
1131                 (insert "%"))
1132                ((eq escape ?b)
1133                 (setq button (widget-create-child-and-convert
1134                               widget 'checkbox :value (not (null chosen)))))
1135                ((eq escape ?v)
1136                 (setq child
1137                       (cond ((not chosen)
1138                              (widget-create-child widget type))
1139                             ((widget-get type :inline)
1140                              (widget-create-child-and-convert
1141                               widget type :value (cdr chosen)))
1142                             (t
1143                              (widget-create-child-and-convert
1144                               widget type :value (car (cdr chosen)))))))
1145                (t 
1146                 (error "Unknown escape `%c'" escape)))))
1147      ;; Update properties.
1148      (and button child (widget-put child :button button))
1149      (and button (widget-put widget :buttons (cons button buttons)))
1150      (and child (widget-put widget :children (cons child children))))))
1151
1152 (defun widget-checklist-match (widget values)
1153   ;; All values must match a type in the checklist.
1154   (and (listp values)
1155        (null (cdr (widget-checklist-match-inline widget values)))))
1156
1157 (defun widget-checklist-match-inline (widget values)
1158   ;; Find the values which match a type in the checklist.
1159   (let ((greedy (widget-get widget :greedy))
1160         (args (copy-list (widget-get widget :args)))
1161         found rest)
1162     (while values
1163       (let ((answer (widget-checklist-match-up args values)))
1164         (cond (answer 
1165                (let ((vals (widget-match-inline answer values)))
1166                  (setq found (append found (car vals))
1167                        values (cdr vals)
1168                        args (delq answer args))))
1169               (greedy
1170                (setq rest (append rest (list (car values)))
1171                      values (cdr values)))
1172               (t 
1173                (setq rest (append rest values)
1174                      values nil)))))
1175     (cons found rest)))
1176
1177 (defun widget-checklist-match-find (widget vals)
1178   ;; Find the vals which match a type in the checklist.
1179   ;; Return an alist of (TYPE MATCH).
1180   (let ((greedy (widget-get widget :greedy))
1181         (args (copy-list (widget-get widget :args)))
1182         found)
1183     (while vals
1184       (let ((answer (widget-checklist-match-up args vals)))
1185         (cond (answer 
1186                (let ((match (widget-match-inline answer vals)))
1187                  (setq found (cons (cons answer (car match)) found)
1188                        vals (cdr match)
1189                        args (delq answer args))))
1190               (greedy
1191                (setq vals (cdr vals)))
1192               (t 
1193                (setq vals nil)))))
1194     found))
1195
1196 (defun widget-checklist-match-up (args vals)
1197   ;; Rerturn the first type from ARGS that matches VALS.
1198   (let (current found)
1199     (while (and args (null found))
1200       (setq current (car args)
1201             args (cdr args)
1202             found (widget-match-inline current vals)))
1203     (and found current)))
1204
1205 (defun widget-checklist-value-get (widget)
1206   ;; The values of all selected items.
1207   (let ((children (widget-get widget :children))
1208         child result)
1209     (while children 
1210       (setq child (car children)
1211             children (cdr children))
1212       (if (widget-value (widget-get child :button))
1213           (setq result (append result (widget-apply child :value-inline)))))
1214     result))
1215
1216 (defun widget-checklist-validate (widget)
1217   ;; Ticked chilren must be valid.
1218   (let ((children (widget-get widget :children))
1219         child button found)
1220     (while (and children (not found))
1221       (setq child (car children)
1222             children (cdr children)
1223             button (widget-get child :button)
1224             found (and (widget-value button)
1225                        (widget-apply child :validate))))
1226     found))
1227
1228 ;;; The `option' Widget
1229
1230 (define-widget 'option 'checklist
1231   "An widget with an optional item."
1232   :inline t)
1233
1234 ;;; The `choice-item' Widget.
1235
1236 (define-widget 'choice-item 'item
1237   "Button items that delegate action events to their parents."
1238   :action 'widget-choice-item-action
1239   :format "%[%t%] \n")
1240
1241 (defun widget-choice-item-action (widget &optional event)
1242   ;; Tell parent what happened.
1243   (widget-apply (widget-get widget :parent) :action event))
1244
1245 ;;; The `radio-button' Widget.
1246
1247 (define-widget 'radio-button 'toggle
1248   "A radio button for use in the `radio' widget."
1249   :notify 'widget-radio-button-notify
1250   :on-type '(choice-item :format "%[(*)%]" t)
1251   :off-type '(choice-item :format "%[( )%]" nil))
1252
1253 (defun widget-radio-button-notify (widget child &optional event)
1254   ;; Notify the parent.
1255   (widget-apply (widget-get widget :parent) :action widget event))
1256
1257 ;;; The `radio-button-choice' Widget.
1258
1259 (define-widget 'radio-button-choice 'default
1260   "Select one of multiple options."
1261   :convert-widget 'widget-choice-convert-widget
1262   :offset 4
1263   :format "%v"
1264   :entry-format "%b %v"
1265   :menu-tag "radio"
1266   :value-create 'widget-radio-value-create
1267   :value-delete 'widget-radio-value-delete
1268   :value-get 'widget-radio-value-get
1269   :value-inline 'widget-radio-value-inline
1270   :value-set 'widget-radio-value-set
1271   :error "You must push one of the buttons"
1272   :validate 'widget-radio-validate
1273   :match 'widget-choice-match
1274   :match-inline 'widget-choice-match-inline
1275   :action 'widget-radio-action)
1276
1277 (defun widget-radio-value-create (widget)
1278   ;; Insert all values
1279   (let ((args (widget-get widget :args))
1280         arg)
1281     (while args 
1282       (setq arg (car args)
1283             args (cdr args))
1284       (widget-radio-add-item widget arg))))
1285
1286 (defun widget-radio-add-item (widget type)
1287   "Add to radio widget WIDGET a new radio button item of type TYPE."
1288   ;; (setq type (widget-convert type))
1289   (and (eq (preceding-char) ?\n)
1290        (widget-get widget :indent)
1291        (insert-char ?  (widget-get widget :indent)))
1292   (widget-specify-insert 
1293    (let* ((value (widget-get widget :value))
1294           (children (widget-get widget :children))
1295           (buttons (widget-get widget :buttons))
1296           (from (point))
1297           (chosen (and (null (widget-get widget :choice))
1298                        (widget-apply type :match value)))
1299           child button)
1300      (insert (widget-get widget :entry-format))
1301      (goto-char from)
1302      ;; Parse % escapes in format.
1303      (while (re-search-forward "%\\([bv%]\\)" nil t)
1304        (let ((escape (aref (match-string 1) 0)))
1305          (replace-match "" t t)
1306          (cond ((eq escape ?%)
1307                 (insert "%"))
1308                ((eq escape ?b)
1309                 (setq button (widget-create-child-and-convert
1310                               widget 'radio-button 
1311                               :value (not (null chosen)))))
1312                ((eq escape ?v)
1313                 (setq child (if chosen
1314                                 (widget-create-child-and-convert
1315                                  widget type :value value)
1316                               (widget-create-child widget type))))
1317                (t 
1318                 (error "Unknown escape `%c'" escape)))))
1319      ;; Update properties.
1320      (when chosen
1321        (widget-put widget :choice type))
1322      (when button 
1323        (widget-put child :button button)
1324        (widget-put widget :buttons (nconc buttons (list button))))
1325      (when child
1326        (widget-put widget :children (nconc children (list child))))
1327      child)))
1328
1329 (defun widget-radio-value-delete (widget)
1330   ;; Delete the child widgets.
1331   (mapcar 'widget-delete (widget-get widget :children))
1332   (widget-put widget :children nil)
1333   (mapcar 'widget-delete (widget-get widget :buttons))
1334   (widget-put widget :buttons nil))
1335
1336 (defun widget-radio-value-get (widget)
1337   ;; Get value of the child widget.
1338   (let ((chosen (widget-radio-chosen widget)))
1339     (and chosen (widget-value chosen))))
1340
1341 (defun widget-radio-chosen (widget)
1342   "Return the widget representing the chosen radio button."
1343   (let ((children (widget-get widget :children))
1344         current found)
1345     (while children
1346       (setq current (car children)
1347             children (cdr children))
1348       (let* ((button (widget-get current :button))
1349              (value (widget-apply button :value-get)))
1350         (when value
1351           (setq found current
1352                 children nil))))
1353     found))
1354
1355 (defun widget-radio-value-inline (widget)
1356   ;; Get value of the child widget.
1357   (let ((children (widget-get widget :children))
1358         current found)
1359     (while children
1360       (setq current (car children)
1361             children (cdr children))
1362       (let* ((button (widget-get current :button))
1363              (value (widget-apply button :value-get)))
1364         (when value
1365           (setq found (widget-apply current :value-inline)
1366                 children nil))))
1367     found))
1368
1369 (defun widget-radio-value-set (widget value)
1370   ;; We can't just delete and recreate a radio widget, since children
1371   ;; can be added after the original creation and won't be recreated
1372   ;; by `:create'.
1373   (let ((children (widget-get widget :children))
1374         current found)
1375     (while children
1376       (setq current (car children)
1377             children (cdr children))
1378       (let* ((button (widget-get current :button))
1379              (match (and (not found)
1380                          (widget-apply current :match value))))
1381         (widget-value-set button match)
1382         (if match 
1383             (widget-value-set current value))
1384         (setq found (or found match))))))
1385
1386 (defun widget-radio-validate (widget)
1387   ;; Valid if we have made a valid choice.
1388   (let ((children (widget-get widget :children))
1389         current found button)
1390     (while (and children (not found))
1391       (setq current (car children)
1392             children (cdr children)
1393             button (widget-get current :button)
1394             found (widget-apply button :value-get)))
1395     (if found
1396         (widget-apply current :validate)
1397       widget)))
1398
1399 (defun widget-radio-action (widget child event)
1400   ;; Check if a radio button was pressed.
1401   (let ((children (widget-get widget :children))
1402         (buttons (widget-get widget :buttons))
1403         current)
1404     (when (memq child buttons)
1405       (while children
1406         (setq current (car children)
1407               children (cdr children))
1408         (let* ((button (widget-get current :button)))
1409           (cond ((eq child button)
1410                  (widget-value-set button t))
1411                 ((widget-value button)
1412                  (widget-value-set button nil)))))))
1413   ;; Pass notification to parent.
1414   (widget-apply widget :notify child event))
1415
1416 ;;; The `insert-button' Widget.
1417
1418 (define-widget 'insert-button 'push-button
1419   "An insert button for the `editable-list' widget."
1420   :tag "INS"
1421   :action 'widget-insert-button-action)
1422
1423 (defun widget-insert-button-action (widget &optional event)
1424   ;; Ask the parent to insert a new item.
1425   (widget-apply (widget-get widget :parent) 
1426                 :insert-before (widget-get widget :widget)))
1427
1428 ;;; The `delete-button' Widget.
1429
1430 (define-widget 'delete-button 'push-button
1431   "A delete button for the `editable-list' widget."
1432   :tag "DEL"
1433   :action 'widget-delete-button-action)
1434
1435 (defun widget-delete-button-action (widget &optional event)
1436   ;; Ask the parent to insert a new item.
1437   (widget-apply (widget-get widget :parent) 
1438                 :delete-at (widget-get widget :widget)))
1439
1440 ;;; The `editable-list' Widget.
1441
1442 (define-widget 'editable-list 'default
1443   "A variable list of widgets of the same type."
1444   :convert-widget 'widget-choice-convert-widget
1445   :offset 12
1446   :format "%v%i\n"
1447   :format-handler 'widget-editable-list-format-handler
1448   :entry-format "%i %d %v"
1449   :menu-tag "editable-list"
1450   :value-create 'widget-editable-list-value-create
1451   :value-delete 'widget-radio-value-delete
1452   :value-get 'widget-editable-list-value-get
1453   :validate 'widget-editable-list-validate
1454   :match 'widget-editable-list-match
1455   :match-inline 'widget-editable-list-match-inline
1456   :insert-before 'widget-editable-list-insert-before
1457   :delete-at 'widget-editable-list-delete-at)
1458
1459 (defun widget-editable-list-format-handler (widget escape)
1460   ;; We recognize the insert button.
1461   (cond ((eq escape ?i)
1462          (and (widget-get widget :indent)
1463               (insert-char ?  (widget-get widget :indent)))
1464          (widget-create-child-and-convert widget 'insert-button))
1465         (t 
1466          (widget-default-format-handler widget escape))))
1467
1468 ;(defun widget-editable-list-format-handler (widget escape)
1469 ;  ;; We recognize the insert button.
1470 ;  (cond ((eq escape ?i)
1471 ;        (insert " ")                   
1472 ;        (backward-char 1)
1473 ;        (let* ((from (point))
1474 ;               (button (widget-create-child-and-convert
1475 ;                        widget 'insert-button)))
1476 ;          (widget-specify-button button from (point)))
1477 ;        (forward-char 1))
1478 ;       (t 
1479 ;        (widget-default-format-handler widget escape))))
1480
1481 (defun widget-editable-list-value-create (widget)
1482   ;; Insert all values
1483   (let* ((value (widget-get widget :value))
1484          (type (nth 0 (widget-get widget :args)))
1485          (inlinep (widget-get type :inline))
1486          children)
1487     (widget-put widget :value-pos (copy-marker (point)))
1488     (set-marker-insertion-type (widget-get widget :value-pos) t)
1489     (while value
1490       (let ((answer (widget-match-inline type value)))
1491         (if answer
1492             (setq children (cons (widget-editable-list-entry-create
1493                                   widget
1494                                   (if inlinep
1495                                       (car answer)
1496                                     (car (car answer)))
1497                                   t)
1498                                  children)
1499                   value (cdr answer))
1500           (setq value nil))))
1501     (widget-put widget :children (nreverse children))))
1502
1503 (defun widget-editable-list-value-get (widget)
1504   ;; Get value of the child widget.
1505   (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
1506                          (widget-get widget :children))))
1507
1508 (defun widget-editable-list-validate (widget)
1509   ;; All the chilren must be valid.
1510   (let ((children (widget-get widget :children))
1511         child found)
1512     (while (and children (not found))
1513       (setq child (car children)
1514             children (cdr children)
1515             found (widget-apply child :validate)))
1516     found))
1517
1518 (defun widget-editable-list-match (widget value)
1519   ;; Value must be a list and all the members must match the type.
1520   (and (listp value)
1521        (null (cdr (widget-editable-list-match-inline widget value)))))
1522
1523 (defun widget-editable-list-match-inline (widget value)
1524   (let ((type (nth 0 (widget-get widget :args)))
1525         (ok t)
1526         found)
1527     (while (and value ok)
1528       (let ((answer (widget-match-inline type value)))
1529         (if answer 
1530             (setq found (append found (car answer))
1531                   value (cdr answer))
1532           (setq ok nil))))
1533     (cons found value)))
1534
1535 (defun widget-editable-list-insert-before (widget before)
1536   ;; Insert a new child in the list of children.
1537   (save-excursion
1538     (let ((children (widget-get widget :children))
1539           (inhibit-read-only t)
1540           after-change-functions)
1541       (cond (before 
1542              (goto-char (widget-get before :entry-from)))
1543             (t
1544              (goto-char (widget-get widget :value-pos))))
1545       (let ((child (widget-editable-list-entry-create 
1546                     widget nil nil)))
1547         (when (< (widget-get child :entry-from) (widget-get widget :from))
1548           (set-marker (widget-get widget :from)
1549                       (widget-get child :entry-from)))
1550         (widget-specify-text (widget-get child :entry-from)
1551                              (widget-get child :entry-to))
1552         (if (eq (car children) before)
1553             (widget-put widget :children (cons child children))
1554           (while (not (eq (car (cdr children)) before))
1555             (setq children (cdr children)))
1556           (setcdr children (cons child (cdr children)))))))
1557   (widget-setup)
1558   (widget-apply widget :notify widget))
1559
1560 (defun widget-editable-list-delete-at (widget child)
1561   ;; Delete child from list of children.
1562   (save-excursion
1563     (let ((buttons (copy-list (widget-get widget :buttons)))
1564           button
1565           (inhibit-read-only t)
1566           after-change-functions)
1567       (while buttons
1568         (setq button (car buttons)
1569               buttons (cdr buttons))
1570         (when (eq (widget-get button :widget) child)
1571           (widget-put widget
1572                       :buttons (delq button (widget-get widget :buttons)))
1573           (widget-delete button))))
1574     (let ((entry-from (widget-get child :entry-from))
1575           (entry-to (widget-get child :entry-to))
1576           (inhibit-read-only t)
1577           after-change-functions)
1578       (widget-delete child)
1579       (delete-region entry-from entry-to)
1580       (set-marker entry-from nil)
1581       (set-marker entry-to nil))
1582     (widget-put widget :children (delq child (widget-get widget :children))))
1583   (widget-setup)
1584   (widget-apply widget :notify widget))
1585
1586 (defun widget-editable-list-entry-create (widget value conv)
1587   ;; Create a new entry to the list.
1588   (let ((type (nth 0 (widget-get widget :args)))
1589         child delete insert)
1590     (widget-specify-insert 
1591      (save-excursion
1592        (and (widget-get widget :indent)
1593             (insert-char ?  (widget-get widget :indent)))
1594        (insert (widget-get widget :entry-format)))
1595      ;; Parse % escapes in format.
1596      (while (re-search-forward "%\\(.\\)" nil t)
1597        (let ((escape (aref (match-string 1) 0)))
1598          (replace-match "" t t)
1599          (cond ((eq escape ?%)
1600                 (insert "%"))
1601                ((eq escape ?i)
1602                 (setq insert (widget-create-child-and-convert
1603                               widget 'insert-button)))
1604                ((eq escape ?d)
1605                 (setq delete (widget-create-child-and-convert
1606                               widget 'delete-button)))
1607                ((eq escape ?v)
1608                 (if conv
1609                     (setq child (widget-create-child-and-convert 
1610                                  widget type :value value))
1611                   (setq child (widget-create-child widget type))))
1612                (t 
1613                 (error "Unknown escape `%c'" escape)))))
1614      (widget-put widget 
1615                  :buttons (cons delete 
1616                                 (cons insert
1617                                       (widget-get widget :buttons))))
1618      (let ((entry-from (copy-marker (point-min)))
1619            (entry-to (copy-marker (point-max))))
1620        (widget-specify-text entry-from entry-to)
1621        (set-marker-insertion-type entry-from t)
1622        (set-marker-insertion-type entry-to nil)
1623        (widget-put child :entry-from entry-from)
1624        (widget-put child :entry-to entry-to)))
1625     (widget-put insert :widget child)
1626     (widget-put delete :widget child)
1627     child))
1628
1629 ;;; The `group' Widget.
1630
1631 (define-widget 'group 'default
1632   "A widget which group other widgets inside."
1633   :convert-widget 'widget-choice-convert-widget
1634   :format "%v"
1635   :value-create 'widget-group-value-create
1636   :value-delete 'widget-radio-value-delete
1637   :value-get 'widget-editable-list-value-get
1638   :validate 'widget-editable-list-validate
1639   :match 'widget-group-match
1640   :match-inline 'widget-group-match-inline)
1641
1642 (defun widget-group-value-create (widget)
1643   ;; Create each component.
1644   (let ((args (widget-get widget :args))
1645         (value (widget-get widget :value))
1646         arg answer children)
1647     (while args
1648       (setq arg (car args)
1649             args (cdr args)
1650             answer (widget-match-inline arg value)
1651             value (cdr answer))
1652       (and (eq (preceding-char) ?\n)
1653            (widget-get widget :indent)
1654            (insert-char ?  (widget-get widget :indent)))
1655       (push (cond ((null answer)
1656                    (widget-create-child widget arg))
1657                   ((widget-get arg :inline)
1658                    (widget-create-child-and-convert
1659                     widget arg :value (car answer)))
1660                   (t
1661                    (widget-create-child-and-convert
1662                     widget arg :value (car (car answer)))))
1663             children))
1664     (widget-put widget :children (nreverse children))))
1665
1666 (defun widget-group-match (widget values)
1667   ;; Match if the components match.
1668   (and (listp values)
1669        (let ((match (widget-group-match-inline widget values)))
1670          (and match (null (cdr match))))))
1671
1672 (defun widget-group-match-inline (widget vals)
1673   ;; Match if the components match.
1674   (let ((args (widget-get widget :args))
1675         argument answer found)
1676     (while args
1677       (setq argument (car args)
1678             args (cdr args)
1679             answer (widget-match-inline argument vals))
1680       (if answer 
1681           (setq vals (cdr answer)
1682                 found (append found (car answer)))
1683         (setq vals nil
1684               args nil)))
1685     (if answer
1686         (cons found vals)
1687       nil)))
1688
1689 ;;; The `widget-help' Widget.
1690
1691 (define-widget 'widget-help 'push-button
1692   "The widget documentation button."
1693   :format "%[[%t]%] %d"
1694   :help-echo "Push me to toggle the documentation."
1695   :action 'widget-help-action)
1696
1697 (defun widget-help-action (widget &optional event)
1698   "Toggle documentation for WIDGET."
1699   (let ((old (widget-get widget :doc))
1700         (new (widget-get widget :widget-doc)))
1701     (widget-put widget :doc new)
1702     (widget-put widget :widget-doc old))
1703   (widget-value-set widget (widget-value widget)))
1704
1705 ;;; The Sexp Widgets.
1706
1707 (define-widget 'const 'item
1708   "An immutable sexp."
1709   :format "%t\n%d")
1710
1711 (define-widget 'function-item 'item
1712   "An immutable function name."
1713   :format "%v\n%h"
1714   :documentation-property (lambda (symbol)
1715                             (condition-case nil
1716                                 (documentation symbol t)
1717                               (error nil)))
1718   :value-delete 'widget-radio-value-delete
1719   :match (lambda (widget value) (symbolp value)))
1720
1721 (define-widget 'variable-item 'item
1722   "An immutable variable name."
1723   :format "%v\n%h"
1724   :documentation-property 'variable-documentation
1725   :value-delete 'widget-radio-value-delete
1726   :match (lambda (widget value) (symbolp value)))
1727
1728 (define-widget 'string 'editable-field
1729   "A string"
1730   :tag "String"
1731   :format "%[%t%]: %v")
1732
1733 (define-widget 'regexp 'string
1734   "A regular expression."
1735   ;; Should do validation.
1736   :tag "Regexp")
1737
1738 (define-widget 'file 'string
1739   "A file widget.  
1740 It will read a file name from the minibuffer when activated."
1741   :format "%[%t%]: %v"
1742   :tag "File"
1743   :action 'widget-file-action)
1744
1745 (defun widget-file-action (widget &optional event)
1746   ;; Read a file name from the minibuffer.
1747   (let* ((value (widget-value widget))
1748          (dir (file-name-directory value))
1749          (file (file-name-nondirectory value))
1750          (menu-tag (widget-apply widget :menu-tag-get))
1751          (must-match (widget-get widget :must-match))
1752          (answer (read-file-name (concat menu-tag ": (defalt `" value "') ")
1753                                  dir nil must-match file)))
1754     (widget-value-set widget (abbreviate-file-name answer))
1755     (widget-apply widget :notify widget event)
1756     (widget-setup)))
1757
1758 (define-widget 'directory 'file
1759   "A directory widget.  
1760 It will read a directory name from the minibuffer when activated."
1761   :tag "Directory")
1762
1763 (define-widget 'symbol 'string
1764   "A lisp symbol."
1765   :value nil
1766   :tag "Symbol"
1767   :match (lambda (widget value) (symbolp value))
1768   :value-to-internal (lambda (widget value)
1769                        (if (symbolp value)
1770                            (symbol-name value)
1771                          value))
1772   :value-to-external (lambda (widget value)
1773                        (if (stringp value)
1774                            (intern value)
1775                          value)))
1776
1777 (define-widget 'function 'symbol
1778   ;; Should complete on functions.
1779   "A lisp function."
1780   :tag "Function")
1781
1782 (define-widget 'variable 'symbol
1783   ;; Should complete on variables.
1784   "A lisp variable."
1785   :tag "Variable")
1786
1787 (define-widget 'sexp 'string
1788   "An arbitrary lisp expression."
1789   :tag "Lisp expression"
1790   :value nil
1791   :validate 'widget-sexp-validate
1792   :match (lambda (widget value) t)
1793   :value-to-internal 'widget-sexp-value-to-internal
1794   :value-to-external (lambda (widget value) (read value)))
1795
1796 (defun widget-sexp-value-to-internal (widget value)
1797   ;; Use pp for printer representation.
1798   (let ((pp (pp-to-string value)))
1799     (while (string-match "\n\\'" pp)
1800       (setq pp (substring pp 0 -1)))
1801     (if (or (string-match "\n\\'" pp)
1802             (> (length pp) 40))
1803         (concat "\n" pp)
1804       pp)))
1805
1806 (defun widget-sexp-validate (widget)
1807   ;; Valid if we can read the string and there is no junk left after it.
1808   (save-excursion
1809     (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
1810       (erase-buffer)
1811       (insert (widget-apply widget :value-get))
1812       (goto-char (point-min))
1813       (condition-case data
1814           (let ((value (read buffer)))
1815             (if (eobp)
1816                 (if (widget-apply widget :match value)
1817                     nil
1818                   (widget-put widget :error (widget-get widget :type-error))
1819                   widget)
1820               (widget-put widget
1821                           :error (format "Junk at end of expression: %s"
1822                                          (buffer-substring (point)
1823                                                            (point-max))))
1824               widget))
1825         (error (widget-put widget :error (error-message-string data))
1826                widget)))))
1827
1828 (define-widget 'integer 'sexp
1829   "An integer."
1830   :tag "Integer"
1831   :value 0
1832   :type-error "This field should contain an integer"
1833   :value-to-internal (lambda (widget value)
1834                        (if (integerp value) 
1835                            (prin1-to-string value)
1836                          value))
1837   :match (lambda (widget value) (integerp value)))
1838
1839 (define-widget 'character 'string
1840   "An character."
1841   :tag "Character"
1842   :value 0
1843   :size 1 
1844   :format "%t: %v\n"
1845   :type-error "This field should contain a character"
1846   :value-to-internal (lambda (widget value)
1847                        (if (integerp value) 
1848                            (char-to-string value)
1849                          value))
1850   :value-to-external (lambda (widget value)
1851                        (if (stringp value)
1852                            (aref value 0)
1853                          value))
1854   :match (lambda (widget value) (integerp value)))
1855
1856 (define-widget 'number 'sexp
1857   "A floating point number."
1858   :tag "Number"
1859   :value 0.0
1860   :type-error "This field should contain a number"
1861   :value-to-internal (lambda (widget value)
1862                        (if (numberp value)
1863                            (prin1-to-string value)
1864                          value))
1865   :match (lambda (widget value) (numberp value)))
1866
1867 (define-widget 'hook 'sexp 
1868   "A emacs lisp hook"
1869   :tag "Hook")
1870
1871 (define-widget 'list 'group
1872   "A lisp list."
1873   :tag "List"
1874   :format "%t:\n%v")
1875
1876 (define-widget 'vector 'group
1877   "A lisp vector."
1878   :tag "Vector"
1879   :format "%t:\n%v"
1880   :match 'widget-vector-match
1881   :value-to-internal (lambda (widget value) (append value nil))
1882   :value-to-external (lambda (widget value) (apply 'vector value)))
1883
1884 (defun widget-vector-match (widget value) 
1885   (and (vectorp value)
1886        (widget-group-match widget
1887                            (widget-apply :value-to-internal widget value))))
1888
1889 (define-widget 'cons 'group
1890   "A cons-cell."
1891   :tag "Cons-cell"
1892   :format "%t:\n%v"
1893   :match 'widget-cons-match
1894   :value-to-internal (lambda (widget value)
1895                        (list (car value) (cdr value)))
1896   :value-to-external (lambda (widget value)
1897                        (cons (nth 0 value) (nth 1 value))))
1898
1899 (defun widget-cons-match (widget value) 
1900   (and (consp value)
1901        (widget-group-match widget
1902                            (widget-apply widget :value-to-internal value))))
1903
1904 (define-widget 'choice 'menu-choice
1905   "A union of several sexp types."
1906   :tag "Choice"
1907   :format "%[%t%]: %v")
1908
1909 (define-widget 'radio 'radio-button-choice
1910   "A union of several sexp types."
1911   :tag "Choice"
1912   :format "%t:\n%v")
1913
1914 (define-widget 'repeat 'editable-list
1915   "A variable length homogeneous list."
1916   :tag "Repeat"
1917   :format "%t:\n%v%i\n")
1918
1919 (define-widget 'set 'checklist
1920   "A list of members from a fixed set."
1921   :tag "Set"
1922   :format "%t:\n%v")
1923
1924 (define-widget 'boolean 'toggle
1925   "To be nil or non-nil, that is the question."
1926   :tag "Boolean"
1927   :format "%t: %v")
1928
1929 ;;; The `color' Widget.
1930
1931 (define-widget 'color-item 'choice-item
1932   "A color name (with sample)."
1933   :format "%v (%[sample%])\n"
1934   :button-face-get 'widget-color-item-button-face-get)
1935
1936 (defun widget-color-item-button-face-get (widget)
1937   ;; We create a face from the value.
1938   (require 'facemenu)
1939   (condition-case nil
1940       (facemenu-get-face (intern (concat "fg:" (widget-value widget))))
1941     (error 'default)))
1942
1943 (define-widget 'color 'push-button
1944   "Choose a color name (with sample)."
1945   :format "%[%t%]: %v"
1946   :tag "Color"
1947   :value "default"
1948   :value-create 'widget-color-value-create
1949   :value-delete 'widget-radio-value-delete
1950   :value-get 'widget-color-value-get
1951   :value-set 'widget-color-value-set
1952   :action 'widget-color-action
1953   :match 'widget-field-match
1954   :tag "Color")
1955
1956 (defvar widget-color-choice-list nil)
1957 ;; Variable holding the possible colors.
1958
1959 (defun widget-color-choice-list ()
1960   (unless widget-color-choice-list
1961     (setq widget-color-choice-list 
1962           (mapcar '(lambda (color) (list color))
1963                   (x-defined-colors))))
1964   widget-color-choice-list)
1965
1966 (defun widget-color-value-create (widget)
1967   (let ((child (widget-create-child-and-convert
1968                 widget 'color-item (widget-get widget :value))))
1969     (widget-put widget :children (list child))))
1970
1971 (defun widget-color-value-get (widget)
1972   ;; Pass command to first child.
1973   (widget-apply (car (widget-get widget :children)) :value-get))
1974
1975 (defun widget-color-value-set (widget value)
1976   ;; Pass command to first child.
1977   (widget-apply (car (widget-get widget :children)) :value-set value))
1978
1979 (defvar widget-color-history nil
1980   "History of entered colors")
1981
1982 (defun widget-color-action (widget &optional event)
1983   ;; Prompt for a color.
1984   (let* ((tag (widget-apply widget :menu-tag-get))
1985          (prompt (concat tag ": "))
1986          (answer (cond ((string-match "XEmacs" emacs-version)
1987                         (read-color prompt))
1988                        ((fboundp 'x-defined-colors)
1989                         (completing-read (concat tag ": ")
1990                                          (widget-color-choice-list) 
1991                                          nil nil nil 'widget-color-history))
1992                        (t
1993                         (read-string prompt (widget-value widget))))))
1994     (unless (zerop (length answer))
1995       (widget-value-set widget answer)
1996       (widget-apply widget :notify widget event)
1997       (widget-setup))))
1998
1999 ;;; The Help Echo
2000
2001 (defun widget-echo-help-mouse ()
2002   "Display the help message for the widget under the mouse.
2003 Enable with (run-with-idle-timer 1 t 'widget-echo-help-mouse)"
2004   (let* ((pos (mouse-position))
2005          (frame (car pos))
2006          (x (car (cdr pos)))
2007          (y (cdr (cdr pos)))
2008          (win (window-at x y frame))
2009          (where (coordinates-in-window-p (cons x y) win)))
2010     (when (consp where)
2011       (save-window-excursion
2012         (progn ; save-excursion
2013           (select-window win)
2014           (let* ((result (compute-motion (window-start win)
2015                                          '(0 . 0)
2016                                          (window-end win)
2017                                          where
2018                                          (window-width win)
2019                                          (cons (window-hscroll) 0)
2020                                          win)))
2021             (when (and (eq (nth 1 result) x)
2022                        (eq (nth 2 result) y))
2023               (widget-echo-help (nth 0 result))))))))
2024   (unless track-mouse
2025     (setq track-mouse t)
2026     (add-hook 'post-command-hook 'widget-stop-mouse-tracking)))
2027
2028 (defun widget-stop-mouse-tracking (&rest args)
2029   "Stop the mouse tracking done while idle."
2030   (remove-hook 'post-command-hook 'widget-stop-mouse-tracking)
2031   (setq track-mouse nil))
2032
2033 (defun widget-echo-help (pos)
2034   "Display the help echo for widget at POS."
2035   (let* ((widget (or (get-text-property pos 'button)
2036                      (get-text-property pos 'field)))
2037          (help-echo (and widget (widget-get widget :help-echo))))
2038     (cond ((stringp help-echo)
2039            (message "%s" help-echo))
2040           ((and (symbolp help-echo) (fboundp help-echo)
2041                 (stringp (setq help-echo (funcall help-echo widget))))
2042            (message "%s" help-echo)))))
2043
2044 ;;; The End:
2045
2046 (provide 'widget-edit)
2047
2048 ;; widget-edit.el ends here