annotate lisp/w3/widget-edit.el @ 16:0293115a14e9 r19-15b91

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