widget.texi 54 KB

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