Mercurial > hg > xemacs-beta
comparison man/widget.texi @ 428:3ecd8885ac67 r21-2-22
Import from CVS: tag r21-2-22
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:28:15 +0200 |
parents | |
children | 9d177e8d4150 |
comparison
equal
deleted
inserted
replaced
427:0a0253eac470 | 428:3ecd8885ac67 |
---|---|
1 \input texinfo.tex | |
2 | |
3 @c %**start of header | |
4 @setfilename ../info/widget.info | |
5 @settitle The Emacs Widget Library | |
6 @iftex | |
7 @afourpaper | |
8 @headings double | |
9 @end iftex | |
10 @c %**end of header | |
11 | |
12 @ifinfo | |
13 @dircategory XEmacs Editor | |
14 @direntry | |
15 * Widgets: (widget). The Emacs Widget Library. | |
16 @end direntry | |
17 @end ifinfo | |
18 | |
19 @node Top, Introduction, (dir), (dir) | |
20 @comment node-name, next, previous, up | |
21 @top The Emacs Widget Library | |
22 | |
23 @menu | |
24 * Introduction:: | |
25 * User Interface:: | |
26 * Programming Example:: | |
27 * Setting Up the Buffer:: | |
28 * Basic Types:: | |
29 * Sexp Types:: | |
30 * Widget Properties:: | |
31 * Defining New Widgets:: | |
32 * Widget Browser:: | |
33 * Widget Minor Mode:: | |
34 * Utilities:: | |
35 * Widget Wishlist:: | |
36 @end menu | |
37 | |
38 @node Introduction, User Interface, Top, Top | |
39 @comment node-name, next, previous, up | |
40 @section Introduction | |
41 | |
42 Most graphical user interface toolkits, such as Motif and XView, provide | |
43 a number of standard user interface controls (sometimes known as | |
44 `widgets' or `gadgets'). Emacs doesn't really support anything like | |
45 this, except for an incredible powerful text ``widget''. On the other | |
46 hand, Emacs does provide the necessary primitives to implement many | |
47 other widgets within a text buffer. The @code{widget} package | |
48 simplifies this task. | |
49 | |
50 The basic widgets are: | |
51 | |
52 @table @code | |
53 @item link | |
54 Areas of text with an associated action. Intended for hypertext links | |
55 embedded in text. | |
56 @item push-button | |
57 Like link, but intended for stand-alone buttons. | |
58 @item editable-field | |
59 An editable text field. It can be either variable or fixed length. | |
60 @item menu-choice | |
61 Allows the user to choose one of multiple options from a menu, each | |
62 option is itself a widget. Only the selected option will be visible in | |
63 the buffer. | |
64 @item radio-button-choice | |
65 Allows the user to choose one of multiple options by activating radio | |
66 buttons. The options are implemented as widgets. All options will be | |
67 visible in the buffer. | |
68 @item item | |
69 A simple constant widget intended to be used in the @code{menu-choice} and | |
70 @code{radio-button-choice} widgets. | |
71 @item choice-item | |
72 An button item only intended for use in choices. When invoked, the user | |
73 will be asked to select another option from the choice widget. | |
74 @item toggle | |
75 A simple @samp{on}/@samp{off} switch. | |
76 @item checkbox | |
77 A checkbox (@samp{[ ]}/@samp{[X]}). | |
78 @item editable-list | |
79 Create an editable list. The user can insert or delete items in the | |
80 list. Each list item is itself a widget. | |
81 @end table | |
82 | |
83 Now of what possible use can support for widgets be in a text editor? | |
84 I'm glad you asked. The answer is that widgets are useful for | |
85 implementing forms. A @dfn{form} in emacs is a buffer where the user is | |
86 supposed to fill out a number of fields, each of which has a specific | |
87 meaning. The user is not supposed to change or delete any of the text | |
88 between the fields. Examples of forms in Emacs are the @file{forms} | |
89 package (of course), the customize buffers, the mail and news compose | |
90 modes, and the @sc{html} form support in the @file{w3} browser. | |
91 | |
92 The advantages for a programmer of using the @code{widget} package to | |
93 implement forms are: | |
94 | |
95 @enumerate | |
96 @item | |
97 More complex field than just editable text are supported. | |
98 @item | |
99 You can give the user immediate feedback if he enters invalid data in a | |
100 text field, and sometimes prevent entering invalid data. | |
101 @item | |
102 You can have fixed sized fields, thus allowing multiple field to be | |
103 lined up in columns. | |
104 @item | |
105 It is simple to query or set the value of a field. | |
106 @item | |
107 Editing happens in buffer, not in the mini-buffer. | |
108 @item | |
109 Packages using the library get a uniform look, making them easier for | |
110 the user to learn. | |
111 @item | |
112 As support for embedded graphics improve, the widget library will | |
113 extended to support it. This means that your code using the widget | |
114 library will also use the new graphic features by automatic. | |
115 @end enumerate | |
116 | |
117 In order to minimize the code that is loaded by users who does not | |
118 create any widgets, the code has been split in two files: | |
119 | |
120 @table @file | |
121 @item widget.el | |
122 This will declare the user variables, define the function | |
123 @code{widget-define}, and autoload the function @code{widget-create}. | |
124 @item wid-edit.el | |
125 Everything else is here, there is no reason to load it explicitly, as | |
126 it will be autoloaded when needed. | |
127 @end table | |
128 | |
129 @node User Interface, Programming Example, Introduction, Top | |
130 @comment node-name, next, previous, up | |
131 @section User Interface | |
132 | |
133 A form consist of read only text for documentation and some fields, | |
134 where each the fields contain two parts, as tag and a value. The tags | |
135 are used to identify the fields, so the documentation can refer to the | |
136 foo field, meaning the field tagged with @samp{Foo}. Here is an example | |
137 form: | |
138 | |
139 @example | |
140 Here is some documentation. | |
141 | |
142 Name: @i{My Name} @strong{Choose}: This option | |
143 Address: @i{Some Place | |
144 In some City | |
145 Some country.} | |
146 | |
147 See also @b{_other work_} for more information. | |
148 | |
149 Numbers: count to three below | |
150 @b{[INS]} @b{[DEL]} @i{One} | |
151 @b{[INS]} @b{[DEL]} @i{Eh, two?} | |
152 @b{[INS]} @b{[DEL]} @i{Five!} | |
153 @b{[INS]} | |
154 | |
155 Select multiple: | |
156 | |
157 @b{[X]} This | |
158 @b{[ ]} That | |
159 @b{[X]} Thus | |
160 | |
161 Select one: | |
162 | |
163 @b{(*)} One | |
164 @b{( )} Another One. | |
165 @b{( )} A Final One. | |
166 | |
167 @b{[Apply Form]} @b{[Reset Form]} | |
168 @end example | |
169 | |
170 The top level widgets in is example are tagged @samp{Name}, | |
171 @samp{Choose}, @samp{Address}, @samp{_other work_}, @samp{Numbers}, | |
172 @samp{Select multiple}, @samp{Select one}, @samp{[Apply Form]}, and | |
173 @samp{[Reset Form]}. There are basically two thing the user can do within | |
174 a form, namely editing the editable text fields and activating the | |
175 buttons. | |
176 | |
177 @subsection Editable Text Fields | |
178 | |
179 In the example, the value for the @samp{Name} is most likely displayed | |
180 in an editable text field, and so are values for each of the members of | |
181 the @samp{Numbers} list. All the normal Emacs editing operations are | |
182 available for editing these fields. The only restriction is that each | |
183 change you make must be contained within a single editable text field. | |
184 For example, capitalizing all text from the middle of one field to the | |
185 middle of another field is prohibited. | |
186 | |
187 Editing text fields are created by the @code{editable-field} widget. | |
188 | |
189 The editing text fields are highlighted with the | |
190 @code{widget-field-face} face, making them easy to find. | |
191 | |
192 @deffn Face widget-field-face | |
193 Face used for other editing fields. | |
194 @end deffn | |
195 | |
196 @subsection Buttons | |
197 | |
198 Some portions of the buffer have an associated @dfn{action}, which can | |
199 be @dfn{invoked} by a standard key or mouse command. These portions | |
200 are called @dfn{buttons}. The default commands for activating a button | |
201 are: | |
202 | |
203 @table @kbd | |
204 @item @key{RET} | |
205 @deffn Command widget-button-press @var{pos} &optional @var{event} | |
206 Invoke the button at @var{pos}, defaulting to point. | |
207 If point is not located on a button, invoke the binding in | |
208 @code{widget-global-map} (by default the global map). | |
209 @end deffn | |
210 | |
211 @item mouse-2 | |
212 @deffn Command widget-button-click @var{event} | |
213 Invoke the button at the location of the mouse pointer. If the mouse | |
214 pointer is located in an editable text field, invoke the binding in | |
215 @code{widget-global-map} (by default the global map). | |
216 @end deffn | |
217 @end table | |
218 | |
219 There are several different kind of buttons, all of which are present in | |
220 the example: | |
221 | |
222 @table @emph | |
223 @item The Option Field Tags. | |
224 When you invoke one of these buttons, you will be asked to choose | |
225 between a number of different options. This is how you edit an option | |
226 field. Option fields are created by the @code{menu-choice} widget. In | |
227 the example, @samp{@b{Choose}} is an option field tag. | |
228 @item The @samp{@b{[INS]}} and @samp{@b{[DEL]}} buttons. | |
229 Activating these will insert or delete elements from a editable list. | |
230 The list is created by the @code{editable-list} widget. | |
231 @item Embedded Buttons. | |
232 The @samp{@b{_other work_}} is an example of an embedded | |
233 button. Embedded buttons are not associated with a fields, but can serve | |
234 any purpose, such as implementing hypertext references. They are | |
235 usually created by the @code{link} widget. | |
236 @item The @samp{@b{[ ]}} and @samp{@b{[X]}} buttons. | |
237 Activating one of these will convert it to the other. This is useful | |
238 for implementing multiple-choice fields. You can create it wit | |
239 @item The @samp{@b{( )}} and @samp{@b{(*)}} buttons. | |
240 Only one radio button in a @code{radio-button-choice} widget can be | |
241 selected at any time. When you invoke one of the unselected radio | |
242 buttons, it will be selected and the previous selected radio button will | |
243 become unselected. | |
244 @item The @samp{@b{[Apply Form]}} @samp{@b{[Reset Form]}} buttons. | |
245 These are explicit buttons made with the @code{push-button} widget. The main | |
246 difference from the @code{link} widget is that the buttons are will be | |
247 displayed as GUI buttons when possible. | |
248 enough. | |
249 @end table | |
250 | |
251 To make them easier to locate, buttons are emphasized in the buffer. | |
252 | |
253 @deffn Face widget-button-face | |
254 Face used for buttons. | |
255 @end deffn | |
256 | |
257 @defopt widget-mouse-face | |
258 Face used for buttons when the mouse pointer is above it. | |
259 @end defopt | |
260 | |
261 @subsection Navigation | |
262 | |
263 You can use all the normal Emacs commands to move around in a form | |
264 buffer, plus you will have these additional commands: | |
265 | |
266 @table @kbd | |
267 @item @key{TAB} | |
268 @deffn Command widget-forward &optional count | |
269 Move point @var{count} buttons or editing fields forward. | |
270 @end deffn | |
271 @item @key{M-TAB} | |
272 @deffn Command widget-backward &optional count | |
273 Move point @var{count} buttons or editing fields backward. | |
274 @end deffn | |
275 @end table | |
276 | |
277 @node Programming Example, Setting Up the Buffer, User Interface, Top | |
278 @comment node-name, next, previous, up | |
279 @section Programming Example | |
280 | |
281 Here is the code to implement the user interface example (see @ref{User | |
282 Interface}). | |
283 | |
284 @lisp | |
285 (require 'widget) | |
286 | |
287 (eval-when-compile | |
288 (require 'wid-edit)) | |
289 | |
290 (defvar widget-example-repeat) | |
291 | |
292 (defun widget-example () | |
293 "Create the widgets from the Widget manual." | |
294 (interactive) | |
295 (kill-buffer (get-buffer-create "*Widget Example*")) | |
296 (switch-to-buffer (get-buffer-create "*Widget Example*")) | |
297 (kill-all-local-variables) | |
298 (make-local-variable 'widget-example-repeat) | |
299 (widget-insert "Here is some documentation.\n\nName: ") | |
300 (widget-create 'editable-field | |
301 :size 13 | |
302 "My Name") | |
303 (widget-create 'menu-choice | |
304 :tag "Choose" | |
305 :value "This" | |
306 :help-echo "Choose me, please!" | |
307 :notify (lambda (widget &rest ignore) | |
308 (message "%s is a good choice!" | |
309 (widget-value widget))) | |
310 '(item :tag "This option" :value "This") | |
311 '(choice-item "That option") | |
312 '(editable-field :menu-tag "No option" "Thus option")) | |
313 (widget-insert "Address: ") | |
314 (widget-create 'editable-field | |
315 "Some Place\nIn some City\nSome country.") | |
316 (widget-insert "\nSee also ") | |
317 (widget-create 'link | |
318 :notify (lambda (&rest ignore) | |
319 (widget-value-set widget-example-repeat | |
320 '("En" "To" "Tre")) | |
321 (widget-setup)) | |
322 "other work") | |
323 (widget-insert " for more information.\n\nNumbers: count to three below\n") | |
324 (setq widget-example-repeat | |
325 (widget-create 'editable-list | |
326 :entry-format "%i %d %v" | |
327 :notify (lambda (widget &rest ignore) | |
328 (let ((old (widget-get widget | |
329 ':example-length)) | |
330 (new (length (widget-value widget)))) | |
331 (unless (eq old new) | |
332 (widget-put widget ':example-length new) | |
333 (message "You can count to %d." new)))) | |
334 :value '("One" "Eh, two?" "Five!") | |
335 '(editable-field :value "three"))) | |
336 (widget-insert "\n\nSelect multiple:\n\n") | |
337 (widget-create 'checkbox t) | |
338 (widget-insert " This\n") | |
339 (widget-create 'checkbox nil) | |
340 (widget-insert " That\n") | |
341 (widget-create 'checkbox | |
342 :notify (lambda (&rest ignore) (message "Tickle")) | |
343 t) | |
344 (widget-insert " Thus\n\nSelect one:\n\n") | |
345 (widget-create 'radio-button-choice | |
346 :value "One" | |
347 :notify (lambda (widget &rest ignore) | |
348 (message "You selected %s" | |
349 (widget-value widget))) | |
350 '(item "One") '(item "Another One.") '(item "A Final One.")) | |
351 (widget-insert "\n") | |
352 (widget-create 'push-button | |
353 :notify (lambda (&rest ignore) | |
354 (if (= (length (widget-value widget-example-repeat)) | |
355 3) | |
356 (message "Congratulation!") | |
357 (error "Three was the count!"))) | |
358 "Apply Form") | |
359 (widget-insert " ") | |
360 (widget-create 'push-button | |
361 :notify (lambda (&rest ignore) | |
362 (widget-example)) | |
363 "Reset Form") | |
364 (widget-insert "\n") | |
365 (use-local-map widget-keymap) | |
366 (widget-setup)) | |
367 @end lisp | |
368 | |
369 @node Setting Up the Buffer, Basic Types, Programming Example, Top | |
370 @comment node-name, next, previous, up | |
371 @section Setting Up the Buffer | |
372 | |
373 Widgets are created with @code{widget-create}, which returns a | |
374 @dfn{widget} object. This object can be queried and manipulated by | |
375 other widget functions, until it is deleted with @code{widget-delete}. | |
376 After the widgets have been created, @code{widget-setup} must be called | |
377 to enable them. | |
378 | |
379 @defun widget-create type [ keyword argument ]@dots{} | |
380 Create and return a widget of type @var{type}. | |
381 The syntax for the @var{type} argument is described in @ref{Basic Types}. | |
382 | |
383 The keyword arguments can be used to overwrite the keyword arguments | |
384 that are part of @var{type}. | |
385 @end defun | |
386 | |
387 @defun widget-delete widget | |
388 Delete @var{widget} and remove it from the buffer. | |
389 @end defun | |
390 | |
391 @defun widget-setup | |
392 Setup a buffer to support widgets. | |
393 | |
394 This should be called after creating all the widgets and before allowing | |
395 the user to edit them. | |
396 @refill | |
397 @end defun | |
398 | |
399 If you want to insert text outside the widgets in the form, the | |
400 recommended way to do that is with @code{widget-insert}. | |
401 | |
402 @defun widget-insert | |
403 Insert the arguments, either strings or characters, at point. | |
404 The inserted text will be read only. | |
405 @end defun | |
406 | |
407 There is a standard widget keymap which you might find useful. | |
408 | |
409 @defvr Const widget-keymap | |
410 A keymap with the global keymap as its parent.@* | |
411 @key{TAB} and @kbd{C-@key{TAB}} are bound to @code{widget-forward} and | |
412 @code{widget-backward}, respectively. @kbd{@key{RET}} and @kbd{mouse-2} | |
413 are bound to @code{widget-button-press} and | |
414 @code{widget-button-}.@refill | |
415 @end defvr | |
416 | |
417 @defvar widget-global-map | |
418 Keymap used by @code{widget-button-press} and @code{widget-button-click} | |
419 when not on a button. By default this is @code{global-map}. | |
420 @end defvar | |
421 | |
422 @node Basic Types, Sexp Types, Setting Up the Buffer, Top | |
423 @comment node-name, next, previous, up | |
424 @section Basic Types | |
425 | |
426 The syntax of a type specification is given below: | |
427 | |
428 @example | |
429 NAME ::= (NAME [KEYWORD ARGUMENT]... ARGS) | |
430 | NAME | |
431 @end example | |
432 | |
433 Where, @var{name} is a widget name, @var{keyword} is the name of a | |
434 property, @var{argument} is the value of the property, and @var{args} | |
435 are interpreted in a widget specific way. | |
436 | |
437 There following keyword arguments that apply to all widgets: | |
438 | |
439 @table @code | |
440 @item :value | |
441 The initial value for widgets of this type. | |
442 | |
443 @item :format | |
444 This string will be inserted in the buffer when you create a widget. | |
445 The following @samp{%} escapes are available: | |
446 | |
447 @table @samp | |
448 @item %[ | |
449 @itemx %] | |
450 The text inside will be marked as a button. | |
451 | |
452 By default, the text will be shown in @code{widget-button-face}, and | |
453 surrounded by brackets. | |
454 | |
455 @defopt widget-button-prefix | |
456 String to prefix buttons. | |
457 @end defopt | |
458 | |
459 @defopt widget-button-suffix | |
460 String to suffix buttons. | |
461 @end defopt | |
462 | |
463 @item %@{ | |
464 @itemx %@} | |
465 The text inside will be displayed with the face specified by | |
466 @code{:sample-face}. | |
467 | |
468 @item %v | |
469 This will be replaces with the buffer representation of the widgets | |
470 value. What this is depends on the widget type. | |
471 | |
472 @item %d | |
473 Insert the string specified by @code{:doc} here. | |
474 | |
475 @item %h | |
476 Like @samp{%d}, with the following modifications: If the documentation | |
477 string is more than one line, it will add a button which will toggle | |
478 between showing only the first line, and showing the full text. | |
479 Furthermore, if there is no @code{:doc} property in the widget, it will | |
480 instead examine the @code{:documentation-property} property. If it is a | |
481 lambda expression, it will be called with the widget's value as an | |
482 argument, and the result will be used as the documentation text. | |
483 | |
484 @item %t | |
485 Insert the string specified by @code{:tag} here, or the @code{princ} | |
486 representation of the value if there is no tag. | |
487 | |
488 @item %% | |
489 Insert a literal @samp{%}. | |
490 @end table | |
491 | |
492 @item :button-face | |
493 Face used to highlight text inside %[ %] in the format. | |
494 | |
495 @item :button-prefix | |
496 @itemx :button-suffix | |
497 | |
498 Text around %[ %] in the format. | |
499 | |
500 These can be | |
501 @table @emph | |
502 @item nil | |
503 No text is inserted. | |
504 | |
505 @item a string | |
506 The string is inserted literally. | |
507 | |
508 @item a symbol | |
509 The value of the symbol is expanded according to this table. | |
510 @end table | |
511 | |
512 @item :doc | |
513 The string inserted by the @samp{%d} escape in the format | |
514 string. | |
515 | |
516 @item :tag | |
517 The string inserted by the @samp{%t} escape in the format | |
518 string. | |
519 | |
520 @item :tag-glyph | |
521 Name of image to use instead of the string specified by `:tag' on | |
522 Emacsen that supports it. | |
523 | |
524 @item :help-echo | |
525 Message displayed whenever you move to the widget with either | |
526 @code{widget-forward} or @code{widget-backward}. | |
527 | |
528 @item :indent | |
529 An integer indicating the absolute number of spaces to indent children | |
530 of this widget. | |
531 | |
532 @item :offset | |
533 An integer indicating how many extra spaces to add to the widget's | |
534 grandchildren compared to this widget. | |
535 | |
536 @item :extra-offset | |
537 An integer indicating how many extra spaces to add to the widget's | |
538 children compared to this widget. | |
539 | |
540 @item :notify | |
541 A function called each time the widget or a nested widget is changed. | |
542 The function is called with two or three arguments. The first argument | |
543 is the widget itself, the second argument is the widget that was | |
544 changed, and the third argument is the event leading to the change, if | |
545 any. | |
546 | |
547 @item :menu-tag | |
548 Tag used in the menu when the widget is used as an option in a | |
549 @code{menu-choice} widget. | |
550 | |
551 @item :menu-tag-get | |
552 Function used for finding the tag when the widget is used as an option | |
553 in a @code{menu-choice} widget. By default, the tag used will be either the | |
554 @code{:menu-tag} or @code{:tag} property if present, or the @code{princ} | |
555 representation of the @code{:value} property if not. | |
556 | |
557 @item :match | |
558 Should be a function called with two arguments, the widget and a value, | |
559 and returning non-nil if the widget can represent the specified value. | |
560 | |
561 @item :validate | |
562 A function which takes a widget as an argument, and return nil if the | |
563 widgets current value is valid for the widget. Otherwise, it should | |
564 return the widget containing the invalid data, and set that widgets | |
565 @code{:error} property to a string explaining the error. | |
566 | |
567 The following predefined function can be used: | |
568 | |
569 @defun widget-children-validate widget | |
570 All the @code{:children} of @var{widget} must be valid. | |
571 @end defun | |
572 | |
573 @item :tab-order | |
574 Specify the order in which widgets are traversed with | |
575 @code{widget-forward} or @code{widget-backward}. This is only partially | |
576 implemented. | |
577 | |
578 @enumerate a | |
579 @item | |
580 Widgets with tabbing order @code{-1} are ignored. | |
581 | |
582 @item | |
583 (Unimplemented) When on a widget with tabbing order @var{n}, go to the | |
584 next widget in the buffer with tabbing order @var{n+1} or @code{nil}, | |
585 whichever comes first. | |
586 | |
587 @item | |
588 When on a widget with no tabbing order specified, go to the next widget | |
589 in the buffer with a positive tabbing order, or @code{nil} | |
590 @end enumerate | |
591 | |
592 @item :parent | |
593 The parent of a nested widget (e.g. a @code{menu-choice} item or an | |
594 element of a @code{editable-list} widget). | |
595 | |
596 @item :sibling-args | |
597 This keyword is only used for members of a @code{radio-button-choice} or | |
598 @code{checklist}. The value should be a list of extra keyword | |
599 arguments, which will be used when creating the @code{radio-button} or | |
600 @code{checkbox} associated with this item. | |
601 | |
602 @end table | |
603 | |
604 @deffn {User Option} widget-glyph-directory | |
605 Directory where glyphs are found. | |
606 Widget will look here for a file with the same name as specified for the | |
607 image, with either a @samp{.xpm} (if supported) or @samp{.xbm} extension. | |
608 @end deffn | |
609 | |
610 @deffn{User Option} widget-glyph-enable | |
611 If non-nil, allow glyphs to appear on displays where they are supported. | |
612 @end deffn | |
613 | |
614 | |
615 @menu | |
616 * link:: | |
617 * url-link:: | |
618 * info-link:: | |
619 * push-button:: | |
620 * editable-field:: | |
621 * text:: | |
622 * menu-choice:: | |
623 * radio-button-choice:: | |
624 * item:: | |
625 * choice-item:: | |
626 * toggle:: | |
627 * checkbox:: | |
628 * checklist:: | |
629 * editable-list:: | |
630 * group:: | |
631 @end menu | |
632 | |
633 @node link, url-link, Basic Types, Basic Types | |
634 @comment node-name, next, previous, up | |
635 @subsection The @code{link} Widget | |
636 | |
637 Syntax: | |
638 | |
639 @example | |
640 TYPE ::= (link [KEYWORD ARGUMENT]... [ VALUE ]) | |
641 @end example | |
642 | |
643 The @var{value}, if present, is used to initialize the @code{:value} | |
644 property. The value should be a string, which will be inserted in the | |
645 buffer. | |
646 | |
647 By default the link will be shown in brackets. | |
648 | |
649 @defopt widget-link-prefix | |
650 String to prefix links. | |
651 @end defopt | |
652 | |
653 @defopt widget-link-suffix | |
654 String to suffix links. | |
655 @end defopt | |
656 | |
657 @node url-link, info-link, link, Basic Types | |
658 @comment node-name, next, previous, up | |
659 @subsection The @code{url-link} Widget | |
660 | |
661 Syntax: | |
662 | |
663 @example | |
664 TYPE ::= (url-link [KEYWORD ARGUMENT]... URL) | |
665 @end example | |
666 | |
667 When this link is invoked, the @sc{www} browser specified by | |
668 @code{browse-url-browser-function} will be called with @var{url}. | |
669 | |
670 @node info-link, push-button, url-link, Basic Types | |
671 @comment node-name, next, previous, up | |
672 @subsection The @code{info-link} Widget | |
673 | |
674 Syntax: | |
675 | |
676 @example | |
677 TYPE ::= (info-link [KEYWORD ARGUMENT]... ADDRESS) | |
678 @end example | |
679 | |
680 When this link is invoked, the built-in info browser is started on | |
681 @var{address}. | |
682 | |
683 @node push-button, editable-field, info-link, Basic Types | |
684 @comment node-name, next, previous, up | |
685 @subsection The @code{push-button} Widget | |
686 | |
687 Syntax: | |
688 | |
689 @example | |
690 TYPE ::= (push-button [KEYWORD ARGUMENT]... [ VALUE ]) | |
691 @end example | |
692 | |
693 The @var{value}, if present, is used to initialize the @code{:value} | |
694 property. The value should be a string, which will be inserted in the | |
695 buffer. | |
696 | |
697 By default the tag will be shown in brackets. | |
698 | |
699 @defopt widget-push-button-prefix | |
700 String to prefix push buttons. | |
701 @end defopt | |
702 | |
703 @defopt widget-push-button-suffix | |
704 String to suffix push buttons. | |
705 @end defopt | |
706 | |
707 @node editable-field, text, push-button, Basic Types | |
708 @comment node-name, next, previous, up | |
709 @subsection The @code{editable-field} Widget | |
710 | |
711 Syntax: | |
712 | |
713 @example | |
714 TYPE ::= (editable-field [KEYWORD ARGUMENT]... [ VALUE ]) | |
715 @end example | |
716 | |
717 The @var{value}, if present, is used to initialize the @code{:value} | |
718 property. The value should be a string, which will be inserted in | |
719 field. This widget will match all string values. | |
720 | |
721 The following extra properties are recognized. | |
722 | |
723 @table @code | |
724 @item :size | |
725 The width of the editable field.@* | |
726 By default the field will reach to the end of the line. | |
727 | |
728 @item :value-face | |
729 Face used for highlighting the editable field. Default is | |
730 @code{widget-field-face}. | |
731 | |
732 @item :secret | |
733 Character used to display the value. You can set this to e.g. @code{?*} | |
734 if the field contains a password or other secret information. By | |
735 default, the value is not secret. | |
736 | |
737 @item :valid-regexp | |
738 By default the @code{:validate} function will match the content of the | |
739 field with the value of this attribute. The default value is @code{""} | |
740 which matches everything. | |
741 | |
742 @item :keymap | |
743 Keymap used in the editable field. The default value is | |
744 @code{widget-field-keymap}, which allows you to use all the normal | |
745 editing commands, even if the buffers major mode suppress some of them. | |
746 Pressing return invokes the function specified by @code{:action}. | |
747 @end table | |
748 | |
749 @node text, menu-choice, editable-field, Basic Types | |
750 @comment node-name, next, previous, up | |
751 @subsection The @code{text} Widget | |
752 | |
753 This is just like @code{editable-field}, but intended for multiline text | |
754 fields. The default @code{:keymap} is @code{widget-text-keymap}, which | |
755 does not rebind the return key. | |
756 | |
757 @node menu-choice, radio-button-choice, text, Basic Types | |
758 @comment node-name, next, previous, up | |
759 @subsection The @code{menu-choice} Widget | |
760 | |
761 Syntax: | |
762 | |
763 @example | |
764 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... ) | |
765 @end example | |
766 | |
767 The @var{type} arguments represents each possible choice. The widgets | |
768 value of will be the value of the chosen @var{type} argument. This | |
769 widget will match any value that matches at least one of the specified | |
770 @var{type} arguments. | |
771 | |
772 @table @code | |
773 @item :void | |
774 Widget type used as a fallback when the value does not match any of the | |
775 specified @var{type} arguments. | |
776 | |
777 @item :case-fold | |
778 Set this to nil if you don't want to ignore case when prompting for a | |
779 choice through the minibuffer. | |
780 | |
781 @item :children | |
782 A list whose car is the widget representing the currently chosen type in | |
783 the buffer. | |
784 | |
785 @item :choice | |
786 The current chosen type | |
787 | |
788 @item :args | |
789 The list of types. | |
790 @end table | |
791 | |
792 @node radio-button-choice, item, menu-choice, Basic Types | |
793 @comment node-name, next, previous, up | |
794 @subsection The @code{radio-button-choice} Widget | |
795 | |
796 Syntax: | |
797 | |
798 @example | |
799 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... ) | |
800 @end example | |
801 | |
802 The @var{type} arguments represents each possible choice. The widgets | |
803 value of will be the value of the chosen @var{type} argument. This | |
804 widget will match any value that matches at least one of the specified | |
805 @var{type} arguments. | |
806 | |
807 The following extra properties are recognized. | |
808 | |
809 @table @code | |
810 @item :entry-format | |
811 This string will be inserted for each entry in the list. | |
812 The following @samp{%} escapes are available: | |
813 @table @samp | |
814 @item %v | |
815 Replaced with the buffer representation of the @var{type} widget. | |
816 @item %b | |
817 Replace with the radio button. | |
818 @item %% | |
819 Insert a literal @samp{%}. | |
820 @end table | |
821 | |
822 @item button-args | |
823 A list of keywords to pass to the radio buttons. Useful for setting | |
824 e.g. the @samp{:help-echo} for each button. | |
825 | |
826 @item :buttons | |
827 The widgets representing the radio buttons. | |
828 | |
829 @item :children | |
830 The widgets representing each type. | |
831 | |
832 @item :choice | |
833 The current chosen type | |
834 | |
835 @item :args | |
836 The list of types. | |
837 @end table | |
838 | |
839 You can add extra radio button items to a @code{radio-button-choice} | |
840 widget after it has been created with the function | |
841 @code{widget-radio-add-item}. | |
842 | |
843 @defun widget-radio-add-item widget type | |
844 Add to @code{radio-button-choice} widget @var{widget} a new radio button item of type | |
845 @var{type}. | |
846 @end defun | |
847 | |
848 Please note that such items added after the @code{radio-button-choice} | |
849 widget has been created will @strong{not} be properly destructed when | |
850 you call @code{widget-delete}. | |
851 | |
852 @node item, choice-item, radio-button-choice, Basic Types | |
853 @comment node-name, next, previous, up | |
854 @subsection The @code{item} Widget | |
855 | |
856 Syntax: | |
857 | |
858 @example | |
859 ITEM ::= (item [KEYWORD ARGUMENT]... VALUE) | |
860 @end example | |
861 | |
862 The @var{value}, if present, is used to initialize the @code{:value} | |
863 property. The value should be a string, which will be inserted in the | |
864 buffer. This widget will only match the specified value. | |
865 | |
866 @node choice-item, toggle, item, Basic Types | |
867 @comment node-name, next, previous, up | |
868 @subsection The @code{choice-item} Widget | |
869 | |
870 Syntax: | |
871 | |
872 @example | |
873 ITEM ::= (choice-item [KEYWORD ARGUMENT]... VALUE) | |
874 @end example | |
875 | |
876 The @var{value}, if present, is used to initialize the @code{:value} | |
877 property. The value should be a string, which will be inserted in the | |
878 buffer as a button. Activating the button of a @code{choice-item} is | |
879 equivalent to activating the parent widget. This widget will only match | |
880 the specified value. | |
881 | |
882 @node toggle, checkbox, choice-item, Basic Types | |
883 @comment node-name, next, previous, up | |
884 @subsection The @code{toggle} Widget | |
885 | |
886 Syntax: | |
887 | |
888 @example | |
889 TYPE ::= (toggle [KEYWORD ARGUMENT]...) | |
890 @end example | |
891 | |
892 The widget has two possible states, `on' and `off', which corresponds to | |
893 a @code{t} or @code{nil} value. | |
894 | |
895 The following extra properties are recognized. | |
896 | |
897 @table @code | |
898 @item :on | |
899 String representing the `on' state. By default the string @samp{on}. | |
900 @item :off | |
901 String representing the `off' state. By default the string @samp{off}. | |
902 @item :on-glyph | |
903 Name of a glyph to be used instead of the `:on' text string, on emacsen | |
904 that supports it. | |
905 @item :off-glyph | |
906 Name of a glyph to be used instead of the `:off' text string, on emacsen | |
907 that supports it. | |
908 @end table | |
909 | |
910 @node checkbox, checklist, toggle, Basic Types | |
911 @comment node-name, next, previous, up | |
912 @subsection The @code{checkbox} Widget | |
913 | |
914 The widget has two possible states, `selected' and `unselected', which | |
915 corresponds to a @code{t} or @code{nil} value. | |
916 | |
917 Syntax: | |
918 | |
919 @example | |
920 TYPE ::= (checkbox [KEYWORD ARGUMENT]...) | |
921 @end example | |
922 | |
923 @node checklist, editable-list, checkbox, Basic Types | |
924 @comment node-name, next, previous, up | |
925 @subsection The @code{checklist} Widget | |
926 | |
927 Syntax: | |
928 | |
929 @example | |
930 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... ) | |
931 @end example | |
932 | |
933 The @var{type} arguments represents each checklist item. The widgets | |
934 value of will be a list containing the value of each ticked @var{type} | |
935 argument. The checklist widget will match a list whose elements all | |
936 matches at least one of the specified @var{type} arguments. | |
937 | |
938 The following extra properties are recognized. | |
939 | |
940 @table @code | |
941 @item :entry-format | |
942 This string will be inserted for each entry in the list. | |
943 The following @samp{%} escapes are available: | |
944 @table @samp | |
945 @item %v | |
946 Replaced with the buffer representation of the @var{type} widget. | |
947 @item %b | |
948 Replace with the checkbox. | |
949 @item %% | |
950 Insert a literal @samp{%}. | |
951 @end table | |
952 | |
953 @item :greedy | |
954 Usually, a checklist will only match if the items are in the exact | |
955 sequence given in the specification. By setting @code{:greedy} to | |
956 non-nil, it will allow the items to come in any sequence. However, if | |
957 you extract the value they will be in the sequence given in the | |
958 checklist. I.e. the original sequence is forgotten. | |
959 | |
960 @item button-args | |
961 A list of keywords to pass to the checkboxes. Useful for setting | |
962 e.g. the @samp{:help-echo} for each checkbox. | |
963 | |
964 @item :buttons | |
965 The widgets representing the checkboxes. | |
966 | |
967 @item :children | |
968 The widgets representing each type. | |
969 | |
970 @item :args | |
971 The list of types. | |
972 @end table | |
973 | |
974 @node editable-list, group, checklist, Basic Types | |
975 @comment node-name, next, previous, up | |
976 @subsection The @code{editable-list} Widget | |
977 | |
978 Syntax: | |
979 | |
980 @example | |
981 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE) | |
982 @end example | |
983 | |
984 The value is a list, where each member represents one widget of type | |
985 @var{type}. | |
986 | |
987 The following extra properties are recognized. | |
988 | |
989 @table @code | |
990 @item :entry-format | |
991 This string will be inserted for each entry in the list. | |
992 The following @samp{%} escapes are available: | |
993 @table @samp | |
994 @item %v | |
995 This will be replaced with the buffer representation of the @var{type} | |
996 widget. | |
997 @item %i | |
998 Insert the @b{[INS]} button. | |
999 @item %d | |
1000 Insert the @b{[DEL]} button. | |
1001 @item %% | |
1002 Insert a literal @samp{%}. | |
1003 @end table | |
1004 | |
1005 @item :insert-button-args | |
1006 A list of keyword arguments to pass to the insert buttons. | |
1007 | |
1008 @item :delete-button-args | |
1009 A list of keyword arguments to pass to the delete buttons. | |
1010 | |
1011 @item :append-button-args | |
1012 A list of keyword arguments to pass to the trailing insert button. | |
1013 | |
1014 | |
1015 @item :buttons | |
1016 The widgets representing the insert and delete buttons. | |
1017 | |
1018 @item :children | |
1019 The widgets representing the elements of the list. | |
1020 | |
1021 @item :args | |
1022 List whose car is the type of the list elements. | |
1023 | |
1024 @end table | |
1025 | |
1026 @node group, , editable-list, Basic Types | |
1027 @comment node-name, next, previous, up | |
1028 @subsection The @code{group} Widget | |
1029 | |
1030 This widget simply group other widget together. | |
1031 | |
1032 Syntax: | |
1033 | |
1034 @example | |
1035 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...) | |
1036 @end example | |
1037 | |
1038 The value is a list, with one member for each @var{type}. | |
1039 | |
1040 @node Sexp Types, Widget Properties, Basic Types, Top | |
1041 @comment | |
1042 @section Sexp Types | |
1043 | |
1044 A number of widgets for editing s-expressions (lisp types) are also | |
1045 available. These basically fall in the following categories. | |
1046 | |
1047 @menu | |
1048 * constants:: | |
1049 * generic:: | |
1050 * atoms:: | |
1051 * composite:: | |
1052 @end menu | |
1053 | |
1054 @node constants, generic, Sexp Types, Sexp Types | |
1055 @comment node-name, next, previous, up | |
1056 @subsection The Constant Widgets. | |
1057 | |
1058 The @code{const} widget can contain any lisp expression, but the user is | |
1059 prohibited from editing edit it, which is mainly useful as a component | |
1060 of one of the composite widgets. | |
1061 | |
1062 The syntax for the @code{const} widget is | |
1063 | |
1064 @example | |
1065 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ]) | |
1066 @end example | |
1067 | |
1068 The @var{value}, if present, is used to initialize the @code{:value} | |
1069 property and can be any s-expression. | |
1070 | |
1071 @deffn Widget const | |
1072 This will display any valid s-expression in an immutable part of the | |
1073 buffer. | |
1074 @end deffn | |
1075 | |
1076 There are two variations of the @code{const} widget, namely | |
1077 @code{variable-item} and @code{function-item}. These should contain a | |
1078 symbol with a variable or function binding. The major difference from | |
1079 the @code{const} widget is that they will allow the user to see the | |
1080 variable or function documentation for the symbol. | |
1081 | |
1082 @deffn Widget variable-item | |
1083 An immutable symbol that is bound as a variable. | |
1084 @end deffn | |
1085 | |
1086 @deffn Widget function-item | |
1087 An immutable symbol that is bound as a function. | |
1088 @end deffn | |
1089 | |
1090 @node generic, atoms, constants, Sexp Types | |
1091 @comment node-name, next, previous, up | |
1092 @subsection Generic Sexp Widget. | |
1093 | |
1094 The @code{sexp} widget can contain any lisp expression, and allows the | |
1095 user to edit it inline in the buffer. | |
1096 | |
1097 The syntax for the @code{sexp} widget is | |
1098 | |
1099 @example | |
1100 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ]) | |
1101 @end example | |
1102 | |
1103 @deffn Widget sexp | |
1104 This will allow you to edit any valid s-expression in an editable buffer | |
1105 field. | |
1106 | |
1107 The @code{sexp} widget takes the same keyword arguments as the | |
1108 @code{editable-field} widget. | |
1109 @end deffn | |
1110 | |
1111 @node atoms, composite, generic, Sexp Types | |
1112 @comment node-name, next, previous, up | |
1113 @subsection Atomic Sexp Widgets. | |
1114 | |
1115 The atoms are s-expressions that does not consist of other | |
1116 s-expressions. A string is an atom, while a list is a composite type. | |
1117 You can edit the value of an atom with the following widgets. | |
1118 | |
1119 The syntax for all the atoms are | |
1120 | |
1121 @example | |
1122 TYPE ::= (NAME [KEYWORD ARGUMENT]... [ VALUE ]) | |
1123 @end example | |
1124 | |
1125 The @var{value}, if present, is used to initialize the @code{:value} | |
1126 property and must be an expression of the same type as the widget. | |
1127 I.e. the string widget can only be initialized with a string. | |
1128 | |
1129 All the atom widgets take the same keyword arguments as the | |
1130 @code{editable-field} widget. | |
1131 | |
1132 @deffn Widget string | |
1133 Allows you to edit a string in an editable field. | |
1134 @end deffn | |
1135 | |
1136 @deffn Widget regexp | |
1137 Allows you to edit a regular expression in an editable field. | |
1138 @end deffn | |
1139 | |
1140 @deffn Widget character | |
1141 Allows you to enter a character in an editable field. | |
1142 @end deffn | |
1143 | |
1144 @deffn Widget file | |
1145 Allows you to edit a file name in an editable field. If you invoke | |
1146 the tag button, you can edit the file name in the mini-buffer with | |
1147 completion. | |
1148 | |
1149 Keywords: | |
1150 @table @code | |
1151 @item :must-match | |
1152 If this is set to non-nil, only existing file names will be allowed in | |
1153 the minibuffer. | |
1154 @end table | |
1155 @end deffn | |
1156 | |
1157 @deffn Widget directory | |
1158 Allows you to edit a directory name in an editable field. | |
1159 Similar to the @code{file} widget. | |
1160 @end deffn | |
1161 | |
1162 @deffn Widget symbol | |
1163 Allows you to edit a lisp symbol in an editable field. | |
1164 @end deffn | |
1165 | |
1166 @deffn Widget function | |
1167 Allows you to edit a lambda expression, or a function name with completion. | |
1168 @end deffn | |
1169 | |
1170 @deffn Widget variable | |
1171 Allows you to edit a variable name, with completion. | |
1172 @end deffn | |
1173 | |
1174 @deffn Widget integer | |
1175 Allows you to edit an integer in an editable field. | |
1176 @end deffn | |
1177 | |
1178 @deffn Widget number | |
1179 Allows you to edit a number in an editable field. | |
1180 @end deffn | |
1181 | |
1182 @deffn Widget boolean | |
1183 Allows you to edit a boolean. In lisp this means a variable which is | |
1184 either nil meaning false, or non-nil meaning true. | |
1185 @end deffn | |
1186 | |
1187 | |
1188 @node composite, , atoms, Sexp Types | |
1189 @comment node-name, next, previous, up | |
1190 @subsection Composite Sexp Widgets. | |
1191 | |
1192 The syntax for the composite are | |
1193 | |
1194 @example | |
1195 TYPE ::= (NAME [KEYWORD ARGUMENT]... COMPONENT...) | |
1196 @end example | |
1197 | |
1198 Where each @var{component} must be a widget type. Each component widget | |
1199 will be displayed in the buffer, and be editable to the user. | |
1200 | |
1201 @deffn Widget cons | |
1202 The value of a @code{cons} widget is a cons-cell where the car is the | |
1203 value of the first component and the cdr is the value of the second | |
1204 component. There must be exactly two components. | |
1205 @end deffn | |
1206 | |
1207 @deffn Widget list | |
1208 The value of a @code{list} widget is a list containing the value of | |
1209 each of its component. | |
1210 @end deffn | |
1211 | |
1212 @deffn Widget vector | |
1213 The value of a @code{vector} widget is a vector containing the value of | |
1214 each of its component. | |
1215 @end deffn | |
1216 | |
1217 The above suffice for specifying fixed size lists and vectors. To get | |
1218 variable length lists and vectors, you can use a @code{choice}, | |
1219 @code{set} or @code{repeat} widgets together with the @code{:inline} | |
1220 keywords. If any component of a composite widget has the @code{:inline} | |
1221 keyword set, its value must be a list which will then be spliced into | |
1222 the composite. For example, to specify a list whose first element must | |
1223 be a file name, and whose remaining arguments should either by the | |
1224 symbol @code{t} or two files, you can use the following widget | |
1225 specification: | |
1226 | |
1227 @example | |
1228 (list file | |
1229 (choice (const t) | |
1230 (list :inline t | |
1231 :value ("foo" "bar") | |
1232 string string))) | |
1233 @end example | |
1234 | |
1235 The value of a widget of this type will either have the form | |
1236 @samp{(file t)} or @code{(file string string)}. | |
1237 | |
1238 This concept of inline is probably hard to understand. It was certainly | |
1239 hard to implement so instead of confuse you more by trying to explain it | |
1240 here, I'll just suggest you meditate over it for a while. | |
1241 | |
1242 @deffn Widget choice | |
1243 Allows you to edit a sexp which may have one of fixed set of types. It | |
1244 is currently implemented with the @code{choice-menu} basic widget, and | |
1245 has a similar syntax. | |
1246 @end deffn | |
1247 | |
1248 @deffn Widget set | |
1249 Allows you to specify a type which must be a list whose elements all | |
1250 belong to given set. The elements of the list is not significant. This | |
1251 is implemented on top of the @code{checklist} basic widget, and has a | |
1252 similar syntax. | |
1253 @end deffn | |
1254 | |
1255 @deffn Widget repeat | |
1256 Allows you to specify a variable length list whose members are all of | |
1257 the same type. Implemented on top of the `editable-list' basic widget, | |
1258 and has a similar syntax. | |
1259 @end deffn | |
1260 | |
1261 @node Widget Properties, Defining New Widgets, Sexp Types, Top | |
1262 @comment node-name, next, previous, up | |
1263 @section Properties | |
1264 | |
1265 You can examine or set the value of a widget by using the widget object | |
1266 that was returned by @code{widget-create}. | |
1267 | |
1268 @defun widget-value widget | |
1269 Return the current value contained in @var{widget}. | |
1270 It is an error to call this function on an uninitialized widget. | |
1271 @end defun | |
1272 | |
1273 @defun widget-value-set widget value | |
1274 Set the value contained in @var{widget} to @var{value}. | |
1275 It is an error to call this function with an invalid @var{value}. | |
1276 @end defun | |
1277 | |
1278 @strong{Important:} You @emph{must} call @code{widget-setup} after | |
1279 modifying the value of a widget before the user is allowed to edit the | |
1280 widget again. It is enough to call @code{widget-setup} once if you | |
1281 modify multiple widgets. This is currently only necessary if the widget | |
1282 contains an editing field, but may be necessary for other widgets in the | |
1283 future. | |
1284 | |
1285 If your application needs to associate some information with the widget | |
1286 objects, for example a reference to the item being edited, it can be | |
1287 done with @code{widget-put} and @code{widget-get}. The property names | |
1288 must begin with a @samp{:}. | |
1289 | |
1290 @defun widget-put widget property value | |
1291 In @var{widget} set @var{property} to @var{value}. | |
1292 @var{property} should be a symbol, while @var{value} can be anything. | |
1293 @end defun | |
1294 | |
1295 @defun widget-get widget property | |
1296 In @var{widget} return the value for @var{property}. | |
1297 @var{property} should be a symbol, the value is what was last set by | |
1298 @code{widget-put} for @var{property}. | |
1299 @end defun | |
1300 | |
1301 @defun widget-member widget property | |
1302 Non-nil if @var{widget} has a value (even nil) for property @var{property}. | |
1303 @end defun | |
1304 | |
1305 Occasionally it can be useful to know which kind of widget you have, | |
1306 i.e. the name of the widget type you gave when the widget was created. | |
1307 | |
1308 @defun widget-type widget | |
1309 Return the name of @var{widget}, a symbol. | |
1310 @end defun | |
1311 | |
1312 Widgets can be in two states: active, which means they are modifiable by | |
1313 the user, or inactive, which means they cannot be modified by the user. | |
1314 You can query or set the state with the following code: | |
1315 | |
1316 @lisp | |
1317 ;; Examine if @var{widget} is active or not. | |
1318 (if (widget-apply @var{widget} :active) | |
1319 (message "Widget is active.") | |
1320 (message "Widget is inactive.") | |
1321 | |
1322 ;; Make @var{widget} inactive. | |
1323 (widget-apply @var{widget} :deactivate) | |
1324 | |
1325 ;; Make @var{widget} active. | |
1326 (widget-apply @var{widget} :activate) | |
1327 @end lisp | |
1328 | |
1329 A widget is inactive if itself, or any of its ancestors (found by | |
1330 following the @code{:parent} link) have been deactivated. To make sure | |
1331 a widget is really active, you must therefore activate both itself, and | |
1332 all its ancestors. | |
1333 | |
1334 @lisp | |
1335 (while widget | |
1336 (widget-apply widget :activate) | |
1337 (setq widget (widget-get widget :parent))) | |
1338 @end lisp | |
1339 | |
1340 You can check if a widget has been made inactive by examining the value | |
1341 of @code{:inactive} keyword. If this is non-nil, the widget itself has | |
1342 been deactivated. This is different from using the @code{:active} | |
1343 keyword, in that the later tell you if the widget @strong{or} any of its | |
1344 ancestors have been deactivated. Do not attempt to set the | |
1345 @code{:inactive} keyword directly. Use the @code{:activate} | |
1346 @code{:deactivated} keywords instead. | |
1347 | |
1348 | |
1349 @node Defining New Widgets, Widget Browser, Widget Properties, Top | |
1350 @comment node-name, next, previous, up | |
1351 @section Defining New Widgets | |
1352 | |
1353 You can define specialized widgets with @code{define-widget}. It allows | |
1354 you to create a shorthand for more complex widgets, including specifying | |
1355 component widgets and default new default values for the keyword | |
1356 arguments. | |
1357 | |
1358 @defun widget-define name class doc &rest args | |
1359 Define a new widget type named @var{name} from @code{class}. | |
1360 | |
1361 @var{name} and class should both be symbols, @code{class} should be one | |
1362 of the existing widget types. | |
1363 | |
1364 The third argument @var{DOC} is a documentation string for the widget. | |
1365 | |
1366 After the new widget has been defined, the following two calls will | |
1367 create identical widgets: | |
1368 | |
1369 @itemize @bullet | |
1370 @item | |
1371 @lisp | |
1372 (widget-create @var{name}) | |
1373 @end lisp | |
1374 | |
1375 @item | |
1376 @lisp | |
1377 (apply widget-create @var{class} @var{args}) | |
1378 @end lisp | |
1379 @end itemize | |
1380 | |
1381 @end defun | |
1382 | |
1383 Using @code{widget-define} does just store the definition of the widget | |
1384 type in the @code{widget-type} property of @var{name}, which is what | |
1385 @code{widget-create} uses. | |
1386 | |
1387 If you just want to specify defaults for keywords with no complex | |
1388 conversions, you can use @code{identity} as your conversion function. | |
1389 | |
1390 The following additional keyword arguments are useful when defining new | |
1391 widgets: | |
1392 @table @code | |
1393 @item :convert-widget | |
1394 Function to convert a widget type before creating a widget of that | |
1395 type. It takes a widget type as an argument, and returns the converted | |
1396 widget type. When a widget is created, this function is called for the | |
1397 widget type and all the widgets parent types, most derived first. | |
1398 | |
1399 The following predefined functions can be used here: | |
1400 | |
1401 @defun widget-types-convert-widget widget | |
1402 Convert @code{:args} as widget types in @var{widget}. | |
1403 @end defun | |
1404 | |
1405 @defun widget-value-convert-widget widget | |
1406 Initialize @code{:value} from @code{:args} in @var{widget}. | |
1407 @end defun | |
1408 | |
1409 @item :value-to-internal | |
1410 Function to convert the value to the internal format. The function | |
1411 takes two arguments, a widget and an external value, and returns the | |
1412 internal value. The function is called on the present @code{:value} | |
1413 when the widget is created, and on any value set later with | |
1414 @code{widget-value-set}. | |
1415 | |
1416 @item :value-to-external | |
1417 Function to convert the value to the external format. The function | |
1418 takes two arguments, a widget and an internal value, and returns the | |
1419 internal value. The function is called on the present @code{:value} | |
1420 when the widget is created, and on any value set later with | |
1421 @code{widget-value-set}. | |
1422 | |
1423 @item :create | |
1424 Function to create a widget from scratch. The function takes one | |
1425 argument, a widget type, and create a widget of that type, insert it in | |
1426 the buffer, and return a widget object. | |
1427 | |
1428 @item :delete | |
1429 Function to delete a widget. The function takes one argument, a widget, | |
1430 and should remove all traces of the widget from the buffer. | |
1431 | |
1432 @item :value-create | |
1433 Function to expand the @samp{%v} escape in the format string. It will | |
1434 be called with the widget as its argument. Should | |
1435 insert a representation of the widgets value in the buffer. | |
1436 | |
1437 @item :value-delete | |
1438 Should remove the representation of the widgets value from the buffer. | |
1439 It will be called with the widget as its argument. It doesn't have to | |
1440 remove the text, but it should release markers and delete nested widgets | |
1441 if such has been used. | |
1442 | |
1443 The following predefined function can be used here: | |
1444 | |
1445 @defun widget-children-value-delete widget | |
1446 Delete all @code{:children} and @code{:buttons} in @var{widget}. | |
1447 @end defun | |
1448 | |
1449 @item :value-get | |
1450 Function to extract the value of a widget, as it is displayed in the | |
1451 buffer. | |
1452 | |
1453 The following predefined function can be used here: | |
1454 | |
1455 @defun widget-value-value-get widget | |
1456 Return the @code{:value} property of @var{widget}. | |
1457 @end defun | |
1458 | |
1459 @item :format-handler | |
1460 Function to handle unknown @samp{%} escapes in the format string. It | |
1461 will be called with the widget and the escape character as arguments. | |
1462 You can set this to allow your widget to handle non-standard escapes. | |
1463 | |
1464 You should end up calling @code{widget-default-format-handler} to handle | |
1465 unknown escape sequences, which will handle the @samp{%h} and any future | |
1466 escape sequences, as well as give an error for unknown escapes. | |
1467 | |
1468 @item :action | |
1469 Function to handle user initiated events. By default, @code{:notify} | |
1470 the parent. | |
1471 | |
1472 The following predefined function can be used here: | |
1473 | |
1474 @defun widget-parent-action widget &optional event | |
1475 Tell @code{:parent} of @var{widget} to handle the @code{:action}.@* | |
1476 Optional @var{event} is the event that triggered the action. | |
1477 @end defun | |
1478 | |
1479 @item :prompt-value | |
1480 Function to prompt for a value in the minibuffer. The function should | |
1481 take four arguments, @var{widget}, @var{prompt}, @var{value}, and | |
1482 @var{unbound} and should return a value for widget entered by the user. | |
1483 @var{prompt} is the prompt to use. @var{value} is the default value to | |
1484 use, unless @var{unbound} is non-nil in which case there are no default | |
1485 value. The function should read the value using the method most natural | |
1486 for this widget, and does not have to check that it matches. | |
1487 @end table | |
1488 | |
1489 If you want to define a new widget from scratch, use the @code{default} | |
1490 widget as its base. | |
1491 | |
1492 @deffn Widget default | |
1493 Widget used as a base for other widgets. | |
1494 | |
1495 It provides most of the functionality that is referred to as ``by | |
1496 default'' in this text. | |
1497 @end deffn | |
1498 | |
1499 @node Widget Browser, Widget Minor Mode, Defining New Widgets, Top | |
1500 @comment node-name, next, previous, up | |
1501 @section Widget Browser | |
1502 | |
1503 There is a separate package to browse widgets. This is intended to help | |
1504 programmers who want to examine the content of a widget. The browser | |
1505 shows the value of each keyword, but uses links for certain keywords | |
1506 such as `:parent', which avoids printing cyclic structures. | |
1507 | |
1508 @deffn Command widget-browse WIDGET | |
1509 Create a widget browser for WIDGET. | |
1510 When called interactively, prompt for WIDGET. | |
1511 @end deffn | |
1512 | |
1513 @deffn Command widget-browse-other-window WIDGET | |
1514 Create a widget browser for WIDGET and show it in another window. | |
1515 When called interactively, prompt for WIDGET. | |
1516 @end deffn | |
1517 | |
1518 @deffn Command widget-browse-at POS | |
1519 Create a widget browser for the widget at POS. | |
1520 When called interactively, use the position of point. | |
1521 @end deffn | |
1522 | |
1523 @node Widget Minor Mode, Utilities, Widget Browser, Top | |
1524 @comment node-name, next, previous, up | |
1525 @section Widget Minor Mode | |
1526 | |
1527 There is a minor mode for manipulating widgets in major modes that | |
1528 doesn't provide any support for widgets themselves. This is mostly | |
1529 intended to be useful for programmers doing experiments. | |
1530 | |
1531 @deffn Command widget-minor-mode | |
1532 Toggle minor mode for traversing widgets. | |
1533 With arg, turn widget mode on if and only if arg is positive. | |
1534 @end deffn | |
1535 | |
1536 @defvar widget-minor-mode-keymap | |
1537 Keymap used in @code{widget-minor-mode}. | |
1538 @end defvar | |
1539 | |
1540 @node Utilities, Widget Wishlist, Widget Minor Mode, Top | |
1541 @comment node-name, next, previous, up | |
1542 @section Utilities. | |
1543 | |
1544 @defun widget-prompt-value widget prompt [ value unbound ] | |
1545 Prompt for a value matching @var{widget}, using @var{prompt}.@* | |
1546 The current value is assumed to be @var{value}, unless @var{unbound} is | |
1547 non-nil.@refill | |
1548 @end defun | |
1549 | |
1550 @defun widget-get-sibling widget | |
1551 Get the item @var{widget} is assumed to toggle.@* | |
1552 This is only meaningful for radio buttons or checkboxes in a list. | |
1553 @end defun | |
1554 | |
1555 @node Widget Wishlist, , Utilities, Top | |
1556 @comment node-name, next, previous, up | |
1557 @section Wishlist | |
1558 | |
1559 @itemize @bullet | |
1560 @item | |
1561 It should be possible to add or remove items from a list with @kbd{C-k} | |
1562 and @kbd{C-o} (suggested by @sc{rms}). | |
1563 | |
1564 @item | |
1565 The @samp{[INS]} and @samp{[DEL]} buttons should be replaced by a single | |
1566 dash (@samp{-}). The dash should be a button that, when invoked, ask | |
1567 whether you want to add or delete an item (@sc{rms} wanted to git rid of | |
1568 the ugly buttons, the dash is my idea). | |
1569 | |
1570 @item | |
1571 The @code{menu-choice} tag should be prettier, something like the abbreviated | |
1572 menus in Open Look. | |
1573 | |
1574 @item | |
1575 Finish @code{:tab-order}. | |
1576 | |
1577 @item | |
1578 Make indentation work with glyphs and proportional fonts. | |
1579 | |
1580 @item | |
1581 Add commands to show overview of object and class hierarchies to the | |
1582 browser. | |
1583 | |
1584 @item | |
1585 Find a way to disable mouse highlight for inactive widgets. | |
1586 | |
1587 @item | |
1588 Find a way to make glyphs look inactive. | |
1589 | |
1590 @item | |
1591 Add @code{property-list} widget. | |
1592 | |
1593 @item | |
1594 Add @code{association-list} widget. | |
1595 | |
1596 @item | |
1597 Add @code{key-binding} widget. | |
1598 | |
1599 @item | |
1600 Add @code{widget} widget for editing widget specifications. | |
1601 | |
1602 @item | |
1603 Find clean way to implement variable length list. | |
1604 See @code{TeX-printer-list} for an explanation. | |
1605 | |
1606 @item | |
1607 @kbd{C-h} in @code{widget-prompt-value} should give type specific help. | |
1608 | |
1609 @item | |
1610 A mailto widget. | |
1611 | |
1612 @item | |
1613 @kbd{C-e e} in a fixed size field should go to the end of the text in | |
1614 the field, not the end of the field itself. | |
1615 | |
1616 @item | |
1617 Use and overlay instead of markers to delimit the widget. Create | |
1618 accessors for the end points. | |
1619 | |
1620 @item | |
1621 Clicking on documentation links should call @code{describe-function} or | |
1622 @code{widget-browse-other-window} and friends directly, instead of going | |
1623 through @code{apropos}. If more than one function is valid for the | |
1624 symbol, it should pop up a menu. | |
1625 | |
1626 @end itemize | |
1627 | |
1628 @contents | |
1629 @bye |