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