98
|
1 ;;; widget-example.el -- example of using the widget library
|
|
2
|
|
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
|
|
4 ;;
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
|
6 ;; Keywords: help, extensions, faces, hypermedia
|
163
|
7 ;; Version: 1.9931
|
98
|
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
|
|
9
|
|
10 (require 'widget)
|
|
11
|
155
|
12 (require 'wid-edit)
|
|
13 (eval-when-compile (require 'cl))
|
98
|
14
|
|
15 (defvar widget-example-repeat)
|
|
16
|
|
17 (defun widget-example ()
|
|
18 "Create the widgets from the Widget manual."
|
|
19 (interactive)
|
|
20 (switch-to-buffer "*Widget Example*")
|
|
21 (kill-all-local-variables)
|
|
22 (make-local-variable 'widget-example-repeat)
|
|
23 (let ((inhibit-read-only t))
|
|
24 (erase-buffer))
|
155
|
25 (let ((all (overlay-lists)))
|
|
26 ;; Delete all the overlays.
|
|
27 (mapcar 'delete-overlay (car all))
|
|
28 (mapcar 'delete-overlay (cdr all)))
|
98
|
29 (widget-insert "Here is some documentation.\n\n")
|
|
30 (widget-create 'editable-field
|
|
31 :size 12
|
|
32 :format "Name: %v "
|
|
33 "My Name")
|
|
34 (widget-create 'menu-choice
|
|
35 :tag "Choose"
|
|
36 :value "This"
|
|
37 :help-echo "Choose me, please!"
|
|
38 :notify (lambda (widget &rest ignore)
|
155
|
39 (message "%s is a good choice!"
|
98
|
40 (widget-value widget)))
|
|
41 '(item :tag "This option" :value "This")
|
|
42 '(choice-item "That option")
|
|
43 '(editable-field :menu-tag "No option" "Thus option"))
|
|
44 (widget-insert "Address: ")
|
|
45 (widget-create 'editable-field
|
|
46 "Some Place\nIn some City\nSome country.")
|
|
47 (widget-insert "\nSee also ")
|
|
48 (widget-create 'link
|
|
49 :notify (lambda (&rest ignore)
|
|
50 (widget-value-set widget-example-repeat
|
|
51 '("En" "To" "Tre"))
|
|
52 (widget-setup))
|
|
53 "other work")
|
|
54 (widget-insert " for more information.\n\nNumbers: count to three below\n")
|
|
55 (setq widget-example-repeat
|
|
56 (widget-create 'editable-list
|
|
57 :entry-format "%i %d %v"
|
|
58 :notify (lambda (widget &rest ignore)
|
|
59 (let ((old (widget-get widget
|
|
60 ':example-length))
|
|
61 (new (length (widget-value widget))))
|
|
62 (unless (eq old new)
|
|
63 (widget-put widget ':example-length new)
|
|
64 (message "You can count to %d." new))))
|
|
65 :value '("One" "Eh, two?" "Five!")
|
|
66 '(editable-field :value "three")))
|
|
67 (widget-insert "\n\nSelect multiple:\n\n")
|
|
68 (widget-create 'checkbox t)
|
|
69 (widget-insert " This\n")
|
|
70 (widget-create 'checkbox nil)
|
|
71 (widget-insert " That\n")
|
|
72 (widget-create 'checkbox
|
|
73 :notify (lambda (&rest ignore) (message "Tickle"))
|
|
74 t)
|
|
75 (widget-insert " Thus\n\nSelect one:\n\n")
|
|
76 (widget-create 'radio-button-choice
|
|
77 :value "One"
|
|
78 :notify (lambda (widget &rest ignore)
|
|
79 (message "You selected %s"
|
|
80 (widget-value widget)))
|
|
81 '(item "One") '(item "Anthor One.") '(item "A Final One."))
|
|
82 (widget-insert "\n")
|
|
83 (widget-create 'push-button
|
|
84 :notify (lambda (&rest ignore)
|
|
85 (if (= (length (widget-value widget-example-repeat))
|
|
86 3)
|
|
87 (message "Congratulation!")
|
|
88 (error "Three was the count!")))
|
|
89 "Apply Form")
|
|
90 (widget-insert " ")
|
|
91 (widget-create 'push-button
|
|
92 :notify (lambda (&rest ignore)
|
|
93 (widget-example))
|
|
94 "Reset Form")
|
|
95 (widget-insert "\n")
|
|
96 (use-local-map widget-keymap)
|
|
97 (widget-setup))
|