annotate lisp/custom/widget-example.el @ 161:28f395d8dc7a r20-3b7

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