forms.texi 33 KB

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