comparison man/widget.texi @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents b980b6286996
children 25f70ba0133c
comparison
equal deleted inserted replaced
148:f659db2a1f73 149:538048ae2ab8
11 11
12 @node Top, Introduction, (dir), (dir) 12 @node Top, Introduction, (dir), (dir)
13 @comment node-name, next, previous, up 13 @comment node-name, next, previous, up
14 @top The Emacs Widget Library 14 @top The Emacs Widget Library
15 15
16 Version: 1.84 16 Version: 1.97
17 17
18 @menu 18 @menu
19 * Introduction:: 19 * Introduction::
20 * User Interface:: 20 * User Interface::
21 * Programming Example:: 21 * Programming Example::
22 * Setting Up the Buffer:: 22 * Setting Up the Buffer::
23 * Basic Types:: 23 * Basic Types::
24 * Sexp Types:: 24 * Sexp Types::
25 * Widget Properties:: 25 * Widget Properties::
26 * Defining New Widgets:: 26 * Defining New Widgets::
27 * Widget Wishlist.:: 27 * Widget Browser::
28 * Widget Minor Mode::
29 * Utilities::
30 * Widget Wishlist::
28 @end menu 31 @end menu
29 32
30 @node Introduction, User Interface, Top, Top 33 @node Introduction, User Interface, Top, Top
31 @comment node-name, next, previous, up 34 @comment node-name, next, previous, up
32 @section Introduction 35 @section Introduction
227 usually created by the @code{link} widget. 230 usually created by the @code{link} widget.
228 @item The @samp{@b{[ ]}} and @samp{@b{[X]}} buttons. 231 @item The @samp{@b{[ ]}} and @samp{@b{[X]}} buttons.
229 Activating one of these will convert it to the other. This is useful 232 Activating one of these will convert it to the other. This is useful
230 for implementing multiple-choice fields. You can create it wit 233 for implementing multiple-choice fields. You can create it wit
231 @item The @samp{@b{( )}} and @samp{@b{(*)}} buttons. 234 @item The @samp{@b{( )}} and @samp{@b{(*)}} buttons.
232 Only one radio button in a @code{radio-button-choice} widget can be selected at any 235 Only one radio button in a @code{radio-button-choice} widget can be
233 time. When you push one of the unselected radio buttons, it will be 236 selected at any time. When you push one of the unselected radio
234 selected and the previous selected radio button will become unselected. 237 buttons, it will be selected and the previous selected radio button will
238 become unselected.
235 @item The @samp{@b{[Apply Form]}} @samp{@b{[Reset Form]}} buttons. 239 @item The @samp{@b{[Apply Form]}} @samp{@b{[Reset Form]}} buttons.
236 These are explicit buttons made with the @code{push-button} widget. The main 240 These are explicit buttons made with the @code{push-button} widget. The main
237 difference from the @code{link} widget is that the buttons are will be 241 difference from the @code{link} widget is that the buttons are will be
238 displayed as GUI buttons when possible. 242 displayed as GUI buttons when possible.
239 enough. 243 enough.
526 A function which takes a widget as an argument, and return nil if the 530 A function which takes a widget as an argument, and return nil if the
527 widgets current value is valid for the widget. Otherwise, it should 531 widgets current value is valid for the widget. Otherwise, it should
528 return the widget containing the invalid data, and set that widgets 532 return the widget containing the invalid data, and set that widgets
529 @code{:error} property to a string explaining the error. 533 @code{:error} property to a string explaining the error.
530 534
535 The following predefined function can be used:
536
537 @defun widget-children-validate widget
538 All the @code{:children} of @var{widget} must be valid.
539 @end defun
540
531 @item :tab-order 541 @item :tab-order
532 Specify the order in which widgets are traversed with 542 Specify the order in which widgets are traversed with
533 @code{widget-forward} or @code{widget-backward}. This is only partially 543 @code{widget-forward} or @code{widget-backward}. This is only partially
534 implemented. 544 implemented.
535 545
583 * choice-item:: 593 * choice-item::
584 * toggle:: 594 * toggle::
585 * checkbox:: 595 * checkbox::
586 * checklist:: 596 * checklist::
587 * editable-list:: 597 * editable-list::
598 * group::
588 @end menu 599 @end menu
589 600
590 @node link, url-link, Basic Types, Basic Types 601 @node link, url-link, Basic Types, Basic Types
591 @comment node-name, next, previous, up 602 @comment node-name, next, previous, up
592 @subsection The @code{link} Widget 603 @subsection The @code{link} Widget
919 Replace with the checkbox. 930 Replace with the checkbox.
920 @item %% 931 @item %%
921 Insert a literal @samp{%}. 932 Insert a literal @samp{%}.
922 @end table 933 @end table
923 934
935 @item :greedy
936 Usually, a checklist will only match if the items are in the exact
937 sequence given in the specification. By setting @code{:greedy} to
938 non-nil, it will allow the items to come in any sequence. However, if
939 you extract the value they will be in the sequence given in the
940 checklist. I.e. the original sequence is forgotten.
941
924 @item button-args 942 @item button-args
925 A list of keywords to pass to the checkboxes. Useful for setting 943 A list of keywords to pass to the checkboxes. Useful for setting
926 e.g. the @samp{:help-echo} for each checkbox. 944 e.g. the @samp{:help-echo} for each checkbox.
927 945
928 @item :buttons 946 @item :buttons
933 951
934 @item :args 952 @item :args
935 The list of types. 953 The list of types.
936 @end table 954 @end table
937 955
938 @node editable-list, , checklist, Basic Types 956 @node editable-list, group, checklist, Basic Types
939 @comment node-name, next, previous, up 957 @comment node-name, next, previous, up
940 @subsection The @code{editable-list} Widget 958 @subsection The @code{editable-list} Widget
941 959
942 Syntax: 960 Syntax:
943 961
944 @example 962 @example
945 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE) 963 TYPE ::= (editable-list [KEYWORD ARGUMENT]... TYPE)
946 @end example 964 @end example
947 965
948 The value is a list, where each member represent one widget of type 966 The value is a list, where each member represents one widget of type
949 @var{type}. 967 @var{type}.
950 968
951 The following extra properties are recognized. 969 The following extra properties are recognized.
952 970
953 @table @code 971 @table @code
985 @item :args 1003 @item :args
986 List whose car is the type of the list elements. 1004 List whose car is the type of the list elements.
987 1005
988 @end table 1006 @end table
989 1007
1008 @node group, , editable-list, Basic Types
1009 @comment node-name, next, previous, up
1010 @subsection The @code{group} Widget
1011
1012 This widget simply group other widget together.
1013
1014 Syntax:
1015
1016 @example
1017 TYPE ::= (group [KEYWORD ARGUMENT]... TYPE...)
1018 @end example
1019
1020 The value is a list, with one member for each @var{type}.
1021
990 @node Sexp Types, Widget Properties, Basic Types, Top 1022 @node Sexp Types, Widget Properties, Basic Types, Top
991 @comment 1023 @comment
992 @section Sexp Types 1024 @section Sexp Types
993 1025
994 A number of widgets for editing s-expressions (lisp types) are also 1026 A number of widgets for editing s-expressions (lisp types) are also
995 available. These basically fall in three categories: @dfn{atoms}, 1027 available. These basically fall in the following categories.
996 @dfn{composite types}, and @dfn{generic}.
997 1028
998 @menu 1029 @menu
1030 * constants::
999 * generic:: 1031 * generic::
1000 * atoms:: 1032 * atoms::
1001 * composite:: 1033 * composite::
1002 @end menu 1034 @end menu
1003 1035
1004 @node generic, atoms, Sexp Types, Sexp Types 1036 @node constants, generic, Sexp Types, Sexp Types
1005 @comment node-name, next, previous, up 1037 @comment node-name, next, previous, up
1006 @subsection The Generic Widget. 1038 @subsection The Constant Widgets.
1007 1039
1008 The @code{const} and @code{sexp} widgets can contain any lisp 1040 The @code{const} widget can contain any lisp expression, but the user is
1009 expression. In the case of the @code{const} widget the user is
1010 prohibited from editing edit it, which is mainly useful as a component 1041 prohibited from editing edit it, which is mainly useful as a component
1011 of one of the composite widgets. 1042 of one of the composite widgets.
1012 1043
1013 The syntax for the generic widgets is 1044 The syntax for the @code{const} widget is
1014 1045
1015 @example 1046 @example
1016 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ]) 1047 TYPE ::= (const [KEYWORD ARGUMENT]... [ VALUE ])
1017 @end example 1048 @end example
1018 1049
1022 @deffn Widget const 1053 @deffn Widget const
1023 This will display any valid s-expression in an immutable part of the 1054 This will display any valid s-expression in an immutable part of the
1024 buffer. 1055 buffer.
1025 @end deffn 1056 @end deffn
1026 1057
1058 There are two variations of the @code{const} widget, namely
1059 @code{variable-item} and @code{function-item}. These should contain a
1060 symbol with a variable or function binding. The major difference from
1061 the @code{const} widget is that they will allow the user to see the
1062 variable or function documentation for the symbol.
1063
1064 @deffn Widget variable-item
1065 An immutable symbol that is bound as a variable.
1066 @end deffn
1067
1068 @deffn Widget function-item
1069 An immutable symbol that is bound as a function.
1070 @end deffn
1071
1072 @node generic, atoms, constants, Sexp Types
1073 @comment node-name, next, previous, up
1074 @subsection Generic Sexp Widget.
1075
1076 The @code{sexp} widget can contain any lisp expression, and allows the
1077 user to edit it inline in the buffer.
1078
1079 The syntax for the @code{sexp} widget is
1080
1081 @example
1082 TYPE ::= (sexp [KEYWORD ARGUMENT]... [ VALUE ])
1083 @end example
1084
1027 @deffn Widget sexp 1085 @deffn Widget sexp
1028 This will allow you to edit any valid s-expression in an editable buffer 1086 This will allow you to edit any valid s-expression in an editable buffer
1029 field. 1087 field.
1030 1088
1031 The @code{sexp} widget takes the same keyword arguments as the 1089 The @code{sexp} widget takes the same keyword arguments as the
1053 All the atom widgets take the same keyword arguments as the 1111 All the atom widgets take the same keyword arguments as the
1054 @code{editable-field} widget. 1112 @code{editable-field} widget.
1055 1113
1056 @deffn Widget string 1114 @deffn Widget string
1057 Allows you to edit a string in an editable field. 1115 Allows you to edit a string in an editable field.
1116 @end deffn
1117
1118 @deffn Widget regexp
1119 Allows you to edit a regular expression in an editable field.
1058 @end deffn 1120 @end deffn
1059 1121
1060 @deffn Widget character 1122 @deffn Widget character
1061 Allows you to enter a character in an editable field. 1123 Allows you to enter a character in an editable field.
1062 @end deffn 1124 @end deffn
1081 1143
1082 @deffn Widget symbol 1144 @deffn Widget symbol
1083 Allows you to edit a lisp symbol in an editable field. 1145 Allows you to edit a lisp symbol in an editable field.
1084 @end deffn 1146 @end deffn
1085 1147
1148 @deffn Widget function
1149 Allows you to edit a lambda expression, or a function name with completion.
1150 @end deffn
1151
1152 @deffn Widget variable
1153 Allows you to edit a variable name, with completion.
1154 @end deffn
1155
1086 @deffn Widget integer 1156 @deffn Widget integer
1087 Allows you to edit an integer in an editable field. 1157 Allows you to edit an integer in an editable field.
1088 @end deffn 1158 @end deffn
1089 1159
1090 @deffn Widget number 1160 @deffn Widget number
1114 The value of a @code{cons} widget is a cons-cell where the car is the 1184 The value of a @code{cons} widget is a cons-cell where the car is the
1115 value of the first component and the cdr is the value of the second 1185 value of the first component and the cdr is the value of the second
1116 component. There must be exactly two components. 1186 component. There must be exactly two components.
1117 @end deffn 1187 @end deffn
1118 1188
1119 @deffn Widget lisp 1189 @deffn Widget list
1120 The value of a @code{lisp} widget is a list containing the value of 1190 The value of a @code{list} widget is a list containing the value of
1121 each of its component. 1191 each of its component.
1122 @end deffn 1192 @end deffn
1123 1193
1124 @deffn Widget vector 1194 @deffn Widget vector
1125 The value of a @code{vector} widget is a vector containing the value of 1195 The value of a @code{vector} widget is a vector containing the value of
1256 ancestors have been deactivated. Do not attempt to set the 1326 ancestors have been deactivated. Do not attempt to set the
1257 @code{:inactive} keyword directly. Use the @code{:activate} 1327 @code{:inactive} keyword directly. Use the @code{:activate}
1258 @code{:deactivated} keywords instead. 1328 @code{:deactivated} keywords instead.
1259 1329
1260 1330
1261 @node Defining New Widgets, Widget Wishlist., Widget Properties, Top 1331 @node Defining New Widgets, Widget Browser, Widget Properties, Top
1262 @comment node-name, next, previous, up 1332 @comment node-name, next, previous, up
1263 @section Defining New Widgets 1333 @section Defining New Widgets
1264 1334
1265 You can define specialized widgets with @code{define-widget}. It allows 1335 You can define specialized widgets with @code{define-widget}. It allows
1266 you to create a shorthand for more complex widgets, including specifying 1336 you to create a shorthand for more complex widgets, including specifying
1306 Function to convert a widget type before creating a widget of that 1376 Function to convert a widget type before creating a widget of that
1307 type. It takes a widget type as an argument, and returns the converted 1377 type. It takes a widget type as an argument, and returns the converted
1308 widget type. When a widget is created, this function is called for the 1378 widget type. When a widget is created, this function is called for the
1309 widget type and all the widgets parent types, most derived first. 1379 widget type and all the widgets parent types, most derived first.
1310 1380
1381 The following predefined functions can be used here:
1382
1383 @defun widget-types-convert-widget widget
1384 Convert @code{:args} as widget types in @var{widget}.
1385 @end defun
1386
1387 @defun widget-value-convert-widget widget
1388 Initialize @code{:value} from @code{:args} in @var{widget}.
1389 @end defun
1390
1311 @item :value-to-internal 1391 @item :value-to-internal
1312 Function to convert the value to the internal format. The function 1392 Function to convert the value to the internal format. The function
1313 takes two arguments, a widget and an external value, and returns the 1393 takes two arguments, a widget and an external value, and returns the
1314 internal value. The function is called on the present @code{:value} 1394 internal value. The function is called on the present @code{:value}
1315 when the widget is created, and on any value set later with 1395 when the widget is created, and on any value set later with
1340 Should remove the representation of the widgets value from the buffer. 1420 Should remove the representation of the widgets value from the buffer.
1341 It will be called with the widget as its argument. It doesn't have to 1421 It will be called with the widget as its argument. It doesn't have to
1342 remove the text, but it should release markers and delete nested widgets 1422 remove the text, but it should release markers and delete nested widgets
1343 if such has been used. 1423 if such has been used.
1344 1424
1425 The following predefined function can be used here:
1426
1427 @defun widget-children-value-delete widget
1428 Delete all @code{:children} and @code{:buttons} in @var{widget}.
1429 @end defun
1430
1431 @item :value-get
1432 Function to extract the value of a widget, as it is displayed in the
1433 buffer.
1434
1435 The following predefined function can be used here:
1436
1437 @defun widget-value-value-get widget
1438 Return the @code{:value} property of @var{widget}.
1439 @end defun
1440
1345 @item :format-handler 1441 @item :format-handler
1346 Function to handle unknown @samp{%} escapes in the format string. It 1442 Function to handle unknown @samp{%} escapes in the format string. It
1347 will be called with the widget and the escape character as arguments. 1443 will be called with the widget and the escape character as arguments.
1348 You can set this to allow your widget to handle non-standard escapes. 1444 You can set this to allow your widget to handle non-standard escapes.
1349 1445
1350 You should end up calling @code{widget-default-format-handler} to handle 1446 You should end up calling @code{widget-default-format-handler} to handle
1351 unknown escape sequences, which will handle the @samp{%h} and any future 1447 unknown escape sequences, which will handle the @samp{%h} and any future
1352 escape sequences, as well as give an error for unknown escapes. 1448 escape sequences, as well as give an error for unknown escapes.
1449
1450 @item :action
1451 Function to handle user initiated events. By default, @code{:notify}
1452 the parent.
1453
1454 The following predefined function can be used here:
1455
1456 @defun widget-parent-action widget &optional event
1457 Tell @code{:parent} of @var{widget} to handle the @code{:action}.@br
1458 Optional @var{event} is the event that triggered the action.
1459 @end defun
1460
1461 @item :prompt-value
1462 Function to prompt for a value in the minibuffer. The function should
1463 take four arguments, @var{widget}, @var{prompt}, @var{value}, and
1464 @var{unbound} and should return a value for widget entered by the user.
1465 @var{prompt} is the prompt to use. @var{value} is the default value to
1466 use, unless @var{unbound} is non-nil in which case there are no default
1467 value. The function should read the value using the method most natural
1468 for this widget, and does not have to check that it matches.
1353 @end table 1469 @end table
1354 1470
1355 If you want to define a new widget from scratch, use the @code{default} 1471 If you want to define a new widget from scratch, use the @code{default}
1356 widget as its base. 1472 widget as its base.
1357 1473
1358 @deffn Widget default [ keyword argument ] 1474 @deffn Widget default
1359 Widget used as a base for other widgets. 1475 Widget used as a base for other widgets.
1360 1476
1361 It provides most of the functionality that is referred to as ``by 1477 It provides most of the functionality that is referred to as ``by
1362 default'' in this text. 1478 default'' in this text.
1363 @end deffn 1479 @end deffn
1364 1480
1365 @node Widget Wishlist., , Defining New Widgets, Top 1481 @node Widget Browser, Widget Minor Mode, Defining New Widgets, Top
1366 @comment node-name, next, previous, up 1482 @comment node-name, next, previous, up
1367 @section Wishlist. 1483 @section Widget Browser
1484
1485 There is a separate package to browse widgets. This is intended to help
1486 programmers who want to examine the content of a widget. The browser
1487 shows the value of each keyword, but uses links for certain keywords
1488 such as `:parent', which avoids printing cyclic structures.
1489
1490 @deffn Command widget-browse WIDGET
1491 Create a widget browser for WIDGET.
1492 When called interactively, prompt for WIDGET.
1493 @end deffn
1494
1495 @deffn Command widget-browse-other-window WIDGET
1496 Create a widget browser for WIDGET and show it in another window.
1497 When called interactively, prompt for WIDGET.
1498 @end deffn
1499
1500 @deffn Command widget-browse-at POS
1501 Create a widget browser for the widget at POS.
1502 When called interactively, use the position of point.
1503 @end deffn
1504
1505 @node Widget Minor Mode, Utilities, Widget Browser, Top
1506 @comment node-name, next, previous, up
1507 @section Widget Minor Mode
1508
1509 There is a minor mode for manipulating widgets in major modes that
1510 doesn't provide any support for widgets themselves. This is mostly
1511 intended to be useful for programmers doing experiments.
1512
1513 @deffn Command widget-minor-mode
1514 Togle minor mode for traversing widgets.
1515 With arg, turn widget mode on if and only if arg is positive.
1516 @end deffn
1517
1518 @defvar widget-minor-mode-keymap
1519 Keymap used in @code{widget-minor-mode}.
1520 @end defvar
1521
1522 @node Utilities, Widget Wishlist, Widget Minor Mode, Top
1523 @comment node-name, next, previous, up
1524 @section Utilities.
1525
1526 @defun widget-prompt-value widget prompt [ value unbound ]
1527 Prompt for a value matching @var{widget}, using @var{prompt}.@br
1528 The current value is assumed to be @var{value}, unless @var{unbound} is
1529 non-nil.@refill
1530 @end defun
1531
1532 @defun widget-get-sibling widget
1533 Get the item @var{widget} is assumed to toggle.@br
1534 This is only meaningful for radio buttons or checkboxes in a list.
1535 @end defun
1536
1537 @node Widget Wishlist, , Utilities, Top
1538 @comment node-name, next, previous, up
1539 @section Wishlist
1368 1540
1369 @itemize @bullet 1541 @itemize @bullet
1370 @item 1542 @item
1371 It should be possible to add or remove items from a list with @kbd{C-k} 1543 It should be possible to add or remove items from a list with @kbd{C-k}
1372 and @kbd{C-o} (suggested by @sc{rms}). 1544 and @kbd{C-o} (suggested by @sc{rms}).
1376 dash (@samp{-}). The dash should be a button that, when activated, ask 1548 dash (@samp{-}). The dash should be a button that, when activated, ask
1377 whether you want to add or delete an item (@sc{rms} wanted to git rid of 1549 whether you want to add or delete an item (@sc{rms} wanted to git rid of
1378 the ugly buttons, the dash is my idea). 1550 the ugly buttons, the dash is my idea).
1379 1551
1380 @item 1552 @item
1381 Widgets such as @code{file} and @code{symbol} should prompt with completion.
1382
1383 @item
1384 The @code{menu-choice} tag should be prettier, something like the abbreviated 1553 The @code{menu-choice} tag should be prettier, something like the abbreviated
1385 menus in Open Look. 1554 menus in Open Look.
1386 1555
1387 @item 1556 @item
1388 The functions used in many widgets, like 1557 Finish @code{:tab-order}.
1389 @code{widget-item-convert-widget}, should not have names that are
1390 specific to the first widget where I happended to use them.
1391
1392 @item
1393 Flag to make @code{widget-move} skip a specified button.
1394
1395 @item
1396 Document `helper' functions for defining new widgets.
1397
1398 @item
1399 Activate the item this is below the mouse when the button is
1400 released, not the item this is below the mouse when the button is
1401 pressed. Dired and grep gets this right. Give feedback if possible.
1402
1403 @item
1404 Use @samp{@@deffn Widget} to document widgets.
1405
1406 @item
1407 Document global keywords in one place.
1408
1409 Document keywords particular to a specific widget in the widget
1410 definition.
1411
1412 Document the `default' widget first.
1413
1414 Split, when needed, keywords into those useful for normal
1415 customization, those primarily useful when deriving, and those who
1416 represent runtime information.
1417
1418 @item
1419 Figure out terminology and @sc{api} for the class/type/object/super
1420 stuff.
1421
1422 Perhaps the correct model is delegation?
1423
1424 @item
1425 Document @code{widget-browse}.
1426 1558
1427 @item 1559 @item
1428 Make indentation work with glyphs and propertional fonts. 1560 Make indentation work with glyphs and propertional fonts.
1429 1561
1430 @item 1562 @item
1431 Add object and class hierarchies to the browser. 1563 Add commands to show overview of object and class hierarchies to the
1564 browser.
1565
1566 @item
1567 Find a way to disable mouse highlight for inactive widgets.
1568
1569 @item
1570 Find a way to make glyphs look inactive.
1571
1572 @item
1573 Add @code{property-list} widget.
1574
1575 @item
1576 Add @code{association-list} widget.
1577
1578 @item
1579 Add @code{key-binding} widget.
1580
1581 @item
1582 Add @code{widget} widget for editing widget specifications.
1583
1584 @item
1585 Find clean way to implement variable length list.
1586 See @code{TeX-printer-list} for an explanation.
1587
1588 @item
1589 @kbd{C-h} in @code{widget-prompt-value} should give type specific help.
1432 1590
1433 @end itemize 1591 @end itemize
1434 1592
1435 @contents 1593 @contents
1436 @bye 1594 @bye