annotate lisp/custom/widget-example.el @ 124:9b50b4588a93 r20-1b15

Import from CVS: tag r20-1b15
author cvs
date Mon, 13 Aug 2007 09:26:39 +0200
parents cca96a509cfe
children 34a5b81f86ba
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
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
7 ;; Version: 1.84
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
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
12 (eval-when-compile
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
13 (require 'wid-edit))
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))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
25 (widget-insert "Here is some documentation.\n\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
26 (widget-create 'editable-field
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
27 :size 12
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
28 :format "Name: %v "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
29 "My Name")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
30 (widget-create 'menu-choice
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
31 :tag "Choose"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
32 :value "This"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
33 :help-echo "Choose me, please!"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
34 :notify (lambda (widget &rest ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
35 (message "%s is a good choice!"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
36 (widget-value widget)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
37 '(item :tag "This option" :value "This")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
38 '(choice-item "That option")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
39 '(editable-field :menu-tag "No option" "Thus option"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
40 (widget-insert "Address: ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
41 (widget-create 'editable-field
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
42 "Some Place\nIn some City\nSome country.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
43 (widget-insert "\nSee also ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
44 (widget-create 'link
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
45 :notify (lambda (&rest ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
46 (widget-value-set widget-example-repeat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
47 '("En" "To" "Tre"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
48 (widget-setup))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
49 "other work")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
50 (widget-insert " for more information.\n\nNumbers: count to three below\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
51 (setq widget-example-repeat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
52 (widget-create 'editable-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
53 :entry-format "%i %d %v"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
54 :notify (lambda (widget &rest ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
55 (let ((old (widget-get widget
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
56 ':example-length))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
57 (new (length (widget-value widget))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
58 (unless (eq old new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
59 (widget-put widget ':example-length new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
60 (message "You can count to %d." new))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
61 :value '("One" "Eh, two?" "Five!")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
62 '(editable-field :value "three")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
63 (widget-insert "\n\nSelect multiple:\n\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
64 (widget-create 'checkbox t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
65 (widget-insert " This\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
66 (widget-create 'checkbox nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
67 (widget-insert " That\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
68 (widget-create 'checkbox
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
69 :notify (lambda (&rest ignore) (message "Tickle"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
70 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
71 (widget-insert " Thus\n\nSelect one:\n\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
72 (widget-create 'radio-button-choice
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
73 :value "One"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
74 :notify (lambda (widget &rest ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
75 (message "You selected %s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
76 (widget-value widget)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
77 '(item "One") '(item "Anthor One.") '(item "A Final One."))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
78 (widget-insert "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
79 (widget-create 'push-button
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
80 :notify (lambda (&rest ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
81 (if (= (length (widget-value widget-example-repeat))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
82 3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
83 (message "Congratulation!")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
84 (error "Three was the count!")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
85 "Apply Form")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
86 (widget-insert " ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
87 (widget-create 'push-button
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
88 :notify (lambda (&rest ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
89 (widget-example))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
90 "Reset Form")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
91 (widget-insert "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92 (use-local-map widget-keymap)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
93 (widget-setup))