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