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