comparison man/widget.texi @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children 697ef44129c6
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
1 \input texinfo.tex 1 \input texinfo.tex
2 2
3 @c %**start of header 3 @c %**start of header
4 @setfilename ../info/widget 4 @setfilename ../info/widget.info
5 @settitle The Emacs Widget Library 5 @settitle The Emacs Widget Library
6 @iftex 6 @iftex
7 @afourpaper 7 @afourpaper
8 @headings double 8 @headings double
9 @end iftex 9 @end iftex
10 @c %**end of header 10 @c %**end of header
11
12 @ifinfo
13 @dircategory XEmacs Editor
14 @direntry
15 * Widgets: (widget). The Emacs Widget Library.
16 @end direntry
17 @end ifinfo
11 18
12 @node Top, Introduction, (dir), (dir) 19 @node Top, Introduction, (dir), (dir)
13 @comment node-name, next, previous, up 20 @comment node-name, next, previous, up
14 @top The Emacs Widget Library 21 @top The Emacs Widget Library
15 22
289 (switch-to-buffer (get-buffer-create "*Widget Example*")) 296 (switch-to-buffer (get-buffer-create "*Widget Example*"))
290 (kill-all-local-variables) 297 (kill-all-local-variables)
291 (make-local-variable 'widget-example-repeat) 298 (make-local-variable 'widget-example-repeat)
292 (widget-insert "Here is some documentation.\n\nName: ") 299 (widget-insert "Here is some documentation.\n\nName: ")
293 (widget-create 'editable-field 300 (widget-create 'editable-field
294 :size 13 301 :size 13
295 "My Name") 302 "My Name")
296 (widget-create 'menu-choice 303 (widget-create 'menu-choice
297 :tag "Choose" 304 :tag "Choose"
298 :value "This" 305 :value "This"
299 :help-echo "Choose me, please!" 306 :help-echo "Choose me, please!"
300 :notify (lambda (widget &rest ignore) 307 :notify (lambda (widget &rest ignore)
301 (message "%s is a good choice!" 308 (message "%s is a good choice!"
302 (widget-value widget))) 309 (widget-value widget)))
303 '(item :tag "This option" :value "This") 310 '(item :tag "This option" :value "This")
304 '(choice-item "That option") 311 '(choice-item "That option")
305 '(editable-field :menu-tag "No option" "Thus option")) 312 '(editable-field :menu-tag "No option" "Thus option"))
306 (widget-insert "Address: ") 313 (widget-insert "Address: ")
307 (widget-create 'editable-field 314 (widget-create 'editable-field
308 "Some Place\nIn some City\nSome country.") 315 "Some Place\nIn some City\nSome country.")
309 (widget-insert "\nSee also ") 316 (widget-insert "\nSee also ")
310 (widget-create 'link 317 (widget-create 'link
311 :notify (lambda (&rest ignore) 318 :notify (lambda (&rest ignore)
312 (widget-value-set widget-example-repeat 319 (widget-value-set widget-example-repeat
313 '("En" "To" "Tre")) 320 '("En" "To" "Tre"))
314 (widget-setup)) 321 (widget-setup))
315 "other work") 322 "other work")
316 (widget-insert " for more information.\n\nNumbers: count to three below\n") 323 (widget-insert " for more information.\n\nNumbers: count to three below\n")
317 (setq widget-example-repeat 324 (setq widget-example-repeat
318 (widget-create 'editable-list 325 (widget-create 'editable-list
319 :entry-format "%i %d %v" 326 :entry-format "%i %d %v"
320 :notify (lambda (widget &rest ignore) 327 :notify (lambda (widget &rest ignore)
321 (let ((old (widget-get widget 328 (let ((old (widget-get widget
322 ':example-length)) 329 ':example-length))
323 (new (length (widget-value widget)))) 330 (new (length (widget-value widget))))
324 (unless (eq old new) 331 (unless (eq old new)
325 (widget-put widget ':example-length new) 332 (widget-put widget ':example-length new)
326 (message "You can count to %d." new)))) 333 (message "You can count to %d." new))))
327 :value '("One" "Eh, two?" "Five!") 334 :value '("One" "Eh, two?" "Five!")
328 '(editable-field :value "three"))) 335 '(editable-field :value "three")))
329 (widget-insert "\n\nSelect multiple:\n\n") 336 (widget-insert "\n\nSelect multiple:\n\n")
330 (widget-create 'checkbox t) 337 (widget-create 'checkbox t)
331 (widget-insert " This\n") 338 (widget-insert " This\n")
332 (widget-create 'checkbox nil) 339 (widget-create 'checkbox nil)
333 (widget-insert " That\n") 340 (widget-insert " That\n")
334 (widget-create 'checkbox 341 (widget-create 'checkbox
335 :notify (lambda (&rest ignore) (message "Tickle")) 342 :notify (lambda (&rest ignore) (message "Tickle"))
336 t) 343 t)
337 (widget-insert " Thus\n\nSelect one:\n\n") 344 (widget-insert " Thus\n\nSelect one:\n\n")
338 (widget-create 'radio-button-choice 345 (widget-create 'radio-button-choice
339 :value "One" 346 :value "One"
340 :notify (lambda (widget &rest ignore) 347 :notify (lambda (widget &rest ignore)
341 (message "You selected %s" 348 (message "You selected %s"
342 (widget-value widget))) 349 (widget-value widget)))
343 '(item "One") '(item "Another One.") '(item "A Final One.")) 350 '(item "One") '(item "Another One.") '(item "A Final One."))
344 (widget-insert "\n") 351 (widget-insert "\n")
345 (widget-create 'push-button 352 (widget-create 'push-button
346 :notify (lambda (&rest ignore) 353 :notify (lambda (&rest ignore)
347 (if (= (length (widget-value widget-example-repeat)) 354 (if (= (length (widget-value widget-example-repeat))
348 3) 355 3)
349 (message "Congratulation!") 356 (message "Congratulation!")
350 (error "Three was the count!"))) 357 (error "Three was the count!")))
351 "Apply Form") 358 "Apply Form")
352 (widget-insert " ") 359 (widget-insert " ")
353 (widget-create 'push-button 360 (widget-create 'push-button
354 :notify (lambda (&rest ignore) 361 :notify (lambda (&rest ignore)
355 (widget-example)) 362 (widget-example))
356 "Reset Form") 363 "Reset Form")
357 (widget-insert "\n") 364 (widget-insert "\n")
358 (use-local-map widget-keymap) 365 (use-local-map widget-keymap)
359 (widget-setup)) 366 (widget-setup))
360 @end lisp 367 @end lisp
361 368
453 String to suffix buttons. 460 String to suffix buttons.
454 @end defopt 461 @end defopt
455 462
456 @item %@{ 463 @item %@{
457 @itemx %@} 464 @itemx %@}
458 The text inside will be displayed with the face specified by 465 The text inside will be displayed in the face specified by
459 @code{:sample-face}. 466 @code{:sample-face}.
460 467
461 @item %v 468 @item %v
462 This will be replaces with the buffer representation of the widgets 469 This will be replaced with the buffer representation of the widget's
463 value. What this is depends on the widget type. 470 value. What this is depends on the widget type.
464 471
465 @item %d 472 @item %d
466 Insert the string specified by @code{:doc} here. 473 Insert the string specified by @code{:doc} here.
467 474
551 Should be a function called with two arguments, the widget and a value, 558 Should be a function called with two arguments, the widget and a value,
552 and returning non-nil if the widget can represent the specified value. 559 and returning non-nil if the widget can represent the specified value.
553 560
554 @item :validate 561 @item :validate
555 A function which takes a widget as an argument, and return nil if the 562 A function which takes a widget as an argument, and return nil if the
556 widgets current value is valid for the widget. Otherwise, it should 563 widget's current value is valid for the widget. Otherwise it should
557 return the widget containing the invalid data, and set that widgets 564 return the widget containing the invalid data, and set that widget's
558 @code{:error} property to a string explaining the error. 565 @code{:error} property to a string explaining the error.
559 566
560 The following predefined function can be used: 567 The following predefined function can be used:
561 568
562 @defun widget-children-validate widget 569 @defun widget-children-validate widget
755 762
756 @example 763 @example
757 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... ) 764 TYPE ::= (menu-choice [KEYWORD ARGUMENT]... TYPE ... )
758 @end example 765 @end example
759 766
760 The @var{type} arguments represents each possible choice. The widgets 767 The @var{type} argument represents each possible choice. The widget's
761 value of will be the value of the chosen @var{type} argument. This 768 value will be that of the chosen @var{type} argument. This widget will
762 widget will match any value that matches at least one of the specified 769 match any value matching at least one of the specified @var{type}
763 @var{type} arguments. 770 arguments.
764 771
765 @table @code 772 @table @code
766 @item :void 773 @item :void
767 Widget type used as a fallback when the value does not match any of the 774 Widget type used as a fallback when the value does not match any of the
768 specified @var{type} arguments. 775 specified @var{type} arguments.
790 797
791 @example 798 @example
792 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... ) 799 TYPE ::= (radio-button-choice [KEYWORD ARGUMENT]... TYPE ... )
793 @end example 800 @end example
794 801
795 The @var{type} arguments represents each possible choice. The widgets 802 The @var{type} argument represents each possible choice. The widget's
796 value of will be the value of the chosen @var{type} argument. This 803 value will be that of the chosen @var{type} argument. This widget will
797 widget will match any value that matches at least one of the specified 804 match any value matching at least one of the specified @var{type}
798 @var{type} arguments. 805 arguments.
799 806
800 The following extra properties are recognized. 807 The following extra properties are recognized.
801 808
802 @table @code 809 @table @code
803 @item :entry-format 810 @item :entry-format
880 887
881 @example 888 @example
882 TYPE ::= (toggle [KEYWORD ARGUMENT]...) 889 TYPE ::= (toggle [KEYWORD ARGUMENT]...)
883 @end example 890 @end example
884 891
885 The widget has two possible states, `on' and `off', which corresponds to 892 The widget has two possible states, `on' and `off', which correspond to
886 a @code{t} or @code{nil} value. 893 a @code{t} or @code{nil} value respectively.
887 894
888 The following extra properties are recognized. 895 The following extra properties are recognized.
889 896
890 @table @code 897 @table @code
891 @item :on 898 @item :on
921 928
922 @example 929 @example
923 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... ) 930 TYPE ::= (checklist [KEYWORD ARGUMENT]... TYPE ... )
924 @end example 931 @end example
925 932
926 The @var{type} arguments represents each checklist item. The widgets 933 The @var{type} arguments represents each checklist item. The widget's
927 value of will be a list containing the value of each ticked @var{type} 934 value will be a list containing the values of all ticked @var{type}
928 argument. The checklist widget will match a list whose elements all 935 arguments. The checklist widget will match a list whose elements all
929 matches at least one of the specified @var{type} arguments. 936 match at least one of the specified @var{type} arguments.
930 937
931 The following extra properties are recognized. 938 The following extra properties are recognized.
932 939
933 @table @code 940 @table @code
934 @item :entry-format 941 @item :entry-format
942 @item %% 949 @item %%
943 Insert a literal @samp{%}. 950 Insert a literal @samp{%}.
944 @end table 951 @end table
945 952
946 @item :greedy 953 @item :greedy
947 Usually, a checklist will only match if the items are in the exact 954 Usually a checklist will only match if the items are in the exact
948 sequence given in the specification. By setting @code{:greedy} to 955 sequence given in the specification. By setting @code{:greedy} to
949 non-nil, it will allow the items to come in any sequence. However, if 956 non-nil, it will allow the items to appear in any sequence. However, if
950 you extract the value they will be in the sequence given in the 957 you extract the values they will be in the sequence given in the
951 checklist. I.e. the original sequence is forgotten. 958 checklist. I.e. the original sequence is forgotten.
952 959
953 @item button-args 960 @item button-args
954 A list of keywords to pass to the checkboxes. Useful for setting 961 A list of keywords to pass to the checkboxes. Useful for setting
955 e.g. the @samp{:help-echo} for each checkbox. 962 e.g. the @samp{:help-echo} for each checkbox.
956 963
1227 1234
1228 The value of a widget of this type will either have the form 1235 The value of a widget of this type will either have the form
1229 @samp{(file t)} or @code{(file string string)}. 1236 @samp{(file t)} or @code{(file string string)}.
1230 1237
1231 This concept of inline is probably hard to understand. It was certainly 1238 This concept of inline is probably hard to understand. It was certainly
1232 hard to implement so instead of confuse you more by trying to explain it 1239 hard to implement so instead of confusing you more by trying to explain
1233 here, I'll just suggest you meditate over it for a while. 1240 it here, I'll just suggest you meditate over it for a while.
1234 1241
1235 @deffn Widget choice 1242 @deffn Widget choice
1236 Allows you to edit a sexp which may have one of fixed set of types. It 1243 Allows you to edit a sexp which may have one of a fixed set of types.
1237 is currently implemented with the @code{choice-menu} basic widget, and 1244 It is currently implemented with the @code{choice-menu} basic widget,
1238 has a similar syntax. 1245 and has a similar syntax.
1239 @end deffn 1246 @end deffn
1240 1247
1241 @deffn Widget set 1248 @deffn Widget set
1242 Allows you to specify a type which must be a list whose elements all 1249 Allows you to specify a type which must be a list whose elements all
1243 belong to given set. The elements of the list is not significant. This 1250 belong to given set. The elements of the list is not significant. This
1317 1324
1318 ;; Make @var{widget} active. 1325 ;; Make @var{widget} active.
1319 (widget-apply @var{widget} :activate) 1326 (widget-apply @var{widget} :activate)
1320 @end lisp 1327 @end lisp
1321 1328
1322 A widget is inactive if itself, or any of its ancestors (found by 1329 A widget is inactive if itself or any of its ancestors (found by
1323 following the @code{:parent} link) have been deactivated. To make sure 1330 following the @code{:parent} link) have been deactivated. To make sure
1324 a widget is really active, you must therefore activate both itself, and 1331 a widget is really active, you must therefore activate both itself and
1325 all its ancestors. 1332 all its ancestors.
1326 1333
1327 @lisp 1334 @lisp
1328 (while widget 1335 (while widget
1329 (widget-apply widget :activate) 1336 (widget-apply widget :activate)
1330 (setq widget (widget-get widget :parent))) 1337 (setq widget (widget-get widget :parent)))
1331 @end lisp 1338 @end lisp
1332 1339
1333 You can check if a widget has been made inactive by examining the value 1340 You can check if a widget has been made inactive by examining the value
1334 of @code{:inactive} keyword. If this is non-nil, the widget itself has 1341 of the @code{:inactive} keyword. If this is non-nil, the widget itself
1335 been deactivated. This is different from using the @code{:active} 1342 has been deactivated. This is different from using the @code{:active}
1336 keyword, in that the later tell you if the widget @strong{or} any of its 1343 keyword, in that the latter tells you if the widget @strong{or} any of
1337 ancestors have been deactivated. Do not attempt to set the 1344 its ancestors have been deactivated. Do not attempt to set the
1338 @code{:inactive} keyword directly. Use the @code{:activate} 1345 @code{:inactive} keyword directly. Use the @code{:activate}
1339 @code{:deactivated} keywords instead. 1346 @code{:deactivate} keywords instead.
1340 1347
1341 1348
1342 @node Defining New Widgets, Widget Browser, Widget Properties, Top 1349 @node Defining New Widgets, Widget Browser, Widget Properties, Top
1343 @comment node-name, next, previous, up 1350 @comment node-name, next, previous, up
1344 @section Defining New Widgets 1351 @section Defining New Widgets
1345 1352
1346 You can define specialized widgets with @code{define-widget}. It allows 1353 You can define specialized widgets with @code{define-widget}. It allows
1347 you to create a shorthand for more complex widgets, including specifying 1354 you to create a shorthand for more complex widgets. This includes
1348 component widgets and default new default values for the keyword 1355 specifying component widgets and new default values for the keyword
1349 arguments. 1356 arguments.
1350 1357
1351 @defun widget-define name class doc &rest args 1358 @defun widget-define name class doc &rest args
1352 Define a new widget type named @var{name} from @code{class}. 1359 Define a new widget type named @var{name} from @code{class}.
1353 1360
1354 @var{name} and class should both be symbols, @code{class} should be one 1361 @var{name} and class should both be symbols, @code{class} should be one
1355 of the existing widget types. 1362 of the existing widget types.
1356 1363
1357 The third argument @var{DOC} is a documentation string for the widget. 1364 The third argument @var{DOC} is a documentation string for the widget.
1358 1365
1359 After the new widget has been defined, the following two calls will 1366 After the new widget has been defined the following two calls will
1360 create identical widgets: 1367 create identical widgets:
1361 1368
1362 @itemize @bullet 1369 @itemize @bullet
1363 @item 1370 @item
1364 @lisp 1371 @lisp
1371 @end lisp 1378 @end lisp
1372 @end itemize 1379 @end itemize
1373 1380
1374 @end defun 1381 @end defun
1375 1382
1376 Using @code{widget-define} does just store the definition of the widget 1383 Using @code{widget-define} just stores the definition of the widget type
1377 type in the @code{widget-type} property of @var{name}, which is what 1384 in the @code{widget-type} property of @var{name}, which is what
1378 @code{widget-create} uses. 1385 @code{widget-create} uses.
1379 1386
1380 If you just want to specify defaults for keywords with no complex 1387 If you just want to specify defaults for keywords with no complex
1381 conversions, you can use @code{identity} as your conversion function. 1388 conversions, you can use @code{identity} as your conversion function.
1382 1389
1385 @table @code 1392 @table @code
1386 @item :convert-widget 1393 @item :convert-widget
1387 Function to convert a widget type before creating a widget of that 1394 Function to convert a widget type before creating a widget of that
1388 type. It takes a widget type as an argument, and returns the converted 1395 type. It takes a widget type as an argument, and returns the converted
1389 widget type. When a widget is created, this function is called for the 1396 widget type. When a widget is created, this function is called for the
1390 widget type and all the widgets parent types, most derived first. 1397 widget type and all the widget's parent types, most derived first.
1391 1398
1392 The following predefined functions can be used here: 1399 The following predefined functions can be used here:
1393 1400
1394 @defun widget-types-convert-widget widget 1401 @defun widget-types-convert-widget widget
1395 Convert @code{:args} as widget types in @var{widget}. 1402 Convert @code{:args} as widget types in @var{widget}.
1399 Initialize @code{:value} from @code{:args} in @var{widget}. 1406 Initialize @code{:value} from @code{:args} in @var{widget}.
1400 @end defun 1407 @end defun
1401 1408
1402 @item :value-to-internal 1409 @item :value-to-internal
1403 Function to convert the value to the internal format. The function 1410 Function to convert the value to the internal format. The function
1404 takes two arguments, a widget and an external value, and returns the 1411 takes two arguments, a widget and an external value. It returns the
1405 internal value. The function is called on the present @code{:value} 1412 internal value. The function is called on the present @code{:value}
1406 when the widget is created, and on any value set later with 1413 when the widget is created, and on any value set later with
1407 @code{widget-value-set}. 1414 @code{widget-value-set}.
1408 1415
1409 @item :value-to-external 1416 @item :value-to-external
1413 when the widget is created, and on any value set later with 1420 when the widget is created, and on any value set later with
1414 @code{widget-value-set}. 1421 @code{widget-value-set}.
1415 1422
1416 @item :create 1423 @item :create
1417 Function to create a widget from scratch. The function takes one 1424 Function to create a widget from scratch. The function takes one
1418 argument, a widget type, and create a widget of that type, insert it in 1425 argument, a widget type, and creates a widget of that type, inserts it
1419 the buffer, and return a widget object. 1426 in the buffer, and returns a widget object.
1420 1427
1421 @item :delete 1428 @item :delete
1422 Function to delete a widget. The function takes one argument, a widget, 1429 Function to delete a widget. The function takes one argument, a widget,
1423 and should remove all traces of the widget from the buffer. 1430 and should remove all traces of the widget from the buffer.
1424 1431
1425 @item :value-create 1432 @item :value-create
1426 Function to expand the @samp{%v} escape in the format string. It will 1433 Function to expand the @samp{%v} escape in the format string. It will
1427 be called with the widget as its argument. Should 1434 be called with the widget as its argument and should insert a
1428 insert a representation of the widgets value in the buffer. 1435 representation of the widget's value in the buffer.
1429 1436
1430 @item :value-delete 1437 @item :value-delete
1431 Should remove the representation of the widgets value from the buffer. 1438 Should remove the representation of the widget's value from the buffer.
1432 It will be called with the widget as its argument. It doesn't have to 1439 It will be called with the widget as its argument. It doesn't have to
1433 remove the text, but it should release markers and delete nested widgets 1440 remove the text, but it should release markers and delete nested widgets
1434 if such has been used. 1441 if such have been used.
1435 1442
1436 The following predefined function can be used here: 1443 The following predefined function can be used here:
1437 1444
1438 @defun widget-children-value-delete widget 1445 @defun widget-children-value-delete widget
1439 Delete all @code{:children} and @code{:buttons} in @var{widget}. 1446 Delete all @code{:children} and @code{:buttons} in @var{widget}.
1453 Function to handle unknown @samp{%} escapes in the format string. It 1460 Function to handle unknown @samp{%} escapes in the format string. It
1454 will be called with the widget and the escape character as arguments. 1461 will be called with the widget and the escape character as arguments.
1455 You can set this to allow your widget to handle non-standard escapes. 1462 You can set this to allow your widget to handle non-standard escapes.
1456 1463
1457 You should end up calling @code{widget-default-format-handler} to handle 1464 You should end up calling @code{widget-default-format-handler} to handle
1458 unknown escape sequences, which will handle the @samp{%h} and any future 1465 unknown escape sequences. It will handle the @samp{%h} and any future
1459 escape sequences, as well as give an error for unknown escapes. 1466 escape sequences as well as give an error for unknown escapes.
1460 1467
1461 @item :action 1468 @item :action
1462 Function to handle user initiated events. By default, @code{:notify} 1469 Function to handle user initiated events. By default, @code{:notify}
1463 the parent. 1470 the parent.
1464 1471
1472 @item :prompt-value 1479 @item :prompt-value
1473 Function to prompt for a value in the minibuffer. The function should 1480 Function to prompt for a value in the minibuffer. The function should
1474 take four arguments, @var{widget}, @var{prompt}, @var{value}, and 1481 take four arguments, @var{widget}, @var{prompt}, @var{value}, and
1475 @var{unbound} and should return a value for widget entered by the user. 1482 @var{unbound} and should return a value for widget entered by the user.
1476 @var{prompt} is the prompt to use. @var{value} is the default value to 1483 @var{prompt} is the prompt to use. @var{value} is the default value to
1477 use, unless @var{unbound} is non-nil in which case there are no default 1484 use, unless @var{unbound} is non-nil. In this case there is no default
1478 value. The function should read the value using the method most natural 1485 value. The function should read the value using the method most natural
1479 for this widget, and does not have to check that it matches. 1486 for this widget and does not have to check whether it matches.
1480 @end table 1487 @end table
1481 1488
1482 If you want to define a new widget from scratch, use the @code{default} 1489 If you want to define a new widget from scratch, use the @code{default}
1483 widget as its base. 1490 widget as its base.
1484 1491