forms.texi 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. \input texinfo @c -*-texinfo-*-
  2. @c documentation for forms-mode
  3. @c Written by Johan Vromans, and edited by Richard Stallman
  4. @comment %**start of header (This is for running Texinfo on a region.)
  5. @setfilename ../info/forms
  6. @settitle Forms Mode User's Manual
  7. @syncodeindex vr cp
  8. @syncodeindex fn cp
  9. @syncodeindex ky cp
  10. @iftex
  11. @finalout
  12. @setchapternewpage odd
  13. @end iftex
  14. @c @smallbook
  15. @comment %**end of header (This is for running Texinfo on a region.)
  16. @dircategory Emacs
  17. @direntry
  18. * Forms: (forms). Emacs package for editing data bases
  19. by filling in forms.
  20. @end direntry
  21. @ifinfo
  22. This file documents Forms mode, a form-editing major mode for GNU Emacs.
  23. Copyright 1989, 1997, 2001 Free Software Foundation, Inc.
  24. Permission is granted to copy, distribute and/or modify this document
  25. under the terms of the GNU Free Documentation License, Version 1.1 or
  26. any later version published by the Free Software Foundation; with no
  27. Invariant Sections, with the Front-Cover texts being ``A GNU
  28. Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
  29. license is included in the section entitled ``GNU Free Documentation
  30. License'' in the Emacs manual.
  31. (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
  32. this GNU Manual, like GNU software. Copies published by the Free
  33. Software Foundation raise funds for GNU development.''
  34. This document is part of a collection distributed under the GNU Free
  35. Documentation License. If you want to distribute this document
  36. separately from the collection, you can do so by adding a copy of the
  37. license to the document, as described in section 6 of the license.
  38. @end ifinfo
  39. @iftex
  40. @titlepage
  41. @sp 6
  42. @center @titlefont{Forms Mode User's Manual}
  43. @sp 4
  44. @center Forms-Mode version 2
  45. @sp 1
  46. @center for GNU Emacs 20.1
  47. @sp 1
  48. @center June 1997
  49. @sp 5
  50. @center Johan Vromans
  51. @center @i{jvromans@@squirrel.nl}
  52. @page
  53. @vskip 0pt plus 1filll
  54. Copyright @copyright{} 1989, 1997, 2001 Free Software Foundation, Inc.
  55. Permission is granted to copy, distribute and/or modify this document
  56. under the terms of the GNU Free Documentation License, Version 1.1 or
  57. any later version published by the Free Software Foundation; with no
  58. Invariant Sections, with the Front-Cover texts being ``A GNU
  59. Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
  60. license is included in the section entitled ``GNU Free Documentation
  61. License'' in the Emacs manual.
  62. (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
  63. this GNU Manual, like GNU software. Copies published by the Free
  64. Software Foundation raise funds for GNU development.''
  65. This document is part of a collection distributed under the GNU Free
  66. Documentation License. If you want to distribute this document
  67. separately from the collection, you can do so by adding a copy of the
  68. license to the document, as described in section 6 of the license.
  69. @page
  70. @end titlepage
  71. @end iftex
  72. @ifinfo
  73. @node Top
  74. @top Forms Mode
  75. Forms mode is an Emacs major mode for working with simple textual data
  76. bases in a forms-oriented manner. In Forms mode, the information in
  77. these files is presented in an Emacs window in a user-defined format,
  78. one record at a time. The user can view records or modify their
  79. contents.
  80. Forms mode is not a simple major mode, but requires two files to do its
  81. job: a control file and a data file. The data file holds the
  82. actual data to be presented. The control file describes
  83. how to present it.
  84. @menu
  85. * Forms Example:: An example: editing the password data base.
  86. * Entering and Exiting Forms Mode::
  87. How to visit a file in Forms mode.
  88. * Forms Commands:: Special commands to use while in Forms mode.
  89. * Data File Format:: How to format the data file.
  90. * Control File Format:: How to control forms mode.
  91. * Format Description:: How to define the forms layout.
  92. * Modifying Forms Contents:: How to modify.
  93. * Miscellaneous:: Forms mode messages and other remarks.
  94. * Error Messages:: List of error messages forms mode can produce.
  95. * Long Example:: A more complex control file example.
  96. * Credits:: Thanks everyone.
  97. * Index:: Index to this manual.
  98. @end menu
  99. @end ifinfo
  100. @node Forms Example
  101. @chapter Forms Example
  102. Let's illustrate Forms mode with an example. Suppose you are looking at
  103. the @file{/etc/passwd} file, and the screen looks like this:
  104. @example
  105. ====== /etc/passwd ======
  106. User : root Uid: 0 Gid: 1
  107. Name : Super User
  108. Home : /
  109. Shell: /bin/sh
  110. @end example
  111. As you can see, the familiar fields from the entry for the super user
  112. are all there, but instead of being colon-separated on one single line,
  113. they make up a forms.
  114. The contents of the forms consist of the contents of the fields of the
  115. record (e.g. @samp{root}, @samp{0}, @samp{1}, @samp{Super User})
  116. interspersed with normal text (e.g @samp{User : }, @samp{Uid: }).
  117. If you modify the contents of the fields, Forms mode will analyze your
  118. changes and update the file appropriately. You cannot modify the
  119. interspersed explanatory text (unless you go to some trouble about it),
  120. because that is marked read-only (@pxref{Text Properties,,, elisp, The
  121. Emacs Lisp Reference Manual}).
  122. The Forms mode control file specifies the relationship between the
  123. format of @file{/etc/passwd} and what appears on the screen in Forms
  124. mode. @xref{Control File Format}.
  125. @node Entering and Exiting Forms Mode
  126. @chapter Entering and Exiting Forms Mode
  127. @table @kbd
  128. @findex forms-find-file
  129. @item M-x forms-find-file @key{RET} @var{control-file} @key{RET}
  130. Visit a database using Forms mode. Specify the name of the
  131. @strong{control file}, not the data file!
  132. @findex forms-find-file-other-window
  133. @item M-x forms-find-file-other-window @key{RET} @var{control-file} @key{RET}
  134. Similar, but displays the file in another window.
  135. @end table
  136. The command @code{forms-find-file} evaluates the file
  137. @var{control-file}, and also visits it in Forms mode. What you see in
  138. its buffer is not the contents of this file, but rather a single record
  139. of the corresponding data file that is visited in its own buffer. So
  140. there are two buffers involved in Forms mode: the @dfn{forms buffer}
  141. that is initially used to visit the control file and that shows the
  142. records being browsed, and the @dfn{data buffer} that holds the data
  143. file being visited. The latter buffer is normally not visible.
  144. Initially, the first record is displayed in the forms buffer.
  145. The mode line displays the major mode name @samp{Forms}, followed by the
  146. minor mode @samp{View} if the data base is read-only. The number of the
  147. current record (@var{n}) and the total number of records in the
  148. file(@var{t}) are shown in the mode line as @samp{@var{n}/@var{t}}. For
  149. example:
  150. @example
  151. --%%-Emacs: passwd-demo (Forms View 1/54)----All-------
  152. @end example
  153. If the buffer is not read-only, you may change the buffer to modify the
  154. fields in the record. When you move to a different record, the contents
  155. of the buffer are parsed using the specifications in
  156. @code{forms-format-list}, and the data file is updated. If the record
  157. has fields that aren't included in the display, they are not changed.
  158. @vindex forms-mode-hooks
  159. Entering Forms mode runs the normal hook @code{forms-mode-hooks} to
  160. perform user-defined customization.
  161. To save any modified data, you can use @kbd{C-x C-s}
  162. (@code{forms-save-buffer}). This does not save the forms buffer (which would
  163. be rather useless), but instead saves the buffer visiting the data file.
  164. To terminate Forms mode, you can use @kbd{C-x C-s} (@code{forms-save-buffer})
  165. and then kill the forms buffer. However, the data buffer will still
  166. remain. If this is not desired, you have to kill this buffer too.
  167. @node Forms Commands
  168. @chapter Forms Commands
  169. The commands of Forms mode belong to the @kbd{C-c} prefix, with one
  170. exception: @key{TAB}, which moves to the next field. Forms mode uses
  171. different key maps for normal mode and read-only mode. In read-only
  172. Forms mode, you can access most of the commands without the @kbd{C-c}
  173. prefix, but you must type ordinary letters instead of control
  174. characters; for example, type @kbd{n} instead of @kbd{C-c C-n}.
  175. If your Emacs has been built with X-toolkit support, Forms mode will
  176. provide its own menu with a number of Forms mode commands.
  177. @table @kbd
  178. @findex forms-next-record
  179. @kindex C-c C-n
  180. @item C-c C-n
  181. Show the next record (@code{forms-next-record}). With a numeric
  182. argument @var{n}, show the @var{n}th next record.
  183. @findex forms-prev-record
  184. @kindex C-c C-p
  185. @item C-c C-p
  186. Show the previous record (@code{forms-prev-record}). With a numeric
  187. argument @var{n}, show the @var{n}th previous record.
  188. @findex forms-jump-record
  189. @kindex C-c C-l
  190. @item C-c C-l
  191. Jump to a record by number (@code{forms-jump-record}). Specify
  192. the record number with a numeric argument.
  193. @findex forms-first-record
  194. @kindex C-c <
  195. @item C-c <
  196. Jump to the first record (@code{forms-first-record}).
  197. @findex forms-last-record
  198. @kindex C-c >
  199. @item C-c >
  200. Jump to the last record (@code{forms-last-record}). This command also
  201. recalculates the number of records in the data file.
  202. @findex forms-next-field
  203. @kindex TAB
  204. @item @key{TAB}
  205. @kindex C-c TAB
  206. @itemx C-c @key{TAB}
  207. Jump to the next field in the current record (@code{forms-next-field}).
  208. With a numeric argument @var{n}, jump forward @var{n} fields. If this command
  209. would move past the last field, it wraps around to the first field.
  210. @findex forms-toggle-read-only
  211. @kindex C-c C-q
  212. @item C-c C-q
  213. Toggles read-only mode (@code{forms-toggle-read-only}). In read-only
  214. Forms mode, you cannot edit the fields; most Forms mode commands can be
  215. accessed without the prefix @kbd{C-c} if you use the normal letter
  216. instead (for example, type @kbd{n} instead of @kbd{C-c C-n}). In edit
  217. mode, you can edit the fields and thus change the contents of the data
  218. base; you must begin Forms mode commands with @code{C-c}. Switching
  219. to edit mode is allowed only if you have write access to the data file.
  220. @findex forms-insert-record
  221. @kindex C-c C-o
  222. @item C-c C-o
  223. Create a new record and insert it before the current record
  224. (@code{forms-insert-record}). It starts out with empty (or default)
  225. contents for its fields; you can then edit the fields. With a numeric
  226. argument, the new record is created @emph{after} the current one.
  227. See also @code{forms-modified-record-filter} in @ref{Modifying Forms
  228. Contents}.
  229. @findex forms-delete-record
  230. @kindex C-c C-k
  231. @item C-c C-k
  232. Delete the current record (@code{forms-delete-record}). You are
  233. prompted for confirmation before the record is deleted unless a numeric
  234. argument has been provided.
  235. @findex forms-search-forward
  236. @kindex C-c C-s @var{regexp} @key{RET}
  237. @item C-c C-s @var{regexp} @key{RET}
  238. Search forward for @var{regexp} in all records following this one
  239. (@code{forms-search-forward}). If found, this record is shown.
  240. If you give an empty argument, the previous regexp is used again.
  241. @findex forms-search-backward
  242. @kindex C-c C-r @var{regexp} @key{RET}
  243. @item C-c C-r @var{regexp} @key{RET}
  244. Search backward for @var{regexp} in all records following this one
  245. (@code{forms-search-backward}). If found, this record is shown.
  246. If you give an empty argument, the previous regexp is used again.
  247. @ignore
  248. @findex forms-exit
  249. @kindex C-c C-x
  250. @item C-c C-x
  251. Terminate Forms mode processing (@code{forms-exit}). The data file is
  252. saved if it has been modified.
  253. @findex forms-exit-no-save
  254. @item M-x forms-exit-no-save
  255. Terminates forms mode processing without saving modified data first.
  256. @end ignore
  257. @findex forms-prev-field
  258. @item M-x forms-prev-field
  259. Similar to @code{forms-next-field} but moves backwards.
  260. @findex forms-save-buffer
  261. @item M-x forms-save-buffer
  262. @kindex C-x C-s
  263. @itemx C-x C-s
  264. Forms mode replacement for @code{save-buffer}. When executed in the
  265. forms buffer it will save the contents of the (modified) data buffer
  266. instead. In Forms mode this function will be bound to @kbd{C-x C-s}.
  267. @findex forms-print
  268. @item M-x forms-print
  269. This command can be used to make a formatted print
  270. of the contents of the data file.
  271. @end table
  272. In addition the command @kbd{M-x revert-buffer} is useful in Forms mode
  273. just as in other modes.
  274. @ignore
  275. @vindex forms-forms-scroll
  276. @findex scroll-up
  277. @findex scroll-down
  278. If the variable @code{forms-forms-scrolls} is set to a value other
  279. than @code{nil} (which it is, by default), the Emacs functions
  280. @code{scroll-up} and @code{scroll-down} will perform a
  281. @code{forms-next-record} and @code{forms-prev-record} when in forms
  282. mode. So you can use your favourite page commands to page through the
  283. data file.
  284. @vindex forms-forms-jump
  285. @findex beginning-of-buffer
  286. @findex end-of-buffer
  287. Likewise, if the variable @code{forms-forms-jump} is not @code{nil}
  288. (which it is, by default), Emacs functions @code{beginning-of-buffer}
  289. and @code{end-of-buffer} will perform @code{forms-first-record} and
  290. @code{forms-last-record} when in forms mode.
  291. @end ignore
  292. The following function key definitions are set up in Forms mode
  293. (whether read-only or not):
  294. @table @kbd
  295. @kindex next
  296. @item next
  297. forms-next-record
  298. @kindex prior
  299. @item prior
  300. forms-prev-record
  301. @kindex begin
  302. @item begin
  303. forms-first-record
  304. @kindex end
  305. @item end
  306. forms-last-record
  307. @kindex S-Tab
  308. @findex forms-prev-field
  309. @item S-Tab
  310. forms-prev-field
  311. @end table
  312. @node Data File Format
  313. @chapter Data File Format
  314. @cindex record
  315. @cindex field
  316. @vindex forms-field-sep
  317. Files for use with Forms mode are very simple---each @dfn{record}
  318. (usually one line) forms the contents of one form. Each record consists
  319. of a number of @dfn{fields}, which are separated by the value of the
  320. string @code{forms-field-sep}, which is @code{"\t"} (a Tab) by default.
  321. @vindex forms-read-file-filter
  322. @vindex forms-write-file-filter
  323. If the format of the data file is not suitable enough you can define the
  324. filter functions @code{forms-read-file-filter} and
  325. @code{forms-write-file-filter}. @code{forms-read-file-filter} is called
  326. when the data file is read from disk into the data buffer. It operates
  327. on the data buffer, ignoring read-only protections. When the data file
  328. is saved to disk @code{forms-write-file-filter} is called to cancel the
  329. effects of @code{forms-read-file-filter}. After being saved,
  330. @code{forms-read-file-filter} is called again to prepare the data buffer
  331. for further processing.
  332. @cindex pseudo-newline
  333. @vindex forms-multi-line
  334. Fields may contain text which shows up in the forms in multiple lines.
  335. These lines are separated in the field using a ``pseudo-newline''
  336. character which is defined by the value of the string
  337. @code{forms-multi-line}. Its default value is @code{"\^k"} (a Control-K
  338. character). If it is
  339. set to @code{nil}, multiple line fields are prohibited.
  340. If the data file does not exist, it is automatically created.
  341. @node Control File Format
  342. @chapter Control File Format
  343. @cindex control file
  344. The Forms mode @dfn{control file} serves two purposes. First, it names
  345. the data file to use, and defines its format and properties. Second,
  346. the Emacs buffer it occupies is used by Forms mode to display the forms.
  347. The contents of the control file are evaluated as a Lisp program. It
  348. should set the following Lisp variables to suitable values:
  349. @table @code
  350. @vindex forms-file
  351. @item forms-file
  352. This variable specifies the name of the data file. Example:
  353. @example
  354. (setq forms-file "my/data-file")
  355. @end example
  356. If the control file doesn't set @code{forms-file}, Forms mode
  357. reports an error.
  358. @vindex forms-format-list
  359. @item forms-format-list
  360. This variable describes the way the fields of the record are formatted on
  361. the screen. For details, see @ref{Format Description}.
  362. @vindex forms-number-of-fields
  363. @item forms-number-of-fields
  364. This variable holds the number of fields in each record of the data
  365. file. Example:
  366. @example
  367. (setq forms-number-of-fields 10)
  368. @end example
  369. @end table
  370. If the control file does not set @code{forms-format-list} a default
  371. format is used. In this situation, Forms mode will deduce the number of
  372. fields from the data file providing this file exists and
  373. @code{forms-number-of-records} has not been set in the control file.
  374. The control file can optionally set the following additional Forms mode
  375. variables. Most of them have default values that are good for most
  376. applications.
  377. @table @code
  378. @vindex forms-field-sep
  379. @item forms-field-sep
  380. This variable may be used to designate the string which separates the
  381. fields in the records of the data file. If not set, it defaults to the
  382. string @code{"\t"} (a Tab character). Example:
  383. @example
  384. (setq forms-field-sep "\t")
  385. @end example
  386. @vindex forms-read-only
  387. @item forms-read-only
  388. If the value is non-@code{nil}, the data file is treated read-only. (Forms
  389. mode also treats the data file as read-only if you don't have access to
  390. write it.) Example:
  391. @example
  392. (set forms-read-only t)
  393. @end example
  394. @vindex forms-multi-line
  395. @item forms-multi-line
  396. This variable specifies the @dfn{pseudo newline} separator that allows
  397. multi-line fields. This separator goes between the ``lines'' within a
  398. field---thus, the field doesn't really contain multiple lines, but it
  399. appears that way when displayed in Forms mode. If the value is
  400. @code{nil}, multi-line text fields are prohibited. The pseudo newline
  401. must not be a character contained in @code{forms-field-sep}.
  402. The default value is @code{"\^k"}, the character Control-K. Example:
  403. @example
  404. (setq forms-multi-line "\^k")
  405. @end example
  406. @ignore
  407. @vindex forms-forms-scroll
  408. @item forms-forms-scroll
  409. @xref{Forms Mode Commands}, for details.
  410. @vindex forms-forms-jump
  411. @item forms-forms-jump
  412. @xref{Forms Mode Commands}, for details.
  413. @end ignore
  414. @findex forms-read-file-filter
  415. @item forms-read-file-filter
  416. This variable holds the name of a function to be called after the data
  417. file has been read in. This can be used to transform the contents of the
  418. data file into a format more suitable for forms processing.
  419. If it is @code{nil}, no function is called. For example, to maintain a
  420. gzipped database:
  421. @example
  422. (defun gzip-read-file-filter ()
  423. (shell-command-on-region (point-min) (point-max)
  424. "gzip -d" t t))
  425. (setq forms-read-file-filter 'gzip-read-file-filter)
  426. @end example
  427. @findex forms-write-file-filter
  428. @item forms-write-file-filter
  429. This variable holds the name of a function to be called before writing
  430. out the contents of the data file.
  431. This can be used to undo the effects of @code{forms-read-file-filter}.
  432. If it is @code{nil}, no function is called. Example:
  433. @example
  434. (defun gzip-write-file-filter ()
  435. (make-variable-buffer-local 'require-final-newline)
  436. (setq require-final-newline nil)
  437. (shell-command-on-region (point-min) (point-max)
  438. "gzip" t t))
  439. (setq forms-write-file-filter 'gzip-write-file-filter)
  440. @end example
  441. @findex forms-new-record-filter
  442. @item forms-new-record-filter
  443. This variable holds a function to be called whenever a new record is created
  444. to supply default values for fields. If it is @code{nil}, no function is
  445. called.
  446. @xref{Modifying Forms Contents}, for details.
  447. @findex forms-modified-record-filter
  448. @item forms-modified-record-filter
  449. This variable holds a function to be called whenever a record is
  450. modified, just before updating the Forms data file. If it is
  451. @code{nil}, no function is called.
  452. @xref{Modifying Forms Contents}, for details.
  453. @findex forms-insert-after
  454. @item forms-insert-after
  455. If this variable is not @code{nil}, new records are created @emph{after} the
  456. current record. Also, upon visiting a file, the initial position will be
  457. at the last record instead of the first one.
  458. @findex forms-check-number-of-fields
  459. @item forms-check-number-of-fields
  460. Normally each record is checked to contain the correct number of fields.
  461. Under certain circumstances, this can be undesirable.
  462. If this variable is set to @code{nil}, these checks will be bypassed.
  463. @end table
  464. @node Format Description
  465. @chapter The Format Description
  466. @vindex forms-format-list
  467. The variable @code{forms-format-list} specifies the format of the data
  468. in the data file, and how to convert the data for display in Forms mode.
  469. Its value must be a list of Forms mode @dfn{formatting elements}, each
  470. of which can be a string, a number, a Lisp list, or a Lisp symbol that
  471. evaluates to one of those. The formatting elements are processed in the
  472. order they appear in the list.
  473. @table @var
  474. @item string
  475. A string formatting element is inserted in the forms ``as is,'' as text
  476. that the user cannot alter.
  477. @item number
  478. A number element selects a field of the record. The contents of this
  479. field are inserted in the display at this point. Field numbers count
  480. starting from 1 (one).
  481. @item list
  482. A formatting element that is a list specifies a function call. This
  483. function is called every time a record is displayed, and its result,
  484. which must be a string, is inserted in the display text. The function
  485. should do nothing but returning a string.
  486. @vindex forms-fields
  487. The function you call can access the fields of the record as a list in
  488. the variable
  489. @code{forms-fields}.
  490. @item symbol
  491. A symbol used as a formatting element should evaluate to a string, number,
  492. or list; the value is interpreted as a formatting element, as described
  493. above.
  494. @end table
  495. If a record does not contain the number of fields as specified in
  496. @code{forms-number-of-fields}, a warning message will be printed. Excess
  497. fields are ignored, missing fields are set to empty.
  498. The control file which displays @file{/etc/passwd} file as demonstrated
  499. in the beginning of this manual might look as follows:
  500. @example
  501. ;; @r{This demo visits @file{/etc/passwd}.}
  502. (setq forms-file "/etc/passwd")
  503. (setq forms-number-of-fields 7)
  504. (setq forms-read-only t) ; @r{to make sure}
  505. (setq forms-field-sep ":")
  506. ;; @r{Don't allow multi-line fields.}
  507. (setq forms-multi-line nil)
  508. (setq forms-format-list
  509. (list
  510. "====== /etc/passwd ======\n\n"
  511. "User : " 1
  512. " Uid: " 3
  513. " Gid: " 4
  514. "\n\n"
  515. "Name : " 5
  516. "\n\n"
  517. "Home : " 6
  518. "\n\n"
  519. "Shell: " 7
  520. "\n"))
  521. @end example
  522. When you construct the value of @code{forms-format-list}, you should
  523. usually either quote the whole value, like this,
  524. @example
  525. (setq forms-format-list
  526. '(
  527. "====== " forms-file " ======\n\n"
  528. "User : " 1
  529. (make-string 20 ?-)
  530. @dots{}
  531. ))
  532. @end example
  533. @noindent
  534. or quote the elements which are lists, like this:
  535. @example
  536. (setq forms-format-list
  537. (list
  538. "====== " forms-file " ======\n\n"
  539. "User : " 1
  540. '(make-string 20 ?-)
  541. @dots{}
  542. ))
  543. @end example
  544. Forms mode validates the contents of @code{forms-format-list} when you
  545. visit a database. If there are errors, processing is aborted with an
  546. error message which includes a descriptive text. @xref{Error Messages},
  547. for a detailed list of error messages.
  548. If no @code{forms-format-list} is specified, Forms mode will supply a
  549. default format list. This list contains the name of the file being
  550. visited, and a simple label for each field indicating the field number.
  551. @node Modifying Forms Contents
  552. @chapter Modifying The Forms Contents
  553. If @code{forms-read-only} is @code{nil}, the user can modify the fields
  554. and records of the database.
  555. All normal editing commands are available for editing the contents of the
  556. displayed record. You cannot delete or modify the fixed, explanatory
  557. text that comes from string formatting elements, but you can modify the
  558. actual field contents.
  559. @ignore
  560. @c This is for the Emacs 18 version only.
  561. If the contents of the forms cannot be recognized properly, this is
  562. signaled using a descriptive text. @xref{Error Messages}, for more info.
  563. The cursor will indicate the last part of the forms which was
  564. successfully parsed. It's important to avoid entering field contents
  565. that would cause confusion with the field-separating fixed text.
  566. @end ignore
  567. If the variable @code{forms-modified-record-filter} is non-@code{nil},
  568. it is called as a function before the new data is written to the data
  569. file. The function receives one argument, a vector that contains the
  570. contents of the fields of the record.
  571. The function can refer to fields with @code{aref} and modify them with
  572. @code{aset}. The first field has number 1 (one); thus, element 0 of the
  573. vector is not used. The function should return the same vector it was
  574. passed; the (possibly modified) contents of the vector determine what is
  575. actually written in the file. Here is an example:
  576. @example
  577. (defun my-modified-record-filter (record)
  578. ;; @r{Modify second field.}
  579. (aset record 2 (current-time-string))
  580. ;; @r{Return the field vector.}
  581. record)
  582. (setq forms-modified-record-filter 'my-modified-record-filter)
  583. @end example
  584. If the variable @code{forms-new-record-filter} is non-@code{nil}, its
  585. value is a function to be called to fill in default values for the
  586. fields of a new record. The function is passed a vector of empty
  587. strings, one for each field; it should return the same vector, with
  588. the desired field values stored in it. Fields are numbered starting
  589. from 1 (one). Example:
  590. @example
  591. (defun my-new-record-filter (fields)
  592. (aset fields 5 (login-name))
  593. (aset fields 1 (current-time-string))
  594. fields)
  595. (setq forms-new-record-filter 'my-new-record-filter)
  596. @end example
  597. @node Miscellaneous
  598. @chapter Miscellaneous
  599. @vindex forms-version
  600. The global variable @code{forms-version} holds the version information
  601. of the Forms mode software.
  602. @findex forms-enumerate
  603. It is very convenient to use symbolic names for the fields in a record.
  604. The function @code{forms-enumerate} provides an elegant means to define
  605. a series of variables whose values are consecutive integers. The
  606. function returns the highest number used, so it can be used to set
  607. @code{forms-number-of-fields} also. For example:
  608. @example
  609. (setq forms-number-of-fields
  610. (forms-enumerate
  611. '(field1 field2 field3 @dots{})))
  612. @end example
  613. This sets @code{field1} to 1, @code{field2} to 2, and so on.
  614. Care has been taken to keep the Forms mode variables buffer-local, so it
  615. is possible to visit multiple files in Forms mode simultaneously, even
  616. if they have different properties.
  617. @findex forms-mode
  618. If you have visited the control file in normal fashion with
  619. @code{find-file} or a like command, you can switch to Forms mode with
  620. the command @code{M-x forms-mode}. If you put @samp{-*- forms -*-} in
  621. the first line of the control file, then visiting it enables Forms mode
  622. automatically. But this makes it hard to edit the control file itself,
  623. so you'd better think twice before using this.
  624. The default format for the data file, using @code{"\t"} to separate
  625. fields and @code{"\^k"} to separate lines within a field, matches the
  626. file format of some popular database programs, e.g. FileMaker. So
  627. @code{forms-mode} can decrease the need to use proprietary software.
  628. @node Error Messages
  629. @chapter Error Messages
  630. This section describes all error messages which can be generated by
  631. forms mode. Error messages that result from parsing the control file
  632. all start with the text @samp{Forms control file error}. Messages
  633. generated while analyzing the definition of @code{forms-format-list}
  634. start with @samp{Forms format error}.
  635. @table @code
  636. @item Forms control file error: `forms-file' has not been set
  637. The variable @code{forms-file} was not set by the control file.
  638. @item Forms control file error: `forms-number-of-fields' has not been set
  639. The variable @code{forms-number-of-fields} was not set by the control
  640. file.
  641. @item Forms control file error: `forms-number-of-fields' must be a number > 0
  642. The variable @code{forms-number-of-fields} did not contain a positive
  643. number.
  644. @item Forms control file error: `forms-field-sep' is not a string
  645. @itemx Forms control file error: `forms-multi-line' must be nil or a one-character string
  646. The variable @code{forms-multi-line} was set to something other than
  647. @code{nil} or a single-character string.
  648. @item Forms control file error: `forms-multi-line' is equal to 'forms-field-sep'
  649. The variable @code{forms-multi-line} may not be equal to
  650. @code{forms-field-sep} for this would make it impossible to distinguish
  651. fields and the lines in the fields.
  652. @item Forms control file error: `forms-new-record-filter' is not a function
  653. @itemx Forms control file error: `forms-modified-record-filter' is not a function
  654. The variable has been set to something else than a function.
  655. @item Forms control file error: `forms-format-list' is not a list
  656. The variable @code{forms-format-list} was not set to a Lisp list
  657. by the control file.
  658. @item Forms format error: field number @var{xx} out of range 1..@var{nn}
  659. A field number was supplied in @code{forms-format-list} with a value of
  660. @var{xx}, which was not greater than zero and smaller than or equal to
  661. the number of fields in the forms, @var{nn}.
  662. @item Forms format error: @var{fun} is not a function
  663. The first element of a list which is an element of
  664. @code{forms-format-list} was not a valid Lisp function.
  665. @item Forms format error: invalid element @var{xx}
  666. A list element was supplied in @code{forms-format-list} which was not a
  667. string, number or list.
  668. @ignore
  669. @c This applies to Emacs 18 only.
  670. @c Error messages generated while a modified form is being analyzed.
  671. @item Parse error: not looking at `...'
  672. When re-parsing the contents of a forms, the text shown could not
  673. be found.
  674. @item Parse error: cannot find `...'
  675. When re-parsing the contents of a forms, the text shown, which
  676. separates two fields, could not be found.
  677. @item Parse error: cannot parse adjacent fields @var{xx} and @var{yy}
  678. Fields @var{xx} and @var{yy} were not separated by text, so could not be
  679. parsed again.
  680. @end ignore
  681. @item Warning: this record has @var{xx} fields instead of @var{yy}
  682. The number of fields in this record in the data file did not match
  683. @code{forms-number-of-fields}. Missing fields will be made empty.
  684. @item Multi-line fields in this record - update refused!
  685. The current record contains newline characters, hence can not be written
  686. back to the data file, for it would corrupt it. Probably you inserted a
  687. newline in a field, while @code{forms-multi-line} was @code{nil}.
  688. @item Field separator occurs in record - update refused!
  689. The current record contains the field separator string inside one of the
  690. fields. It can not be written back to the data file, for it would
  691. corrupt it. Probably you inserted the field separator string in a field.
  692. @item Record number @var{xx} out of range 1..@var{yy}
  693. A jump was made to non-existing record @var{xx}. @var{yy} denotes the
  694. number of records in the file.
  695. @item Stuck at record @var{xx}
  696. An internal error prevented a specific record from being retrieved.
  697. @item No write access to @code{"}@var{file}@code{"}
  698. An attempt was made to enable edit mode on a file that has been write
  699. protected.
  700. @item Search failed: @var{regexp}
  701. The @var{regexp} could not be found in the data file. Forward searching
  702. is done from the current location until the end of the file, then
  703. retrying from the beginning of the file until the current location.
  704. Backward searching is done from the current location until the beginning
  705. of the file, then retrying from the end of the file until the current
  706. location.
  707. @item Wrapped
  708. A search completed successfully after wrapping around.
  709. @item Warning: number of records changed to @var{nn}
  710. Forms mode's idea of the number of records has been adjusted to the
  711. number of records actually present in the data file.
  712. @item Problem saving buffers?
  713. An error occurred while saving the data file buffer. Most likely, Emacs
  714. did ask to confirm deleting the buffer because it had been modified, and
  715. you said `no'.
  716. @end table
  717. @node Long Example
  718. @chapter Long Example
  719. The following example exploits most of the features of Forms mode.
  720. This example is included in the distribution as file @file{forms-d2.el}.
  721. @example
  722. ;; demo2 -- demo forms-mode -*- emacs-lisp -*-
  723. ;; @r{This sample forms exploit most of the features of forms mode.}
  724. ;; @r{Set the name of the data file.}
  725. (setq forms-file "forms-d2.dat")
  726. ;; @r{Use @code{forms-enumerate} to set field names and number thereof.}
  727. (setq forms-number-of-fields
  728. (forms-enumerate
  729. '(arch-newsgroup ; 1
  730. arch-volume ; 2
  731. arch-issue ; and ...
  732. arch-article ; ... so
  733. arch-shortname ; ... ... on
  734. arch-parts
  735. arch-from
  736. arch-longname
  737. arch-keywords
  738. arch-date
  739. arch-remarks)))
  740. ;; @r{The following functions are used by this form for layout purposes.}
  741. ;;
  742. (defun arch-tocol (target &optional fill)
  743. "Produces a string to skip to column TARGET.
  744. Prepends newline if needed.
  745. The optional FILL should be a character, used to fill to the column."
  746. (if (null fill)
  747. (setq fill ? ))
  748. (if (< target (current-column))
  749. (concat "\n" (make-string target fill))
  750. (make-string (- target (current-column)) fill)))
  751. ;;
  752. (defun arch-rj (target field &optional fill)
  753. "Produces a string to skip to column TARGET\
  754. minus the width of field FIELD.
  755. Prepends newline if needed.
  756. The optional FILL should be a character,
  757. used to fill to the column."
  758. (arch-tocol (- target (length (nth field forms-fields))) fill))
  759. ;; @r{Record filters.}
  760. ;;
  761. (defun new-record-filter (the-record)
  762. "Form a new record with some defaults."
  763. (aset the-record arch-from (user-full-name))
  764. (aset the-record arch-date (current-time-string))
  765. the-record) ; return it
  766. (setq forms-new-record-filter 'new-record-filter)
  767. ;; @r{The format list.}
  768. (setq forms-format-list
  769. (list
  770. "====== Public Domain Software Archive ======\n\n"
  771. arch-shortname
  772. " - " arch-longname
  773. "\n\n"
  774. "Article: " arch-newsgroup
  775. "/" arch-article
  776. " "
  777. '(arch-tocol 40)
  778. "Issue: " arch-issue
  779. " "
  780. '(arch-rj 73 10)
  781. "Date: " arch-date
  782. "\n\n"
  783. "Submitted by: " arch-from
  784. "\n"
  785. '(arch-tocol 79 ?-)
  786. "\n"
  787. "Keywords: " arch-keywords
  788. "\n\n"
  789. "Parts: " arch-parts
  790. "\n\n====== Remarks ======\n\n"
  791. arch-remarks
  792. ))
  793. ;; @r{That's all, folks!}
  794. @end example
  795. @node Credits
  796. @chapter Credits
  797. Bug fixes and other useful suggestions were supplied by
  798. Harald Hanche-Olsen (@code{hanche@@imf.unit.no}),
  799. @code{cwitty@@portia.stanford.edu},
  800. Jonathan I. Kamens,
  801. Per Cederqvist (@code{ceder@@signum.se}),
  802. Michael Lipka (@code{lipka@@lip.hanse.de}),
  803. Andy Piper (@code{ajp@@eng.cam.ac.uk}),
  804. Frederic Pierresteguy (@code{F.Pierresteguy@@frcl.bull.fr}),
  805. Ignatios Souvatzis
  806. and Richard Stallman (@code{rms@@gnu.org}).
  807. This documentation was slightly inspired by the documentation of ``rolo
  808. mode'' by Paul Davis at Schlumberger Cambridge Research
  809. (@code{davis%scrsu1%sdr.slb.com@@relay.cs.net}).
  810. None of this would have been possible without GNU Emacs of the Free
  811. Software Foundation. Thanks, Richard!
  812. @node Index
  813. @unnumbered Index
  814. @printindex cp
  815. @contents
  816. @bye