comparison man/widget.texi @ 412:697ef44129c6 r21-2-14

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