widget.texi 54 KB

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