diff options
| author | Mauro Aranda | 2023-09-02 07:55:12 -0300 |
|---|---|---|
| committer | Eli Zaretskii | 2023-09-02 14:25:04 +0300 |
| commit | 71a85e226687c3150179ca36ecd67ea2bb0cfd13 (patch) | |
| tree | 4249c015f6951c9ef6f427785c66d2fe71681459 | |
| parent | 2137fdfd55006598da70807361ac7b4b8e44ad22 (diff) | |
| download | emacs-71a85e226687c3150179ca36ecd67ea2bb0cfd13.tar.gz emacs-71a85e226687c3150179ca36ecd67ea2bb0cfd13.zip | |
A revision to the Widget manual
* doc/misc/widget.texi (Widgets Basics, Working with Widgets)
(Widgets and the Buffer, Widget Gallery, Customization): New chapters.
(Basic Types, Sexp Types): Demote to subsections.
(Widget Browser): Rename to Inspecting Widgets.
(Widget Properties): Remove.
(Top): Adapt menu to changes.
(Introduction): Rearrange text. Move warnings to a better place, and
user options to the Customization chapter.
(User Interface): Don't fully describe commands and customization
options here.
(Setting Up the Buffer): Expand on widget creation process and add
documentation for useful functions which deal with
creation/conversion.
(Defining New Widgets): Expand the documentation on define-widget.
All relevant properties moved to the description of the default
widget, in Widget Gallery.
(Utilities): Add some more useful functions not previously documented.
(Wishlist): Remove out-of-date items.
| -rw-r--r-- | doc/misc/widget.texi | 2467 |
1 files changed, 1914 insertions, 553 deletions
diff --git a/doc/misc/widget.texi b/doc/misc/widget.texi index 13b37ab5b54..eb411f29c5c 100644 --- a/doc/misc/widget.texi +++ b/doc/misc/widget.texi | |||
| @@ -49,14 +49,16 @@ modify this GNU manual.'' | |||
| 49 | * Introduction:: | 49 | * Introduction:: |
| 50 | * User Interface:: | 50 | * User Interface:: |
| 51 | * Programming Example:: | 51 | * Programming Example:: |
| 52 | * Widgets Basics:: | ||
| 52 | * Setting Up the Buffer:: | 53 | * Setting Up the Buffer:: |
| 53 | * Basic Types:: | 54 | * Working with Widgets:: |
| 54 | * Sexp Types:: | 55 | * Widgets and the Buffer:: |
| 55 | * Widget Properties:: | 56 | * Widget Gallery:: |
| 56 | * Defining New Widgets:: | 57 | * Defining New Widgets:: |
| 57 | * Widget Browser:: | 58 | * Inspecting Widgets:: |
| 58 | * Widget Minor Mode:: | 59 | * Widget Minor Mode:: |
| 59 | * Utilities:: | 60 | * Utilities:: |
| 61 | * Customization:: | ||
| 60 | * Widget Wishlist:: | 62 | * Widget Wishlist:: |
| 61 | * GNU Free Documentation License:: | 63 | * GNU Free Documentation License:: |
| 62 | * Index:: | 64 | * Index:: |
| @@ -68,7 +70,7 @@ modify this GNU manual.'' | |||
| 68 | Most graphical user interface toolkits provide a number of standard | 70 | Most graphical user interface toolkits provide a number of standard |
| 69 | user interface controls (sometimes known as ``widgets'' or ``gadgets''). | 71 | user interface controls (sometimes known as ``widgets'' or ``gadgets''). |
| 70 | Emacs doesn't really support anything like this, except for an | 72 | Emacs doesn't really support anything like this, except for an |
| 71 | incredibly powerful text ``widget.'' On the other hand, Emacs does | 73 | incredibly powerful text ``widget''. On the other hand, Emacs does |
| 72 | provide the necessary primitives to implement many other widgets | 74 | provide the necessary primitives to implement many other widgets |
| 73 | within a text buffer. The @code{widget} package simplifies this task. | 75 | within a text buffer. The @code{widget} package simplifies this task. |
| 74 | 76 | ||
| @@ -85,13 +87,13 @@ Like link, but intended for stand-alone buttons. | |||
| 85 | @item editable-field | 87 | @item editable-field |
| 86 | An editable text field. It can be either variable or fixed length. | 88 | An editable text field. It can be either variable or fixed length. |
| 87 | @item menu-choice | 89 | @item menu-choice |
| 88 | Allows the user to choose one of multiple options from a menu, each | 90 | Allows the user to choose one of multiple options from a menu, where |
| 89 | option is itself a widget. Only the selected option will be visible in | 91 | each option is itself a widget. Only the selected option is visible |
| 90 | the buffer. | 92 | in the buffer. |
| 91 | @item radio-button-choice | 93 | @item radio-button-choice |
| 92 | Allows the user to choose one of multiple options by activating radio | 94 | Allows the user to choose one of multiple options by activating radio |
| 93 | buttons. The options are implemented as widgets. All options will be | 95 | buttons. The options are implemented as widgets. All options are |
| 94 | visible in the buffer. | 96 | visible in the buffer, with the selected one marked as chosen. |
| 95 | @item item | 97 | @item item |
| 96 | A simple constant widget intended to be used in the @code{menu-choice} and | 98 | A simple constant widget intended to be used in the @code{menu-choice} and |
| 97 | @code{radio-button-choice} widgets. | 99 | @code{radio-button-choice} widgets. |
| @@ -137,9 +139,9 @@ Editing happens in the buffer, not in the mini-buffer. | |||
| 137 | Packages using the library get a uniform look, making them easier for | 139 | Packages using the library get a uniform look, making them easier for |
| 138 | the user to learn. | 140 | the user to learn. |
| 139 | @item | 141 | @item |
| 140 | As support for embedded graphics improve, the widget library will be | 142 | As support for embedded graphics improve, the Widget library will be |
| 141 | extended to use the GUI features. This means that your code using the | 143 | extended to use the GUI features. This means that your code using the |
| 142 | widget library will also use the new graphic features automatically. | 144 | Widget library will also use the new graphic features automatically. |
| 143 | @end enumerate | 145 | @end enumerate |
| 144 | 146 | ||
| 145 | @node User Interface | 147 | @node User Interface |
| @@ -201,12 +203,6 @@ middle of another field is prohibited. | |||
| 201 | 203 | ||
| 202 | Editable text fields are created by the @code{editable-field} widget. | 204 | Editable text fields are created by the @code{editable-field} widget. |
| 203 | 205 | ||
| 204 | @strong{Warning:} In an @code{editable-field} widget, the editable | ||
| 205 | field must not be adjacent to another widget---that won't work. | ||
| 206 | You must put some text in between. Either make this text part of | ||
| 207 | the @code{editable-field} widget itself, or insert it with | ||
| 208 | @code{widget-insert}. | ||
| 209 | |||
| 210 | The @code{:format} keyword is useful for generating the necessary | 206 | The @code{:format} keyword is useful for generating the necessary |
| 211 | text; for instance, if you give it a value of @code{"Name: %v "}, | 207 | text; for instance, if you give it a value of @code{"Name: %v "}, |
| 212 | the @samp{Name: } part will provide the necessary separating text | 208 | the @samp{Name: } part will provide the necessary separating text |
| @@ -215,17 +211,9 @@ separating text after the field. If you don't include the | |||
| 215 | @code{:size} keyword, the field will extend to the end of the | 211 | @code{:size} keyword, the field will extend to the end of the |
| 216 | line, and the terminating newline will provide separation after. | 212 | line, and the terminating newline will provide separation after. |
| 217 | 213 | ||
| 218 | @strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape | ||
| 219 | must be preceded by some other text in the @code{:format} string | ||
| 220 | (if specified). | ||
| 221 | |||
| 222 | The editing text fields are highlighted with the | 214 | The editing text fields are highlighted with the |
| 223 | @code{widget-field-face} face, making them easy to find. | 215 | @code{widget-field-face} face, making them easy to find. |
| 224 | 216 | ||
| 225 | @deffn Face widget-field-face | ||
| 226 | Face used for other editing fields. | ||
| 227 | @end deffn | ||
| 228 | |||
| 229 | @section Buttons | 217 | @section Buttons |
| 230 | 218 | ||
| 231 | @cindex widget buttons | 219 | @cindex widget buttons |
| @@ -233,24 +221,9 @@ Face used for other editing fields. | |||
| 233 | Some portions of the buffer have an associated @dfn{action}, which can | 221 | Some portions of the buffer have an associated @dfn{action}, which can |
| 234 | be @dfn{invoked} by a standard key or mouse command. These portions | 222 | be @dfn{invoked} by a standard key or mouse command. These portions |
| 235 | are called @dfn{buttons}. The default commands for activating a button | 223 | are called @dfn{buttons}. The default commands for activating a button |
| 236 | are: | 224 | are @code{widget-button-press} and @code{widget-button-click}. The |
| 237 | 225 | user typically interacts with the buttons with a key, like @key{RET}, | |
| 238 | @table @kbd | 226 | or with the mouse buttons. |
| 239 | @item @key{RET} | ||
| 240 | @deffn Command widget-button-press @var{pos} &optional @var{event} | ||
| 241 | Invoke the button at @var{pos}, defaulting to point. | ||
| 242 | If point is not located on a button, invoke the binding in | ||
| 243 | @code{widget-global-map} (by default the global map). | ||
| 244 | @end deffn | ||
| 245 | |||
| 246 | @kindex mouse-2 @r{(on button widgets}) | ||
| 247 | @item mouse-2 | ||
| 248 | @deffn Command widget-button-click @var{event} | ||
| 249 | Invoke the button at the location of the mouse pointer. If the mouse | ||
| 250 | pointer is located in an editable text field, invoke the binding in | ||
| 251 | @code{widget-global-map} (by default the global map). | ||
| 252 | @end deffn | ||
| 253 | @end table | ||
| 254 | 227 | ||
| 255 | There are several different kind of buttons, all of which are present in | 228 | There are several different kind of buttons, all of which are present in |
| 256 | the example: | 229 | the example: |
| @@ -286,33 +259,15 @@ main difference from the @code{link} widget is that the buttons will be | |||
| 286 | displayed as GUI buttons when possible. | 259 | displayed as GUI buttons when possible. |
| 287 | @end table | 260 | @end table |
| 288 | 261 | ||
| 289 | To make them easier to locate, buttons are emphasized in the buffer. | 262 | To make them easier to locate, buttons are emphasized in the buffer |
| 290 | 263 | with a distinctive face, like @code{widget-button-face} or | |
| 291 | @deffn Face widget-button-face | 264 | @code{widget-mouse-face}. |
| 292 | Face used for buttons. | ||
| 293 | @end deffn | ||
| 294 | |||
| 295 | @defopt widget-mouse-face | ||
| 296 | Face used for highlighting a button when the mouse pointer moves across | ||
| 297 | it. | ||
| 298 | @end defopt | ||
| 299 | 265 | ||
| 300 | @section Navigation | 266 | @section Navigation |
| 301 | 267 | ||
| 302 | You can use all the normal Emacs commands to move around in a form | 268 | You can use all the normal Emacs commands to move around in a form |
| 303 | buffer, plus you will have these additional commands: | 269 | buffer, plus you will have these additional commands to navigate from |
| 304 | 270 | widget to widget: @code{widget-forward} and @code{widget-backward}. | |
| 305 | @table @kbd | ||
| 306 | @item @key{TAB} | ||
| 307 | @deffn Command widget-forward &optional count | ||
| 308 | Move point @var{count} buttons or editing fields forward. | ||
| 309 | @end deffn | ||
| 310 | @item @kbd{M-@key{TAB}} | ||
| 311 | @itemx @kbd{S-@key{TAB}} | ||
| 312 | @deffn Command widget-backward &optional count | ||
| 313 | Move point @var{count} buttons or editing fields backward. | ||
| 314 | @end deffn | ||
| 315 | @end table | ||
| 316 | 271 | ||
| 317 | @node Programming Example | 272 | @node Programming Example |
| 318 | @chapter Programming Example | 273 | @chapter Programming Example |
| @@ -414,85 +369,598 @@ Interface}). | |||
| 414 | (widget-setup)) | 369 | (widget-setup)) |
| 415 | @end lisp | 370 | @end lisp |
| 416 | 371 | ||
| 372 | @node Widgets Basics | ||
| 373 | @chapter Widgets Basics | ||
| 374 | @cindex widget object | ||
| 375 | The Widget Library deals with widgets objects. A widget object has | ||
| 376 | properties whose value may be anything, be it numbers, strings, | ||
| 377 | symbols, functions, etc. Those properties are referred to as keywords | ||
| 378 | and are responsible for the way a widget is represented in a buffer, | ||
| 379 | and control the way a user or a program can interact with it. | ||
| 380 | |||
| 381 | @cindex widget inheritance | ||
| 382 | The library defines several widget types, and gives you a way to | ||
| 383 | define new types as well. In addition, widgets can derive from other | ||
| 384 | types, creating a sort of widget inheritance. In fact, all widgets | ||
| 385 | defined in the Widget Library share a common parent, the @dfn{default} | ||
| 386 | widget. In this manual, when we talk about a default behavior, we | ||
| 387 | usually mean the behavior as defined by this @code{default} widget. | ||
| 388 | @xref{Widget Gallery}, for a description of each defined widget. | ||
| 389 | |||
| 390 | Defining a new type that derives from a previous one is not mandatory | ||
| 391 | to create widgets that work very different from a specified type. | ||
| 392 | When creating a widget, you can override any default property, | ||
| 393 | including functions, that control the widget. That is, you can | ||
| 394 | specialize a widget on creation, without having to define it as a new | ||
| 395 | type of widget. | ||
| 396 | |||
| 397 | In addition to the function for defining a widget, this library | ||
| 398 | provides functions to create widgets, query and change its properties, | ||
| 399 | respond to user events and destroy them. The following sections | ||
| 400 | describe them. | ||
| 401 | |||
| 402 | @cindex widget value | ||
| 403 | One important property of a widget is its @dfn{value}. All widgets | ||
| 404 | may have a value, which is stored in a so-called @dfn{internal format}. | ||
| 405 | For the rest of Emacs, the widget presents its value in a so-called | ||
| 406 | @dfn{external format}. Both formats can be equal or different, and | ||
| 407 | each widget is responsible for defining how the conversion between | ||
| 408 | each format should happen. | ||
| 409 | |||
| 410 | @c FIXME: Briefly describe inline widgets? | ||
| 411 | @c The inline concept is described elsewhere, and it's difficult to | ||
| 412 | @c describe. | ||
| 413 | |||
| 414 | The value property is an important property for almost all widgets, | ||
| 415 | and perhaps more important for @code{editable-field} widgets. This | ||
| 416 | type of widgets allow the user to edit them via the usual editing | ||
| 417 | commands in Emacs. They can also be edited programmatically. | ||
| 418 | @strong{Important:} You @emph{must} call @code{widget-setup} after | ||
| 419 | modifying the value of a widget before the user is allowed to edit the | ||
| 420 | widget again. It is enough to call @code{widget-setup} once if you | ||
| 421 | modify multiple widgets. This is currently only necessary if the widget | ||
| 422 | contains an editing field, but may be necessary for other widgets in the | ||
| 423 | future. | ||
| 424 | |||
| 425 | @cindex widget properties | ||
| 426 | If your application needs to associate some information with the widget | ||
| 427 | objects, for example a reference to the item being edited, it can be | ||
| 428 | done with the @code{widget-put} and @code{widget-get} functions. The | ||
| 429 | property names, as shown, are keywords, so they must begin with a | ||
| 430 | @samp{:}. | ||
| 431 | |||
| 417 | @node Setting Up the Buffer | 432 | @node Setting Up the Buffer |
| 418 | @chapter Setting Up the Buffer | 433 | @chapter Setting Up the Buffer |
| 434 | @cindex widget creation, widget conversion | ||
| 435 | To show the widgets in a buffer, you have to create them. Widget | ||
| 436 | creation is actually a two-step process: conversion and creation per | ||
| 437 | se. With simple projects, usually the conversion step isn't really | ||
| 438 | important, and you only care about widget creation, so feel free to | ||
| 439 | skip the conversion description until you really need to know it. | ||
| 440 | |||
| 441 | Widget conversion is the process that involves taking a widget | ||
| 442 | specification and transforming it into a @dfn{widget} object, suitable | ||
| 443 | to be created, queried and manipulated with other widget functions. | ||
| 444 | Widget creation is the process that takes a widget object and actually | ||
| 445 | inserts it in the buffer. | ||
| 446 | |||
| 447 | The simplest function to create a widget is @code{widget-create}, which | ||
| 448 | gets a widget specification and returns a widget object. | ||
| 449 | |||
| 450 | @defun widget-create type [ keyword argument ]@dots{} args | ||
| 451 | Create and return a widget of type @var{type}, converting it. | ||
| 452 | |||
| 453 | @var{type} is a symbol that specifies a widget type. @var{keyword} | ||
| 454 | may be one of the properties supported by the widget type, and | ||
| 455 | @var{argument} specify the value for that property. These keyword | ||
| 456 | arguments can be used to overwrite the keyword arguments that are part | ||
| 457 | of @var{type} by default, as well as to provide other properties not | ||
| 458 | present in @var{type} by default. @var{args} holds additional | ||
| 459 | information for the creation of @var{type} and each widget type is | ||
| 460 | responsible for handling that information in a specific way. | ||
| 461 | |||
| 462 | The syntax for the @var{type} argument is described in @ref{Widget | ||
| 463 | Gallery}, and in more detail in every widget where it's relevant. | ||
| 464 | @end defun | ||
| 419 | 465 | ||
| 420 | Widgets are created with @code{widget-create}, which returns a | 466 | There are other functions for creating widgets, useful when you work |
| 421 | @dfn{widget} object. This object can be queried and manipulated by | 467 | with composite widgets. That is, widgets that are part of other |
| 422 | other widget functions, until it is deleted with @code{widget-delete}. | 468 | widgets. |
| 423 | After the widgets have been created, @code{widget-setup} must be called | ||
| 424 | to enable them. | ||
| 425 | 469 | ||
| 426 | @defun widget-create type [ keyword argument ]@dots{} | 470 | @defun widget-create-child-and-convert parent type &rest args |
| 427 | Create and return a widget of type @var{type}. | 471 | Create a widget of type @var{type} as a child of @var{parent}. |
| 428 | The syntax for the @var{type} argument is described in @ref{Basic Types}. | ||
| 429 | 472 | ||
| 430 | The keyword arguments can be used to overwrite the keyword arguments | 473 | Before creating it, converts @var{type} using the keyword arguments |
| 431 | that are part of @var{type}. | 474 | provided in @var{args}. |
| 475 | @c FIXME: Is this description useful? | ||
| 476 | Adds the @code{:indent} property, unless it is already present, and | ||
| 477 | sets it to the sum of the values of: @code{:indent} and @code{:offset} | ||
| 478 | from @var{parent} and @code{:extra-offset} from @var{type}. | ||
| 479 | |||
| 480 | Returns a widget object, with the property @code{:parent} set to | ||
| 481 | @var{PARENT}. | ||
| 432 | @end defun | 482 | @end defun |
| 433 | 483 | ||
| 434 | @defun widget-delete widget | 484 | @defun widget-create-child parent type |
| 435 | Delete @var{widget} and remove it from the buffer. | 485 | Create a widget of type @var{type} as a child of @var{parent}. |
| 486 | |||
| 487 | This function is like @code{widget-create-child-and-convert} but it | ||
| 488 | doesn't convert @var{type}, so it expects an already converted widget. | ||
| 489 | @end defun | ||
| 490 | |||
| 491 | @defun widget-create-child-value parent type value | ||
| 492 | Create a widget of type @var{type} as a child of @var{parent} with | ||
| 493 | value @var{value}. | ||
| 494 | |||
| 495 | This function is like @code{widget-create-child}, but it lets you | ||
| 496 | specify a value for the widget. | ||
| 497 | |||
| 498 | Converts @var{value} to the internal format, as specified by | ||
| 499 | @var{type}, and stores it into the @code{:value} property of @var{type}. | ||
| 500 | That means, @var{value} should be in the external format, as | ||
| 501 | specified by @var{type}. | ||
| 436 | @end defun | 502 | @end defun |
| 437 | 503 | ||
| 504 | All these creating functions described here use the function stored in | ||
| 505 | the @code{:create} property. So, to modify the creation logic for a | ||
| 506 | widget, you can provide a different @code{:create} function. | ||
| 507 | |||
| 508 | When you're done creating widgets and you're ready for the user to | ||
| 509 | interact with the buffer, use the function @code{widget-setup}. | ||
| 510 | |||
| 438 | @defun widget-setup | 511 | @defun widget-setup |
| 439 | Set up a buffer to support widgets. | 512 | Setup the current buffer, so that editable widgets can be edited. |
| 440 | 513 | ||
| 441 | This should be called after creating all the widgets and before allowing | 514 | This should be called after creating all the widgets and before allowing |
| 442 | the user to edit them. | 515 | the user to edit them. |
| 443 | @end defun | 516 | @end defun |
| 444 | 517 | ||
| 445 | If you want to insert text outside the widgets in the form, the | 518 | As mentioned, all these functions return a widget object. That widget |
| 446 | recommended way to do that is with @code{widget-insert}. | 519 | object can be queried and manipulated with widget functions that |
| 520 | take widgets as arguments, until deleting it with the widgets | ||
| 521 | functions available to delete widgets. Even if you don't save the | ||
| 522 | returned widget object, you still can interact programmatically with | ||
| 523 | the widget. @xref{Working with Widgets}. | ||
| 447 | 524 | ||
| 448 | @defun widget-insert | 525 | @defun widget-delete widget |
| 449 | Insert the arguments, either strings or characters, at point. | 526 | Delete the widget @var{widget} and remove it from the buffer. |
| 450 | The inserted text will be read-only. | ||
| 451 | @end defun | 527 | @end defun |
| 452 | 528 | ||
| 453 | There is a standard widget keymap which you might find useful. | 529 | @defun widget-children-value-delete widget |
| 530 | Delete all children and buttons in widget @var{widget}. | ||
| 454 | 531 | ||
| 455 | @findex widget-button-press | 532 | This function does not delete @var{widget} itself, only the widgets |
| 456 | @findex widget-button-click | 533 | stored in the @code{:children} and @code{:buttons} properties. It |
| 534 | also sets those properties to @code{nil}. | ||
| 535 | @end defun | ||
| 536 | |||
| 537 | As with the creation mechanism, the function stored in @code{:delete} | ||
| 538 | controls the deletion mechanism for a widget. | ||
| 539 | |||
| 540 | Additionally, the library provides a way to make a copy of a widget. | ||
| 541 | |||
| 542 | @defun widget-copy widget | ||
| 543 | Makes a copy of widget @var{widget} and returns it. | ||
| 544 | |||
| 545 | It uses the function stored in the @code{:copy} property of @var{widget} | ||
| 546 | and returns the widget that that function returns. | ||
| 547 | @end defun | ||
| 548 | |||
| 549 | As discussed, there is a conversion step when creating a widget. To | ||
| 550 | do the conversion without actually creating the widget, you can use | ||
| 551 | the @code{widget-convert} function. | ||
| 552 | |||
| 553 | @defun widget-convert type &rest args | ||
| 554 | Convert @var{type} to a widget object, using keyword arguments @var{args}. | ||
| 555 | |||
| 556 | Returns a widget object, suitable for creation. It calls the function | ||
| 557 | stored in the @code{:convert-widget} property, after putting into the | ||
| 558 | @code{:args} property the arguments that the widget in question needs. | ||
| 559 | If @var{type} has a @code{:value} property, either originally or after | ||
| 560 | doing the conversion, this function converts the value stored in | ||
| 561 | @code{:value} to the internal format, and stores it into @code{:value}. | ||
| 562 | @end defun | ||
| 563 | |||
| 564 | Apart from only creating widgets in the buffer, It's useful to have | ||
| 565 | plain text. For inserting text, the recommended way is with the | ||
| 566 | @code{widget-insert} function. | ||
| 567 | |||
| 568 | @defun widget-insert &rest args | ||
| 569 | Insert @var{args}, either strings or characters, at point. | ||
| 570 | |||
| 571 | Uses @code{insert} to perform the insertion, passing @var{args} as | ||
| 572 | argument. @xref{Insertion,,,elisp, the Emacs Lisp Reference Manual}, | ||
| 573 | for more information about @var{args}. | ||
| 574 | |||
| 575 | The resulting text will be read-only. | ||
| 576 | @end defun | ||
| 577 | |||
| 578 | @node Working with Widgets | ||
| 579 | @chapter Working with Widgets | ||
| 580 | This section covers the more important functions needed to query and | ||
| 581 | manipulate widgets in a generic way. Widgets may have additional | ||
| 582 | functions for interacting with them, those are described in the | ||
| 583 | description for each widget. @xref{Widget Gallery}. | ||
| 584 | |||
| 585 | @defun widgetp widget | ||
| 586 | Non-@code{nil} if @var{widget} is a widget. | ||
| 587 | @end defun | ||
| 588 | |||
| 589 | @defun widget-type widget | ||
| 590 | Return the type of widget @var{widget}, a symbol. | ||
| 591 | |||
| 592 | This function is useful to find out which kind of widget @var{widget} | ||
| 593 | represents, i.e., the name of the widget type when the widget | ||
| 594 | was created. | ||
| 595 | @end defun | ||
| 596 | |||
| 597 | @defun widget-member widget property | ||
| 598 | Non-@code{nil} if widget @var{widget} has a value (even @code{nil}) for | ||
| 599 | property @var{property}. | ||
| 600 | @end defun | ||
| 601 | |||
| 602 | @defun widget-get widget property | ||
| 603 | For widget @var{widget}, return the value of the property @var{property}. | ||
| 604 | |||
| 605 | @var{property} should be a keyword, and the value is what was last set by | ||
| 606 | @code{widget-put} for @var{property}. | ||
| 607 | @end defun | ||
| 608 | |||
| 609 | @defun widget-put widget property value | ||
| 610 | For widget @var{widget}, set the property @var{property} to @var{value}. | ||
| 611 | @var{property} should be a keyword, while @var{value} can be anything. | ||
| 612 | @end defun | ||
| 613 | |||
| 614 | @defun widget-at &optional pos | ||
| 615 | Return the widget at position @var{pos}, or at point if @var{pos} is @code{nil}. | ||
| 616 | @end defun | ||
| 617 | |||
| 618 | @defun widget-field-at pos | ||
| 619 | Return the widget field at position POS, or @code{nil} if there is none. | ||
| 620 | @end defun | ||
| 621 | |||
| 622 | @defun widget-apply widget property &rest args | ||
| 623 | Apply the function stored in @var{property} to @var{widget}, passing @var{args} | ||
| 624 | as additional arguments to the function. | ||
| 625 | |||
| 626 | Returns the result of that function call. | ||
| 627 | @end defun | ||
| 628 | |||
| 629 | @defun widget-value widget | ||
| 630 | Return the current value contained in @var{widget}. | ||
| 631 | |||
| 632 | Note that the value returned by this function might differ from what's | ||
| 633 | stored in the @code{:value} property of @var{widget}. This is because | ||
| 634 | this function extracts the current value of @var{widget} from the | ||
| 635 | buffer, taking editions into account. | ||
| 636 | |||
| 637 | The value returned is in the external format, after getting it with | ||
| 638 | the @code{:value-get} function. | ||
| 639 | |||
| 640 | It is an error to call this function on an uninitialized widget. | ||
| 641 | @end defun | ||
| 642 | |||
| 643 | @defun widget-value-set widget value | ||
| 644 | Set the value contained in @var{widget} to @var{value}. | ||
| 645 | |||
| 646 | Converts @var{value} to the internal format, and then sets it by | ||
| 647 | applying the @code{:value-set} function. | ||
| 648 | |||
| 649 | It is an error to call this function with an invalid @var{value}, that | ||
| 650 | is, a value that @var{widget} cannot represent. | ||
| 651 | @end defun | ||
| 652 | |||
| 653 | @defun widget-default-get widget | ||
| 654 | Return the default external value of widget @var{widget}. | ||
| 655 | |||
| 656 | The default value is the one stored in @code{:value} or the result of | ||
| 657 | applying the @code{:default-get} function to the arguments of | ||
| 658 | @var{widget}, as stored in @code{:args}. A value of @code{nil} is | ||
| 659 | ignored by default, so in order for a widget to respect @code{nil} as | ||
| 660 | a value, it has to override the @code{:default-get} function. | ||
| 661 | @end defun | ||
| 662 | |||
| 663 | @defun widget-type-default-get widget | ||
| 664 | Convert the @code{:type} attribute in @var{widget} and return its | ||
| 665 | default value. | ||
| 666 | @end defun | ||
| 667 | |||
| 668 | @defun widget-child-value-get widget | ||
| 669 | Return the value of the first member of @code{:children} in | ||
| 670 | @var{widget}. | ||
| 671 | @end defun | ||
| 672 | |||
| 673 | @defun widget-child-value-inline widget | ||
| 674 | Return the inline value of the first member of @code{:children} in | ||
| 675 | @var{widget}. | ||
| 676 | |||
| 677 | The inline value is whatever the function stored in | ||
| 678 | @code{:value-inline} returns. | ||
| 679 | @end defun | ||
| 680 | |||
| 681 | @defun widget-type-value-create widget | ||
| 682 | Create a child widget for @var{widget}, of type stored in | ||
| 683 | @code{:type}. | ||
| 684 | |||
| 685 | Creates the child widget taking the value from the @code{:value} | ||
| 686 | property and stores the newly created widget in the @code{:children} | ||
| 687 | property of @var{widget}. | ||
| 688 | |||
| 689 | The value stored in @code{:type} should be an unconverted widget | ||
| 690 | type. | ||
| 691 | @end defun | ||
| 692 | |||
| 693 | @defun widget-value-convert-widget widget | ||
| 694 | Initializes the @code{:value} property of @var{widget} from | ||
| 695 | @code{:args}. | ||
| 696 | |||
| 697 | Sets @code{:args} to @code{nil} and returns the modified widget | ||
| 698 | @var{widget}. | ||
| 699 | @end defun | ||
| 700 | |||
| 701 | @defun widget-value-value-get widget | ||
| 702 | Return the value stored in @code{:value} for widget @var{widget}. | ||
| 703 | |||
| 704 | This is different to getting the current value for @var{widget} with | ||
| 705 | @code{widget-value}, since that function extracts the value from the | ||
| 706 | buffer. | ||
| 707 | @end defun | ||
| 708 | |||
| 709 | @defun widget-apply-action widget &optional event | ||
| 710 | Apply the function stored in @code{:action} to @var{widget}, in | ||
| 711 | response to @var{event}. | ||
| 712 | |||
| 713 | It is an error to call this function with an inactive widget. | ||
| 714 | @end defun | ||
| 715 | |||
| 716 | @defun widget-parent-action widget &optional event | ||
| 717 | Tell @code{:parent} of @var{widget} to handle @var{event}. | ||
| 718 | |||
| 719 | Optional @var{event} is the event that triggered the action. | ||
| 720 | @end defun | ||
| 721 | |||
| 722 | @defun widget-child-validate widget | ||
| 723 | Check that the first member of @code{:children} in @var{widget} is valid. | ||
| 724 | |||
| 725 | To be valid means that the widget value passes the checks that the | ||
| 726 | function stored in @code{:validate} makes. | ||
| 727 | @end defun | ||
| 728 | |||
| 729 | @defun widget-children-validate widget | ||
| 730 | Check that all @code{:children} in @var{widget} are valid. | ||
| 731 | |||
| 732 | Returns @code{nil} on success, or the first child that isn't valid. | ||
| 733 | @end defun | ||
| 734 | |||
| 735 | @defun widget-type-match widget value | ||
| 736 | Return non-@code{nil} if @var{VALUE} matches the value for the | ||
| 737 | @code{:type} widget. | ||
| 738 | |||
| 739 | As with the other type functions, the widget stored in @code{:type} | ||
| 740 | should be an unconverted widget. | ||
| 741 | @end defun | ||
| 742 | |||
| 743 | @defun widget-types-copy widget | ||
| 744 | Copy the @code{:args} value in @var{widget} and store them in @code{:args}. | ||
| 745 | |||
| 746 | Makes the copies by calling @code{widget-copy} on each element present | ||
| 747 | in @code{:args}. Returns the modified widget @var{widget}. | ||
| 748 | @end defun | ||
| 749 | |||
| 750 | @defun widget-types-convert-widget widget | ||
| 751 | Convert the @code{:args} value in @var{widget} and store them in | ||
| 752 | @code{args}. | ||
| 753 | |||
| 754 | Returns the modified widget @var{widget}. | ||
| 755 | @end defun | ||
| 756 | |||
| 757 | @node Widgets and the Buffer | ||
| 758 | @chapter Widgets and the Buffer | ||
| 759 | This chapter describes commands that are specific to buffers that | ||
| 760 | contain widgets. | ||
| 761 | |||
| 762 | @cindex widget keybindings | ||
| 457 | @defvr Const widget-keymap | 763 | @defvr Const widget-keymap |
| 458 | @key{TAB} and @kbd{C-@key{TAB}} are bound to @code{widget-forward} and | 764 | Keymap containing useful bindings for buffers containing widgets. |
| 459 | @code{widget-backward}, respectively. @key{RET} and @kbd{mouse-2} | 765 | |
| 460 | are bound to @code{widget-button-press} and | 766 | Binds @key{TAB} and @kbd{C-@key{TAB}} to @code{widget-forward} and |
| 461 | @code{widget-button-click}. | 767 | @code{widget-backward}, respectively. It also binds @key{RET} to |
| 768 | @code{widget-button-press} and @kbd{down-mouse-1} and | ||
| 769 | @kbd{down-mouse-2} to @code{widget-button-click}. | ||
| 462 | @end defvr | 770 | @end defvr |
| 463 | 771 | ||
| 772 | There's also a keymap for events that the Widget library doesn't need | ||
| 773 | to handle. | ||
| 774 | |||
| 464 | @defvar widget-global-map | 775 | @defvar widget-global-map |
| 465 | Keymap used by @code{widget-button-press} and @code{widget-button-click} | 776 | Keymap used by @code{widget-button-press} and @code{widget-button-click} |
| 466 | when not on a button. By default this is @code{global-map}. | 777 | when not on a button. By default this is @code{global-map}. |
| 467 | @end defvar | 778 | @end defvar |
| 468 | 779 | ||
| 469 | @node Basic Types | 780 | In addition to these two keymaps, each widget might define a keymap of |
| 470 | @chapter Basic Types | 781 | its own, active when events happen at that widget. |
| 782 | |||
| 783 | @cindex widget navigation | ||
| 784 | The following navigation commands are available: | ||
| 785 | |||
| 786 | @table @kbd | ||
| 787 | @item @key{TAB} | ||
| 788 | @deffn Command widget-forward &optional count | ||
| 789 | Move point @var{count} buttons or editing fields forward. | ||
| 790 | @end deffn | ||
| 791 | @item @kbd{M-@key{TAB}} | ||
| 792 | @itemx @kbd{S-@key{TAB}} | ||
| 793 | @deffn Command widget-backward &optional count | ||
| 794 | Move point @var{count} buttons or editing fields backward. | ||
| 795 | @end deffn | ||
| 796 | @end table | ||
| 797 | |||
| 798 | |||
| 799 | When editing an @code{editable-field} widget, the following commands | ||
| 800 | are available: | ||
| 471 | 801 | ||
| 472 | This is the general syntax of a type specification: | 802 | @table @kbd |
| 803 | @item @key{C-e} | ||
| 804 | @deffn Command widget-end-of-line | ||
| 805 | Move point to the end of field or end of line, whichever is first. | ||
| 806 | @end deffn | ||
| 807 | |||
| 808 | @item @kbd{C-k} | ||
| 809 | @deffn Command widget-kill-line | ||
| 810 | Kill to end of field or end of line, whichever is first. | ||
| 811 | @end deffn | ||
| 812 | |||
| 813 | @item @kbd{M-TAB} | ||
| 814 | @deffn Command widget-complete | ||
| 815 | Complete the content of the editable field at point. | ||
| 816 | @end deffn | ||
| 817 | |||
| 818 | @item @kbd{C-m} | ||
| 819 | @deffn Command widget-field-activate | ||
| 820 | Invoke the editable field at point. | ||
| 821 | @end deffn | ||
| 822 | @end table | ||
| 473 | 823 | ||
| 824 | The following two are commands that can execute widget actions. | ||
| 825 | @table @kbd | ||
| 826 | @item @key{RET} | ||
| 827 | @findex widget-button-press | ||
| 828 | @deffn Command widget-button-press @var{pos} &optional @var{event} | ||
| 829 | Invoke the button at @var{pos}, defaulting to point. | ||
| 830 | |||
| 831 | Invocation means to run the function stored in the @code{:action} | ||
| 832 | property. | ||
| 833 | |||
| 834 | If point is not located on a button, invoke the binding in | ||
| 835 | @code{widget-global-map} (by default the global map). | ||
| 836 | @end deffn | ||
| 837 | |||
| 838 | @kindex mouse-2 @r{(on button widgets}) | ||
| 839 | @item mouse-2 | ||
| 840 | @findex widget-button-click | ||
| 841 | @deffn Command widget-button-click @var{event} | ||
| 842 | Invoke the button at the location of the mouse pointer. | ||
| 843 | |||
| 844 | If the mouse pointer is located in an editable text field, invoke the | ||
| 845 | binding in @code{widget-global-map} (by default the global map). | ||
| 846 | |||
| 847 | In case the mouse-click is on a widget, calls the function stored in | ||
| 848 | the @code{:mouse-down-action} property. | ||
| 849 | @end deffn | ||
| 850 | @end table | ||
| 851 | |||
| 852 | @node Widget Gallery | ||
| 853 | @chapter Widget Gallery | ||
| 854 | @cindex widget syntax | ||
| 855 | All widgets can be created from a type specification. The general | ||
| 856 | syntax of a type specification is: | ||
| 857 | |||
| 858 | @c FIXME: Add BNF reference here? If yes, what reference? | ||
| 474 | @example | 859 | @example |
| 475 | @var{name} ::= (@var{name} [@var{keyword} @var{argument}]... @var{args}) | 860 | @var{name} ::= (@var{name} [@var{keyword} @var{argument}]... @var{args}) |
| 476 | | @var{name} | 861 | | @var{name} |
| 477 | @end example | 862 | @end example |
| 478 | 863 | ||
| 479 | Where, @var{name} is a widget name, @var{keyword} is the name of a | 864 | Where @var{name} is a widget name, as defined with |
| 480 | property, @var{argument} is the value of the property, and @var{args} | 865 | @code{define-widget}, @var{keyword} is the name of a property and |
| 481 | are interpreted in a widget specific way. | 866 | @var{argument} is the value for that property, and @var{args} are |
| 867 | interpreted in a widget specific way. @xref{Defining New Widgets}. | ||
| 868 | |||
| 869 | @menu | ||
| 870 | * Basic Types:: | ||
| 871 | * Sexp Types:: | ||
| 872 | @end menu | ||
| 873 | |||
| 874 | @node Basic Types | ||
| 875 | @section Basic Types | ||
| 876 | |||
| 877 | @menu | ||
| 878 | * default:: | ||
| 879 | * item:: | ||
| 880 | * link:: | ||
| 881 | * url-link:: | ||
| 882 | * info-link:: | ||
| 883 | * function-link:: | ||
| 884 | * variable-link:: | ||
| 885 | * face-link:: | ||
| 886 | * file-link:: | ||
| 887 | * emacs-library-link:: | ||
| 888 | * emacs-commentary-link:: | ||
| 889 | * push-button:: | ||
| 890 | * editable-field:: | ||
| 891 | * text:: | ||
| 892 | * menu-choice:: | ||
| 893 | * radio-button-choice:: | ||
| 894 | * choice-item:: | ||
| 895 | * toggle:: | ||
| 896 | * radio-button-toggle:: | ||
| 897 | * checkbox:: | ||
| 898 | * checklist:: | ||
| 899 | * editable-list:: | ||
| 900 | * group:: | ||
| 901 | * documentation-string:: | ||
| 902 | @end menu | ||
| 903 | |||
| 904 | @node default | ||
| 905 | @subsection The @code{default} Widget | ||
| 906 | @findex default@r{ widget} | ||
| 907 | The most basic widget in the Widget Library is the @dfn{default} | ||
| 908 | widget. It provides the basic behavior for all other widgets, and all | ||
| 909 | its properties are present by default in derived widgets. You're | ||
| 910 | seldom (if ever) going to effectively create a default widget, but | ||
| 911 | here we describe its properties and behavior, so that we can describe | ||
| 912 | other widgets only by mentioning the properties and behavior those | ||
| 913 | other widgets specialize. | ||
| 914 | |||
| 915 | @deffn Widget default | ||
| 916 | Widget used as a base for other widgets. | ||
| 917 | |||
| 918 | It provides most of the functionality that is referred to as ``by | ||
| 919 | default'' in this text. If you want to define a new widget from | ||
| 920 | scratch, use the @code{default} widget as its base. | ||
| 921 | @end deffn | ||
| 482 | 922 | ||
| 483 | @cindex keyword arguments | 923 | @cindex keyword arguments |
| 484 | The following keyword arguments apply to all widgets: | 924 | The following keyword arguments apply to all widgets: |
| 485 | 925 | ||
| 486 | @table @code | 926 | @table @code |
| 927 | @vindex create@r{ keyword} | ||
| 928 | @item :create | ||
| 929 | Function to create a widget from scratch. | ||
| 930 | |||
| 931 | The function takes one argument, a widget type, and creates a widget | ||
| 932 | of that type, inserts it in the buffer, and returns a widget object. | ||
| 933 | |||
| 934 | By default, it inserts the widget at point, using the format provided | ||
| 935 | in the @code{:format} property. | ||
| 936 | |||
| 937 | @vindex delete@r{ keyword} | ||
| 938 | @item :delete | ||
| 939 | Function to delete a widget. | ||
| 940 | |||
| 941 | The function should take one argument, a widget, and should remove all | ||
| 942 | traces of the widget from the buffer. | ||
| 943 | |||
| 944 | The default value is: | ||
| 945 | |||
| 946 | @defun widget-default-delete widget | ||
| 947 | Remove @var{widget} from the buffer. | ||
| 948 | Delete all @code{:children} and @code{:buttons} in @var{widget}. | ||
| 949 | @end defun | ||
| 950 | |||
| 951 | In most cases you should not change this value, but instead use | ||
| 952 | @code{:value-delete} to make any additional cleanup. | ||
| 953 | |||
| 487 | @cindex internal format | 954 | @cindex internal format |
| 488 | @cindex external format | 955 | @cindex external format |
| 489 | @vindex value@r{ keyword} | 956 | @vindex value@r{ keyword} |
| 490 | @item :value | 957 | @item :value |
| 491 | The initial value for widgets of this type. Typically, a widget | 958 | The initial value for widgets of this type. |
| 492 | represents its value in two formats: external and internal. The | 959 | |
| 493 | external format is the value as the rest of Emacs sees it, and the | 960 | Typically, a widget represents its value in two formats: external and |
| 494 | internal format is a representation that the widget defines and uses | 961 | internal. The external format is the value as the rest of Emacs sees |
| 495 | in a widget specific way. | 962 | it, and the internal format is a representation that the widget |
| 963 | defines and uses in a widget specific way. | ||
| 496 | 964 | ||
| 497 | Both formats might be the same for certain widgets and might differ | 965 | Both formats might be the same for certain widgets and might differ |
| 498 | for others, and there is no guarantee about which format the value | 966 | for others, and there is no guarantee about which format the value |
| @@ -500,6 +968,68 @@ stored in the @code{:value} property has. However, when creating a | |||
| 500 | widget or defining a new one (@pxref{Defining New Widgets}), the | 968 | widget or defining a new one (@pxref{Defining New Widgets}), the |
| 501 | @code{:value} should be in the external format. | 969 | @code{:value} should be in the external format. |
| 502 | 970 | ||
| 971 | @vindex value-to-internal@r{ keyword} | ||
| 972 | @item :value-to-internal | ||
| 973 | Function to convert the value to the internal format. | ||
| 974 | |||
| 975 | The function takes two arguments, a widget and an external value, and | ||
| 976 | returns the internal value. The function is called on the present | ||
| 977 | @code{:value} when the widget is created, and on any value set later | ||
| 978 | with @code{widget-value-set}. | ||
| 979 | |||
| 980 | @vindex value-to-external@r{ keyword} | ||
| 981 | @item :value-to-external | ||
| 982 | Function to convert the value to the external format. | ||
| 983 | |||
| 984 | The function takes two arguments, a widget and an internal value, and | ||
| 985 | returns the value in the external format. | ||
| 986 | |||
| 987 | @vindex value-create@r{ keyword} | ||
| 988 | @item :value-create | ||
| 989 | Function to expand the @samp{%v} escape in the format string. | ||
| 990 | |||
| 991 | It will be called with the widget as its argument and should insert a | ||
| 992 | representation of the widget's value in the buffer. | ||
| 993 | |||
| 994 | @vindex value-delete@r{ keyword} | ||
| 995 | @item :value-delete | ||
| 996 | A function that should remove the representation of the widget's value | ||
| 997 | from the buffer. | ||
| 998 | |||
| 999 | It will be called with the widget as its argument. It doesn't have to | ||
| 1000 | remove the text, but it should release markers and delete nested widgets | ||
| 1001 | if these are not listed in @code{:children} or @code{:buttons}. | ||
| 1002 | |||
| 1003 | By default, it's a no-op. | ||
| 1004 | |||
| 1005 | @vindex value-get@r{ keyword} | ||
| 1006 | @item :value-get | ||
| 1007 | Function to extract the value of a widget, as it is displayed in the | ||
| 1008 | buffer. | ||
| 1009 | |||
| 1010 | @vindex value-set@r{ keyword} | ||
| 1011 | @item :value-set | ||
| 1012 | Function that takes a widget and a value as arguments, and recreates | ||
| 1013 | it. | ||
| 1014 | |||
| 1015 | The value must already be in the internal format for widget. By | ||
| 1016 | default, it deletes the widget with the @code{:delete} function and | ||
| 1017 | creates it again with the @code{:create} function. | ||
| 1018 | |||
| 1019 | @vindex value-inline@r{ keyword} | ||
| 1020 | @item :value-inline | ||
| 1021 | Function that takes a widget and returns its value, inlined. | ||
| 1022 | |||
| 1023 | Inlined means that if the widget is not inline (i.e., its | ||
| 1024 | @code{:inline} property is @code{nil}), the return value is wrapped in | ||
| 1025 | a list. | ||
| 1026 | |||
| 1027 | @vindex default-get@r{ keyword} | ||
| 1028 | @item :default-get | ||
| 1029 | Function that takes a widget and returns its default value. | ||
| 1030 | |||
| 1031 | By default, it just returns the value stored in @code{:value}. | ||
| 1032 | |||
| 503 | @vindex format@r{ keyword} | 1033 | @vindex format@r{ keyword} |
| 504 | @item :format | 1034 | @item :format |
| 505 | This string will be inserted in the buffer when you create a widget. | 1035 | This string will be inserted in the buffer when you create a widget. |
| @@ -513,14 +1043,6 @@ The text inside will be marked as a button. | |||
| 513 | By default, the text will be shown in @code{widget-button-face}, and | 1043 | By default, the text will be shown in @code{widget-button-face}, and |
| 514 | surrounded by brackets. | 1044 | surrounded by brackets. |
| 515 | 1045 | ||
| 516 | @defopt widget-button-prefix | ||
| 517 | String to prefix buttons. | ||
| 518 | @end defopt | ||
| 519 | |||
| 520 | @defopt widget-button-suffix | ||
| 521 | String to suffix buttons. | ||
| 522 | @end defopt | ||
| 523 | |||
| 524 | @item %@{ | 1046 | @item %@{ |
| 525 | @itemx %@} | 1047 | @itemx %@} |
| 526 | The text inside will be displayed with the face specified by | 1048 | The text inside will be displayed with the face specified by |
| @@ -530,9 +1052,6 @@ The text inside will be displayed with the face specified by | |||
| 530 | This will be replaced with the buffer representation of the widget's | 1052 | This will be replaced with the buffer representation of the widget's |
| 531 | value. What this is depends on the widget type. | 1053 | value. What this is depends on the widget type. |
| 532 | 1054 | ||
| 533 | @strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape | ||
| 534 | must be preceded by some other text in the format string (if specified). | ||
| 535 | |||
| 536 | @item %d | 1055 | @item %d |
| 537 | Insert the string specified by @code{:doc} here. | 1056 | Insert the string specified by @code{:doc} here. |
| 538 | 1057 | ||
| @@ -561,6 +1080,11 @@ Face used to highlight text inside %[ %] in the format. | |||
| 561 | @vindex button-suffix@r{ keyword} | 1080 | @vindex button-suffix@r{ keyword} |
| 562 | @item :button-prefix | 1081 | @item :button-prefix |
| 563 | @itemx :button-suffix | 1082 | @itemx :button-suffix |
| 1083 | Strings used as prefix and suffix for widgets that are buttons. | ||
| 1084 | |||
| 1085 | By default, the values are @code{widget-button-prefix} and | ||
| 1086 | @code{widget-button-suffix}. | ||
| 1087 | |||
| 564 | Text around %[ %] in the format. | 1088 | Text around %[ %] in the format. |
| 565 | 1089 | ||
| 566 | These can be | 1090 | These can be |
| @@ -594,10 +1118,11 @@ Emacsen that supports it. | |||
| 594 | @item :help-echo | 1118 | @item :help-echo |
| 595 | Specifies how to display a message whenever you move to the widget with | 1119 | Specifies how to display a message whenever you move to the widget with |
| 596 | either @code{widget-forward} or @code{widget-backward} or move the mouse | 1120 | either @code{widget-forward} or @code{widget-backward} or move the mouse |
| 597 | over it (using the standard @code{help-echo} mechanism). The argument | 1121 | over it (using the standard @code{help-echo} mechanism). |
| 598 | is either a string to display, a function of one argument, the widget, | 1122 | |
| 599 | which should return a string to display, or a form that evaluates to | 1123 | The value is either a string to display, or a function of one |
| 600 | such a string. | 1124 | argument, the widget. If a function, it should return a string to |
| 1125 | display, or a form that evaluates to such a string. | ||
| 601 | 1126 | ||
| 602 | @vindex follow-link@r{ keyword} | 1127 | @vindex follow-link@r{ keyword} |
| 603 | @item :follow-link | 1128 | @item :follow-link |
| @@ -607,7 +1132,12 @@ Specifies how to interpret a @key{mouse-1} click on the widget. | |||
| 607 | @vindex indent@r{ keyword} | 1132 | @vindex indent@r{ keyword} |
| 608 | @item :indent | 1133 | @item :indent |
| 609 | An integer indicating the absolute number of spaces to indent children | 1134 | An integer indicating the absolute number of spaces to indent children |
| 610 | of this widget. | 1135 | of this widget. Its value might be @code{nil} too, which corresponds |
| 1136 | to a value of 0. | ||
| 1137 | |||
| 1138 | The default @code{:create} functions and the functions that create the | ||
| 1139 | value per se use this property as a rudimentary layout mechanism for | ||
| 1140 | the widgets. | ||
| 611 | 1141 | ||
| 612 | @vindex offset@r{ keyword} | 1142 | @vindex offset@r{ keyword} |
| 613 | @item :offset | 1143 | @item :offset |
| @@ -619,14 +1149,6 @@ grandchildren compared to this widget. | |||
| 619 | An integer indicating how many extra spaces to add to the widget's | 1149 | An integer indicating how many extra spaces to add to the widget's |
| 620 | children compared to this widget. | 1150 | children compared to this widget. |
| 621 | 1151 | ||
| 622 | @vindex notify@r{ keyword} | ||
| 623 | @item :notify | ||
| 624 | A function called each time the widget or a nested widget is changed. | ||
| 625 | The function is called with two or three arguments. The first argument | ||
| 626 | is the widget itself, the second argument is the widget that was | ||
| 627 | changed, and the third argument is the event leading to the change, if | ||
| 628 | any. | ||
| 629 | |||
| 630 | @vindex menu-tag@r{ keyword} | 1152 | @vindex menu-tag@r{ keyword} |
| 631 | @item :menu-tag | 1153 | @item :menu-tag |
| 632 | Tag used in the menu when the widget is used as an option in a | 1154 | Tag used in the menu when the widget is used as an option in a |
| @@ -634,10 +1156,12 @@ Tag used in the menu when the widget is used as an option in a | |||
| 634 | 1156 | ||
| 635 | @vindex menu-tag-get@r{ keyword} | 1157 | @vindex menu-tag-get@r{ keyword} |
| 636 | @item :menu-tag-get | 1158 | @item :menu-tag-get |
| 637 | Function used for finding the tag when the widget is used as an option | 1159 | Function that takes a widget and returns the tag when the widget is |
| 638 | in a @code{menu-choice} widget. By default, the tag used will be either the | 1160 | used as an option in a @code{menu-choice} widget. |
| 639 | @code{:menu-tag} or @code{:tag} property if present, or the @code{princ} | 1161 | |
| 640 | representation of the @code{:value} property if not. | 1162 | By default, the tag used will be either the @code{:menu-tag} or |
| 1163 | @code{:tag} property if present, or the @code{princ} representation of | ||
| 1164 | the @code{:value} property if not. | ||
| 641 | 1165 | ||
| 642 | @vindex match@r{ keyword} | 1166 | @vindex match@r{ keyword} |
| 643 | @item :match | 1167 | @item :match |
| @@ -648,22 +1172,19 @@ represent the specified value. | |||
| 648 | @vindex validate@r{ keyword} | 1172 | @vindex validate@r{ keyword} |
| 649 | @item :validate | 1173 | @item :validate |
| 650 | A function which takes a widget as an argument, and returns @code{nil} | 1174 | A function which takes a widget as an argument, and returns @code{nil} |
| 651 | if the widget's current value is valid for the widget. Otherwise it | 1175 | if the widget's current value is valid for the widget. |
| 652 | should return the widget containing the invalid data, and set that | ||
| 653 | widget's @code{:error} property to a string explaining the error. | ||
| 654 | 1176 | ||
| 655 | The following predefined function can be used: | 1177 | Otherwise, it should return the widget containing the invalid data, |
| 1178 | and set that widget's @code{:error} property to a string explaining | ||
| 1179 | the error. | ||
| 656 | 1180 | ||
| 657 | @defun widget-children-validate widget | 1181 | By default, it always returns @code{nil}. |
| 658 | All the @code{:children} of @var{widget} must be valid. | ||
| 659 | @end defun | ||
| 660 | 1182 | ||
| 661 | @vindex tab-order@r{ keyword} | 1183 | @vindex tab-order@r{ keyword} |
| 662 | @item :tab-order | 1184 | @item :tab-order |
| 663 | Specify the order in which widgets are traversed with | 1185 | Specify the order in which widgets are traversed with |
| 664 | @code{widget-forward} or @code{widget-backward}. This is only partially | 1186 | @code{widget-forward} or @code{widget-backward}. This is only partially |
| 665 | implemented. | 1187 | implemented. |
| 666 | |||
| 667 | @enumerate a | 1188 | @enumerate a |
| 668 | @item | 1189 | @item |
| 669 | Widgets with tabbing order @code{-1} are ignored. | 1190 | Widgets with tabbing order @code{-1} are ignored. |
| @@ -690,39 +1211,208 @@ This keyword is only used for members of a @code{radio-button-choice} or | |||
| 690 | arguments, which will be used when creating the @code{radio-button} or | 1211 | arguments, which will be used when creating the @code{radio-button} or |
| 691 | @code{checkbox} associated with this item. | 1212 | @code{checkbox} associated with this item. |
| 692 | 1213 | ||
| 1214 | @vindex completions-function@r{ keyword} | ||
| 1215 | @item :completions-function | ||
| 1216 | Function that takes a widget and returns completion data for that | ||
| 1217 | widget, like @code{completion-at-point-functions} would. | ||
| 1218 | @xref{Completion,,,elisp, the Emacs Lisp Reference Manual}. It's | ||
| 1219 | used by @code{editable-field} widgets to provide completions. | ||
| 1220 | |||
| 1221 | By default, it looks into the property @code{:completions}, which | ||
| 1222 | should be a completion table. If @code{:completions} is @code{nil}, | ||
| 1223 | then it calls the function stored either in the @code{:complete} or | ||
| 1224 | @code{:complete-function} property. | ||
| 1225 | |||
| 1226 | @vindex format-handler@r{ keyword} | ||
| 1227 | @item :format-handler | ||
| 1228 | Function to handle unknown @samp{%} escapes in the format string. | ||
| 1229 | |||
| 1230 | It takes a widget and the character that follows the @samp{%} as | ||
| 1231 | arguments. You can set this to allow your widget to handle | ||
| 1232 | non-standard escapes in your own specialized widgets. | ||
| 1233 | |||
| 1234 | @findex widget-default-format-handler | ||
| 1235 | You should end up calling @code{widget-default-format-handler} to handle | ||
| 1236 | unknown escape sequences, which will handle the @samp{%h} and any future | ||
| 1237 | escape sequences, as well as give an error for unknown escapes. | ||
| 1238 | |||
| 1239 | @vindex button-face-get@r{ keyword} | ||
| 1240 | @item :button-face-get | ||
| 1241 | Function to return the face used to fontify a widget button. | ||
| 1242 | |||
| 1243 | Takes a widget and returns an appropriate face for the widget. By | ||
| 1244 | default, it either returns the face stored in the @code{:button-face} | ||
| 1245 | property, or calls the @code{:button-face-get} function from the | ||
| 1246 | parent of the widget, if it has one. | ||
| 1247 | |||
| 1248 | @vindex mouse-face-get@r{ keyword} | ||
| 1249 | @item :mouse-face-get | ||
| 1250 | Function to return the face used to fontify a widget when the mouse | ||
| 1251 | pointer hovers over it. | ||
| 1252 | |||
| 1253 | Takes a widget and returns an appropriate face. By default, it either | ||
| 1254 | returns the face stored in the @code{:mouse-face} property, or calls | ||
| 1255 | the @code{:button-face-get} function from the parent of the widget, if | ||
| 1256 | it has one. | ||
| 1257 | |||
| 1258 | @vindex copy@r{ keyword} | ||
| 1259 | @item :copy | ||
| 1260 | Function to deep copy a widget type. | ||
| 1261 | |||
| 1262 | It takes a shallow copy of the widget type as an argument (made by | ||
| 1263 | @code{copy-sequence}), and returns a deep copy. The purpose of this | ||
| 1264 | is to avoid having different instances of combined widgets share | ||
| 1265 | nested attributes. | ||
| 1266 | |||
| 1267 | Its value by default is @code{identity}. | ||
| 1268 | |||
| 1269 | @vindex active@r{ keyword} | ||
| 1270 | @item :active | ||
| 1271 | Function that takes a widget and returns @code{t} if it is active. | ||
| 1272 | |||
| 1273 | A widget might be effectively always active, if its | ||
| 1274 | @code{:always-active} property is @code{t}. | ||
| 1275 | |||
| 1276 | @cindex active widget | ||
| 1277 | @cindex inactive widget | ||
| 1278 | @cindex activate a widget | ||
| 1279 | @cindex deactivate a widget | ||
| 1280 | Widgets can be in two states: active, which means they are modifiable by | ||
| 1281 | the user, or inactive, which means they cannot be modified by the user. | ||
| 1282 | You can query or set the state with the following code: | ||
| 1283 | |||
| 1284 | @lisp | ||
| 1285 | ;; Examine if @var{widget} is active or not. | ||
| 1286 | (if (widget-apply @var{widget} :active) | ||
| 1287 | (message "Widget is active.") | ||
| 1288 | (message "Widget is inactive.") | ||
| 1289 | |||
| 1290 | ;; Make @var{widget} inactive. | ||
| 1291 | (widget-apply @var{widget} :deactivate) | ||
| 1292 | |||
| 1293 | ;; Make @var{widget} active. | ||
| 1294 | (widget-apply @var{widget} :activate) | ||
| 1295 | @end lisp | ||
| 1296 | |||
| 1297 | A widget is inactive if it, or any of its ancestors (found by | ||
| 1298 | following the @code{:parent} link), have been deactivated. To make sure | ||
| 1299 | a widget is really active, you must therefore activate both it and | ||
| 1300 | all its ancestors. | ||
| 1301 | |||
| 1302 | @lisp | ||
| 1303 | (while widget | ||
| 1304 | (widget-apply widget :activate) | ||
| 1305 | (setq widget (widget-get widget :parent))) | ||
| 1306 | @end lisp | ||
| 1307 | |||
| 1308 | You can check if a widget has been made inactive by examining the value | ||
| 1309 | of the @code{:inactive} keyword. If this is non-@code{nil}, the widget itself | ||
| 1310 | has been deactivated. This is different from using the @code{:active} | ||
| 1311 | keyword, in that the latter tells you if the widget @strong{or} any of | ||
| 1312 | its ancestors have been deactivated. Do not attempt to set the | ||
| 1313 | @code{:inactive} keyword directly. Use the @code{:activate} | ||
| 1314 | @code{:deactivate} functions instead. | ||
| 1315 | |||
| 1316 | @vindex activate@r{ keyword} | ||
| 1317 | @item :activate | ||
| 1318 | Function that takes a widget and makes it active for user | ||
| 1319 | modifications. | ||
| 1320 | |||
| 1321 | @vindex deactivate@r{ keyword} | ||
| 1322 | @item :deactivate | ||
| 1323 | Function that takes a widget and makes it inactive for user | ||
| 1324 | modifications. | ||
| 1325 | |||
| 1326 | @vindex action@r{ keyword} | ||
| 1327 | @item :action | ||
| 1328 | Function that takes a widget and optionally an event, and handles a | ||
| 1329 | user initiated event. | ||
| 1330 | |||
| 1331 | By default, uses the @code{:notify} function to notify the widget's | ||
| 1332 | parent about the event. | ||
| 1333 | |||
| 1334 | @vindex mouse-down-action@r{ keyword} | ||
| 1335 | @item :mouse-down-action | ||
| 1336 | Function that takes a widget and optionally an event, and handles a | ||
| 1337 | mouse click on the widget. | ||
| 1338 | |||
| 1339 | By default, it does nothing. | ||
| 1340 | |||
| 1341 | @vindex notify@r{ keyword} | ||
| 1342 | @item :notify | ||
| 1343 | A function called each time the widget or a nested widget is changed. | ||
| 1344 | |||
| 1345 | The function is called with two or three arguments. The first argument | ||
| 1346 | is the widget itself, the second argument is the widget that was | ||
| 1347 | changed, and the third argument is the event leading to the change, if | ||
| 1348 | any. | ||
| 1349 | |||
| 1350 | By default, it passes the notification to the widget's parent. | ||
| 1351 | |||
| 1352 | @vindex prompt-value@r{ keyword} | ||
| 1353 | @item :prompt-value | ||
| 1354 | Function to prompt for a value in the minibuffer. | ||
| 1355 | |||
| 1356 | The function should take four arguments, a widget, a prompt (a | ||
| 1357 | string), a value and a boolean, and should return a value for the | ||
| 1358 | widget, entered by the user. | ||
| 1359 | |||
| 1360 | The prompt is the prompt to use. The value is the default value to | ||
| 1361 | use, unless the fourtha argument is non-@code{nil}, in which case | ||
| 1362 | there is no default value. | ||
| 1363 | |||
| 1364 | The function should read the value using the method most natural for | ||
| 1365 | this widget, and does not have to check that it matches. | ||
| 693 | @end table | 1366 | @end table |
| 694 | 1367 | ||
| 695 | @deffn {User Option} widget-image-directory | 1368 | @node item |
| 696 | Directory where Widget should look for images. | 1369 | @subsection The @code{item} Widget |
| 697 | Widget will look here for a file with the same name as specified for the | 1370 | @findex item@r{ widget} |
| 698 | image, with either a @file{.xpm} (if supported) or @file{.xbm} extension. | ||
| 699 | @end deffn | ||
| 700 | 1371 | ||
| 701 | @deffn{User Option} widget-image-enable | 1372 | Syntax: |
| 702 | If non-@code{nil}, allow images to appear on displays where they are supported. | ||
| 703 | @end deffn | ||
| 704 | 1373 | ||
| 1374 | @example | ||
| 1375 | @var{type} ::= (item [@var{keyword} @var{argument}]... @var{value}) | ||
| 1376 | @end example | ||
| 705 | 1377 | ||
| 706 | @menu | 1378 | A useful widget that holds a constant value, and can be included in |
| 707 | * link:: | 1379 | other widgets. Its super is the @code{default} widget. |
| 708 | * url-link:: | 1380 | |
| 709 | * info-link:: | 1381 | As can be seen in the syntax, the @code{item} widget is one of the |
| 710 | * push-button:: | 1382 | widget that handles the @var{args} argument to @code{widget-create} in |
| 711 | * editable-field:: | 1383 | a specific way. If present, @var{value} is used to initialize the |
| 712 | * text:: | 1384 | @code{:value} property. When created, it inserts the value as a |
| 713 | * menu-choice:: | 1385 | string in the buffer. |
| 714 | * radio-button-choice:: | 1386 | |
| 715 | * item:: | 1387 | By default, it has the following properties: |
| 716 | * choice-item:: | 1388 | |
| 717 | * toggle:: | 1389 | @table @code |
| 718 | * checkbox:: | 1390 | @item :convert-widget |
| 719 | * checklist:: | 1391 | The function that allows it to handle @var{value}. |
| 720 | * editable-list:: | 1392 | |
| 721 | * group:: | 1393 | @item :value-create |
| 722 | @end menu | 1394 | Prints the representation of @code{:value} in the buffer. |
| 1395 | |||
| 1396 | @item :value-get | ||
| 1397 | Returns the value stored in @code{:value}. | ||
| 1398 | |||
| 1399 | @item :match | ||
| 1400 | A value matches the @code{item} widget if it's @code{equal} to its | ||
| 1401 | @code{:value}. | ||
| 1402 | |||
| 1403 | @item :match-inline | ||
| 1404 | Inline values match the @code{item} widget if @code{:value} is a | ||
| 1405 | sublist of values. | ||
| 1406 | |||
| 1407 | @item :action | ||
| 1408 | The @code{item} widget notifies itself of an event. | ||
| 1409 | |||
| 1410 | @item :format | ||
| 1411 | By default, the @code{item} widget inserts its tag in the buffer. | ||
| 1412 | @end table | ||
| 723 | 1413 | ||
| 724 | @node link | 1414 | @node link |
| 725 | @section The @code{link} Widget | 1415 | @subsection The @code{link} Widget |
| 726 | @findex link@r{ widget} | 1416 | @findex link@r{ widget} |
| 727 | 1417 | ||
| 728 | Syntax: | 1418 | Syntax: |
| @@ -731,22 +1421,42 @@ Syntax: | |||
| 731 | @var{type} ::= (link [@var{keyword} @var{argument}]... [ @var{value} ]) | 1421 | @var{type} ::= (link [@var{keyword} @var{argument}]... [ @var{value} ]) |
| 732 | @end example | 1422 | @end example |
| 733 | 1423 | ||
| 1424 | A widget to represent an embedded link. Its super is the @code{item} | ||
| 1425 | widget. | ||
| 1426 | |||
| 734 | The @var{value}, if present, is used to initialize the @code{:value} | 1427 | The @var{value}, if present, is used to initialize the @code{:value} |
| 735 | property. The value should be a string, which will be inserted in the | 1428 | property. The value should be a string, which will be inserted in the |
| 736 | buffer. | 1429 | buffer. |
| 737 | 1430 | ||
| 738 | By default the link will be shown in brackets. | 1431 | By default, it has the following properties: |
| 739 | 1432 | ||
| 740 | @defopt widget-link-prefix | 1433 | @table @code |
| 741 | String to prefix links. | 1434 | @item :button-prefix |
| 742 | @end defopt | 1435 | The value of @code{widget-link-prefix}. |
| 743 | 1436 | ||
| 744 | @defopt widget-link-suffix | 1437 | @item :button-suffix |
| 745 | String to suffix links. | 1438 | The value of @code{widget-link-suffix}. |
| 746 | @end defopt | 1439 | |
| 1440 | @item :keymap | ||
| 1441 | A custom keymap for the link widget, so that it can respond to mouse clicks. | ||
| 1442 | |||
| 1443 | @item :follow-link | ||
| 1444 | This property allows the link to respect the value of | ||
| 1445 | @code{mouse-1-click-follows-link}. @xref{Clickable Text,,,elisp, the Emacs Lisp Reference Manual}. | ||
| 1446 | |||
| 1447 | @item :format | ||
| 1448 | Buttonizes the link, to make it clickable. | ||
| 1449 | |||
| 1450 | If you override this property, you should make sure to provide the | ||
| 1451 | @samp{%[} and @samp{%]} escape sequences, so that the link is | ||
| 1452 | clickable. | ||
| 1453 | |||
| 1454 | @end table | ||
| 1455 | |||
| 1456 | By default the link will be shown in brackets. | ||
| 747 | 1457 | ||
| 748 | @node url-link | 1458 | @node url-link |
| 749 | @section The @code{url-link} Widget | 1459 | @subsection The @code{url-link} Widget |
| 750 | @findex url-link@r{ widget} | 1460 | @findex url-link@r{ widget} |
| 751 | 1461 | ||
| 752 | Syntax: | 1462 | Syntax: |
| @@ -755,12 +1465,14 @@ Syntax: | |||
| 755 | @var{type} ::= (url-link [@var{keyword} @var{argument}]... @var{url}) | 1465 | @var{type} ::= (url-link [@var{keyword} @var{argument}]... @var{url}) |
| 756 | @end example | 1466 | @end example |
| 757 | 1467 | ||
| 758 | @findex browse-url-browser-function@r{, and @code{url-link} widget} | 1468 | A widget to represent a link to a web page. Its super is the |
| 759 | When this link is invoked, the @acronym{WWW} browser specified by | 1469 | @code{link} widget. |
| 760 | @code{browse-url-browser-function} will be called with @var{url}. | 1470 | |
| 1471 | It overrides the @code{:action} property to open up the @var{url} | ||
| 1472 | specified. | ||
| 761 | 1473 | ||
| 762 | @node info-link | 1474 | @node info-link |
| 763 | @section The @code{info-link} Widget | 1475 | @subsection The @code{info-link} Widget |
| 764 | @findex info-link@r{ widget} | 1476 | @findex info-link@r{ widget} |
| 765 | 1477 | ||
| 766 | Syntax: | 1478 | Syntax: |
| @@ -769,11 +1481,104 @@ Syntax: | |||
| 769 | @var{type} ::= (info-link [@var{keyword} @var{argument}]... @var{address}) | 1481 | @var{type} ::= (info-link [@var{keyword} @var{argument}]... @var{address}) |
| 770 | @end example | 1482 | @end example |
| 771 | 1483 | ||
| 772 | When this link is invoked, the built-in Info reader is started on | 1484 | A widget to represent a link to an info file. Its super is the |
| 773 | @var{address}. | 1485 | @code{link} widget. |
| 1486 | |||
| 1487 | It overrides the @code{:action} property, to a function to start the | ||
| 1488 | built-in Info reader on @var{address}, when invoked. | ||
| 1489 | |||
| 1490 | @node function-link | ||
| 1491 | @subsection The @code{function-link} Widget | ||
| 1492 | @findex function-link@r{ widget} | ||
| 1493 | Syntax: | ||
| 1494 | |||
| 1495 | @example | ||
| 1496 | @var{type} ::= (function-link [@var{keyword} @var{argument}]... @var{function}) | ||
| 1497 | @end example | ||
| 1498 | |||
| 1499 | A widget to represent a link to an Emacs function. Its super is the | ||
| 1500 | @code{link} widget. | ||
| 1501 | |||
| 1502 | It overrides the @code{:action} property, to a function to describe | ||
| 1503 | @var{function}. | ||
| 1504 | |||
| 1505 | @node variable-link | ||
| 1506 | @subsection The @code{variable-link} Widget | ||
| 1507 | @findex variable-link@r{ widget} | ||
| 1508 | Syntax: | ||
| 1509 | |||
| 1510 | @example | ||
| 1511 | @var{type} ::= (variable-link [@var{keyword} @var{argument}]... @var{var}) | ||
| 1512 | @end example | ||
| 1513 | |||
| 1514 | A widget to represent a link to an Emacs variable. Its super is the | ||
| 1515 | @code{link} widget. | ||
| 1516 | |||
| 1517 | It overrides the @code{:action} property, to a function to describe | ||
| 1518 | @var{var}. | ||
| 1519 | |||
| 1520 | @node face-link | ||
| 1521 | @subsection The @code{face-link} Widget | ||
| 1522 | @findex face-link@r{ widget} | ||
| 1523 | Syntax: | ||
| 1524 | |||
| 1525 | @example | ||
| 1526 | @var{type} ::= (face-link [@var{keyword} @var{argument}]... @var{face}) | ||
| 1527 | @end example | ||
| 1528 | |||
| 1529 | A widget to represent a link to an Emacs face. Its super is the | ||
| 1530 | @code{link} widget. | ||
| 1531 | |||
| 1532 | It overrides the @code{:action} property, to a function to describe | ||
| 1533 | @var{face}. | ||
| 1534 | |||
| 1535 | @node file-link | ||
| 1536 | @subsection The @code{file-link} Widget | ||
| 1537 | @findex file-link@r{ widget} | ||
| 1538 | Syntax: | ||
| 1539 | |||
| 1540 | @example | ||
| 1541 | @var{type} ::= (file-link [@var{keyword} @var{argument}]... @var{file}) | ||
| 1542 | @end example | ||
| 1543 | |||
| 1544 | A widget to represent a link to a file. Its super is the | ||
| 1545 | @code{link} widget. | ||
| 1546 | |||
| 1547 | It overrides the @code{:action} property, to a function to find the file | ||
| 1548 | @var{file}. | ||
| 1549 | |||
| 1550 | @node emacs-library-link | ||
| 1551 | @subsection The @code{emacs-library-link} Widget | ||
| 1552 | @findex emacs-library-link@r{ widget} | ||
| 1553 | Syntax: | ||
| 1554 | |||
| 1555 | @example | ||
| 1556 | @var{type} ::= (emacs-library-link [@var{keyword} @var{argument}]... @var{file}) | ||
| 1557 | @end example | ||
| 1558 | |||
| 1559 | A widget to represent a link to an Emacs Lisp file. Its super is the | ||
| 1560 | @code{link} widget. | ||
| 1561 | |||
| 1562 | It overrides the @code{:action} property, to a function to find the file | ||
| 1563 | @var{file}. | ||
| 1564 | |||
| 1565 | @node emacs-commentary-link | ||
| 1566 | @subsection The @code{emacs-commentary-link} Widget | ||
| 1567 | @findex emacs-commentary-link@r{ widget} | ||
| 1568 | Syntax: | ||
| 1569 | |||
| 1570 | @example | ||
| 1571 | @var{type} ::= (emacs-commentary-link [@var{keyword} @var{argument}]... @var{file}) | ||
| 1572 | @end example | ||
| 1573 | |||
| 1574 | A widget to represent a link to the Comment section of an Emacs Lisp | ||
| 1575 | file. Its super is the @code{link} widget. | ||
| 1576 | |||
| 1577 | It overrides the @code{:action} property, to a function to find the file | ||
| 1578 | @var{file} and put point in the Comment section. | ||
| 774 | 1579 | ||
| 775 | @node push-button | 1580 | @node push-button |
| 776 | @section The @code{push-button} Widget | 1581 | @subsection The @code{push-button} Widget |
| 777 | @findex push-button@r{ widget} | 1582 | @findex push-button@r{ widget} |
| 778 | 1583 | ||
| 779 | Syntax: | 1584 | Syntax: |
| @@ -782,22 +1587,37 @@ Syntax: | |||
| 782 | @var{type} ::= (push-button [@var{keyword} @var{argument}]... [ @var{value} ]) | 1587 | @var{type} ::= (push-button [@var{keyword} @var{argument}]... [ @var{value} ]) |
| 783 | @end example | 1588 | @end example |
| 784 | 1589 | ||
| 1590 | A widget that acts as a pushable button. Its super is the @code{item} | ||
| 1591 | widget. | ||
| 1592 | |||
| 785 | The @var{value}, if present, is used to initialize the @code{:value} | 1593 | The @var{value}, if present, is used to initialize the @code{:value} |
| 786 | property. The value should be a string, which will be inserted in the | 1594 | property. The value should be a string, which will be inserted in the |
| 787 | buffer. | 1595 | buffer. |
| 788 | 1596 | ||
| 789 | By default the tag will be shown in brackets. | 1597 | By default, it has the following properties: |
| 1598 | @table @code | ||
| 1599 | @item :button-prefix | ||
| 1600 | The empty string. | ||
| 790 | 1601 | ||
| 791 | @defopt widget-push-button-prefix | 1602 | @item :button-suffix |
| 792 | String to prefix push buttons. | 1603 | The empty string. |
| 793 | @end defopt | ||
| 794 | 1604 | ||
| 795 | @defopt widget-push-button-suffix | 1605 | @item :value-create |
| 796 | String to suffix push buttons. | 1606 | Inserts a representation of the ``on'' and ``off'' states for the push |
| 797 | @end defopt | 1607 | button. |
| 1608 | |||
| 1609 | The representation might be an image, stored in the @code{:tag-glyph} | ||
| 1610 | property, or text. If it is text, it might be the value of the | ||
| 1611 | @code{:tag} property, or the @code{:value} of the widget, surrounded | ||
| 1612 | with @code{widget-push-button-prefix} and | ||
| 1613 | @code{widget-push-button-suffix}. @xref{Customization}. | ||
| 1614 | |||
| 1615 | @item :format | ||
| 1616 | Buttonizes the widget, to make it clickable. | ||
| 1617 | @end table | ||
| 798 | 1618 | ||
| 799 | @node editable-field | 1619 | @node editable-field |
| 800 | @section The @code{editable-field} Widget | 1620 | @subsection The @code{editable-field} Widget |
| 801 | @findex editable-field@r{ widget} | 1621 | @findex editable-field@r{ widget} |
| 802 | 1622 | ||
| 803 | Syntax: | 1623 | Syntax: |
| @@ -806,56 +1626,137 @@ Syntax: | |||
| 806 | @var{type} ::= (editable-field [@var{keyword} @var{argument}]... [ @var{value} ]) | 1626 | @var{type} ::= (editable-field [@var{keyword} @var{argument}]... [ @var{value} ]) |
| 807 | @end example | 1627 | @end example |
| 808 | 1628 | ||
| 1629 | A widget that can be edited by the user. Its super is the | ||
| 1630 | @code{default} widget. | ||
| 1631 | |||
| 809 | The @var{value}, if present, is used to initialize the @code{:value} | 1632 | The @var{value}, if present, is used to initialize the @code{:value} |
| 810 | property. The value should be a string, which will be inserted in the | 1633 | property. The value should be a string, which will be inserted in the |
| 811 | field. This widget will match all string values. | 1634 | field. If not present, @code{:value} is the empty string. |
| 812 | 1635 | ||
| 813 | The following extra properties are recognized: | 1636 | @strong{Warning:} In an @code{editable-field} widget, the editable |
| 1637 | field must not be adjacent to another widget---that won't work. | ||
| 1638 | You must put some text in between. Either make this text part of | ||
| 1639 | the @code{editable-field} widget itself, or insert it with | ||
| 1640 | @code{widget-insert}. | ||
| 1641 | |||
| 1642 | This widget either overrides or adds the following properties: | ||
| 814 | 1643 | ||
| 815 | @table @code | 1644 | @table @code |
| 1645 | @item :convert-widget | ||
| 1646 | Just like the @code{item} widget, this function allows it to | ||
| 1647 | initialize @code{:value} from @var{value}. | ||
| 1648 | |||
| 1649 | @vindex keymap@r{ keyword} | ||
| 1650 | @vindex widget-field-keymap | ||
| 1651 | @item :keymap | ||
| 1652 | Keymap used in the editable field. | ||
| 1653 | |||
| 1654 | The default value is @code{widget-field-keymap}, which allows the user | ||
| 1655 | to use all the normal editing commands, even if the buffer's major | ||
| 1656 | mode suppresses some of them. Pressing @key{RET} invokes the function | ||
| 1657 | specified by @code{:action}. | ||
| 1658 | |||
| 1659 | @item :format | ||
| 1660 | By default, it specifies to insert only the widget's value. | ||
| 1661 | |||
| 1662 | @strong{Warning:} In an @code{editable-field} widget, the @samp{%v} escape | ||
| 1663 | must be preceded by some other text in the @code{:format} string (if | ||
| 1664 | specified). | ||
| 1665 | |||
| 816 | @vindex size@r{ keyword} | 1666 | @vindex size@r{ keyword} |
| 817 | @item :size | 1667 | @item :size |
| 818 | The width of the editable field.@* | 1668 | The width of the editable field. |
| 1669 | |||
| 819 | By default the field will reach to the end of the line. | 1670 | By default the field will reach to the end of the line. |
| 820 | 1671 | ||
| 821 | @vindex value-face@r{ keyword} | 1672 | @vindex value-face@r{ keyword} |
| 822 | @item :value-face | 1673 | @item :value-face |
| 823 | Face used for highlighting the editable field. Default is | 1674 | Face used for highlighting the editable field. |
| 824 | @code{widget-field-face}, see @ref{User Interface}. | 1675 | |
| 1676 | Default is @code{widget-field-face}, @pxref{User Interface}. | ||
| 825 | 1677 | ||
| 826 | @vindex secret@r{ keyword} | 1678 | @vindex secret@r{ keyword} |
| 827 | @item :secret | 1679 | @item :secret |
| 828 | Character used to display the value. You can set this to, e.g., @code{?*} | 1680 | Character used to display the value. |
| 829 | if the field contains a password or other secret information. By | 1681 | |
| 830 | default, this is @code{nil}, and the value is not secret. | 1682 | You can set this to, e.g., @code{?*} if the field contains a password |
| 1683 | or other secret information. By default, this is @code{nil}, and the | ||
| 1684 | value is not secret. | ||
| 831 | 1685 | ||
| 832 | @vindex valid-regexp@r{ keyword} | 1686 | @vindex valid-regexp@r{ keyword} |
| 833 | @item :valid-regexp | 1687 | @item :valid-regexp |
| 834 | By default the @code{:validate} function will match the content of the | 1688 | By default the @code{:validate} function will match the content of the |
| 835 | field with the value of this attribute. The default value is @code{""} | 1689 | field with the value of this attribute. |
| 836 | which matches everything. | ||
| 837 | 1690 | ||
| 838 | @vindex keymap@r{ keyword} | 1691 | The default value is @code{""} which matches everything. |
| 839 | @vindex widget-field-keymap | 1692 | |
| 840 | @item :keymap | 1693 | @item :validate |
| 841 | Keymap used in the editable field. The default value is | 1694 | Returns @code{nil} if the current value of the widget matches the |
| 842 | @code{widget-field-keymap}, which allows you to use all the normal | 1695 | @code{:valid-regexp} value. |
| 843 | editing commands, even if the buffer's major mode suppresses some of | 1696 | |
| 844 | them. Pressing @key{RET} invokes the function specified by | 1697 | @item :prompt-internal |
| 845 | @code{:action}. | 1698 | A function to read a value for widget, used by the |
| 1699 | @code{:prompt-value} function. | ||
| 1700 | |||
| 1701 | @item :prompt-history | ||
| 1702 | A variable that holds the history of field minibuffer edits. | ||
| 1703 | |||
| 1704 | @item :prompt-value | ||
| 1705 | A function that uses the @code{:prompt-internal} function and the | ||
| 1706 | @code{:prompt-history} value to prompt for a string, and retun the | ||
| 1707 | user response in the external format. | ||
| 1708 | |||
| 1709 | @item :action | ||
| 1710 | When invoked, moves point to the next field. | ||
| 1711 | |||
| 1712 | @item :value-create | ||
| 1713 | Function that takes care of creating the widget, respecting its | ||
| 1714 | @code{:size} and @code{:value}. | ||
| 1715 | |||
| 1716 | @item :value-set | ||
| 1717 | Function to use to modify programatically the current value of the | ||
| 1718 | widget. | ||
| 1719 | |||
| 1720 | @item :value-delete | ||
| 1721 | Function that removes the widget so it cannot be edited anymore. | ||
| 1722 | |||
| 1723 | @item :value-get | ||
| 1724 | Function to return the current text in the widget. | ||
| 1725 | |||
| 1726 | It takes an optional argument, @var{no-truncate}. If | ||
| 1727 | @var{no-truncate} is nil, truncates trailing spaces. | ||
| 1728 | |||
| 1729 | @item :match | ||
| 1730 | Function that makes the widget match any string value. | ||
| 846 | @end table | 1731 | @end table |
| 847 | 1732 | ||
| 848 | @node text | 1733 | @node text |
| 849 | @section The @code{text} Widget | 1734 | @subsection The @code{text} Widget |
| 850 | @findex text@r{ widget} | 1735 | @findex text@r{ widget} |
| 851 | 1736 | ||
| 1737 | Syntax: | ||
| 1738 | |||
| 1739 | @example | ||
| 1740 | @var{type} ::= (text [@var{keyword} @var{argument}]... [ @var{value} ]) | ||
| 1741 | @end example | ||
| 1742 | |||
| 1743 | A widget just like the @code{editable-field} widget, but intended for | ||
| 1744 | multiline text fields. Its super is the @code{editable-field} widget. | ||
| 1745 | |||
| 1746 | It overrides the following properties: | ||
| 1747 | |||
| 1748 | @table @code | ||
| 1749 | @item :format | ||
| 1750 | By default, prints a tag and the value. | ||
| 1751 | |||
| 852 | @vindex widget-text-keymap | 1752 | @vindex widget-text-keymap |
| 853 | This is just like @code{editable-field}, but intended for multiline text | 1753 | @item :keymap |
| 854 | fields. The default @code{:keymap} is @code{widget-text-keymap}, which | 1754 | The default is @code{widget-text-keymap}, which does not rebind the |
| 855 | does not rebind the @key{RET} key. | 1755 | @key{RET} key. |
| 1756 | @end table | ||
| 856 | 1757 | ||
| 857 | @node menu-choice | 1758 | @node menu-choice |
| 858 | @section The @code{menu-choice} Widget | 1759 | @subsection The @code{menu-choice} Widget |
| 859 | @findex menu-choice@r{ widget} | 1760 | @findex menu-choice@r{ widget} |
| 860 | 1761 | ||
| 861 | Syntax: | 1762 | Syntax: |
| @@ -864,21 +1765,37 @@ Syntax: | |||
| 864 | @var{type} ::= (menu-choice [@var{keyword} @var{argument}]... @var{type} ... ) | 1765 | @var{type} ::= (menu-choice [@var{keyword} @var{argument}]... @var{type} ... ) |
| 865 | @end example | 1766 | @end example |
| 866 | 1767 | ||
| 1768 | A widget to represent a menu of options. Its super is the | ||
| 1769 | @code{default} widget. | ||
| 1770 | |||
| 867 | The @var{type} argument represents each possible choice. The widget's | 1771 | The @var{type} argument represents each possible choice. The widget's |
| 868 | value will be that of the chosen @var{type} argument. This widget will | 1772 | value will be that of the chosen @var{type} argument. |
| 869 | match any value matching at least one of the specified @var{type} | 1773 | |
| 870 | arguments. | 1774 | It either overrides or adds the following properties: |
| 871 | 1775 | ||
| 872 | @table @code | 1776 | @table @code |
| 1777 | @item :convert-widget | ||
| 1778 | A function that takes care of converting each possible choice. | ||
| 1779 | |||
| 1780 | @item :copy | ||
| 1781 | A function to copy each possible choice. | ||
| 1782 | |||
| 1783 | @item :format | ||
| 1784 | By default, buttonize the tag and show the value. | ||
| 1785 | |||
| 873 | @vindex void@r{ keyword} | 1786 | @vindex void@r{ keyword} |
| 874 | @item :void | 1787 | @item :void |
| 875 | Widget type used as a fallback when the value does not match any of the | 1788 | Widget type used as a fallback when the value does not match any of the |
| 876 | specified @var{type} arguments. | 1789 | specified @var{type} arguments. |
| 877 | 1790 | ||
| 1791 | By default this is an @code{item} widget. | ||
| 1792 | |||
| 878 | @vindex case-fold@r{ keyword} | 1793 | @vindex case-fold@r{ keyword} |
| 879 | @item :case-fold | 1794 | @item :case-fold |
| 880 | Set this to @code{nil} if you don't want to ignore case when prompting for a | 1795 | If @code{nil} don't ignore case when prompting for a choice through |
| 881 | choice through the minibuffer. | 1796 | the minibuffer. |
| 1797 | |||
| 1798 | By default, its value is @code{t}. | ||
| 882 | 1799 | ||
| 883 | @vindex children@r{ keyword} | 1800 | @vindex children@r{ keyword} |
| 884 | @item :children | 1801 | @item :children |
| @@ -892,10 +1809,54 @@ The current chosen type. | |||
| 892 | @vindex args@r{ keyword} | 1809 | @vindex args@r{ keyword} |
| 893 | @item :args | 1810 | @item :args |
| 894 | The list of types. | 1811 | The list of types. |
| 1812 | |||
| 1813 | @item :value-create | ||
| 1814 | The function that inserts the current value for the widget. | ||
| 1815 | |||
| 1816 | It inserts the first choice that matches, as with the @code{:match} | ||
| 1817 | function, the value of the widget. | ||
| 1818 | |||
| 1819 | @item :value-get | ||
| 1820 | Returns the value of the first child for the widget (see the | ||
| 1821 | description for @code{:children} above). | ||
| 1822 | |||
| 1823 | @item :value-inline | ||
| 1824 | Returns the inline value of the first child for the widget. | ||
| 1825 | |||
| 1826 | @item :default-get | ||
| 1827 | The default value for this widget is the default value for the first | ||
| 1828 | choice, in case @code{:value} is missing. | ||
| 1829 | |||
| 1830 | This means that if you want a specific default value for the | ||
| 1831 | @code{menu-choice} widget, you should either pass a @code{:value} | ||
| 1832 | property when creating it, or arrange the choices so that the first | ||
| 1833 | one can hold your desired default value. | ||
| 1834 | |||
| 1835 | @item :mouse-down-action | ||
| 1836 | A function that takes care of showing a menu, if possible and desired. | ||
| 1837 | |||
| 1838 | @item :action | ||
| 1839 | A function that takes care of getting a new choice for the widget. | ||
| 1840 | |||
| 1841 | Depending on the number of choices available, it may show a menu or | ||
| 1842 | just toggle the choices, or even do nothing at all. | ||
| 1843 | |||
| 1844 | After getting the choice, it recreates the widget and notifies it. | ||
| 1845 | |||
| 1846 | @item :validate | ||
| 1847 | Returns @code{nil} if the widget's value is a valid choice. | ||
| 1848 | |||
| 1849 | @item :match | ||
| 1850 | This widget will match any value matching at least one of the | ||
| 1851 | specified @var{type} arguments. | ||
| 1852 | |||
| 1853 | @item :match-inline | ||
| 1854 | A function that returns non-@code{nil} if the values match the widget, | ||
| 1855 | taking into account the @code{:inline} property. | ||
| 895 | @end table | 1856 | @end table |
| 896 | 1857 | ||
| 897 | @node radio-button-choice | 1858 | @node radio-button-choice |
| 898 | @section The @code{radio-button-choice} Widget | 1859 | @subsection The @code{radio-button-choice} Widget |
| 899 | @findex radio-button-choice@r{ widget} | 1860 | @findex radio-button-choice@r{ widget} |
| 900 | 1861 | ||
| 901 | Syntax: | 1862 | Syntax: |
| @@ -904,14 +1865,28 @@ Syntax: | |||
| 904 | @var{type} ::= (radio-button-choice [@var{keyword} @var{argument}]... @var{type} ... ) | 1865 | @var{type} ::= (radio-button-choice [@var{keyword} @var{argument}]... @var{type} ... ) |
| 905 | @end example | 1866 | @end example |
| 906 | 1867 | ||
| 907 | The component types specify the choices, with one radio button for | 1868 | A widget to represent a choice from multiple options. Its super is |
| 1869 | the @code{default} widget. | ||
| 1870 | |||
| 1871 | The component @var{types} specify the choices, with one radio button for | ||
| 908 | each. The widget's value will be that of the chosen @var{type} | 1872 | each. The widget's value will be that of the chosen @var{type} |
| 909 | argument. This widget matches any value that matches at least one of | 1873 | argument. |
| 910 | the specified @var{type} arguments. | ||
| 911 | 1874 | ||
| 912 | The following extra properties are recognized. | 1875 | It overrides the following properties: |
| 913 | 1876 | ||
| 914 | @table @code | 1877 | @table @code |
| 1878 | @item :convert-widget | ||
| 1879 | As other composite widgets, a function that takes care of converting | ||
| 1880 | each available choice. | ||
| 1881 | |||
| 1882 | @item :copy | ||
| 1883 | A function to copy each available choice. | ||
| 1884 | |||
| 1885 | @item :action | ||
| 1886 | A function that checks if any radio button was pressed and activates | ||
| 1887 | the pressed one, possibly deactivating an old one. Then, it notifies | ||
| 1888 | itself. | ||
| 1889 | |||
| 915 | @vindex entry-format@r{ keyword} | 1890 | @vindex entry-format@r{ keyword} |
| 916 | @item :entry-format | 1891 | @item :entry-format |
| 917 | This string will be inserted for each entry in the list. | 1892 | This string will be inserted for each entry in the list. |
| @@ -925,6 +1900,9 @@ Replace with the radio button. | |||
| 925 | Insert a literal @samp{%}. | 1900 | Insert a literal @samp{%}. |
| 926 | @end table | 1901 | @end table |
| 927 | 1902 | ||
| 1903 | @item :format | ||
| 1904 | By default, it inserts its value. | ||
| 1905 | |||
| 928 | @vindex button-args@r{ keyword} | 1906 | @vindex button-args@r{ keyword} |
| 929 | @item :button-args | 1907 | @item :button-args |
| 930 | A list of keywords to pass to the radio buttons. Useful for setting, | 1908 | A list of keywords to pass to the radio buttons. Useful for setting, |
| @@ -940,11 +1918,38 @@ The widgets representing each type. | |||
| 940 | 1918 | ||
| 941 | @vindex choice@r{ keyword} | 1919 | @vindex choice@r{ keyword} |
| 942 | @item :choice | 1920 | @item :choice |
| 943 | The current chosen type | 1921 | The current chosen type. |
| 944 | 1922 | ||
| 945 | @vindex args@r{ keyword} | 1923 | @vindex args@r{ keyword} |
| 946 | @item :args | 1924 | @item :args |
| 947 | The list of types. | 1925 | The list of types. |
| 1926 | |||
| 1927 | @item :value-create | ||
| 1928 | A function to insert all available choices. | ||
| 1929 | |||
| 1930 | @item :value-get | ||
| 1931 | Returns the value for the chosen widget. | ||
| 1932 | |||
| 1933 | @item :value-set | ||
| 1934 | A function to set the value to one of its available options. | ||
| 1935 | |||
| 1936 | @item :value-inline | ||
| 1937 | A function that returns the inline value of the child widget. | ||
| 1938 | |||
| 1939 | @item :offset | ||
| 1940 | By default, this widget has an offset of 4. | ||
| 1941 | |||
| 1942 | @item :validate | ||
| 1943 | The widget validates if the current value is valid for one of its | ||
| 1944 | children. | ||
| 1945 | |||
| 1946 | @item :match | ||
| 1947 | This widget matches any value that matches at least one of | ||
| 1948 | the specified @var{type} arguments. | ||
| 1949 | |||
| 1950 | @item :match-inline | ||
| 1951 | Like the @code{:match} function, but taking into account inline | ||
| 1952 | values. | ||
| 948 | @end table | 1953 | @end table |
| 949 | 1954 | ||
| 950 | You can add extra radio button items to a @code{radio-button-choice} | 1955 | You can add extra radio button items to a @code{radio-button-choice} |
| @@ -960,22 +1965,8 @@ Please note that such items added after the @code{radio-button-choice} | |||
| 960 | widget has been created will @strong{not} be properly destructed when | 1965 | widget has been created will @strong{not} be properly destructed when |
| 961 | you call @code{widget-delete}. | 1966 | you call @code{widget-delete}. |
| 962 | 1967 | ||
| 963 | @node item | ||
| 964 | @section The @code{item} Widget | ||
| 965 | @findex item@r{ widget} | ||
| 966 | |||
| 967 | Syntax: | ||
| 968 | |||
| 969 | @example | ||
| 970 | @var{item} ::= (item [@var{keyword} @var{argument}]... @var{value}) | ||
| 971 | @end example | ||
| 972 | |||
| 973 | The @var{value}, if present, is used to initialize the @code{:value} | ||
| 974 | property. The value should be a string, which will be inserted in the | ||
| 975 | buffer. This widget will only match the specified value. | ||
| 976 | |||
| 977 | @node choice-item | 1968 | @node choice-item |
| 978 | @section The @code{choice-item} Widget | 1969 | @subsection The @code{choice-item} Widget |
| 979 | @findex choice-item@r{ widget} | 1970 | @findex choice-item@r{ widget} |
| 980 | 1971 | ||
| 981 | Syntax: | 1972 | Syntax: |
| @@ -984,14 +1975,26 @@ Syntax: | |||
| 984 | @var{item} ::= (choice-item [@var{keyword} @var{argument}]... @var{value}) | 1975 | @var{item} ::= (choice-item [@var{keyword} @var{argument}]... @var{value}) |
| 985 | @end example | 1976 | @end example |
| 986 | 1977 | ||
| 1978 | A widget to represent a choice in a @code{menu-choice} widget. Its | ||
| 1979 | super is the @code{item} widget. | ||
| 1980 | |||
| 987 | The @var{value}, if present, is used to initialize the @code{:value} | 1981 | The @var{value}, if present, is used to initialize the @code{:value} |
| 988 | property. The value should be a string, which will be inserted in the | 1982 | property. |
| 989 | buffer as a button. Activating the button of a @code{choice-item} is | 1983 | |
| 990 | equivalent to activating the parent widget. This widget will only match | 1984 | It overrides the following properties: |
| 991 | the specified value. | 1985 | |
| 1986 | @table @code | ||
| 1987 | @item :action | ||
| 1988 | Activating the button of a @code{choice-item} is equivalent to | ||
| 1989 | activating the parent widget. | ||
| 1990 | |||
| 1991 | @item :format | ||
| 1992 | By default, it buttonizes the tag (i.e., its value) and adds a newline | ||
| 1993 | character at the end of the widget. | ||
| 1994 | @end table | ||
| 992 | 1995 | ||
| 993 | @node toggle | 1996 | @node toggle |
| 994 | @section The @code{toggle} Widget | 1997 | @subsection The @code{toggle} Widget |
| 995 | @findex toggle@r{ widget} | 1998 | @findex toggle@r{ widget} |
| 996 | 1999 | ||
| 997 | Syntax: | 2000 | Syntax: |
| @@ -1000,43 +2003,136 @@ Syntax: | |||
| 1000 | @var{type} ::= (toggle [@var{keyword} @var{argument}]...) | 2003 | @var{type} ::= (toggle [@var{keyword} @var{argument}]...) |
| 1001 | @end example | 2004 | @end example |
| 1002 | 2005 | ||
| 2006 | A widget that can toggle between two states. Its super is the | ||
| 2007 | @code{item} widget. | ||
| 2008 | |||
| 1003 | The widget has two possible states, @samp{on} and @samp{off}, which | 2009 | The widget has two possible states, @samp{on} and @samp{off}, which |
| 1004 | correspond to a @code{t} or @code{nil} value, respectively. | 2010 | correspond to a @code{t} or @code{nil} value, respectively. |
| 1005 | 2011 | ||
| 1006 | The following extra properties are recognized: | 2012 | It either overrides or adds the following properties: |
| 1007 | 2013 | ||
| 1008 | @table @code | 2014 | @table @code |
| 2015 | @item :format | ||
| 2016 | By default, it buttonizes the value and adds a newline at the end of | ||
| 2017 | the widget. | ||
| 2018 | |||
| 1009 | @item :on | 2019 | @item :on |
| 1010 | A string representing the @samp{on} state. By default the string | 2020 | A string representing the @samp{on} state. By default the string |
| 1011 | @samp{on}. | 2021 | @samp{on}. |
| 2022 | |||
| 1012 | @item :off | 2023 | @item :off |
| 1013 | A string representing the @samp{off} state. By default the string | 2024 | A string representing the @samp{off} state. By default the string |
| 1014 | @samp{off}. | 2025 | @samp{off}. |
| 2026 | |||
| 1015 | @vindex on-glyph@r{ keyword} | 2027 | @vindex on-glyph@r{ keyword} |
| 1016 | @item :on-glyph | 2028 | @item :on-glyph |
| 1017 | Name of a glyph to be used instead of the @samp{:on} text string, on | 2029 | Name of a glyph to be used instead of the @samp{:on} text string, on |
| 1018 | emacsen that supports this. | 2030 | emacsen that supports this. |
| 2031 | |||
| 1019 | @vindex off-glyph@r{ keyword} | 2032 | @vindex off-glyph@r{ keyword} |
| 1020 | @item :off-glyph | 2033 | @item :off-glyph |
| 1021 | Name of a glyph to be used instead of the @samp{:off} text string, on | 2034 | Name of a glyph to be used instead of the @samp{:off} text string, on |
| 1022 | emacsen that supports this. | 2035 | emacsen that supports this. |
| 2036 | |||
| 2037 | @item :value-create | ||
| 2038 | A function for creating the widget's value, according to its | ||
| 2039 | @samp{:on} or @samp{:off} state. | ||
| 2040 | |||
| 2041 | @item :action | ||
| 2042 | Function to toggle the state of the widget. After toggling, it | ||
| 2043 | notifies itself. | ||
| 2044 | |||
| 2045 | @item :match | ||
| 2046 | This widget matches anything. | ||
| 2047 | @end table | ||
| 2048 | |||
| 2049 | @node radio-button-toggle | ||
| 2050 | @subsection The @code{radio-button-toggle} Widget | ||
| 2051 | @findex radio-button-toggle@r{ widget} | ||
| 2052 | Syntax: | ||
| 2053 | |||
| 2054 | @example | ||
| 2055 | @var{type} ::= (radio-button-toggle [@var{keyword} @var{argument}]...) | ||
| 2056 | @end example | ||
| 2057 | |||
| 2058 | A toggle to use in the @code{radio} widget. | ||
| 2059 | |||
| 2060 | It overrides the following properties: | ||
| 2061 | |||
| 2062 | @table @code | ||
| 2063 | @item :button-prefix | ||
| 2064 | The empty string. | ||
| 2065 | |||
| 2066 | @item :button-suffix | ||
| 2067 | The empty string. | ||
| 2068 | |||
| 2069 | @item :on | ||
| 2070 | The string ``(*)'', to represent the @samp{on} state. | ||
| 2071 | |||
| 2072 | @item :off | ||
| 2073 | The string ``( )'', to represent the @samp{off} state. | ||
| 2074 | |||
| 2075 | @item :on-glyph | ||
| 2076 | The name of an image to represent the @samp{on} state. | ||
| 2077 | |||
| 2078 | @item :off-glpyh | ||
| 2079 | The name of an image to represent the @samp{off} state. | ||
| 2080 | |||
| 2081 | @item :format | ||
| 2082 | By default, it buttonizes its value. | ||
| 2083 | |||
| 2084 | @item :notify | ||
| 2085 | A function to notify its parent. | ||
| 1023 | @end table | 2086 | @end table |
| 1024 | 2087 | ||
| 1025 | @node checkbox | 2088 | @node checkbox |
| 1026 | @section The @code{checkbox} Widget | 2089 | @subsection The @code{checkbox} Widget |
| 1027 | @findex checkbox@r{ widget} | 2090 | @findex checkbox@r{ widget} |
| 1028 | 2091 | ||
| 1029 | This widget has two possible states, @samp{selected} and | ||
| 1030 | @samp{unselected}, which corresponds to a @code{t} or @code{nil} value. | ||
| 1031 | |||
| 1032 | Syntax: | 2092 | Syntax: |
| 1033 | 2093 | ||
| 1034 | @example | 2094 | @example |
| 1035 | @var{type} ::= (checkbox [@var{keyword} @var{argument}]...) | 2095 | @var{type} ::= (checkbox [@var{keyword} @var{argument}]...) |
| 1036 | @end example | 2096 | @end example |
| 1037 | 2097 | ||
| 2098 | A widget to represent a toggle widget, with a checkbox. Its super is | ||
| 2099 | the @code{toggle} widget. | ||
| 2100 | |||
| 2101 | This widget has two possible states, @samp{selected} and | ||
| 2102 | @samp{unselected}, which corresponds to a @code{t} or @code{nil} | ||
| 2103 | value, respectively. | ||
| 2104 | |||
| 2105 | It either overrides or adds the following properties: | ||
| 2106 | |||
| 2107 | @table @code | ||
| 2108 | @item :button-prefix | ||
| 2109 | The empty string. | ||
| 2110 | |||
| 2111 | @item :button-suffix | ||
| 2112 | The empty string. | ||
| 2113 | |||
| 2114 | @item :format | ||
| 2115 | By default, buttonizes the value. | ||
| 2116 | |||
| 2117 | @item :on | ||
| 2118 | By default, the string ``[X]''. | ||
| 2119 | |||
| 2120 | @item :off | ||
| 2121 | By default, the string ``[ ]''. | ||
| 2122 | |||
| 2123 | @item :on-glyph | ||
| 2124 | The name of the image to use when the state is @samp{on}. | ||
| 2125 | |||
| 2126 | @item :off-glyph | ||
| 2127 | The name of the image to use when the state is @samp{off}. | ||
| 2128 | |||
| 2129 | @item :action | ||
| 2130 | A function that toggles the checkbox, notifies the parents and in the | ||
| 2131 | @samp{on} state, activates its siblings. | ||
| 2132 | @end table | ||
| 2133 | |||
| 1038 | @node checklist | 2134 | @node checklist |
| 1039 | @section The @code{checklist} Widget | 2135 | @subsection The @code{checklist} Widget |
| 1040 | @findex checklist@r{ widget} | 2136 | @findex checklist@r{ widget} |
| 1041 | 2137 | ||
| 1042 | Syntax: | 2138 | Syntax: |
| @@ -1045,14 +2141,26 @@ Syntax: | |||
| 1045 | @var{type} ::= (checklist [@var{keyword} @var{argument}]... @var{type} ... ) | 2141 | @var{type} ::= (checklist [@var{keyword} @var{argument}]... @var{type} ... ) |
| 1046 | @end example | 2142 | @end example |
| 1047 | 2143 | ||
| 2144 | A widget to represent a multiplice choice. Its super is the | ||
| 2145 | @code{default} widget. | ||
| 2146 | |||
| 1048 | The @var{type} arguments represent each checklist item. The widget's | 2147 | The @var{type} arguments represent each checklist item. The widget's |
| 1049 | value will be a list containing the values of all checked @var{type} | 2148 | value will be a list containing the values of all checked @var{type} |
| 1050 | arguments. The checklist widget will match a list whose elements all | 2149 | arguments. |
| 1051 | match at least one of the specified @var{type} arguments. | ||
| 1052 | 2150 | ||
| 1053 | The following extra properties are recognized: | 2151 | It either overrides or adds the following properties: |
| 1054 | 2152 | ||
| 1055 | @table @code | 2153 | @table @code |
| 2154 | @item :convert-widget | ||
| 2155 | As other composite widgets, a function that takes care of converting | ||
| 2156 | each checklist item. | ||
| 2157 | |||
| 2158 | @item :copy | ||
| 2159 | A function to copy each checklist item. | ||
| 2160 | |||
| 2161 | @item :format | ||
| 2162 | By default, it inserts its value. | ||
| 2163 | |||
| 1056 | @vindex entry-format@r{ keyword} | 2164 | @vindex entry-format@r{ keyword} |
| 1057 | @item :entry-format | 2165 | @item :entry-format |
| 1058 | This string will be inserted for each entry in the list. | 2166 | This string will be inserted for each entry in the list. |
| @@ -1066,14 +2174,6 @@ Replace with the checkbox. | |||
| 1066 | Insert a literal @samp{%}. | 2174 | Insert a literal @samp{%}. |
| 1067 | @end table | 2175 | @end table |
| 1068 | 2176 | ||
| 1069 | @vindex greedy@r{ keyword} | ||
| 1070 | @item :greedy | ||
| 1071 | Usually a checklist will only match if the items are in the exact | ||
| 1072 | sequence given in the specification. By setting @code{:greedy} to | ||
| 1073 | non-@code{nil}, it will allow the items to come in any sequence. | ||
| 1074 | However, if you extract the value they will be in the sequence given | ||
| 1075 | in the checklist, i.e., the original sequence is forgotten. | ||
| 1076 | |||
| 1077 | @vindex button-args@r{ keyword} | 2177 | @vindex button-args@r{ keyword} |
| 1078 | @item :button-args | 2178 | @item :button-args |
| 1079 | A list of keywords to pass to the checkboxes. Useful for setting, | 2179 | A list of keywords to pass to the checkboxes. Useful for setting, |
| @@ -1090,10 +2190,35 @@ The widgets representing each type. | |||
| 1090 | @vindex args@r{ keyword} | 2190 | @vindex args@r{ keyword} |
| 1091 | @item :args | 2191 | @item :args |
| 1092 | The list of types. | 2192 | The list of types. |
| 2193 | |||
| 2194 | @item :value-create | ||
| 2195 | The function that takes care of inserting all values. | ||
| 2196 | |||
| 2197 | @item :value-get | ||
| 2198 | A function that returns all values of selected items. | ||
| 2199 | |||
| 2200 | @item :validate | ||
| 2201 | A function that ensures all selected children are valid. | ||
| 2202 | |||
| 2203 | @item :match | ||
| 2204 | The checklist widget will match a list whose elements all | ||
| 2205 | match at least one of the specified @var{type} arguments. | ||
| 2206 | |||
| 2207 | @item :match-inline | ||
| 2208 | Like the @code{:match} function, but taking into account the | ||
| 2209 | @code{:inline} property. | ||
| 2210 | |||
| 2211 | @vindex greedy@r{ keyword} | ||
| 2212 | @item :greedy | ||
| 2213 | Usually a checklist will only match if the items are in the exact | ||
| 2214 | sequence given in the specification. By setting @code{:greedy} to | ||
| 2215 | non-@code{nil}, it will allow the items to come in any sequence. | ||
| 2216 | However, if you extract the value they will be in the sequence given | ||
| 2217 | in the checklist, i.e., the original sequence is forgotten. | ||
| 1093 | @end table | 2218 | @end table |
| 1094 | 2219 | ||
| 1095 | @node editable-list | 2220 | @node editable-list |
| 1096 | @section The @code{editable-list} Widget | 2221 | @subsection The @code{editable-list} Widget |
| 1097 | @findex editable-list@r{ widget} | 2222 | @findex editable-list@r{ widget} |
| 1098 | 2223 | ||
| 1099 | Syntax: | 2224 | Syntax: |
| @@ -1102,12 +2227,19 @@ Syntax: | |||
| 1102 | @var{type} ::= (editable-list [@var{keyword} @var{argument}]... @var{type}) | 2227 | @var{type} ::= (editable-list [@var{keyword} @var{argument}]... @var{type}) |
| 1103 | @end example | 2228 | @end example |
| 1104 | 2229 | ||
| 1105 | The value is a list, where each member represents one widget of type | 2230 | A widget that can hold a variable list of widgets of the same type, |
| 1106 | @var{type}. | 2231 | represented by @var{type}. Its super is the @code{default} widget. |
| 1107 | 2232 | ||
| 1108 | The following extra properties are recognized: | 2233 | It either overrides or adds the following properties: |
| 1109 | 2234 | ||
| 1110 | @table @code | 2235 | @table @code |
| 2236 | @item :convert-widget | ||
| 2237 | As other composite widgets, a function that takes care of converting | ||
| 2238 | each type in @var{type}. | ||
| 2239 | |||
| 2240 | @item :copy | ||
| 2241 | A function to copy the types given in @var{type}. | ||
| 2242 | |||
| 1111 | @vindex entry-format@r{ keyword} | 2243 | @vindex entry-format@r{ keyword} |
| 1112 | @item :entry-format | 2244 | @item :entry-format |
| 1113 | This string will be inserted for each entry in the list. | 2245 | This string will be inserted for each entry in the list. |
| @@ -1117,9 +2249,9 @@ The following @samp{%} escapes are available: | |||
| 1117 | This will be replaced with the buffer representation of the @var{type} | 2249 | This will be replaced with the buffer representation of the @var{type} |
| 1118 | widget. | 2250 | widget. |
| 1119 | @item %i | 2251 | @item %i |
| 1120 | Insert the @b{[INS]} button. | 2252 | Insert the @b{[INS]} button, a widget of type @code{insert-button}. |
| 1121 | @item %d | 2253 | @item %d |
| 1122 | Insert the @b{[DEL]} button. | 2254 | Insert the @b{[DEL]} button, a widget of type @code{delete-button}. |
| 1123 | @item %% | 2255 | @item %% |
| 1124 | Insert a literal @samp{%}. | 2256 | Insert a literal @samp{%}. |
| 1125 | @end table | 2257 | @end table |
| @@ -1140,6 +2272,18 @@ A list of keyword arguments to pass to the trailing insert button. | |||
| 1140 | @item :buttons | 2272 | @item :buttons |
| 1141 | The widgets representing the insert and delete buttons. | 2273 | The widgets representing the insert and delete buttons. |
| 1142 | 2274 | ||
| 2275 | @item :format | ||
| 2276 | By default, insert its value and at the and adds an insert button. | ||
| 2277 | |||
| 2278 | This is useful so that new elements can be added to the list upon user | ||
| 2279 | request. | ||
| 2280 | |||
| 2281 | @item :format-handler | ||
| 2282 | A function that recognize the escape for inserting an insert button. | ||
| 2283 | |||
| 2284 | @item :offset | ||
| 2285 | By default, this widget has an offset of 12. | ||
| 2286 | |||
| 1143 | @vindex children@r{ keyword} | 2287 | @vindex children@r{ keyword} |
| 1144 | @item :children | 2288 | @item :children |
| 1145 | The widgets representing the elements of the list. | 2289 | The widgets representing the elements of the list. |
| @@ -1147,24 +2291,124 @@ The widgets representing the elements of the list. | |||
| 1147 | @vindex args@r{ keyword} | 2291 | @vindex args@r{ keyword} |
| 1148 | @item :args | 2292 | @item :args |
| 1149 | List whose @sc{car} is the type of the list elements. | 2293 | List whose @sc{car} is the type of the list elements. |
| 2294 | |||
| 2295 | @item :insert-before | ||
| 2296 | Function to insert a new widget as a child of the @code{editable-list} | ||
| 2297 | widget. | ||
| 2298 | |||
| 2299 | This function inserts a recently deleted child, if there is one. That | ||
| 2300 | is useful, so that the user can move elements in a list easily. If | ||
| 2301 | there is not a recently deleted child, it inserts a child with its | ||
| 2302 | default value. | ||
| 2303 | |||
| 2304 | @item :delete-at | ||
| 2305 | Function to delete a child from the widget, and store it into the | ||
| 2306 | @code{:last-deleted} list, so that it can be reinserted when the | ||
| 2307 | @code{:insert-before} function executes. | ||
| 2308 | |||
| 2309 | @item :value-create | ||
| 2310 | The function that takes care of inserting all values. | ||
| 2311 | |||
| 2312 | @item :value-get | ||
| 2313 | Function that returns a list with the value of the child widgets. | ||
| 2314 | |||
| 2315 | @item :validate | ||
| 2316 | This widget validates if all children validate. | ||
| 2317 | |||
| 2318 | @item :match | ||
| 2319 | To match, the value must be a list and all the list members must match | ||
| 2320 | the specified @var{type}. | ||
| 2321 | |||
| 2322 | @item :match-inline | ||
| 2323 | Like the @code{:match} function, but taking into account inline | ||
| 2324 | values and widgets. | ||
| 1150 | @end table | 2325 | @end table |
| 1151 | 2326 | ||
| 1152 | @node group | 2327 | @node group |
| 1153 | @section The @code{group} Widget | 2328 | @subsection The @code{group} Widget |
| 1154 | @findex group@r{ widget} | 2329 | @findex group@r{ widget} |
| 1155 | 2330 | ||
| 1156 | This widget simply group other widgets together. | ||
| 1157 | |||
| 1158 | Syntax: | 2331 | Syntax: |
| 1159 | 2332 | ||
| 1160 | @example | 2333 | @example |
| 1161 | @var{type} ::= (group [@var{keyword} @var{argument}]... @var{type}...) | 2334 | @var{type} ::= (group [@var{keyword} @var{argument}]... @var{type}...) |
| 1162 | @end example | 2335 | @end example |
| 1163 | 2336 | ||
| 1164 | The value is a list, with one member for each @var{type}. | 2337 | A widget to group other widgets. Its super is the @code{default} |
| 2338 | widget. | ||
| 2339 | |||
| 2340 | Its value is a list, with one member for each @var{type}. | ||
| 2341 | |||
| 2342 | It overrides the following properties: | ||
| 2343 | |||
| 2344 | @table @code | ||
| 2345 | @item :convert-widget | ||
| 2346 | As other composite widgets, a function that takes care of converting | ||
| 2347 | each widget in @var{type}. | ||
| 2348 | |||
| 2349 | @item :copy | ||
| 2350 | A function to copy the types given in @var{type}. | ||
| 2351 | |||
| 2352 | @item :format | ||
| 2353 | By default, displays a newline character and its value. | ||
| 2354 | |||
| 2355 | @item :value-create | ||
| 2356 | A function to create each of its components. | ||
| 2357 | |||
| 2358 | @item :value-get | ||
| 2359 | The same function used by the @code{editable-list} widget. | ||
| 2360 | |||
| 2361 | @item :default-get | ||
| 2362 | A function that returns a list whose members are the default values of | ||
| 2363 | each widget it groups. | ||
| 2364 | |||
| 2365 | @item :validate | ||
| 2366 | This widget validates if all of its children validate. | ||
| 2367 | |||
| 2368 | @item :match | ||
| 2369 | This widget matches a value that matches each of its components. | ||
| 2370 | |||
| 2371 | @item :match-inline | ||
| 2372 | As @code{:match}, but taking into account widgets and values that are | ||
| 2373 | inline. | ||
| 2374 | @end table | ||
| 2375 | |||
| 2376 | @node documentation-string | ||
| 2377 | @subsection The @code{documentation-string} Widget | ||
| 2378 | @findex documentation-string@r{ widget} | ||
| 2379 | Syntax: | ||
| 2380 | |||
| 2381 | @example | ||
| 2382 | @var{type} ::= (documentation-string [@var{keyword} @var{argument}]... @var{value}) | ||
| 2383 | @end example | ||
| 2384 | |||
| 2385 | A widget to represent a documentation string. Its super is the | ||
| 2386 | @code{item} widget. | ||
| 2387 | |||
| 2388 | It either overrides or adds the following properties: | ||
| 2389 | |||
| 2390 | @table @code | ||
| 2391 | @item :format | ||
| 2392 | By default, insert its value. | ||
| 2393 | |||
| 2394 | @item :value-create | ||
| 2395 | Function to insert a documentation string, possibly hiding part of the | ||
| 2396 | documentation if its large. | ||
| 2397 | |||
| 2398 | To show or hide the rest of the documentation, uses a | ||
| 2399 | @code{visibility} widget. | ||
| 2400 | |||
| 2401 | @item :action | ||
| 2402 | Function to toggle showing the documentation upon an event. | ||
| 2403 | |||
| 2404 | @item :visibility-widget | ||
| 2405 | A symbol, the type of the widget to use for the visibility widget. | ||
| 2406 | |||
| 2407 | This is, by default, the symbol @code{visibility}. | ||
| 2408 | @end table | ||
| 1165 | 2409 | ||
| 1166 | @node Sexp Types | 2410 | @node Sexp Types |
| 1167 | @chapter Sexp Types | 2411 | @section Sexp Types |
| 1168 | @cindex sexp types | 2412 | @cindex sexp types |
| 1169 | 2413 | ||
| 1170 | A number of widgets for editing @dfn{s-expressions} (Lisp types), sexp | 2414 | A number of widgets for editing @dfn{s-expressions} (Lisp types), sexp |
| @@ -1179,7 +2423,7 @@ categories described in this section. | |||
| 1179 | @end menu | 2423 | @end menu |
| 1180 | 2424 | ||
| 1181 | @node constants | 2425 | @node constants |
| 1182 | @section The Constant Widgets | 2426 | @subsection The Constant Widgets |
| 1183 | @cindex constant widgets | 2427 | @cindex constant widgets |
| 1184 | 2428 | ||
| 1185 | The @code{const} widget can contain any Lisp expression, but the user is | 2429 | The @code{const} widget can contain any Lisp expression, but the user is |
| @@ -1192,19 +2436,26 @@ The syntax for the @code{const} widget is: | |||
| 1192 | @var{type} ::= (const [@var{keyword} @var{argument}]... [ @var{value} ]) | 2436 | @var{type} ::= (const [@var{keyword} @var{argument}]... [ @var{value} ]) |
| 1193 | @end example | 2437 | @end example |
| 1194 | 2438 | ||
| 1195 | The @var{value}, if present, is used to initialize the @code{:value} | 2439 | Its super is the @code{item} widget. The @var{value}, if present, is |
| 1196 | property and can be any s-expression. | 2440 | used to initialize the @code{:value} property and can be any |
| 2441 | s-expression. | ||
| 1197 | 2442 | ||
| 1198 | @deffn Widget const | 2443 | @deffn Widget const |
| 1199 | This will display any valid s-expression in an immutable part of the | 2444 | This will display any valid s-expression in an immutable part of the |
| 1200 | buffer. | 2445 | buffer. |
| 2446 | |||
| 2447 | It overrides the @code{:prompt-value} function, to avoid prompting and | ||
| 2448 | just return the widget's value. | ||
| 1201 | @end deffn | 2449 | @end deffn |
| 1202 | 2450 | ||
| 1203 | There are two variations of the @code{const} widget, namely | 2451 | There are two variations of the @code{const} widget, namely |
| 1204 | @code{variable-item} and @code{function-item}. These should contain a | 2452 | @code{variable-item} and @code{function-item}. These should contain a |
| 1205 | symbol with a variable or function binding. The major difference from | 2453 | symbol with a variable or function binding, respectively. The major |
| 1206 | the @code{const} widget is that they will allow the user to see the | 2454 | difference from the @code{const} widget is that they will allow the |
| 1207 | variable or function documentation for the symbol. | 2455 | user to see the variable or function documentation for the symbol. |
| 2456 | |||
| 2457 | This is accomplished via using the @samp{%h} format escape, and adding | ||
| 2458 | an appropiate @code{:documentation-property} function for each widget. | ||
| 1208 | 2459 | ||
| 1209 | @deffn Widget variable-item | 2460 | @deffn Widget variable-item |
| 1210 | An immutable symbol that is bound as a variable. | 2461 | An immutable symbol that is bound as a variable. |
| @@ -1215,7 +2466,7 @@ An immutable symbol that is bound as a function. | |||
| 1215 | @end deffn | 2466 | @end deffn |
| 1216 | 2467 | ||
| 1217 | @node generic | 2468 | @node generic |
| 1218 | @section Generic Sexp Widget | 2469 | @subsection Generic Sexp Widget |
| 1219 | @cindex generic sexp widget | 2470 | @cindex generic sexp widget |
| 1220 | 2471 | ||
| 1221 | The @code{sexp} widget can contain any Lisp expression, and allows the | 2472 | The @code{sexp} widget can contain any Lisp expression, and allows the |
| @@ -1228,23 +2479,42 @@ The syntax for the @code{sexp} widget is: | |||
| 1228 | @end example | 2479 | @end example |
| 1229 | 2480 | ||
| 1230 | @deffn Widget sexp | 2481 | @deffn Widget sexp |
| 1231 | This will allow you to edit any valid s-expression in an editable buffer | 2482 | This widget represents an editable field that's useful to edit any |
| 1232 | field. | 2483 | valid s-expression. |
| 1233 | 2484 | ||
| 1234 | The @code{sexp} widget takes the same keyword arguments as the | 2485 | The @code{sexp} widget takes the same keyword arguments as the |
| 1235 | @code{editable-field} widget. @xref{editable-field}. | 2486 | @code{editable-field} widget. @xref{editable-field}. |
| 2487 | |||
| 2488 | Its default value is @code{nil}. | ||
| 2489 | @end deffn | ||
| 2490 | |||
| 2491 | @deffn Widget restricted-sexp | ||
| 2492 | A widget to edit Lisp expressions restricted to certain values or | ||
| 2493 | types. Its super is the @code{sexp} widget. | ||
| 2494 | |||
| 2495 | It works just like the sexp widget, but it overrides the @code{:match} | ||
| 2496 | function to match for certain values. To use this widget, either you | ||
| 2497 | must define a @code{:match} function or give a | ||
| 2498 | @code{:match-alternatives} property. The @code{:match-alternatives} | ||
| 2499 | property holds a list of predicate functions to call when checking if | ||
| 2500 | a given value matches the widget. Each predicate function will be | ||
| 2501 | called with one argument, the value to be matched, and should return | ||
| 2502 | non-@code{nil} on success. | ||
| 2503 | |||
| 2504 | As an example, the @code{integer} widget overrides | ||
| 2505 | @code{:match-alternatives} to @code{(integerp)}. | ||
| 1236 | @end deffn | 2506 | @end deffn |
| 1237 | 2507 | ||
| 1238 | @node atoms | 2508 | @node atoms |
| 1239 | @section Atomic Sexp Widgets | 2509 | @subsection Atomic Sexp Widgets |
| 1240 | @cindex atomic sexp widget | 2510 | @cindex atomic sexp widget |
| 1241 | 2511 | ||
| 1242 | The atoms are s-expressions that do not consist of other s-expressions. | 2512 | The atoms are s-expressions that do not consist of other s-expressions. |
| 1243 | For example, a string, a file name, or a symbol are atoms, while a list | 2513 | For example, a string, a file name, or a symbol are atoms, while a list |
| 1244 | is a composite type. You can edit the value of an atom with the | 2514 | is a composite type. You can edit the value of an atom with the |
| 1245 | following widgets. | 2515 | widgets described in this section. |
| 1246 | 2516 | ||
| 1247 | The syntax for all the atoms are: | 2517 | The syntax for all the atoms is: |
| 1248 | 2518 | ||
| 1249 | @example | 2519 | @example |
| 1250 | @var{type} ::= (@var{construct} [@var{keyword} @var{argument}]... [ @var{value} ]) | 2520 | @var{type} ::= (@var{construct} [@var{keyword} @var{argument}]... [ @var{value} ]) |
| @@ -1252,68 +2522,151 @@ The syntax for all the atoms are: | |||
| 1252 | 2522 | ||
| 1253 | The @var{value}, if present, is used to initialize the @code{:value} | 2523 | The @var{value}, if present, is used to initialize the @code{:value} |
| 1254 | property and must be an expression of the same type as the widget. | 2524 | property and must be an expression of the same type as the widget. |
| 1255 | That is, the string widget can only be initialized with a string. | 2525 | That is, for example, the string widget can only be initialized with a |
| 2526 | string. | ||
| 1256 | 2527 | ||
| 1257 | All the atom widgets take the same keyword arguments as the | 2528 | All the atom widgets take the same keyword arguments as the |
| 1258 | @code{editable-field} widget. @xref{editable-field}. | 2529 | @code{editable-field} widget. @xref{editable-field}. |
| 1259 | 2530 | ||
| 1260 | @deffn Widget string | 2531 | @deffn Widget string |
| 1261 | Allows you to edit a string in an editable field. | 2532 | An editable field widget that can represent any Lisp string. |
| 2533 | |||
| 2534 | It offers completion via the ispell library and the @code{:complete} | ||
| 2535 | property. | ||
| 1262 | @end deffn | 2536 | @end deffn |
| 1263 | 2537 | ||
| 1264 | @deffn Widget regexp | 2538 | @deffn Widget regexp |
| 1265 | Allows you to edit a regular expression in an editable field. | 2539 | An editable field widget that can represent a regular expression. |
| 2540 | |||
| 2541 | Overrides the @code{:match} and the @code{:validate} properties to | ||
| 2542 | check that the value is a valid regexp. | ||
| 1266 | @end deffn | 2543 | @end deffn |
| 1267 | 2544 | ||
| 1268 | @deffn Widget character | 2545 | @deffn Widget character |
| 1269 | Allows you to enter a character in an editable field. | 2546 | An editable field widget that can represent a character. |
| 2547 | |||
| 2548 | The character widget represents some characters (like the newline | ||
| 2549 | character) in a special manner, to make it easier for the user to see | ||
| 2550 | what's the content of the character field. | ||
| 1270 | @end deffn | 2551 | @end deffn |
| 1271 | 2552 | ||
| 1272 | @deffn Widget file | 2553 | @deffn Widget file |
| 1273 | Allows you to edit a file name in an editable field. | 2554 | A widget for editing file names. |
| 1274 | 2555 | ||
| 1275 | Keywords: | 2556 | Keywords: |
| 1276 | @table @code | 2557 | @table @code |
| 2558 | @item :completions | ||
| 2559 | Offers file name completion to the user. | ||
| 2560 | |||
| 2561 | @item :prompt-value | ||
| 2562 | A function to read a file name from the minibuffer. | ||
| 2563 | |||
| 1277 | @vindex must-match@r{ keyword} | 2564 | @vindex must-match@r{ keyword} |
| 1278 | @item :must-match | 2565 | @item :must-match |
| 1279 | If this is set to non-@code{nil}, only existing file names will be | 2566 | If this is set to non-@code{nil}, only existing file names are allowed |
| 1280 | allowed in the minibuffer. | 2567 | when prompting for a value in the minibuffer. |
| 2568 | |||
| 2569 | @item :match | ||
| 2570 | The widget matches if the value is a string, and the file whose name | ||
| 2571 | is that string is an existing file, or if @code{:must-match} is | ||
| 2572 | @code{nil}. | ||
| 2573 | |||
| 2574 | @item :validate | ||
| 2575 | The widget is valid if its value matches. | ||
| 2576 | |||
| 1281 | @end table | 2577 | @end table |
| 1282 | @end deffn | 2578 | @end deffn |
| 1283 | 2579 | ||
| 1284 | @deffn Widget directory | 2580 | @deffn Widget directory |
| 1285 | Allows you to edit a directory name in an editable field. | 2581 | A widget for editing directory names. |
| 1286 | Similar to the @code{file} widget. | 2582 | |
| 2583 | Its super is the @code{file} widget, and it overrides the | ||
| 2584 | @code{:completions} property, to offer completions only for | ||
| 2585 | directories. | ||
| 1287 | @end deffn | 2586 | @end deffn |
| 1288 | 2587 | ||
| 1289 | @deffn Widget symbol | 2588 | @deffn Widget symbol |
| 1290 | Allows you to edit a Lisp symbol in an editable field. | 2589 | A widget for editing a Lisp symbol. |
| 2590 | |||
| 2591 | Its value by default is @code{nil}. | ||
| 1291 | @end deffn | 2592 | @end deffn |
| 1292 | 2593 | ||
| 1293 | @deffn Widget function | 2594 | @deffn Widget function |
| 1294 | Allows you to edit a lambda expression, or a function name with completion. | 2595 | A widget for editing a lambda expression, or a function name, offering |
| 2596 | completion. Its super is the @code{restricted-sexp} widget. | ||
| 1295 | @end deffn | 2597 | @end deffn |
| 1296 | 2598 | ||
| 1297 | @deffn Widget variable | 2599 | @deffn Widget variable |
| 1298 | Allows you to edit a variable name, with completion. | 2600 | A widget for editing variable names, offering completion. Its super |
| 2601 | is the @code{symbol} widget. | ||
| 1299 | @end deffn | 2602 | @end deffn |
| 1300 | 2603 | ||
| 1301 | @deffn Widget integer | 2604 | @deffn Widget integer |
| 1302 | Allows you to edit an integer in an editable field. | 2605 | A widget for editing integers in an editable field. Its super is the |
| 2606 | @code{restricted-sexp} widget. | ||
| 2607 | |||
| 2608 | It has a default @code{:value} of 0. | ||
| 2609 | @end deffn | ||
| 2610 | |||
| 2611 | @deffn Widget natnum | ||
| 2612 | A widget for editing non-negative integers. Its super is the | ||
| 2613 | @code{restricted-sexp} widget. | ||
| 2614 | |||
| 2615 | It has a default @code{:value} of 0. | ||
| 2616 | @end deffn | ||
| 2617 | |||
| 2618 | @deffn Widget float | ||
| 2619 | A widget for editing a floating point number. Its super is the | ||
| 2620 | @code{restricted-sexp} widget. | ||
| 2621 | |||
| 2622 | It has a default @code{:value} of 0.0. | ||
| 1303 | @end deffn | 2623 | @end deffn |
| 1304 | 2624 | ||
| 1305 | @deffn Widget number | 2625 | @deffn Widget number |
| 1306 | Allows you to edit a number in an editable field. | 2626 | A widget for editing a number, either floating point or integer. Its |
| 2627 | super is the @code{restricted-sexp} widget. | ||
| 2628 | |||
| 2629 | It has a default @code{:value} of 0.0. | ||
| 1307 | @end deffn | 2630 | @end deffn |
| 1308 | 2631 | ||
| 1309 | @deffn Widget boolean | 2632 | @deffn Widget boolean |
| 1310 | Allows you to edit a boolean. In Lisp this means a variable which is | 2633 | A widget for editing a boolean value. Its super is the @code{toggle} |
| 1311 | either @code{nil} meaning false, or non-@code{nil} meaning true. | 2634 | widget. |
| 2635 | |||
| 2636 | Its value may be @code{nil}, meaning false, or non-@code{nil}, meaning | ||
| 2637 | true. | ||
| 2638 | @end deffn | ||
| 2639 | |||
| 2640 | @deffn Widget color | ||
| 2641 | A widget to edit a color name. | ||
| 2642 | |||
| 2643 | In addition, shows a sample that shows the selected color, if any. | ||
| 1312 | @end deffn | 2644 | @end deffn |
| 1313 | 2645 | ||
| 2646 | @deffn Widget other | ||
| 2647 | A widget useful as the last item in a @code{choice} widget, since it | ||
| 2648 | matches any value. | ||
| 2649 | |||
| 2650 | Its super is the @code{sexp} widget, and its @code{:value} is | ||
| 2651 | @code{other}, by default. | ||
| 2652 | @end deffn | ||
| 2653 | |||
| 2654 | @deffn Widget coding-system | ||
| 2655 | A widget that can represent a coding system name, offering | ||
| 2656 | completions. @xref{Coding Systems,,,elisp, the Emacs Lisp Reference | ||
| 2657 | Manual}. Its super is the @code{symbol} widget. | ||
| 2658 | |||
| 2659 | It has a default value of @code{undecided}. | ||
| 2660 | @end deffn | ||
| 2661 | |||
| 2662 | @deffn Widget key | ||
| 2663 | A widget to represent a key sequence. | ||
| 2664 | |||
| 2665 | It uses a special keymap as the @code{:keymap}. | ||
| 2666 | @end deffn | ||
| 1314 | 2667 | ||
| 1315 | @node composite | 2668 | @node composite |
| 1316 | @section Composite Sexp Widgets | 2669 | @subsection Composite Sexp Widgets |
| 1317 | @cindex composite sexp widgets | 2670 | @cindex composite sexp widgets |
| 1318 | 2671 | ||
| 1319 | The syntax for the composite widget construct is: | 2672 | The syntax for the composite widget construct is: |
| @@ -1327,6 +2680,9 @@ where each @var{component} must be a widget type. Each component widget | |||
| 1327 | will be displayed in the buffer, and will be editable by the user. | 2680 | will be displayed in the buffer, and will be editable by the user. |
| 1328 | 2681 | ||
| 1329 | @deffn Widget cons | 2682 | @deffn Widget cons |
| 2683 | A widget to edit cons-cell values. Its super is the @code{group} | ||
| 2684 | widget. | ||
| 2685 | |||
| 1330 | The value of a @code{cons} widget must be a cons-cell whose @sc{car} | 2686 | The value of a @code{cons} widget must be a cons-cell whose @sc{car} |
| 1331 | and @sc{cdr} have two specified types. It uses this syntax: | 2687 | and @sc{cdr} have two specified types. It uses this syntax: |
| 1332 | 2688 | ||
| @@ -1336,8 +2692,10 @@ and @sc{cdr} have two specified types. It uses this syntax: | |||
| 1336 | @end deffn | 2692 | @end deffn |
| 1337 | 2693 | ||
| 1338 | @deffn Widget choice | 2694 | @deffn Widget choice |
| 1339 | The value matched by a @code{choice} widget must have one of a fixed | 2695 | A widget to hold a value of one of a fixed set of types. Its super is |
| 1340 | set of types. The widget's syntax is as follows: | 2696 | the @code{menu-choice} widget. |
| 2697 | |||
| 2698 | The widget's syntax is as follows: | ||
| 1341 | 2699 | ||
| 1342 | @example | 2700 | @example |
| 1343 | @var{type} ::= (choice [@var{keyword} @var{argument}]... @var{type} ... ) | 2701 | @var{type} ::= (choice [@var{keyword} @var{argument}]... @var{type} ... ) |
| @@ -1345,9 +2703,19 @@ set of types. The widget's syntax is as follows: | |||
| 1345 | 2703 | ||
| 1346 | The value of a @code{choice} widget can be anything that matches any of the | 2704 | The value of a @code{choice} widget can be anything that matches any of the |
| 1347 | @var{types}. | 2705 | @var{types}. |
| 2706 | |||
| 2707 | This widget only displays the widget that corresponds to the current | ||
| 2708 | choice. | ||
| 2709 | @end deffn | ||
| 2710 | |||
| 2711 | @deffn Widget radio | ||
| 2712 | A widget to hold a value of one of a fixed set of options. Its super is | ||
| 2713 | the @code{radio-button-choice} widget. | ||
| 1348 | @end deffn | 2714 | @end deffn |
| 1349 | 2715 | ||
| 1350 | @deffn Widget list | 2716 | @deffn Widget list |
| 2717 | A widget to edit a list value. Its super is the @code{group} widget. | ||
| 2718 | |||
| 1351 | The value of a @code{list} widget must be a list whose element types | 2719 | The value of a @code{list} widget must be a list whose element types |
| 1352 | match the specified component types: | 2720 | match the specified component types: |
| 1353 | 2721 | ||
| @@ -1355,15 +2723,18 @@ match the specified component types: | |||
| 1355 | @var{type} ::= (list [@var{keyword} @var{argument}]... @var{component-type}...) | 2723 | @var{type} ::= (list [@var{keyword} @var{argument}]... @var{component-type}...) |
| 1356 | @end example | 2724 | @end example |
| 1357 | 2725 | ||
| 1358 | Thus, @code{(list string number)} matches lists of two elements, | 2726 | Thus, for example, @code{(list string number)} matches lists of two |
| 1359 | the first being a string and the second being a number. | 2727 | elements, the first being a string and the second being a number. |
| 1360 | @end deffn | 2728 | @end deffn |
| 1361 | 2729 | ||
| 1362 | @deffn Widget vector | 2730 | @deffn Widget vector |
| 2731 | A widget to edit a vector value. Its super is the @code{group} | ||
| 2732 | widget. | ||
| 2733 | |||
| 1363 | The @code{vector} widget is like the @code{list} widget but matches | 2734 | The @code{vector} widget is like the @code{list} widget but matches |
| 1364 | vectors instead of lists. Thus, @code{(vector string number)} matches | 2735 | vectors instead of lists. Thus, for example, @code{(vector string |
| 1365 | vectors of two elements, the first being a string and the second being | 2736 | number)} matches vectors of two elements, the first being a string and |
| 1366 | a number. | 2737 | the second being a number. |
| 1367 | @end deffn | 2738 | @end deffn |
| 1368 | 2739 | ||
| 1369 | The above suffice for specifying fixed size lists and vectors. To get | 2740 | The above suffice for specifying fixed size lists and vectors. To get |
| @@ -1393,8 +2764,12 @@ trying to explain it here, I'll just suggest you meditate over it for | |||
| 1393 | a while. | 2764 | a while. |
| 1394 | 2765 | ||
| 1395 | @deffn Widget set | 2766 | @deffn Widget set |
| 1396 | Specifies a type whose values are the lists whose elements all belong | 2767 | A widget to hold a list of members from a fixed set. Its super is the |
| 1397 | to a given set. The order of elements of the list is not significant. | 2768 | @code{checklist} widget. |
| 2769 | |||
| 2770 | Its value is a list where the elements all belong to a given set. The | ||
| 2771 | order of elements of the list is not significant. | ||
| 2772 | |||
| 1398 | Here's the syntax: | 2773 | Here's the syntax: |
| 1399 | 2774 | ||
| 1400 | @example | 2775 | @example |
| @@ -1407,111 +2782,55 @@ Use @code{const} to specify each permitted element, like this: | |||
| 1407 | 2782 | ||
| 1408 | @deffn Widget repeat | 2783 | @deffn Widget repeat |
| 1409 | Specifies a list of any number of elements that fit a certain type. | 2784 | Specifies a list of any number of elements that fit a certain type. |
| 2785 | Its super is the @code{editable-list} widget. | ||
| 1410 | 2786 | ||
| 1411 | @example | 2787 | @example |
| 1412 | @var{type} ::= (repeat [@var{keyword} @var{argument}]... @var{type}) | 2788 | @var{type} ::= (repeat [@var{keyword} @var{argument}]... @var{type}) |
| 1413 | @end example | 2789 | @end example |
| 1414 | @end deffn | 2790 | @end deffn |
| 1415 | 2791 | ||
| 1416 | @node Widget Properties | 2792 | @deffn Widget plist |
| 1417 | @chapter Properties | 2793 | A widget to edit property lists. Its super is the @code{list} widget. |
| 1418 | @cindex properties of widgets | ||
| 1419 | @cindex widget properties | ||
| 1420 | |||
| 1421 | You can examine or set the value of a widget by using the widget object | ||
| 1422 | that was returned by @code{widget-create}. | ||
| 1423 | |||
| 1424 | @defun widget-value widget | ||
| 1425 | Return the current value contained in @var{widget}. | ||
| 1426 | It is an error to call this function on an uninitialized widget. | ||
| 1427 | @end defun | ||
| 1428 | |||
| 1429 | @defun widget-value-set widget value | ||
| 1430 | Set the value contained in @var{widget} to @var{value}. | ||
| 1431 | It is an error to call this function with an invalid @var{value}. | ||
| 1432 | @end defun | ||
| 1433 | |||
| 1434 | @strong{Important:} You @emph{must} call @code{widget-setup} after | ||
| 1435 | modifying the value of a widget before the user is allowed to edit the | ||
| 1436 | widget again. It is enough to call @code{widget-setup} once if you | ||
| 1437 | modify multiple widgets. This is currently only necessary if the widget | ||
| 1438 | contains an editing field, but may be necessary for other widgets in the | ||
| 1439 | future. | ||
| 1440 | |||
| 1441 | If your application needs to associate some information with the widget | ||
| 1442 | objects, for example a reference to the item being edited, it can be | ||
| 1443 | done with @code{widget-put} and @code{widget-get}. The property names | ||
| 1444 | must begin with a @samp{:}. | ||
| 1445 | |||
| 1446 | @defun widget-put widget property value | ||
| 1447 | In @var{widget} set @var{property} to @var{value}. | ||
| 1448 | @var{property} should be a symbol, while @var{value} can be anything. | ||
| 1449 | @end defun | ||
| 1450 | |||
| 1451 | @defun widget-get widget property | ||
| 1452 | In @var{widget} return the value for @var{property}. | ||
| 1453 | @var{property} should be a symbol, the value is what was last set by | ||
| 1454 | @code{widget-put} for @var{property}. | ||
| 1455 | @end defun | ||
| 1456 | |||
| 1457 | @defun widget-member widget property | ||
| 1458 | Non-@code{nil} if @var{widget} has a value (even @code{nil}) for | ||
| 1459 | property @var{property}. | ||
| 1460 | @end defun | ||
| 1461 | |||
| 1462 | @defun widget-apply widget property &rest args | ||
| 1463 | Apply the value of @var{property} to @var{widget}, passing @var{args} | ||
| 1464 | as additional arguments to the function. Return the result of that | ||
| 1465 | function call. | ||
| 1466 | @end defun | ||
| 1467 | 2794 | ||
| 1468 | Occasionally it can be useful to know which kind of widget you have, | 2795 | It recognizes the following properties: |
| 1469 | i.e., the name of the widget type you gave when the widget was created. | ||
| 1470 | 2796 | ||
| 1471 | @defun widget-type widget | 2797 | @table @code |
| 1472 | Return the name of @var{widget}, a symbol. | 2798 | @item :options |
| 1473 | @end defun | 2799 | A given set of recommended key-value values for the @code{plist} |
| 1474 | 2800 | widget. Each option shows up as a checklist item. | |
| 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 | 2801 | ||
| 1483 | @lisp | 2802 | @item :key-type |
| 1484 | ;; Examine if @var{widget} is active or not. | 2803 | The widget type to use for the plist keys. By default, it uses the |
| 1485 | (if (widget-apply @var{widget} :active) | 2804 | @code{symbol} widget. |
| 1486 | (message "Widget is active.") | ||
| 1487 | (message "Widget is inactive.") | ||
| 1488 | 2805 | ||
| 1489 | ;; Make @var{widget} inactive. | 2806 | @item :value-type |
| 1490 | (widget-apply @var{widget} :deactivate) | 2807 | The widget type to use for the plist values. By default, it uses the |
| 2808 | @code{sexp} widget. | ||
| 2809 | @end table | ||
| 2810 | @end deffn | ||
| 1491 | 2811 | ||
| 1492 | ;; Make @var{widget} active. | 2812 | @deffn Widget alist |
| 1493 | (widget-apply @var{widget} :activate) | 2813 | A widget to edit association lists. Its super is the @code{list} |
| 1494 | @end lisp | 2814 | widget. |
| 1495 | 2815 | ||
| 1496 | A widget is inactive if it, or any of its ancestors (found by | 2816 | It recognizes the same properties that the @code{plist} widget, with |
| 1497 | following the @code{:parent} link), have been deactivated. To make sure | 2817 | the difference that the @code{:key-type} uses by default a @code{sexp} |
| 1498 | a widget is really active, you must therefore activate both it and | 2818 | widget. |
| 1499 | all its ancestors. | 2819 | @end deffn |
| 1500 | 2820 | ||
| 1501 | @lisp | 2821 | Most composite widgets do not allow for recursion. That is, none of |
| 1502 | (while widget | 2822 | the contained widgets may be of the same type that is currently being |
| 1503 | (widget-apply widget :activate) | 2823 | defined. To allow for this kind of widgets, there's the @code{lazy} |
| 1504 | (setq widget (widget-get widget :parent))) | 2824 | widget. |
| 1505 | @end lisp | ||
| 1506 | 2825 | ||
| 1507 | You can check if a widget has been made inactive by examining the value | 2826 | @deffn Widget lazy |
| 1508 | of the @code{:inactive} keyword. If this is non-@code{nil}, the widget itself | 2827 | A base widget for recursive data structures. Its super is the |
| 1509 | has been deactivated. This is different from using the @code{:active} | 2828 | @code{default} widget. |
| 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 | 2829 | ||
| 2830 | When instantiated, it contains a single inferior widget of the widget | ||
| 2831 | type specified in the @code{:type} property. Its value is the same as | ||
| 2832 | the value of this inferior widget. | ||
| 2833 | @end deffn | ||
| 1515 | 2834 | ||
| 1516 | @node Defining New Widgets | 2835 | @node Defining New Widgets |
| 1517 | @chapter Defining New Widgets | 2836 | @chapter Defining New Widgets |
| @@ -1520,19 +2839,27 @@ its ancestors have been deactivated. Do not attempt to set the | |||
| 1520 | 2839 | ||
| 1521 | You can define specialized widgets with @code{define-widget}. It allows | 2840 | You can define specialized widgets with @code{define-widget}. It allows |
| 1522 | you to create a shorthand for more complex widgets, including specifying | 2841 | you to create a shorthand for more complex widgets, including specifying |
| 1523 | component widgets and new default values for the keyword | 2842 | component widgets and new default values for the keyword arguments. |
| 1524 | arguments. | ||
| 1525 | 2843 | ||
| 1526 | @defun define-widget name class doc &rest args | 2844 | @defun define-widget name class doc &rest args |
| 1527 | Define a new widget type named @var{name} from @code{class}. | 2845 | Define a new widget type named @var{name} that derives from @var{class}. |
| 1528 | 2846 | ||
| 1529 | @var{name} and class should both be symbols, @code{class} should be one | 2847 | @var{name} and @var{class} should both be symbols, and @var{class} |
| 1530 | of the existing widget types. | 2848 | should be one of the existing widget types. |
| 1531 | 2849 | ||
| 1532 | The third argument @var{doc} is a documentation string for the widget. | 2850 | The third argument @var{doc} is a documentation string for the widget. |
| 1533 | 2851 | ||
| 1534 | After the new widget has been defined, the following two calls will | 2852 | @var{args} should be key-value pairs, overriding keyword values of |
| 1535 | create identical widgets: | 2853 | @var{class}, or adding new recognized keywords for @var{name}. |
| 2854 | |||
| 2855 | Usually, you'll want to derive from an existing widget type, like the | ||
| 2856 | @code{editable-field} widget, or the @code{default} widget, but it's | ||
| 2857 | also possible to derive from nothing, by passing a value of @code{nil} | ||
| 2858 | as @var{class}. Note that if you do this, you're entirely responsible | ||
| 2859 | for defining a whole new default behavior for your widgets. | ||
| 2860 | |||
| 2861 | After using this function, the following two calls will create | ||
| 2862 | identical widgets: | ||
| 1536 | 2863 | ||
| 1537 | @itemize @bullet | 2864 | @itemize @bullet |
| 1538 | @item | 2865 | @item |
| @@ -1555,170 +2882,67 @@ in the @code{widget-type} property of @var{name}, which is what | |||
| 1555 | If you only want to specify defaults for keywords with no complex | 2882 | If you only want to specify defaults for keywords with no complex |
| 1556 | conversions, you can use @code{identity} as your conversion function. | 2883 | conversions, you can use @code{identity} as your conversion function. |
| 1557 | 2884 | ||
| 1558 | The following additional keyword arguments are useful when defining new | 2885 | When defining new widgets, the @code{:convert-widget} property might |
| 1559 | widgets: | 2886 | be useful: |
| 2887 | |||
| 1560 | @table @code | 2888 | @table @code |
| 1561 | @vindex convert-widget@r{ keyword} | 2889 | @vindex convert-widget@r{ keyword} |
| 1562 | @item :convert-widget | 2890 | @item :convert-widget |
| 1563 | Function to convert a widget type before creating a widget of that | 2891 | Function to convert a widget type before creating a widget of that |
| 1564 | type. It takes a widget type as an argument, and returns the converted | 2892 | type. |
| 1565 | widget type. When a widget is created, this function is called for the | ||
| 1566 | widget type and all the widget's parent types, most derived first. | ||
| 1567 | |||
| 1568 | The following predefined functions can be used here: | ||
| 1569 | |||
| 1570 | @defun widget-types-convert-widget widget | ||
| 1571 | Convert @code{:args} as widget types in @var{widget}. | ||
| 1572 | @end defun | ||
| 1573 | |||
| 1574 | @defun widget-value-convert-widget widget | ||
| 1575 | Initialize @code{:value} from @code{:args} in @var{widget}. | ||
| 1576 | @end defun | ||
| 1577 | |||
| 1578 | @vindex copy@r{ keyword} | ||
| 1579 | @item :copy | ||
| 1580 | Function to deep copy a widget type. It takes a shallow copy of the | ||
| 1581 | widget type as an argument (made by @code{copy-sequence}), and returns a | ||
| 1582 | deep copy. The purpose of this is to avoid having different instances | ||
| 1583 | of combined widgets share nested attributes. | ||
| 1584 | |||
| 1585 | The following predefined functions can be used here: | ||
| 1586 | |||
| 1587 | @defun widget-types-copy widget | ||
| 1588 | Copy @code{:args} as widget types in @var{widget}. | ||
| 1589 | @end defun | ||
| 1590 | |||
| 1591 | @vindex value-to-internal@r{ keyword} | ||
| 1592 | @item :value-to-internal | ||
| 1593 | Function to convert the value to the internal format. The function | ||
| 1594 | takes two arguments, a widget and an external value, and returns the | ||
| 1595 | internal value. The function is called on the present @code{:value} | ||
| 1596 | when the widget is created, and on any value set later with | ||
| 1597 | @code{widget-value-set}. | ||
| 1598 | |||
| 1599 | @vindex value-to-external@r{ keyword} | ||
| 1600 | @item :value-to-external | ||
| 1601 | Function to convert the value to the external format. The function | ||
| 1602 | takes two arguments, a widget and an internal value, and returns the | ||
| 1603 | external value. | ||
| 1604 | |||
| 1605 | @vindex create@r{ keyword} | ||
| 1606 | @item :create | ||
| 1607 | Function to create a widget from scratch. The function takes one | ||
| 1608 | argument, a widget type, and creates a widget of that type, inserts it | ||
| 1609 | in the buffer, and returns a widget object. | ||
| 1610 | |||
| 1611 | @vindex delete@r{ keyword} | ||
| 1612 | @item :delete | ||
| 1613 | Function to delete a widget. The function takes one argument, a widget, | ||
| 1614 | and should remove all traces of the widget from the buffer. | ||
| 1615 | 2893 | ||
| 1616 | The default value is: | 2894 | It takes a widget type as an argument, and returns the converted |
| 2895 | widget type. When a widget is created, this function is called for | ||
| 2896 | the widget type and all the widget's parent types, most derived first. | ||
| 1617 | 2897 | ||
| 1618 | @defun widget-default-delete widget | 2898 | The predefined functions @code{widget-types-convert-widget} and |
| 1619 | Remove @var{widget} from the buffer. | 2899 | @code{widget-value-convert-widget} can be used here. |
| 1620 | Delete all @code{:children} and @code{:buttons} in @var{widget}. | ||
| 1621 | @end defun | ||
| 1622 | |||
| 1623 | In most cases you should not change this value, but instead use | ||
| 1624 | @code{:value-delete} to make any additional cleanup. | ||
| 1625 | |||
| 1626 | @vindex value-create@r{ keyword} | ||
| 1627 | @item :value-create | ||
| 1628 | Function to expand the @samp{%v} escape in the format string. It will | ||
| 1629 | be called with the widget as its argument and should insert a | ||
| 1630 | representation of the widget's value in the buffer. | ||
| 1631 | |||
| 1632 | Nested widgets should be listed in @code{:children} or @code{:buttons} | ||
| 1633 | to make sure they are automatically deleted. | ||
| 1634 | |||
| 1635 | @vindex value-delete@r{ keyword} | ||
| 1636 | @item :value-delete | ||
| 1637 | Should remove the representation of the widget's value from the buffer. | ||
| 1638 | It will be called with the widget as its argument. It doesn't have to | ||
| 1639 | remove the text, but it should release markers and delete nested widgets | ||
| 1640 | if these are not listed in @code{:children} or @code{:buttons}. | ||
| 1641 | |||
| 1642 | @vindex value-get@r{ keyword} | ||
| 1643 | @item :value-get | ||
| 1644 | Function to extract the value of a widget, as it is displayed in the | ||
| 1645 | buffer. | ||
| 1646 | |||
| 1647 | The following predefined function can be used here: | ||
| 1648 | |||
| 1649 | @defun widget-value-value-get widget | ||
| 1650 | Return the @code{:value} property of @var{widget}. | ||
| 1651 | @end defun | ||
| 1652 | |||
| 1653 | @vindex format-handler@r{ keyword} | ||
| 1654 | @item :format-handler | ||
| 1655 | Function to handle unknown @samp{%} escapes in the format string. It | ||
| 1656 | will be called with the widget and the character that follows the | ||
| 1657 | @samp{%} as arguments. You can set this to allow your widget to handle | ||
| 1658 | non-standard escapes. | ||
| 1659 | |||
| 1660 | @findex widget-default-format-handler | ||
| 1661 | You should end up calling @code{widget-default-format-handler} to handle | ||
| 1662 | unknown escape sequences, which will handle the @samp{%h} and any future | ||
| 1663 | escape sequences, as well as give an error for unknown escapes. | ||
| 1664 | |||
| 1665 | @vindex action@r{ keyword} | ||
| 1666 | @item :action | ||
| 1667 | Function to handle user initiated events. By default, @code{:notify} | ||
| 1668 | the parent. | ||
| 1669 | |||
| 1670 | The following predefined function can be used here: | ||
| 1671 | |||
| 1672 | @defun widget-parent-action widget &optional event | ||
| 1673 | Tell @code{:parent} of @var{widget} to handle the @code{:action}. | ||
| 1674 | Optional @var{event} is the event that triggered the action. | ||
| 1675 | @end defun | ||
| 1676 | |||
| 1677 | @vindex prompt-value@r{ keyword} | ||
| 1678 | @item :prompt-value | ||
| 1679 | Function to prompt for a value in the minibuffer. The function should | ||
| 1680 | take four arguments, @var{widget}, @var{prompt}, @var{value}, and | ||
| 1681 | @var{unbound} and should return a value for widget entered by the user. | ||
| 1682 | @var{prompt} is the prompt to use. @var{value} is the default value to | ||
| 1683 | use, unless @var{unbound} is non-@code{nil}, in which case there is no default | ||
| 1684 | value. The function should read the value using the method most natural | ||
| 1685 | for this widget, and does not have to check that it matches. | ||
| 1686 | @end table | 2900 | @end table |
| 1687 | 2901 | ||
| 1688 | If you want to define a new widget from scratch, use the @code{default} | 2902 | @node Inspecting Widgets |
| 1689 | widget as its base. | 2903 | @chapter Inspecting Widgets |
| 1690 | |||
| 1691 | @deffn Widget default | ||
| 1692 | Widget used as a base for other widgets. | ||
| 1693 | |||
| 1694 | It provides most of the functionality that is referred to as ``by | ||
| 1695 | default'' in this text. | ||
| 1696 | @end deffn | ||
| 1697 | |||
| 1698 | @node Widget Browser | ||
| 1699 | @chapter Widget Browser | ||
| 1700 | @cindex widget browser | 2904 | @cindex widget browser |
| 1701 | 2905 | ||
| 1702 | There is a separate package to browse widgets. This is intended to help | 2906 | There is a separate package to browse widgets, in |
| 1703 | programmers who want to examine the content of a widget. The browser | 2907 | @samp{wid-browse.el}. This is intended to help programmers who want |
| 1704 | shows the value of each keyword, but uses links for certain keywords | 2908 | to examine the content of a widget. The browser shows the value of |
| 1705 | such as @samp{:parent}, which avoids printing cyclic structures. | 2909 | each keyword, but uses links for certain keywords such as |
| 2910 | @samp{:parent}, which avoids printing cyclic structures. | ||
| 1706 | 2911 | ||
| 1707 | @deffn Command widget-browse @var{widget} | 2912 | @deffn Command widget-browse @var{widget} |
| 1708 | Create a widget browser for @var{widget}. | 2913 | Create a widget browser for @var{widget}. |
| 2914 | |||
| 1709 | When called interactively, prompt for @var{widget}. | 2915 | When called interactively, prompt for @var{widget}. |
| 1710 | @end deffn | 2916 | @end deffn |
| 1711 | 2917 | ||
| 1712 | @deffn Command widget-browse-other-window @var{widget} | 2918 | @deffn Command widget-browse-other-window @var{widget} |
| 1713 | Create a widget browser for @var{widget} and show it in another window. | 2919 | Create a widget browser for @var{widget} and show it in another window. |
| 2920 | |||
| 1714 | When called interactively, prompt for @var{widget}. | 2921 | When called interactively, prompt for @var{widget}. |
| 1715 | @end deffn | 2922 | @end deffn |
| 1716 | 2923 | ||
| 1717 | @deffn Command widget-browse-at @var{pos} | 2924 | @deffn Command widget-browse-at @var{pos} |
| 1718 | Create a widget browser for the widget at @var{pos}. | 2925 | Create a widget browser for the widget at @var{pos}. |
| 2926 | |||
| 1719 | When called interactively, use the position of point. | 2927 | When called interactively, use the position of point. |
| 1720 | @end deffn | 2928 | @end deffn |
| 1721 | 2929 | ||
| 2930 | In addition, there's a function to describe the widget at point. | ||
| 2931 | |||
| 2932 | @deffn Command widget-describe &optional widget-or-pos | ||
| 2933 | Describe the widget at point. | ||
| 2934 | |||
| 2935 | When called from Lisp, @var{widget-or-pos} might be the widget to | ||
| 2936 | describe or a buffer position where a widget is present. If | ||
| 2937 | @var{widget-or-pos} is @code{nil}, the widget to describe is the | ||
| 2938 | widget at point. | ||
| 2939 | |||
| 2940 | This command sets up a help buffer for providing information about the | ||
| 2941 | widget, mainly its @code{:action} and @code{:mouse-down-action} | ||
| 2942 | functions, and provides links to describe it in more detail using the | ||
| 2943 | @code{widget-browse} commands described above. | ||
| 2944 | @end deffn | ||
| 2945 | |||
| 1722 | @node Widget Minor Mode | 2946 | @node Widget Minor Mode |
| 1723 | @chapter Widget Minor Mode | 2947 | @chapter Widget Minor Mode |
| 1724 | @cindex widget minor mode | 2948 | @cindex widget minor mode |
| @@ -1740,14 +2964,24 @@ Keymap used in @code{widget-minor-mode}. | |||
| 1740 | @chapter Utilities | 2964 | @chapter Utilities |
| 1741 | @cindex utility functions for widgets | 2965 | @cindex utility functions for widgets |
| 1742 | 2966 | ||
| 2967 | Here we describe some utility functions that don't really have a place | ||
| 2968 | earlier in this manual. | ||
| 2969 | |||
| 1743 | @defun widget-prompt-value widget prompt [ value unbound ] | 2970 | @defun widget-prompt-value widget prompt [ value unbound ] |
| 1744 | Prompt for a value matching @var{widget}, using @var{prompt}. | 2971 | Prompt for a value matching @var{widget}, using @var{prompt}. |
| 1745 | The current value is assumed to be @var{value}, unless @var{unbound} is | 2972 | The current value is assumed to be @var{value}, unless @var{unbound} is |
| 1746 | non-@code{nil}. | 2973 | non-@code{nil}. |
| 2974 | |||
| 2975 | Converts @var{widget} before prompting, and for prompting it uses the | ||
| 2976 | @code{:prompt-value} function. This function returns the user | ||
| 2977 | ``answer'', and it's an error if that answer doesn't match the widget, | ||
| 2978 | as with the @code{:match} function. | ||
| 2979 | |||
| 2980 | If the answer matches the widget, returns the answer. | ||
| 1747 | @end defun | 2981 | @end defun |
| 1748 | 2982 | ||
| 1749 | @defun widget-get-sibling widget | 2983 | @defun widget-get-sibling widget |
| 1750 | Get the item which @var{widget} is assumed to toggle. | 2984 | Get the item which @var{widget} should toggle. |
| 1751 | This is only meaningful for radio buttons or checkboxes in a list. | 2985 | This is only meaningful for radio buttons or checkboxes in a list. |
| 1752 | @end defun | 2986 | @end defun |
| 1753 | 2987 | ||
| @@ -1773,6 +3007,142 @@ the form (@var{name} . @var{value}) (i.e., the simplified format), | |||
| 1773 | then the return value is the @var{value} of the chosen element. | 3007 | then the return value is the @var{value} of the chosen element. |
| 1774 | @end defun | 3008 | @end defun |
| 1775 | 3009 | ||
| 3010 | @defun widget-image-find image | ||
| 3011 | Create a graphical button from @var{image}, an image or a file name | ||
| 3012 | sans extension. | ||
| 3013 | |||
| 3014 | If @var{image} is a file name, the file should be in | ||
| 3015 | @code{widget-image-directory}, or in a place where @code{find-image} | ||
| 3016 | will find it. | ||
| 3017 | @end defun | ||
| 3018 | |||
| 3019 | @defun widget-image-insert widget tag image | ||
| 3020 | As part of @var{widget}, insert the text @var{tag} or, if supported, | ||
| 3021 | the image @var{image}. | ||
| 3022 | |||
| 3023 | @var{image} should be as described in @code{widget-image-find}. | ||
| 3024 | @end defun | ||
| 3025 | |||
| 3026 | @defun widget-echo-help pos | ||
| 3027 | Display help-echo text for the widget at @var{pos}. | ||
| 3028 | |||
| 3029 | Uses the value of @code{:help-echo}. If it is a function, it calls it | ||
| 3030 | to get a string. Otherwise, it @code{eval}s it. | ||
| 3031 | @end defun | ||
| 3032 | |||
| 3033 | @node Customization | ||
| 3034 | @chapter Customization | ||
| 3035 | This chapter is about the customization options for the Widget | ||
| 3036 | library, for the end user. | ||
| 3037 | |||
| 3038 | @deffn Face widget-field-face | ||
| 3039 | Face used for other editing fields. | ||
| 3040 | @end deffn | ||
| 3041 | |||
| 3042 | @deffn Face widget-button-face | ||
| 3043 | Face used for buttons. | ||
| 3044 | @end deffn | ||
| 3045 | |||
| 3046 | @defopt widget-mouse-face | ||
| 3047 | Face used for highlighting a button when the mouse pointer moves | ||
| 3048 | across it. | ||
| 3049 | |||
| 3050 | The default value is @code{highlight}. | ||
| 3051 | @end defopt | ||
| 3052 | |||
| 3053 | @defopt widget-image-directory | ||
| 3054 | Directory where Widget should look for images. | ||
| 3055 | |||
| 3056 | Widget will look here for a file with the same name as specified for the | ||
| 3057 | image, with either a @file{.xpm} (if supported) or @file{.xbm} extension. | ||
| 3058 | @end defopt | ||
| 3059 | |||
| 3060 | @defopt widget-image-enable | ||
| 3061 | If non-@code{nil}, allow images to appear on displays where they are supported. | ||
| 3062 | @end defopt | ||
| 3063 | |||
| 3064 | @defopt widget-image-conversion | ||
| 3065 | An alist to convert symbols from image formats to file name suffixes. | ||
| 3066 | |||
| 3067 | Each element is a cons cell (@var{format} . @var{suffix}), where | ||
| 3068 | @var{format} is a symbol that represents an image format and | ||
| 3069 | @var{suffix} is its correspondent suffix. | ||
| 3070 | @end defopt | ||
| 3071 | |||
| 3072 | @defopt widget-button-prefix | ||
| 3073 | String to prefix buttons. | ||
| 3074 | @end defopt | ||
| 3075 | |||
| 3076 | @defopt widget-button-suffix | ||
| 3077 | String to suffix buttons. | ||
| 3078 | @end defopt | ||
| 3079 | |||
| 3080 | @defopt widget-push-button-prefix | ||
| 3081 | String to prefix push buttons. | ||
| 3082 | @end defopt | ||
| 3083 | |||
| 3084 | @defopt widget-push-button-suffix | ||
| 3085 | String to suffix push buttons. | ||
| 3086 | @end defopt | ||
| 3087 | |||
| 3088 | @defopt widget-link-prefix | ||
| 3089 | String to prefix links. | ||
| 3090 | @end defopt | ||
| 3091 | |||
| 3092 | @defopt widget-link-suffix | ||
| 3093 | String to suffix links. | ||
| 3094 | @end defopt | ||
| 3095 | |||
| 3096 | @defopt widget-choice-toggle | ||
| 3097 | If non-@code{nil}, toggle when there are just two options. | ||
| 3098 | |||
| 3099 | By default, its value is @code{nil}. | ||
| 3100 | @end defopt | ||
| 3101 | |||
| 3102 | @defopt widget-documentation-links | ||
| 3103 | If non-@code{nil}, add hyperlinks to documentation strings. | ||
| 3104 | @end defopt | ||
| 3105 | |||
| 3106 | @defopt widget-documentation-link-regexp | ||
| 3107 | A regexp that matches potential links in documentation strings. The | ||
| 3108 | link itself should match to the first group. | ||
| 3109 | @end defopt | ||
| 3110 | |||
| 3111 | @defopt widget-documentation-link-p | ||
| 3112 | A predicate function to test if a string is useful as a link. The | ||
| 3113 | function is called with one argument, a string, and should return | ||
| 3114 | non-@code{nil} if there should be a link for that string. | ||
| 3115 | |||
| 3116 | By default, the value is @code{intern-soft}. | ||
| 3117 | @end defopt | ||
| 3118 | |||
| 3119 | @defopt widget-documentation-link-type | ||
| 3120 | A symbol that represents a widget type to use for links in | ||
| 3121 | documentation strings. | ||
| 3122 | |||
| 3123 | By default, the value is @code{documentation-link}. | ||
| 3124 | @end defopt | ||
| 3125 | |||
| 3126 | @defopt widget-menu-max-size | ||
| 3127 | Maximum size for a popup menu. By default, its value is 40. | ||
| 3128 | |||
| 3129 | If a function ask you to choose from a menu that is larger than this | ||
| 3130 | value, it will use the minibuffer. | ||
| 3131 | @end defopt | ||
| 3132 | |||
| 3133 | @defopt widget-menu-max-shortcuts | ||
| 3134 | Largest number of items for which it works to choose one with a | ||
| 3135 | character. | ||
| 3136 | |||
| 3137 | For a larger number, use the minibuffer. | ||
| 3138 | @end defopt | ||
| 3139 | |||
| 3140 | @defopt widget-menu-minibuffer-flag | ||
| 3141 | Whether to use the minibuffer to ask for a choice. | ||
| 3142 | |||
| 3143 | If @code{nil}, the default, read a single character. | ||
| 3144 | @end defopt | ||
| 3145 | |||
| 1776 | @node Widget Wishlist | 3146 | @node Widget Wishlist |
| 1777 | @chapter Wishlist | 3147 | @chapter Wishlist |
| 1778 | @cindex todo | 3148 | @cindex todo |
| @@ -1809,15 +3179,6 @@ Find a way to disable mouse highlight for inactive widgets. | |||
| 1809 | Find a way to make glyphs look inactive. | 3179 | Find a way to make glyphs look inactive. |
| 1810 | 3180 | ||
| 1811 | @item | 3181 | @item |
| 1812 | Add @code{property-list} widget. | ||
| 1813 | |||
| 1814 | @item | ||
| 1815 | Add @code{association-list} widget. | ||
| 1816 | |||
| 1817 | @item | ||
| 1818 | Add @code{key-binding} widget. | ||
| 1819 | |||
| 1820 | @item | ||
| 1821 | Add @code{widget} widget for editing widget specifications. | 3182 | Add @code{widget} widget for editing widget specifications. |
| 1822 | 3183 | ||
| 1823 | @item | 3184 | @item |