home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
3
/
3566
< prev
next >
Wrap
Internet Message Format
|
1991-07-02
|
31KB
From: jv@mh.nl (Johan Vromans)
Newsgroups: gnu.emacs.sources,alt.sources
Subject: GNU Emacs forms-mode version 1.2.7 (part 2 of 3)
Message-ID: <1991Jul1.132216.10645@pronto.mh.nl>
Date: 1 Jul 91 13:22:16 GMT
Submitted-by: jv@mh.nl
Archive-name: forms/part02
---- Cut Here and feed the following to sh ----
#!/bin/sh
# this is forms.shr.02 (part 2 of forms)
# do not concatenate these parts, unpack them in order with /bin/sh
# file forms.ti continued
#
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 2; then
echo Please unpack part "$Scheck" next!
exit 1
else
exit 0
fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
echo 'x - still skipping forms.ti'
else
echo 'x - continuing file forms.ti'
sed 's/^X//' << 'SHAR_EOF' >> 'forms.ti' &&
@section Key bindings
X
This section describes the key bindings as they are defined when
invoking forms mode.@*
All commands must be prefixed with @kbd{C-c} when editing a forms. If a
forms is read-only, @kbd{C-c} is not used. The only exception to
this rule is @code{forms-next-field}, which is bound to @kbd{TAB} in all
maps.
X
@table @kbd
X
@itemx C-c @key{TAB}
@code{forms-next-field}
X
@itemx C-c @key{SPC}
@code{forms-next-record}
X
@itemx C-c <
@code{forms-first-record}
X
@itemx C-c >
@code{forms-first-record}
X
@itemx C-c d
@code{forms-delete-record}
X
@itemx C-c e
@code{forms-edit-mode}
X
@itemx C-c i
@code{forms-insert-record}
X
@itemx C-c j
@code{forms-jump-record}
X
@itemx C-c n
@code{forms-next-record}
X
@itemx C-c p
@code{forms-prev-record}
X
@itemx C-c q
@code{forms-exit}
X
@itemx C-c s @var{regexp}
@code{forms-search}
X
@itemx C-c v
@code{forms-view-mode}
X
@itemx C-c x
@code{forms-exit-no-save}
X
@itemx C-c ?
@code{describe-mode}
X
@itemx C-c @key{DEL}
@code{forms-prev-record}
X
@end table
X
@node Miscellaneous, Error Messages, Key Bindings, Top
@section Miscellaneous
X
@vindex forms-version
A global variable @code{forms-version} holds the version information of
the current implementation of forms mode.
X
@findex forms-enumerate
It is very convenient to use symbolic names for the fields in a record.
The function @code{forms-enumerate} provides an elegant means to define
a series of variables to consecutive numbers.
The function returns the higest number used, so it can be used to set
@code{forms-number-of-fields} also:
@example
(setq forms-number-of-fields
X (forms-enumerate
X '(field1 field2 field3 ... )))
@end example
X
@code{field1} will be set to 1, @code{field2} to 2 and so on.
X
Care has been taken to localize the current information of the forms
mode, so it is possible to visit multiple files in forms mode
simultaneously, even if they have different properties.
X
Since buffer-local functions are not available in this version of GNU
Emacs, the definitions of the filter functions
@code{forms-new-record-filter} and @code{forms-modified-record-filter}
are copied into internal, buffer local variables when forms-mode is
initialized.
X
If a control file is visited using the standard @code{find-file}
commands, forms mode can be enabled with the command @code{M-x forms-mode}.@*
Forms mode will be automatically enabled if the file contains
the string @code{"-*- forms -*-"} somewhere in the first line. However,
this makes it hard to edit the control file itself so you'd better think
twice before using this.
X
The default format for the data file, using @key{TAB} to separate fields
and @code{C-k} to separate multi-line fields, matches the file format of
some popular Macintosh database programs, e.g. FileMaker. So
@code{forms-mode} could decrease the need to use Apple computers.
X
@node Error Messages, Examples, Miscellaneous, Top
@section Error Messages
X
This section describes all error messages which can be generated by
forms mode.
X
@table @code
@item 'forms-file' has not been set
The variable @code{forms-file} was not set by the control file.
X
@item 'forms-number-of-fields' has not been set
The variable @code{forms-number-of-fields} was not set by the control
file.
X
@item 'forms-number-of-fields' must be > 0
The variable @code{forms-number-of-fields} did not contain a positive
number.
X
@item 'forms-field-sep' is not a string
@itemx 'forms-multi-line' must be nil or a one-character string
The variable @code{forms-multi-line} was set to something other than
@code{nil or} a single-character string.
X
@item 'forms-multi-line' is equal to 'forms-field-sep'
The variable @code{forms-multi-line} may not be equal to
@code{forms-field-sep} for this would make it impossible to distinguish
fields and the lines in the fields.
X
@item 'forms-format-list' has not been set
@itemx 'forms-format-list' is not a list
The variable @code{forms-format-list} was not set to a lisp @code{list}
by the control file.
X
@item Forms error: field number @var{XX} out of range 1..@var{NN}
A field number was supplied with a value of @var{XX}, which was not
greater than zero and smaller than or equal to the number of fields in the
forms, @var{NN}.
X
@item Forms error: not a function @var{FUN}
The first element of the lisp list specified in @code{forms-format-list}
did not have a function value.
X
@item Invalid element in 'forms-format-list': @var{XX}
A list element was supplied in @code{forms-format-list} which was not a
@code{string}, @code{number} nor a @code{lisp list}.
X
@item Parse error: not looking at "..."
When re-parsing the contents of a forms, the text shown could not
be found.
X
@item Parse error: cannot find "..."
When re-parsing the contents of a forms, the text shown, which
separates two fields, could not be found.
X
@item Parse error: cannot parse adjacent fields @var{XX} and @var{YY}
Fields @var{XX} and @var{YY} were not separated by text, so could not be
parsed again.
X
@item Record has @var{XX} fields instead of @var{YY}
The number of fields in this record in the data file did not match
@code{forms-number-of-fields}. Missing fields will be set to empty.
X
@item Multi-line fields in this record - update refused!
The current record contains newline characters, hence can not be written
back to the data file, for it would corrupt it.@*
probably a field was set to a multi-line value, while the setting of
@code{forms-multi-line} prohibited this.
X
@item Record number @var{XX} out of range 1..@var{YY}
A jump was made to non-existing record @var{XX}. @var{YY} denotes the
number of records in the file.
X
@item Stuck at record @var{XX}
An internal error prevented a specific record from being retrieved.
X
@end table
X
@node Examples, Credits, Error Messages, Top
@section Examples
X
The following example exploits most of the features of forms-mode.
This example is included in the distribution as file @file{demo2}.
X
@example
;; demo2 -- demo forms-mode -*- emacs-lisp -*-
X
;; SCCS Status : demo2 1.1.2
;; Author : Johan Vromans
;; Created On : 1989
;; Last Modified By: Johan Vromans
;; Last Modified On: Mon Jul 1 13:56:31 1991
;; Update Count : 2
;; Status : OK
;;
;; This sample forms exploit most of the features of forms mode.
X
;; Set the name of the data file.
(setq forms-file "demo2.dat")
X
;; Use 'forms-enumerate' to set field names and number thereof.
(setq forms-number-of-fields
X (forms-enumerate
X '(arch-newsgroup ; 1
X arch-volume ; 2
X arch-issue ; and ...
X arch-article ; ... so
X arch-shortname ; ... ... on
X arch-parts
X arch-from
X arch-longname
X arch-keywords
X arch-date
X arch-remarks)))
X
;; The following functions are used by this form for layout purposes.
;;
(defun arch-tocol (target &optional fill)
X "Produces a string to skip to column TARGET. Prepends newline if needed.
The optional FILL should be a character, used to fill to the column."
X (if (null fill)
X (setq fill ? ))
X (if (< target (current-column))
X (concat "\n" (make-string target fill))
X (make-string (- target (current-column)) fill)))
;;
(defun arch-rj (target field &optional fill)
X "Produces a string to skip to column TARGET minus the width of field FIELD.
Prepends newline if needed. The optional FILL should be a character,
used to fill to the column."
X (arch-tocol (- target (length (nth field forms-fields))) fill))
X
;; Record filters.
;; This example uses the (defun ...) method of defining.
;;
(defun forms-new-record-filter (the-record)
X "Form a new record with some defaults."
X (aset the-record arch-from (user-full-name))
X (aset the-record arch-date (current-time-string))
X the-record ; return it
)
X
;; The format list.
(setq forms-format-list
X (list
X "====== Public Domain Software Archive ======\n\n"
X arch-shortname
X " - " arch-longname
X "\n\n"
X "Article: " arch-newsgroup
X "/" arch-article
X " "
X '(arch-tocol 40)
X "Issue: " arch-issue
X " "
X '(arch-rj 73 10)
X "Date: " arch-date
X "\n\n"
X "Submitted by: " arch-from
X "\n"
X '(arch-tocol 79 ?-)
X "\n"
X "Keywords: " arch-keywords
X "\n\n"
X "Parts: " arch-parts
X "\n\n====== Remarks ======\n\n"
X arch-remarks
X ))
X
;; That's all, folks!
@end example
X
@node Credits, Concept Index, Examples, Top
@section Credits
X
Forms mode is developed by Johan Vromans @code{<jv@@mh.nl>} at Multihouse
Reseach in the Netherlands.
X
Harald Hanche-Olsen @code{<hanche@@imf.unit.no>} supplied the idea for
the new record filter, and provided better replacements for some
internal functions.
X
Bugfixes and other useful suggestions were supplied by
cwitty@@portia.stanford.edu, Jonathan I. Kamens, Ignatios Souvatzis and
Harald Hanche-Olsen.
X
This documentation was slightly inspired by the documentation of ``rolo
mode'' by Paul Davis at Schlumberger Cambridge Research
@code{<davis%scrsu1%sdr.slb.com@@relay.cs.net>}.
X
None of this would have been possible without GNU Emacs of the Free
Software Foundation. Thanks, Richard!
X
@node Concept Index, Variable Index, Credits, Top
@unnumbered Concept Index
@printindex cp
X
@node Variable Index, Function Index, Concept Index, Top
@unnumbered Variable Index
@printindex vr
X
@node Function Index, , Variable Index, Top
@unnumbered Function Index
@printindex fn
X
@contents
@bye
X
@c Local Variables:
@c eval: (headers)
@c eval: (setq comment-start "@c ")
@c eval: (setq comment-start-skip "@c +")
@c End:
SHAR_EOF
echo 'File forms.ti is complete' &&
chmod 0444 forms.ti ||
echo 'restore of forms.ti failed'
Wc_c="`wc -c < 'forms.ti'`"
test 28722 -eq "$Wc_c" ||
echo 'forms.ti: original size 28722, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= forms.el ==============
if test -f 'forms.el' -a X"$1" != X"-c"; then
echo 'x - skipping forms.el (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting forms.el (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'forms.el' &&
;;; forms.el -- Forms Mode - A GNU Emacs Major Mode
;;; SCCS Status : @(#)@ forms 1.2.7
;;; Author : Johan Vromans
;;; Created On : 1989
;;; Last Modified By: Johan Vromans
;;; Last Modified On: Mon Jul 1 14:13:20 1991
;;; Update Count : 15
;;; Status : OK
X
;;; This file is part of GNU Emacs.
;;; GNU Emacs is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY. No author or distributor
;;; accepts responsibility to anyone for the consequences of using it
;;; or for whether it serves any particular purpose or works at all,
;;; unless he says so in writing. Refer to the GNU Emacs General Public
;;; License for full details.
X
;;; Everyone is granted permission to copy, modify and redistribute
;;; GNU Emacs, but only under the conditions described in the
;;; GNU Emacs General Public License. A copy of this license is
;;; supposed to have been given to you along with GNU Emacs so you
;;; can know your rights and responsibilities.
;;; If you don't have this copy, write to the Free Software
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;;
X
;;; HISTORY
;;; 1-Jul-1991 Johan Vromans
;;; Normalized error messages.
;;; 30-Jun-1991 Johan Vromans
;;; Add support for forms-modified-record-filter.
;;; Allow the filter functions to be the name of a function.
;;; Fix: parse--format used forms--dynamic-text destructively.
;;; Internally optimized the forms-format-list.
;;; Added support for debugging.
;;; Stripped duplicate documentation.
;;;
;;; 29-Jun-1991 Johan Vromans
;;; Add support for functions and lisp symbols in forms-format-list.
;;; Add function forms-enumerate.
X
(provide 'forms-mode)
X
;;; Visit a file using a form.
;;;
;;; === Naming conventions
;;;
;;; The names of all variables and functions start with 'form-'.
;;; Names which start with 'form--' are intended for internal use, and
;;; should *NOT* be used from the outside.
;;;
;;; All variables are buffer-local, to enable multiple forms visits
;;; simultaneously.
;;; Variable 'forms--mode-setup' is local to *ALL* buffers, for it
;;; controls if forms-mode has been enabled in a buffer.
;;;
;;; === How it works ===
;;;
;;; Forms mode means visiting a data file which is supposed to consist
;;; of records each containing a number of fields. The records are
;;; separated by a newline, the fields are separated by a user-defined
;;; field separater (default: TAB).
;;; When shown, a record is transferred to an emacs buffer and
;;; presented using a user-defined form. One record is shown at a
;;; time.
;;;
;;; Forms mode is a composite mode. It involves two files, and two
;;; buffers.
;;; The first file, called the control file, defines the name of the
;;; data file and the forms format. This file buffer will be used to
;;; present the forms.
;;; The second file holds the actual data. The buffer of this file
;;; will be buried, for it is never accessed directly.
;;;
;;; Forms mode is invoked using "forms-find-file control-file".
;;; Alternativily forms-find-file-other-window can be used.
;;;
;;; You may also visit the control file, and switch to forms mode by hand
;;; with M-x forms-mode .
;;;
;;; Automatic mode switching is supported, so you may use "find-file"
;;; if you specify "-*- forms -*-" in the first line of the control file.
;;;
;;; The control file is visited, evaluated using
;;; eval-current-buffer, and should set at least the following
;;; variables:
;;;
;;; forms-file [string] the name of the data file.
;;;
;;; forms-number-of-fields [integer]
;;; The number of fields in each record.
;;;
;;; forms-format-list [list] formatting instructions.
;;;
;;; The forms-format-list should be a list, each element containing
;;;
;;; - a string, e.g. "hello" (which is inserted \"as is\"),
;;;
;;; - an integer, denoting a field number. The contents of the field
;;; are inserted at this point.
;;; The first field has number one.
;;;
;;; - a function call, e.g. (insert "text"). This function call is
;;; dynamically evaluated and should return a string. It should *NOT*
;;; have side-effects on the forms being constructed.
;;; The current fields are available to the function in the variable
;;; forms-fields, they should *NOT* be modified.
;;;
;;; - a lisp symbol, that must evaluate to one of the above.
;;;
;;; Optional variables which may be set in the control file:
;;;
;;; forms-field-sep [string, default TAB]
;;; The field separator used to separate the
;;; fields in the data file. It may be a string.
;;;
;;; forms-read-only [bool, default nil]
;;; 't' means that the data file is visited read-only.
;;; If no write access to the data file is
;;; possible, read-only mode is enforced.
;;;
;;; forms-multi-line [string, default "^K"]
;;; If non-null the records of the data file may
;;; contain fields which span multiple lines in
;;; the form.
;;; This variable denoted the separator character
;;; to be used for this purpose. Upon display, all
;;; occurrencies of this character are translated
;;; to newlines. Upon storage they are translated
;;; back to the separator.
;;;
;;; forms-forms-scroll [bool, default t]
;;; If non-nil: redefine scroll-up/down to perform
;;; forms-next/prev-field if in forms mode.
;;;
;;; forms-forms-jump [bool, default t]
;;; If non-nil: redefine beginning/end-of-buffer
;;; to performs forms-first/last-field if in
;;; forms mode.
;;;
;;; forms-new-record-filter [symbol, no default]
;;; If defined: this should be the name of a
;;; function that is called when a new
;;; record is created. It can be used to fill in
;;; the new record with default fields, for example.
;;; Instead of the name of the function, it may
;;; be the function itself.
;;;
;;; forms-modified-record-filter [symbol, no default]
;;; If defined: this should be the name of a
;;; function that is called when a record has
;;; been modified. It is called after the fields
;;; are parsed. It can be used to register
;;; modification dates, for example.
;;; Instead of the name of the function, it may
;;; be the function itself.
;;;
;;; After evaluating the control file, its buffer is cleared and used
;;; for further processing.
;;; The data file (as designated by "forms-file") is visited in a buffer
;;; (forms--file-buffer) which will not normally be shown.
;;; Great malfunctioning may be expected if this file/buffer is modified
;;; outside of this package while it's being visited!
;;;
;;; A record from the data file is transferred from the data file,
;;; split into fields (into forms--the-record-list), and displayed using
;;; the specs in forms-format-list.
;;; A format routine 'forms--format' is built upon startup to format
;;; the records.
;;;
;;; When a form is changed the record is updated as soon as this form
;;; is left. The contents of the form are parsed using forms-format-list,
;;; and the fields which are deduced from the form are modified. So,
;;; fields not shown on the forms retain their origional values.
;;; The newly formed record and replaces the contents of the
;;; old record in forms--file-buffer.
;;; A parse routine 'forms--parser' is built upon startup to parse
;;; the records.
;;;
;;; Two exit functions exist: forms-exit (which saves) and forms-exit-no-save
;;; (which doesn't). However, if forms-exit-no-save is executed and the file
;;; buffer has been modified, emacs will ask questions.
;;;
;;; Other functions are:
;;;
;;; paging (forward, backward) by record
;;; jumping (first, last, random number)
;;; searching
;;; creating and deleting records
;;; reverting the form (NOT the file buffer)
;;; switching edit <-> view mode v.v.
;;; jumping from field to field
;;;
;;; As an documented side-effect: jumping to the last record in the
;;; file (using forms-last-record) will adjust forms--total-records if
;;; needed.
;;;
;;; Commands and keymaps:
;;;
;;; A local keymap 'forms-mode-map' is used in the forms buffer.
;;; As conventional, this map can be accessed with C-c prefix.
;;; In read-only mode, the C-c prefix must be omitted.
;;;
;;; Default bindings:
;;;
;;; \C-c forms-mode-map
;;; TAB forms-next-field
;;; SPC forms-next-record
;;; < forms-first-record
;;; > forms-last-record
;;; ? describe-mode
;;; d forms-delete-record
;;; e forms-edit-mode
;;; i forms-insert-record
;;; j forms-jump-record
;;; n forms-next-record
;;; p forms-prev-record
;;; q forms-exit
;;; s forms-search
;;; v forms-view-mode
;;; x forms-exit-no-save
;;; DEL forms-prev-record
;;;
;;; Standard functions scroll-up, scroll-down, beginning-of-buffer and
;;; end-of-buffer are wrapped with re-definitions, which map them to
;;; next/prev record and first/last record.
;;; Buffer-local variables forms-forms-scroll and forms-forms-jump
;;; may be used to control these redefinitions.
;;;
;;; Function save-buffer is also wrapped to perform a sensible action.
;;; A revert-file-hook is defined to revert a forms to original.
;;;
;;; For convenience, TAB is always bound to forms-next-field, so you
;;; don't need the C-c prefix for this command.
;;;
;;; Global variables and constants
X
(defconst forms-version "1.2.7"
X "Version of forms-mode implementation")
X
(defvar forms-forms-scrolls t
X "If non-null: redefine scroll-up/down to be used with forms-mode.")
X
(defvar forms-forms-jumps t
X "If non-null: redefine beginning/end-of-buffer to be used with forms-mode.")
X
(defvar forms-mode-hooks nil
X "Hook functions to be run upon entering forms mode.")
;;;
;;; Mandatory variables - must be set by evaluating the control file
X
(defvar forms-file nil
X "Name of the file holding the data.")
X
(defvar forms-format-list nil
X "List of formatting specifications.")
X
(defvar forms-number-of-fields nil
X "Number of fields per record.")
X
;;;
;;; Optional variables with default values
X
(defvar forms-field-sep "\t"
X "Field separator character (default TAB)")
X
(defvar forms-read-only nil
X "Read-only mode (defaults to the write access on the data file).")
X
(defvar forms-multi-line "\C-k"
X "Character to separate multi-line fields (default ^K)")
X
(defvar forms-forms-scroll t
X "Redefine scroll-up/down to perform forms-next/prev-record when in
X forms mode.")
X
(defvar forms-forms-jump t
X "Redefine beginning/end-of-buffer to perform forms-first/last-record
X when in forms mode.")
X
;;;
;;; Internal variables.
X
(defvar forms--file-buffer nil
X "Buffer which holds the file data")
X
(defvar forms--total-records 0
X "Total number of records in the data file.")
X
(defvar forms--current-record 0
X "Number of the record currently on the screen.")
X
(defvar forms-mode-map nil ; yes - this one is global
X "Keymap for form buffer.")
X
(defvar forms--markers nil
X "Field markers in the screen.")
X
(defvar forms--number-of-markers 0
X "Number of fields on screen.")
X
(defvar forms--the-record-list nil
X "List of strings of the current record, as parsed from the file.")
X
(defvar forms--search-regexp nil
X "Last regexp used by forms-search.")
X
(defvar forms--format nil
X "Formatting routine.")
X
(defvar forms--parser nil
X "Forms parser routine.")
X
(defvar forms--mode-setup nil
X "Internal - keeps track of forms-mode being set-up.")
(make-variable-buffer-local 'forms--mode-setup)
X
(defvar forms--new-record-filter nil
X "Internal - set if a new record filter has been defined.")
X
(defvar forms--modified-record-filter nil
X "Internal - set if a modified record filter has been defined.")
X
(defvar forms--dynamic-text nil
X "Internal - holds dynamic text to insert between fields.")
X
(defvar forms-fields nil
X "List with fields of the current forms. First field has number 1.")
X
;;;
;;; forms-mode
;;;
;;; This is not a simple major mode, as usual. Therefore, forms-mode
;;; takes an optional argument 'primary' which is used for the initial
;;; set-up. Normal use would leave 'primary' to nil.
;;;
;;; A global buffer-local variable 'forms--mode-setup' has the same effect
;;; but makes it possible to auto-invoke forms-mode using find-file.
;;;
;;; Note: although it seems logical to have (make-local-variable) executed
;;; where the variable is first needed, I deliberately placed all calls
;;; in the forms-mode function.
X
(defun forms-mode (&optional primary)
X "Major mode to visit files in a field-structured manner using a form.
X
X Commands (prefix with C-c if not in read-only mode):
X \\{forms-mode-map}"
X
X (interactive) ; no - 'primary' is not prefix arg
X
X ;; Primary set-up: evaluate buffer and check if the mandatory
X ;; variables have been set.
X (if (or primary (not forms--mode-setup))
X (progn
X (kill-all-local-variables)
X
X ;; make mandatory variables
X (make-local-variable 'forms-file)
X (make-local-variable 'forms-number-of-fields)
X (make-local-variable 'forms-format-list)
X
X ;; make optional variables
X (make-local-variable 'forms-field-sep)
X (make-local-variable 'forms-read-only)
X (make-local-variable 'forms-multi-line)
X (make-local-variable 'forms-forms-scroll)
X (make-local-variable 'forms-forms-jump)
X (fmakunbound 'forms-new-record-filter)
X
X ;; eval the buffer, should set variables
X (eval-current-buffer)
X
X ;; check if the mandatory variables make sense.
X (or forms-file
X (error "'forms-file' has not been set"))
X (or forms-number-of-fields
X (error "'forms-number-of-fields' has not been set"))
X (or (> forms-number-of-fields 0)
X (error "'forms-number-of-fields' must be > 0")
X (or (stringp forms-field-sep))
X (error "'forms-field-sep' is not a string"))
X (if forms-multi-line
X (if (and (stringp forms-multi-line)
X (eq (length forms-multi-line) 1))
X (if (string= forms-multi-line forms-field-sep)
X (error "'forms-multi-line' is equal to 'forms-field-sep'"))
X (error "'forms-multi-line' must be nil or a one-character string")))
X
X ;; validate and process forms-format-list
X (make-local-variable 'forms--number-of-markers)
X (make-local-variable 'forms--markers)
X (forms--process-format-list)
X
X ;; build the formatter and parser
X (make-local-variable 'forms--format)
X (forms--make-format)
X (make-local-variable 'forms--parser)
X (forms--make-parser)
X
X ;; check if record filters are defined
X (make-local-variable 'forms--new-record-filter)
X (setq forms--new-record-filter
X (cond
X ((fboundp 'forms-new-record-filter)
X (symbol-function 'forms-new-record-filter))
X ((and (boundp 'forms-new-record-filter)
X (fboundp forms-new-record-filter))
X forms-new-record-filter)))
X (fmakunbound 'forms-new-record-filter)
X (make-local-variable 'forms--modified-record-filter)
X (setq forms--modified-record-filter
X (cond
X ((fboundp 'forms-modified-record-filter)
X (symbol-function 'forms-modified-record-filter))
X ((and (boundp 'forms-modified-record-filter)
X (fboundp forms-modified-record-filter))
X forms-modified-record-filter)))
X (fmakunbound 'forms-modified-record-filter)
X
X ;; dynamic text support
X (make-local-variable 'forms--dynamic-text)
X (make-local-variable 'forms-fields)
X
X ;; prepare this buffer for further processing
X (setq buffer-read-only nil)
X
X ;; prevent accidental overwrite of the control file and autosave
X (setq buffer-file-name nil)
X (auto-save-mode nil)
X
X ;; and clean it
X (erase-buffer)))
X
X ;; make local variables
X (make-local-variable 'forms--file-buffer)
X (make-local-variable 'forms--total-records)
X (make-local-variable 'forms--current-record)
X (make-local-variable 'forms--the-record-list)
X (make-local-variable 'forms--search-rexexp)
X
X ;; A bug in the current Emacs release prevents a keymap
X ;; which is buffer-local from being used by 'describe-mode'.
X ;; Hence we'll leave it global.
X ;;(make-local-variable 'forms-mode-map)
X (if forms-mode-map ; already defined
X nil
X (setq forms-mode-map (make-keymap))
X (forms--mode-commands forms-mode-map)
X (forms--change-commands))
X
X ;; find the data file
X (setq forms--file-buffer (find-file-noselect forms-file))
X
X ;; count the number of records, and set see if it may be modified
X (let (ro)
X (setq forms--total-records
X (save-excursion
X (set-buffer forms--file-buffer)
X (bury-buffer (current-buffer))
X (setq ro buffer-read-only)
X (count-lines (point-min) (point-max))))
X (if ro
X (setq forms-read-only t)))
X
X ;; set the major mode indicator
X (setq major-mode 'forms-mode)
X (setq mode-name "Forms")
X (make-local-variable 'minor-mode-alist) ; needed?
X (forms--set-minor-mode)
X (forms--set-keymaps)
X
X (set-buffer-modified-p nil)
X
X ;; We have our own revert function - use it
X (make-local-variable 'revert-buffer-function)
X (setq revert-buffer-function 'forms-revert-buffer)
X
X ;; setup the first (or current) record to show
X (if (< forms--current-record 1)
X (setq forms--current-record 1))
X (forms-jump-record forms--current-record)
X
X ;; user customising
X (run-hooks 'forms-mode-hooks)
X
X ;; be helpful
X (forms--help)
X
X ;; initialization done
X (setq forms--mode-setup t))
X
;;;
;;; forms-process-format-list
;;;
;;; Validates forms-format-list.
;;;
;;; Sets forms--number-of-markers and forms--markers.
X
(defun forms--process-format-list ()
X "Validate forms-format-list and set some global variables."
X
X (forms--debug "forms-forms-list before 1st pass:\n"
X 'forms-format-list)
X
X ;; it must be non-nil
X (or forms-format-list
X (error "'forms-format-list' has not been set"))
X ;; it must be a list ...
X (or (listp forms-format-list)
X (error "'forms-format-list' is not a list"))
X
X (setq forms--number-of-markers 0)
X
X (let ((the-list forms-format-list) ; the list of format elements
X (this-item 0) ; element in list
X (field-num 0)) ; highest field number
X
X (setq forms-format-list nil) ; gonna rebuild
X
X (while the-list
X
X (let ((el (car-safe the-list))
X (rem (cdr-safe the-list)))
X
X ;; if it is a symbol, eval it first
X (if (and (symbolp el)
X (boundp el))
X (setq el (eval el)))
X
X (cond
X
X ;; try string ...
X ((stringp el)) ; string is OK
X
X ;; try numeric ...
X ((numberp el)
X
X (if (or (<= el 0)
X (> el forms-number-of-fields))
X (error
X "Forms error: field number %d out of range 1..%d"
X el forms-number-of-fields))
X
X (setq forms--number-of-markers (1+ forms--number-of-markers))
X (if (> el field-num)
X (setq field-num el)))
X
X ;; try function
X ((listp el)
X (or (fboundp (car-safe el))
X (error
X "Forms error: not a function: %s"
X (prin1-to-string (car-safe el)))))
X
X ;; else
X (t
X (error "Invalid element in 'forms-format-list': %s"
X (prin1-to-string el))))
X
X ;; advance to next element of the list
X (setq the-list rem)
X (setq forms-format-list
X (append forms-format-list (list el) nil)))))
X
X (forms--debug "forms-forms-list after 1st pass:\n"
X 'forms-format-list)
X
X ;; concat adjacent strings
X (setq forms-format-list (forms--concat-adjacent forms-format-list))
X
X (forms--debug "forms-forms-list after 2nd pass:\n"
X 'forms-format-list
X 'forms--number-of-markers)
SHAR_EOF
true || echo 'restore of forms.el failed'
fi
echo 'End of forms part 2'
echo 'File forms.el is continued in part 3'
echo 3 > _shar_seq_.tmp
exit 0
--
Johan Vromans jv@mh.nl via internet backbones
Multihouse Automatisering bv uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------