annotate lisp/custom/widget-example.el @ 26:441bb1e64a06 r19-15b96

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