1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00
emacs/lisp/forms.el

1721 lines
54 KiB
EmacsLisp
Raw Normal View History

1993-06-12 20:53:59 +00:00
;;; forms.el -- Forms mode: edit a file as a form to fill in.
1993-06-19 00:15:32 +00:00
;;; Copyright (C) 1991, 1993 Free Software Foundation, Inc.
1993-06-12 20:53:59 +00:00
(forms--set-minor-mode): Rewrite so that describe-mode can parse the value of minor-mode-alist correctly. The string " View" is now dependent on the value of forms-read-only. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Corrected error message text. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-10-21 00:43:51 +00:00
;; Author: Johan Vromans <jv@nl.net>
;; Version: $Revision: 2.4 $
1993-06-12 20:53:59 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
1991-05-20 20:35:19 +00:00
1993-06-12 20:53:59 +00:00
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Commentary:
1991-05-20 20:35:19 +00:00
;;; Visit a file using a form.
;;;
;;; === Naming conventions
;;;
;;; The names of all variables and functions start with 'forms-'.
;;; Names which start with 'forms--' are intended for internal use, and
1991-05-20 20:35:19 +00:00
;;; 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
1991-05-20 20:35:19 +00:00
;;; 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
1991-05-20 20:35:19 +00:00
;;; 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
1991-05-20 20:35:19 +00:00
;;; time.
;;;
;;; Forms mode is a composite mode. It involves two files, and two
1991-05-20 20:35:19 +00:00
;;; 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
1991-05-20 20:35:19 +00:00
;;; present the forms.
;;; The second file holds the actual data. The buffer of this file
1991-05-20 20:35:19 +00:00
;;; will be buried, for it is never accessed directly.
;;;
;;; Forms mode is invoked using M-x forms-find-file control-file .
;;; Alternativily `forms-find-file-other-window' can be used.
1991-05-20 20:35:19 +00:00
;;;
;;; You may also visit the control file, and switch to forms mode by hand
;;; with M-x forms-mode .
;;;
;;; Automatic mode switching is supported if you specify
;;; "-*- forms -*-" in the first line of the control file.
1991-05-20 20:35:19 +00:00
;;;
;;; The control file is visited, evaluated using `eval-current-buffer',
;;; and should set at least the following variables:
1991-05-20 20:35:19 +00:00
;;;
;;; forms-file [string]
;;; The name of the data file.
1991-05-20 20:35:19 +00:00
;;;
;;; forms-number-of-fields [integer]
1991-05-20 20:35:19 +00:00
;;; The number of fields in each record.
;;;
;;; forms-format-list [list]
;;; Formatting instructions.
1991-05-20 20:35:19 +00:00
;;;
;;; `forms-format-list' should be a list, each element containing
1991-05-20 20:35:19 +00:00
;;;
;;; - a string, e.g. "hello". The string is inserted in the forms
;;; "as is".
;;;
;;; - an integer, denoting a field number.
;;; The contents of this field are inserted at this point.
;;; Fields are numbered starting with 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.
1991-07-01 18:06:13 +00:00
;;;
1991-05-20 20:35:19 +00:00
;;; 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.
1991-05-20 20:35:19 +00:00
;;;
;;; forms-read-only [bool, default nil]
;;; Non-nil means that the data file is visited
;;; read-only (view mode) as opposed to edit mode.
1991-05-20 20:35:19 +00:00
;;; If no write access to the data file is
;;; possible, view mode is enforced.
1991-05-20 20:35:19 +00:00
;;;
;;; forms-multi-line [string, default "^K"]
;;; If non-null the records of the data file may
;;; contain fields that can span multiple lines in
1991-05-20 20:35:19 +00:00
;;; the form.
;;; This variable denotes the separator character
;;; to be used for this purpose. Upon display, all
1991-05-20 20:35:19 +00:00
;;; occurrencies of this character are translated
;;; to newlines. Upon storage they are translated
;;; back to the separator character.
1991-05-20 20:35:19 +00:00
;;;
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; forms-forms-scroll [bool, default nil]
;;; Non-nil means: rebind locally the commands that
;;; perform `scroll-up' or `scroll-down' to use
;;; `forms-next-field' resp. `forms-prev-field'.
1991-05-20 20:35:19 +00:00
;;;
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; forms-forms-jump [bool, default nil]
;;; Non-nil means: rebind locally the commands that
;;; perform `beginning-of-buffer' or `end-of-buffer'
;;; to perform `forms-first-field' resp. `forms-last-field'.
1991-05-20 20:35:19 +00:00
;;;
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; forms-new-record-filter [symbol, default nil]
;;; If not nil: this should be the name of a
1991-07-01 18:06:13 +00:00
;;; function that is called when a new
;;; record is created. It can be used to fill in
1991-05-20 20:35:19 +00:00
;;; the new record with default fields, for example.
1991-07-01 18:06:13 +00:00
;;;
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; forms-modified-record-filter [symbol, default nil]
;;; If not nil: this should be the name of a
1991-07-01 18:06:13 +00:00
;;; function that is called when a record has
;;; been modified. It is called after the fields
;;; are parsed. It can be used to register
1991-07-01 18:06:13 +00:00
;;; modification dates, for example.
1991-05-20 20:35:19 +00:00
;;;
;;; forms-use-text-properties [bool, see text for default]
;;; This variable controls if forms mode should use
;;; text properties to protect the form text from being
;;; modified (using text-property `read-only').
;;; Also, the read-write fields are shown using a
;;; distinct face, if possible.
;;; This variable defaults to t if running Emacs 19
;;; with text properties.
;;; The default face to show read-write fields is
;;; copied from face `region'.
;;;
;;; forms-ro-face [symbol, default 'default]
;;; This is the face that is used to show
;;; read-only text on the screen.If used, this
;;; variable should be set to a symbol that is a
;;; valid face.
;;; E.g.
;;; (make-face 'my-face)
;;; (setq forms-ro-face 'my-face)
;;;
;;; forms-rw-face [symbol, default 'region]
;;; This is the face that is used to show
;;; read-write text on the screen.
;;;
1991-05-20 20:35:19 +00:00
;;; 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.
1991-05-20 20:35:19 +00:00
;;; Great malfunctioning may be expected if this file/buffer is modified
;;; outside of this package while it is being visited!
1991-05-20 20:35:19 +00:00
;;;
;;; Normal operation is to transfer one line (record) from the data file,
;;; split it into fields (into `forms--the-record-list'), and display it
;;; using the specs in `forms-format-list'.
;;; A format routine `forms--format' is built upon startup to format
;;; the records according to `forms-format-list'.
1991-05-20 20:35:19 +00:00
;;;
;;; When a form is changed the record is updated as soon as this form
;;; is left. The contents of the form are parsed using information
;;; obtained from `forms-format-list', and the fields which are
;;; deduced from the form are modified. Fields not shown on the forms
;;; retain their origional values. The newly formed record then
;;; replaces the contents of the old record in `forms--file-buffer'.
;;; A parse routine `forms--parser' is built upon startup to parse
1991-05-20 20:35:19 +00:00
;;; the records.
;;;
;;; Two exit functions exist: `forms-exit' and `forms-exit-no-save'.
;;; `forms-exit' saves the data to the file, if modified.
;;; `forms-exit-no-save` does not. However, if `forms-exit-no-save'
;;; is executed and the file buffer has been modified, Emacs will ask
;;; questions anyway.
1991-05-20 20:35:19 +00:00
;;;
;;; Other functions provided by forms mode are:
1991-05-20 20:35:19 +00:00
;;;
;;; 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.
;;;
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; The forms buffer can be in on eof two modes: edit mode or view
;;; mode. View mode is a read-only mode, you cannot modify the
;;; contents of the buffer.
1991-05-20 20:35:19 +00:00
;;;
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; Edit mode commands:
;;;
;;; TAB forms-next-field
;;; \C-c TAB forms-next-field
;;; \C-c < forms-first-record
;;; \C-c > forms-last-record
;;; \C-c ? describe-mode
;;; \C-c \C-k forms-delete-record
;;; \C-c \C-q forms-toggle-read-only
;;; \C-c \C-o forms-insert-record
;;; \C-c \C-l forms-jump-record
;;; \C-c \C-n forms-next-record
;;; \C-c \C-p forms-prev-record
;;; \C-c \C-s forms-search
;;; \C-c \C-x forms-exit
;;;
;;; Read-only mode commands:
;;;
;;; SPC forms-next-record
;;; DEL forms-prev-record
;;; ? describe-mode
;;; \C-q forms-toggle-read-only
;;; l forms-jump-record
;;; n forms-next-record
;;; p forms-prev-record
;;; s forms-search
;;; x forms-exit
;;;
;;; Of course, it is also possible to use the \C-c prefix to obtain the
;;; same command keys as in edit mode.
;;;
;;; The following bindings are available, independent of the mode:
;;;
;;; [next] forms-next-record
;;; [prior] forms-prev-record
;;; [begin] forms-first-record
;;; [end] forms-last-record
;;; [S-TAB] forms-prev-field
;;; [backtab] forms-prev-field
1991-05-20 20:35:19 +00:00
;;;
;;; For convenience, TAB is always bound to `forms-next-field', so you
;;; don't need the C-c prefix for this command.
;;;
;;; As mentioned above (see `forms-forms-scroll' and `forms-forms-jump')
;;; the bindings of standard functions `scroll-up', `scroll-down',
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
;;; `beginning-of-buffer' and `end-of-buffer' can be locally replaced with
1993-06-19 00:08:24 +00:00
;;; forms mode functions next/prev record and first/last
;;; record.
1991-05-20 20:35:19 +00:00
;;;
;;; `local-write-file hook' is defined to save the actual data file
;;; instead of the buffer data, `revert-file-hook' is defined to
1993-06-19 00:08:24 +00:00
;;; revert a forms to original.
1993-06-12 20:53:59 +00:00
;;; Code:
;;; Global variables and constants:
1991-05-20 20:35:19 +00:00
1993-06-12 20:53:59 +00:00
(provide 'forms) ;;; official
(provide 'forms-mode) ;;; for compatibility
(forms--set-minor-mode): Rewrite so that describe-mode can parse the value of minor-mode-alist correctly. The string " View" is now dependent on the value of forms-read-only. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Corrected error message text. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-10-21 00:43:51 +00:00
(defconst forms-version (substring "$Revision: 2.4 $" 11 -2)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
"The version number of forms-mode (as string). The complete RCS id is:
(forms--set-minor-mode): Rewrite so that describe-mode can parse the value of minor-mode-alist correctly. The string " View" is now dependent on the value of forms-read-only. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Corrected error message text. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-10-21 00:43:51 +00:00
$Id: forms.el,v 2.4 1993/10/20 20:39:47 jv Exp $")
1991-05-20 20:35:19 +00:00
(defvar forms-mode-hooks nil
1993-06-12 20:53:59 +00:00
"Hook functions to be run upon entering Forms mode.")
;;; Mandatory variables - must be set by evaluating the control file.
1991-05-20 20:35:19 +00:00
(defvar forms-file nil
1991-07-01 18:06:13 +00:00
"Name of the file holding the data.")
1991-05-20 20:35:19 +00:00
(defvar forms-format-list nil
1991-07-01 18:06:13 +00:00
"List of formatting specifications.")
1991-05-20 20:35:19 +00:00
(defvar forms-number-of-fields nil
"Number of fields per record.")
1993-06-12 20:53:59 +00:00
;;; Optional variables with default values.
1991-05-20 20:35:19 +00:00
(defvar forms-field-sep "\t"
1993-06-12 20:53:59 +00:00
"Field separator character (default TAB).")
1991-05-20 20:35:19 +00:00
(defvar forms-read-only nil
"Non-nil means: visit the file in view (read-only) mode.
(Defaults to the write access on the data file).")
1991-05-20 20:35:19 +00:00
(defvar forms-multi-line "\C-k"
"If not nil: use this character to separate multi-line fields (default C-k).")
1991-05-20 20:35:19 +00:00
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(defvar forms-forms-scroll nil
1993-06-19 00:15:32 +00:00
"*Non-nil means replace scroll-up/down commands in Forms mode.
The replacement commands performs forms-next/prev-record.")
1991-05-20 20:35:19 +00:00
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(defvar forms-forms-jump nil
1993-06-19 00:15:32 +00:00
"*Non-nil means redefine beginning/end-of-buffer in Forms mode.
The replacement commands performs forms-first/last-record.")
(defvar forms-new-record-filter nil
"The name of a function that is called when a new record is created.")
(defvar forms-modified-record-filter nil
"The name of a function that is called when a record has been modified.")
(defvar forms-fields nil
"List with fields of the current forms. First field has number 1.
This variable is for use by the filter routines only.
The contents may NOT be modified.")
(defvar forms-use-text-properties (fboundp 'set-text-properties)
"*Non-nil means: use emacs-19 text properties.
Defaults to t if this emacs is capable of handling text properties.")
(defvar forms-ro-face 'default
"The face (a symbol) that is used to display read-only text on the screen.")
(defvar forms-rw-face 'region
"The face (a symbol) that is used to display read-write text on the screen.")
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
;;; Internal variables.
(defvar forms--file-buffer nil
"Buffer which holds the file data")
(defvar forms--total-records 0
"Total number of records in the data file.")
(defvar forms--current-record 0
"Number of the record currently on the screen.")
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(defvar forms-mode-map nil
1991-05-20 20:35:19 +00:00
"Keymap for form buffer.")
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(defvar forms-mode-ro-map nil
"Keymap for form buffer in view mode.")
(defvar forms-mode-edit-map nil
"Keymap for form buffer in edit mode.")
1991-05-20 20:35:19 +00:00
(defvar forms--markers nil
"Field markers in the screen.")
(defvar forms--dyntexts nil
"Dynamic texts (resulting from function calls) on the screen.")
1991-05-20 20:35:19 +00:00
(defvar forms--the-record-list nil
"List of strings of the current record, as parsed from the file.")
(defvar forms--search-regexp nil
"Last regexp used by forms-search.")
(defvar forms--format nil
"Formatting routine.")
(defvar forms--parser nil
"Forms parser routine.")
(defvar forms--mode-setup nil
"To keep track of forms-mode being set-up.")
1991-05-20 20:35:19 +00:00
(make-variable-buffer-local 'forms--mode-setup)
1991-07-01 18:06:13 +00:00
(defvar forms--dynamic-text nil
"Array that holds dynamic texts to insert between fields.")
1991-07-01 18:06:13 +00:00
(defvar forms--elements nil
"Array with the order in which the fields are displayed.")
1991-07-01 18:06:13 +00:00
(defvar forms--ro-face nil
"Face used to represent read-only data on the screen.")
1993-06-12 20:53:59 +00:00
(defvar forms--rw-face nil
"Face used to represent read-write data on the screen.")
1993-06-12 20:53:59 +00:00
;;;###autoload
1991-05-20 20:35:19 +00:00
(defun forms-mode (&optional primary)
"Major mode to visit files in a field-structured manner using a form.
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
Commands: Equivalent keys in read-only mode:
TAB forms-next-field TAB
\\C-c TAB forms-next-field
\\C-c < forms-first-record <
\\C-c > forms-last-record >
\\C-c ? describe-mode ?
\\C-c \\C-k forms-delete-record
\\C-c \\C-q forms-toggle-read-only q
\\C-c \\C-o forms-insert-record
\\C-c \\C-l forms-jump-record l
\\C-c \\C-n forms-next-record n
\\C-c \\C-p forms-prev-record p
\\C-c \\C-s forms-search s
\\C-c \\C-x forms-exit x
"
(interactive)
1991-05-20 20:35:19 +00:00
;; 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 have deliberately
;; placed all calls in this function.
1991-05-20 20:35:19 +00:00
;; Primary set-up: evaluate buffer and check if the mandatory
;; variables have been set.
(if (or primary (not forms--mode-setup))
(progn
;;(message "forms: setting up...")
1991-05-20 20:35:19 +00:00
(kill-all-local-variables)
;; Make mandatory variables.
1991-05-20 20:35:19 +00:00
(make-local-variable 'forms-file)
(make-local-variable 'forms-number-of-fields)
(make-local-variable 'forms-format-list)
;; Make optional variables.
1991-05-20 20:35:19 +00:00
(make-local-variable 'forms-field-sep)
(make-local-variable 'forms-read-only)
(make-local-variable 'forms-multi-line)
(make-local-variable 'forms-forms-scroll)
(make-local-variable 'forms-forms-jump)
(make-local-variable 'forms-use-text-properties)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(make-local-variable 'forms-new-record-filter)
(make-local-variable 'forms-modified-record-filter)
;; Make sure no filters exist.
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(setq forms-new-record-filter nil)
(setq forms-modified-record-filter nil)
;; If running Emacs 19 under X, setup faces to show read-only and
;; read-write fields.
(if (fboundp 'make-face)
(progn
(make-local-variable 'forms-ro-face)
(make-local-variable 'forms-rw-face)))
1991-05-20 20:35:19 +00:00
;; eval the buffer, should set variables
;;(message "forms: processing control file...")
1991-05-20 20:35:19 +00:00
(eval-current-buffer)
;; check if the mandatory variables make sense.
(or forms-file
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms control file error: "
"'forms-file' has not been set")))
1991-05-20 20:35:19 +00:00
(or forms-number-of-fields
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms control file error: "
"'forms-number-of-fields' has not been set")))
(or (and (numberp forms-number-of-fields)
(> forms-number-of-fields 0))
(error (concat "Forms control file error: "
"'forms-number-of-fields' must be a number > 0")))
(or (stringp forms-field-sep)
(error (concat "Forms control file error: "
"'forms-field-sep' is not a string")))
1991-05-20 20:35:19 +00:00
(if forms-multi-line
(if (and (stringp forms-multi-line)
(eq (length forms-multi-line) 1))
(if (string= forms-multi-line forms-field-sep)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms control file error: "
"'forms-multi-line' is equal to 'forms-field-sep'")))
(error (concat "Forms control file error: "
"'forms-multi-line' must be nil or a one-character string"))))
(or (fboundp 'set-text-properties)
(setq forms-use-text-properties nil))
1991-05-20 20:35:19 +00:00
;; Validate and process forms-format-list.
;;(message "forms: pre-processing format list...")
1991-05-20 20:35:19 +00:00
(forms--process-format-list)
;; Build the formatter and parser.
;;(message "forms: building formatter...")
1991-05-20 20:35:19 +00:00
(make-local-variable 'forms--format)
(make-local-variable 'forms--markers)
(make-local-variable 'forms--dyntexts)
(make-local-variable 'forms--elements)
;;(message "forms: building parser...")
1991-05-20 20:35:19 +00:00
(forms--make-format)
(make-local-variable 'forms--parser)
(forms--make-parser)
;;(message "forms: building parser... done.")
1991-05-20 20:35:19 +00:00
;; Check if record filters are defined.
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(if (and forms-new-record-filter
(not (fboundp forms-new-record-filter)))
(error (concat "Forms control file error: "
"'forms-new-record-filter' is not a function")))
(if (and forms-modified-record-filter
(not (fboundp forms-modified-record-filter)))
(error (concat "Forms control file error: "
"'forms-modified-record-filter' is not a function")))
1991-07-01 18:06:13 +00:00
;; The filters acces the contents of the forms using `forms-fields'.
1991-07-01 18:06:13 +00:00
(make-local-variable 'forms-fields)
1991-05-20 20:35:19 +00:00
;; Dynamic text support.
(make-local-variable 'forms--dynamic-text)
1991-05-20 20:35:19 +00:00
;; Prevent accidental overwrite of the control file and autosave.
1991-05-20 20:35:19 +00:00
(setq buffer-file-name nil)
(auto-save-mode nil)
;; Prepare this buffer for further processing.
(setq buffer-read-only nil)
(erase-buffer)
;;(message "forms: setting up... done.")
))
;; Copy desired faces to the actual variables used by the forms formatter.
(if (fboundp 'make-face)
(progn
(make-local-variable 'forms--ro-face)
(make-local-variable 'forms--rw-face)
(if forms-read-only
(progn
(setq forms--ro-face forms-ro-face)
(setq forms--rw-face forms-ro-face))
(setq forms--ro-face forms-ro-face)
(setq forms--rw-face forms-rw-face))))
1991-05-20 20:35:19 +00:00
;; Make more local variables.
1991-05-20 20:35:19 +00:00
(make-local-variable 'forms--file-buffer)
(make-local-variable 'forms--total-records)
(make-local-variable 'forms--current-record)
(make-local-variable 'forms--the-record-list)
(make-local-variable 'forms--search-regexp)
1991-05-20 20:35:19 +00:00
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
; The keymaps are global, so multiple forms mode buffers can share them.
;(make-local-variable 'forms-mode-map)
;(make-local-variable 'forms-mode-ro-map)
;(make-local-variable 'forms-mode-edit-map)
1991-05-20 20:35:19 +00:00
(if forms-mode-map ; already defined
nil
;;(message "forms: building keymap...")
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(forms--mode-commands)
;;(message "forms: building keymap... done.")
)
1991-05-20 20:35:19 +00:00
;; find the data file
(setq forms--file-buffer (find-file-noselect forms-file))
;; count the number of records, and set see if it may be modified
(let (ro)
(setq forms--total-records
(save-excursion
(prog1
(progn
;;(message "forms: counting records...")
(set-buffer forms--file-buffer)
(bury-buffer (current-buffer))
(setq ro buffer-read-only)
(count-lines (point-min) (point-max)))
;;(message "forms: counting records... done.")
)))
1991-05-20 20:35:19 +00:00
(if ro
(setq forms-read-only t)))
;;(message "forms: proceeding setup...")
1991-05-20 20:35:19 +00:00
;; set the major mode indicator
(setq major-mode 'forms-mode)
(setq mode-name "Forms")
(forms--set-minor-mode): Rewrite so that describe-mode can parse the value of minor-mode-alist correctly. The string " View" is now dependent on the value of forms-read-only. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Corrected error message text. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-10-21 00:43:51 +00:00
;; Since we aren't really implementing a minor mode, we hack the modeline
;; directly to get the text " View " into forms-read-only form buffers. For
;; that reason, this variable must be buffer only.
(make-local-variable 'minor-mode-alist)
(setq minor-mode-alist (list (list 'forms-read-only " View")))
;;(message "forms: proceeding setup (keymaps)...")
1991-05-20 20:35:19 +00:00
(forms--set-keymaps)
;;(message "forms: proceeding setup (commands)...")
1993-06-19 00:08:24 +00:00
(forms--change-commands)
1991-05-20 20:35:19 +00:00
;;(message "forms: proceeding setup (buffer)...")
1991-05-20 20:35:19 +00:00
(set-buffer-modified-p nil)
;; setup the first (or current) record to show
(if (< forms--current-record 1)
(setq forms--current-record 1))
(forms-jump-record forms--current-record)
;; user customising
;;(message "forms: proceeding setup (user hooks)...")
1991-05-20 20:35:19 +00:00
(run-hooks 'forms-mode-hooks)
;;(message "forms: setting up... done.")
1991-05-20 20:35:19 +00:00
;; be helpful
(forms--help)
;; initialization done
(setq forms--mode-setup t))
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
(defun forms--process-format-list ()
;; Validate `forms-format-list' and set some global variables.
;; Symbols in the list are evaluated, and consecutive strings are
;; concatenated.
;; Array `forms--elements' is constructed that contains the order
;; of the fields on the display. This array is used by
;; `forms--parser-using-text-properties' to extract the fields data
;; from the form on the screen.
;; Upon completion, `forms-format-list' is garanteed correct, so
;; `forms--make-format' and `forms--make-parser' do not need to perform
;; any checks.
;; Verify that `forms-format-list' is not nil.
1991-05-20 20:35:19 +00:00
(or forms-format-list
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms control file error: "
"'forms-format-list' has not been set")))
;; It must be a list.
1991-05-20 20:35:19 +00:00
(or (listp forms-format-list)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms control file error: "
"'forms-format-list' is not a list")))
1991-05-20 20:35:19 +00:00
;; Assume every field is painted once.
;; `forms--elements' will grow if needed.
(setq forms--elements (make-vector forms-number-of-fields nil))
1991-05-20 20:35:19 +00:00
(let ((the-list forms-format-list) ; the list of format elements
1991-07-01 18:06:13 +00:00
(this-item 0) ; element in list
(prev-item nil)
1991-05-20 20:35:19 +00:00
(field-num 0)) ; highest field number
1991-07-01 18:06:13 +00:00
(setq forms-format-list nil) ; gonna rebuild
1991-05-20 20:35:19 +00:00
(while the-list
(let ((el (car-safe the-list))
(rem (cdr-safe the-list)))
;; If it is a symbol, eval it first.
1991-07-01 18:06:13 +00:00
(if (and (symbolp el)
(boundp el))
(setq el (eval el)))
1991-05-20 20:35:19 +00:00
(cond
;; Try string ...
((stringp el)
(if (stringp prev-item) ; try to concatenate strings
(setq prev-item (concat prev-item el))
(if prev-item
(setq forms-format-list
(append forms-format-list (list prev-item) nil)))
(setq prev-item el)))
;; Try numeric ...
1991-07-01 18:06:13 +00:00
((numberp el)
1991-05-20 20:35:19 +00:00
;; Validate range.
1991-05-20 20:35:19 +00:00
(if (or (<= el 0)
(> el forms-number-of-fields))
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms format error: "
"field number %d out of range 1..%d")
el forms-number-of-fields))
1991-05-20 20:35:19 +00:00
;; Store forms order.
(if (> field-num (length forms--elements))
(setq forms--elements (vconcat forms--elements (1- el)))
(aset forms--elements field-num (1- el)))
(setq field-num (1+ field-num))
(if prev-item
(setq forms-format-list
(append forms-format-list (list prev-item) nil)))
(setq prev-item el))
;; Try function ...
1991-07-01 18:06:13 +00:00
((listp el)
;; Validate.
1991-07-01 18:06:13 +00:00
(or (fboundp (car-safe el))
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms format error: "
"not a function "
(prin1-to-string (car-safe el)))))
;; Shift.
(if prev-item
(setq forms-format-list
(append forms-format-list (list prev-item) nil)))
(setq prev-item el))
1991-07-01 18:06:13 +00:00
1991-05-20 20:35:19 +00:00
;; else
(t
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(error (concat "Forms format error: "
"invalid element "
(prin1-to-string el)))))
1991-05-20 20:35:19 +00:00
;; Advance to next element of the list.
(setq the-list rem)))
1991-05-20 20:35:19 +00:00
;; Append last item.
(if prev-item
(progn
(setq forms-format-list
(append forms-format-list (list prev-item) nil))
;; Append a newline if the last item is a field.
;; This prevents parsing problems.
;; Also it makes it possible to insert an empty last field.
(if (numberp prev-item)
(setq forms-format-list
(append forms-format-list (list "\n") nil))))))
(forms--debug 'forms-format-list
'forms--elements))
1993-06-12 20:53:59 +00:00
;; Special treatment for read-only segments.
;;
;; If text is inserted between two read-only segments, it inherits the
;; read-only properties. This is not what we want.
;; To solve this, read-only segments get the `insert-in-front-hooks'
;; property set with a function that temporarily switches the properties
;; of the first character of the segment to read-write, so the new
;; text gets the right properties.
;; The `post-command-hook' is used to restore the original properties.
(defvar forms--iif-start nil
"Record start of modification command.")
(defvar forms--iif-properties nil
"Original properties of the character being overridden.")
(defun forms--iif-hook (begin end)
"`insert-in-front-hooks' function for read-only segments."
;; Note start location. By making it a marker that points one
;; character beyond the actual location, it is guaranteed to move
;; correctly if text is inserted.
(or forms--iif-start
(setq forms--iif-start (copy-marker (1+ (point)))))
;; Check if there is special treatment required.
(if (or (<= forms--iif-start 2)
(get-text-property (- forms--iif-start 2)
'read-only))
(progn
;; Fetch current properties.
(setq forms--iif-properties
(text-properties-at (1- forms--iif-start)))
;; Replace them.
(let ((inhibit-read-only t))
(set-text-properties
(1- forms--iif-start) forms--iif-start
(list 'face forms--rw-face 'front-sticky '(face))))
;; Enable `post-command-hook' to restore the properties.
(setq post-command-hook
(append (list 'forms--iif-post-command-hook) post-command-hook)))
;; No action needed. Clear marker.
(setq forms--iif-start nil)))
(defun forms--iif-post-command-hook ()
"`post-command-hook' function for read-only segments."
;; Disable `post-command-hook'.
(setq post-command-hook
(delq 'forms--iif-hook-post-command-hook post-command-hook))
;; Restore properties.
(if forms--iif-start
(let ((inhibit-read-only t))
(set-text-properties
(1- forms--iif-start) forms--iif-start
forms--iif-properties)))
;; Cleanup.
(setq forms--iif-start nil))
(defvar forms--marker)
(defvar forms--dyntext)
1991-05-20 20:35:19 +00:00
(defun forms--make-format ()
"Generate `forms--format' using the information in `forms-format-list'."
;; The real work is done using a mapcar of `forms--make-format-elt' on
;; `forms-format-list'.
;; This function sets up the necessary environment, and decides
;; which function to mapcar.
(let ((forms--marker 0)
(forms--dyntext 0))
(setq
forms--format
(if forms-use-text-properties
(` (lambda (arg)
(let ((inhibit-read-only t))
(,@ (apply 'append
(mapcar 'forms--make-format-elt-using-text-properties
forms-format-list)))
;; Prevent insertion before the first text.
(,@ (if (numberp (car forms-format-list))
nil
'((add-text-properties (point-min) (1+ (point-min))
'(front-sticky (read-only))))))
;; Prevent insertion after the last text.
(remove-text-properties (1- (point)) (point)
'(rear-nonsticky)))
(setq forms--iif-start nil)))
(` (lambda (arg)
(,@ (apply 'append
(mapcar 'forms--make-format-elt forms-format-list)))))))
;; We have tallied the number of markers and dynamic texts,
;; so we can allocate the arrays now.
(setq forms--markers (make-vector forms--marker nil))
(setq forms--dyntexts (make-vector forms--dyntext nil)))
1991-07-01 18:06:13 +00:00
(forms--debug 'forms--format))
1991-05-20 20:35:19 +00:00
(defun forms--make-format-elt-using-text-properties (el)
"Helper routine to generate format function."
;; The format routine `forms--format' will look like
;;
;; ;; preamble
;; (lambda (arg)
;; (let ((inhibit-read-only t))
;;
;; ;; A string, e.g. "text: ".
;; (set-text-properties
;; (point)
;; (progn (insert "text: ") (point))
;; (list 'face forms--ro-face
;; 'read-only 1
;; 'insert-in-front-hooks 'forms--iif-hook
;; 'rear-nonsticky '(read-only face insert-in-front-hooks)))
;;
;; ;; A field, e.g. 6.
;; (let ((here (point)))
;; (aset forms--markers 0 (point-marker))
;; (insert (elt arg 5))
;; (or (= (point) here)
;; (set-text-properties
;; here (point)
;; (list 'face forms--rw-face
;; 'front-sticky '(face))))
;;
;; ;; Another string, e.g. "\nmore text: ".
;; (set-text-properties
;; (point)
;; (progn (insert "\nmore text: ") (point))
;; (list 'face forms--ro-face
;; 'read-only 2
;; 'insert-in-front-hooks 'forms--iif-hook
;; 'rear-nonsticky '(read-only face insert-in-front-hooks)))
;;
;; ;; A function, e.g. (tocol 40).
;; (set-text-properties
;; (point)
;; (progn
;; (insert (aset forms--dyntexts 0 (tocol 40)))
;; (point))
;; (list 'face forms--ro-face
;; 'read-only 2
;; 'insert-in-front-hooks 'forms--iif-hook
;; 'rear-nonsticky '(read-only face insert-in-front-hooks)))
;;
;; ;; Prevent insertion before the first text.
;; (add-text-properties (point-min) (1+ (point-min))
;; '(front-sticky (read-only))))))
;; ;; Prevent insertion after the last text.
;; (remove-text-properties (1- (point)) (point)
;; '(rear-nonsticky)))
;;
;; ;; wrap up
;; (setq forms--iif-start nil)
;; ))
(cond
((stringp el)
(` ((set-text-properties
(point) ; start at point
(progn ; until after insertion
(insert (, el))
(point))
(list 'face forms--ro-face ; read-only appearance
'read-only (,@ (list (1+ forms--marker)))
'insert-in-front-hooks '(forms--iif-hook)
'rear-nonsticky '(face read-only insert-in-front-hooks))))))
((numberp el)
(` ((let ((here (point)))
(aset forms--markers
(, (prog1 forms--marker
(setq forms--marker (1+ forms--marker))))
(point-marker))
(insert (elt arg (, (1- el))))
(or (= (point) here)
(set-text-properties
here (point)
(list 'face forms--rw-face
'front-sticky '(face))))))))
((listp el)
(` ((set-text-properties
(point)
(progn
(insert (aset forms--dyntexts
(, (prog1 forms--dyntext
(setq forms--dyntext (1+ forms--dyntext))))
(, el)))
(point))
(list 'face forms--ro-face
'read-only (,@ (list (1+ forms--marker)))
'insert-in-front-hooks '(forms--iif-hook)
'rear-nonsticky '(read-only face insert-in-front-hooks))))))
;; end of cond
))
1991-05-20 20:35:19 +00:00
(defun forms--make-format-elt (el)
"Helper routine to generate format function."
;; If we're not using text properties, the format routine
;; `forms--format' will look like
;;
;; (lambda (arg)
;; ;; a string, e.g. "text: "
;; (insert "text: ")
;; ;; a field, e.g. 6
;; (aset forms--markers 0 (point-marker))
;; (insert (elt arg 5))
;; ;; another string, e.g. "\nmore text: "
;; (insert "\nmore text: ")
;; ;; a function, e.g. (tocol 40)
;; (insert (aset forms--dyntexts 0 (tocol 40)))
;; ... )
1993-06-12 20:53:59 +00:00
(cond
((stringp el)
(` ((insert (, el)))))
((numberp el)
(prog1
(` ((aset forms--markers (, forms--marker) (point-marker))
1993-06-12 20:53:59 +00:00
(insert (elt arg (, (1- el))))))
(setq forms--marker (1+ forms--marker))))
1993-06-12 20:53:59 +00:00
((listp el)
(prog1
(` ((insert (aset forms--dyntexts (, forms--dyntext) (, el)))))
(setq forms--dyntext (1+ forms--dyntext))))))
1993-06-12 20:53:59 +00:00
(defvar forms--field)
(defvar forms--recordv)
(defvar forms--seen-text)
1991-05-20 20:35:19 +00:00
(defun forms--make-parser ()
"Generate `forms--parser' from the information in `forms-format-list'."
;; If we can use text properties, we simply set it to
;; `forms--parser-using-text-properties'.
;; Otherwise, the function is constructed using a mapcar of
;; `forms--make-parser-elt on `forms-format-list'.
(setq
forms--parser
(if forms-use-text-properties
(function forms--parser-using-text-properties)
(let ((forms--field nil)
(forms--seen-text nil)
(forms--dyntext 0))
;; Note: we add a nil element to the list passed to `mapcar',
;; see `forms--make-parser-elt' for details.
(` (lambda nil
(let (here)
(goto-char (point-min))
(,@ (apply 'append
(mapcar
'forms--make-parser-elt
(append forms-format-list (list nil)))))))))))
1991-07-01 18:06:13 +00:00
(forms--debug 'forms--parser))
1991-05-20 20:35:19 +00:00
(defun forms--parser-using-text-properties ()
"Extract field info from forms when using text properties."
;; Using text properties, we can simply jump to the markers, and
;; extract the information up to the following read-only segment.
(let ((i 0)
here there)
(while (< i (length forms--markers))
(goto-char (setq here (aref forms--markers i)))
(if (get-text-property here 'read-only)
(aset forms--recordv (aref forms--elements i) nil)
(if (setq there
(next-single-property-change here 'read-only))
(aset forms--recordv (aref forms--elements i)
(buffer-substring here there))
(aset forms--recordv (aref forms--elements i)
(buffer-substring here (point-max)))))
(setq i (1+ i)))))
1991-05-20 20:35:19 +00:00
(defun forms--make-parser-elt (el)
"Helper routine to generate forms parser function."
;; The parse routine will look like:
;;
;; (lambda nil
;; (let (here)
;; (goto-char (point-min))
;;
;; ;; "text: "
;; (if (not (looking-at "text: "))
;; (error "Parse error: cannot find \"text: \""))
;; (forward-char 6) ; past "text: "
;;
;; ;; 6
;; ;; "\nmore text: "
;; (setq here (point))
;; (if (not (search-forward "\nmore text: " nil t nil))
;; (error "Parse error: cannot find \"\\nmore text: \""))
;; (aset forms--recordv 5 (buffer-substring here (- (point) 12)))
;;
;; ;; (tocol 40)
;; (let ((forms--dyntext (car-safe forms--dynamic-text)))
;; (if (not (looking-at (regexp-quote forms--dyntext)))
;; (error "Parse error: not looking at \"%s\"" forms--dyntext))
;; (forward-char (length forms--dyntext))
;; (setq forms--dynamic-text (cdr-safe forms--dynamic-text)))
;; ...
;; ;; final flush (due to terminator sentinel, see below)
;; (aset forms--recordv 7 (buffer-substring (point) (point-max)))
1991-07-01 18:06:13 +00:00
(cond
((stringp el)
(prog1
(if forms--field
1991-07-01 18:06:13 +00:00
(` ((setq here (point))
(if (not (search-forward (, el) nil t nil))
(error "Parse error: cannot find \"%s\"" (, el)))
(aset forms--recordv (, (1- forms--field))
1991-07-01 18:06:13 +00:00
(buffer-substring here
(- (point) (, (length el)))))))
(` ((if (not (looking-at (, (regexp-quote el))))
(error "Parse error: not looking at \"%s\"" (, el)))
(forward-char (, (length el))))))
(setq forms--seen-text t)
(setq forms--field nil)))
1991-07-01 18:06:13 +00:00
((numberp el)
(if forms--field
1991-07-01 18:06:13 +00:00
(error "Cannot parse adjacent fields %d and %d"
forms--field el)
(setq forms--field el)
1991-07-01 18:06:13 +00:00
nil))
((null el)
(if forms--field
(` ((aset forms--recordv (, (1- forms--field))
1991-07-01 18:06:13 +00:00
(buffer-substring (point) (point-max)))))))
((listp el)
(prog1
(if forms--field
1991-07-01 18:06:13 +00:00
(` ((let ((here (point))
(forms--dyntext (aref forms--dyntexts (, forms--dyntext))))
(if (not (search-forward forms--dyntext nil t nil))
(error "Parse error: cannot find \"%s\"" forms--dyntext))
(aset forms--recordv (, (1- forms--field))
1991-07-01 18:06:13 +00:00
(buffer-substring here
(- (point) (length forms--dyntext)))))))
(` ((let ((forms--dyntext (aref forms--dyntexts (, forms--dyntext))))
(if (not (looking-at (regexp-quote forms--dyntext)))
(error "Parse error: not looking at \"%s\"" forms--dyntext))
(forward-char (length forms--dyntext))))))
(setq forms--dyntext (1+ forms--dyntext))
(setq forms--seen-text t)
(setq forms--field nil)))
1991-07-01 18:06:13 +00:00
))
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
(defun forms--set-keymaps ()
"Set the keymaps used in this mode."
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(use-local-map (if forms-read-only
forms-mode-ro-map
forms-mode-edit-map)))
(defun forms--mode-commands ()
"Fill the Forms mode keymaps."
;; `forms-mode-map' is always accessible via \C-c prefix.
(setq forms-mode-map (make-keymap))
(define-key forms-mode-map "\t" 'forms-next-field)
(define-key forms-mode-map "\C-k" 'forms-delete-record)
(define-key forms-mode-map "\C-q" 'forms-toggle-read-only)
(define-key forms-mode-map "\C-o" 'forms-insert-record)
(define-key forms-mode-map "\C-l" 'forms-jump-record)
(define-key forms-mode-map "\C-n" 'forms-next-record)
(define-key forms-mode-map "\C-p" 'forms-prev-record)
(define-key forms-mode-map "\C-s" 'forms-search)
(define-key forms-mode-map "\C-x" 'forms-exit)
(define-key forms-mode-map "<" 'forms-first-record)
(define-key forms-mode-map ">" 'forms-last-record)
(define-key forms-mode-map "?" 'describe-mode)
(define-key forms-mode-map "\C-?" 'forms-prev-record)
;; `forms-mode-ro-map' replaces the local map when in read-only mode.
(setq forms-mode-ro-map (make-keymap))
(suppress-keymap forms-mode-ro-map)
(define-key forms-mode-ro-map "\C-c" forms-mode-map)
(define-key forms-mode-ro-map "\t" 'forms-next-field)
(define-key forms-mode-ro-map "q" 'forms-toggle-read-only)
(define-key forms-mode-ro-map "l" 'forms-jump-record)
(define-key forms-mode-ro-map "n" 'forms-next-record)
(define-key forms-mode-ro-map "p" 'forms-prev-record)
(define-key forms-mode-ro-map "s" 'forms-search)
(define-key forms-mode-ro-map "x" 'forms-exit)
(define-key forms-mode-ro-map "<" 'forms-first-record)
(define-key forms-mode-ro-map ">" 'forms-last-record)
(define-key forms-mode-ro-map "?" 'describe-mode)
(define-key forms-mode-ro-map " " 'forms-next-record)
(forms--mode-commands1 forms-mode-ro-map)
;; This is the normal, local map.
(setq forms-mode-edit-map (make-keymap))
(define-key forms-mode-edit-map "\t" 'forms-next-field)
(define-key forms-mode-edit-map "\C-c" forms-mode-map)
(forms--mode-commands1 forms-mode-edit-map)
)
(defun forms--mode-commands1 (map)
"Helper routine to define keys."
(define-key map [TAB] 'forms-next-field)
(define-key map [S-tab] 'forms-prev-field)
(define-key map [next] 'forms-next-record)
(define-key map [prior] 'forms-prev-record)
(define-key map [begin] 'forms-first-record)
(define-key map [last] 'forms-last-record)
(define-key map [backtab] 'forms-prev-field)
1991-05-20 20:35:19 +00:00
)
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
;;; Changed functions
(defun forms--change-commands ()
"Localize some commands for Forms mode."
1991-05-20 20:35:19 +00:00
;; scroll-down -> forms-prev-record
;; scroll-up -> forms-next-record
1993-06-19 00:15:32 +00:00
(if forms-forms-scroll
(progn
(substitute-key-definition 'scroll-up 'forms-next-record
(current-local-map)
(current-global-map))
(substitute-key-definition 'scroll-down 'forms-prev-record
(current-local-map)
(current-global-map))))
1991-05-20 20:35:19 +00:00
;;
;; beginning-of-buffer -> forms-first-record
;; end-of-buffer -> forms-end-record
1993-06-19 00:15:32 +00:00
(if forms-forms-jump
(progn
(substitute-key-definition 'beginning-of-buffer 'forms-first-record
(current-local-map)
(current-global-map))
(substitute-key-definition 'end-of-buffer 'forms-last-record
(current-local-map)
(current-global-map))))
1991-05-20 20:35:19 +00:00
;;
;; save-buffer -> forms--save-buffer
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(make-local-variable 'local-write-file-hooks)
1993-06-19 00:15:32 +00:00
(add-hook 'local-write-file-hooks
(function
(lambda (nil)
(forms--checkmod)
(save-excursion
(set-buffer forms--file-buffer)
(save-buffer))
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
t)))
;; We have our own revert function - use it
(make-local-variable 'revert-buffer-function)
(setq revert-buffer-function 'forms-revert-buffer)
t)
1991-05-20 20:35:19 +00:00
(defun forms--help ()
"Initial help for Forms mode."
1991-05-20 20:35:19 +00:00
;; We should use
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(message (substitute-command-keys (concat
"\\[forms-next-record]:next"
" \\[forms-prev-record]:prev"
" \\[forms-first-record]:first"
" \\[forms-last-record]:last"
" \\[describe-mode]:help"))))
; but it's too slow ....
; (if forms-read-only
; (message "SPC:next DEL:prev <:first >:last ?:help q:exit")
; (message "C-c n:next C-c p:prev C-c <:first C-c >:last C-c ?:help C-c q:exit"))
; )
1991-05-20 20:35:19 +00:00
(defun forms--trans (subj arg rep)
"Translate in SUBJ all chars ARG into char REP. ARG and REP should
1991-05-20 20:35:19 +00:00
be single-char strings."
(let ((i 0)
(x (length subj))
(re (regexp-quote arg))
(k (string-to-char rep)))
(while (setq i (string-match re subj i))
(aset subj i k)
(setq i (1+ i)))))
(defun forms--exit (query &optional save)
"Internal exit from forms mode function."
1991-05-20 20:35:19 +00:00
(let ((buf (buffer-name forms--file-buffer)))
(forms--checkmod)
(if (and save
(buffer-modified-p forms--file-buffer))
(save-excursion
(set-buffer forms--file-buffer)
(save-buffer)))
(save-excursion
(set-buffer forms--file-buffer)
(delete-auto-save-file-if-necessary)
(kill-buffer (current-buffer)))
(if (get-buffer buf) ; not killed???
(if save
(progn
(beep)
(message "Problem saving buffers?")))
(delete-auto-save-file-if-necessary)
(kill-buffer (current-buffer)))))
(defun forms--get-record ()
"Fetch the current record from the file buffer."
;; This function is executed in the context of the `forms--file-buffer'.
1991-05-20 20:35:19 +00:00
(or (bolp)
(beginning-of-line nil))
(let ((here (point)))
(prog2
(end-of-line)
(buffer-substring here (point))
(goto-char here))))
(defun forms--show-record (the-record)
"Format THE-RECORD and display it in the current buffer."
1991-05-20 20:35:19 +00:00
;; Split the-record.
1991-05-20 20:35:19 +00:00
(let (the-result
(start-pos 0)
found-pos
(field-sep-length (length forms-field-sep)))
(if forms-multi-line
(forms--trans the-record forms-multi-line "\n"))
;; Add an extra separator (makes splitting easy).
1991-05-20 20:35:19 +00:00
(setq the-record (concat the-record forms-field-sep))
(while (setq found-pos (string-match forms-field-sep the-record start-pos))
(let ((ent (substring the-record start-pos found-pos)))
(setq the-result
(append the-result (list ent)))
(setq start-pos (+ field-sep-length found-pos))))
(setq forms--the-record-list the-result))
(setq buffer-read-only nil)
(if forms-use-text-properties
(let ((inhibit-read-only t))
(set-text-properties (point-min) (point-max) nil)))
1991-05-20 20:35:19 +00:00
(erase-buffer)
;; Verify the number of fields, extend forms--the-record-list if needed.
1991-05-20 20:35:19 +00:00
(if (= (length forms--the-record-list) forms-number-of-fields)
nil
(beep)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(message "Warning: this record has %d fields instead of %d"
1991-05-20 20:35:19 +00:00
(length forms--the-record-list) forms-number-of-fields)
(if (< (length forms--the-record-list) forms-number-of-fields)
(setq forms--the-record-list
(append forms--the-record-list
(make-list
(- forms-number-of-fields
(length forms--the-record-list))
"")))))
;; Call the formatter function.
1991-07-01 18:06:13 +00:00
(setq forms-fields (append (list nil) forms--the-record-list nil))
1991-05-20 20:35:19 +00:00
(funcall forms--format forms--the-record-list)
;; Prepare.
1991-05-20 20:35:19 +00:00
(goto-char (point-min))
(set-buffer-modified-p nil)
(setq buffer-read-only forms-read-only)
(setq mode-line-process
(concat " " forms--current-record "/" forms--total-records)))
(defun forms--parse-form ()
"Parse contents of form into list of strings."
;; The contents of the form are parsed, and a new list of strings
;; is constructed.
;; A vector with the strings from the original record is
;; constructed, which is updated with the new contents. Therefore
1991-05-20 20:35:19 +00:00
;; fields which were not in the form are not modified.
;; Finally, the vector is transformed into a list for further processing.
(let (forms--recordv)
1991-05-20 20:35:19 +00:00
;; Build the vector.
(setq forms--recordv (vconcat forms--the-record-list))
1991-05-20 20:35:19 +00:00
;; Parse the form and update the vector.
1991-07-01 18:06:13 +00:00
(let ((forms--dynamic-text forms--dynamic-text))
(funcall forms--parser))
1991-05-20 20:35:19 +00:00
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(if forms-modified-record-filter
1991-07-01 18:06:13 +00:00
;; As a service to the user, we add a zeroth element so she
;; can use the same indices as in the forms definition.
(let ((the-fields (vconcat [nil] forms--recordv)))
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(setq the-fields (funcall forms-modified-record-filter the-fields))
1991-07-01 18:06:13 +00:00
(cdr (append the-fields nil)))
;; Transform to a list and return.
(append forms--recordv nil))))
1991-05-20 20:35:19 +00:00
(defun forms--update ()
"Update current record with contents of form.
As a side effect: sets `forms--the-record-list'."
1991-05-20 20:35:19 +00:00
(if forms-read-only
(progn
(message "Read-only buffer!")
(beep))
(let (the-record)
;; Build new record.
1991-05-20 20:35:19 +00:00
(setq forms--the-record-list (forms--parse-form))
(setq the-record
(mapconcat 'identity forms--the-record-list forms-field-sep))
;; Handle multi-line fields, if allowed.
1991-05-20 20:35:19 +00:00
(if forms-multi-line
(forms--trans the-record "\n" forms-multi-line))
;; A final sanity check before updating.
1991-05-20 20:35:19 +00:00
(if (string-match "\n" the-record)
(progn
(message "Multi-line fields in this record - update refused!")
(beep))
(save-excursion
(set-buffer forms--file-buffer)
;; Use delete-region instead of kill-region, to avoid
;; adding junk to the kill-ring.
(delete-region (save-excursion (beginning-of-line) (point))
(save-excursion (end-of-line) (point)))
1991-05-20 20:35:19 +00:00
(insert the-record)
(beginning-of-line))))))
(defun forms--checkmod ()
"Check if this form has been modified, and call forms--update if so."
(if (buffer-modified-p nil)
(let ((here (point)))
(forms--update)
(set-buffer-modified-p nil)
(goto-char here))))
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
;;; Start and exit
;;;###autoload
1991-05-20 20:35:19 +00:00
(defun forms-find-file (fn)
"Visit a file in Forms mode."
1991-05-20 20:35:19 +00:00
(interactive "fForms file: ")
(find-file-read-only fn)
(or forms--mode-setup (forms-mode t)))
;;;###autoload
1991-05-20 20:35:19 +00:00
(defun forms-find-file-other-window (fn)
"Visit a file in Forms mode in other window."
1991-05-20 20:35:19 +00:00
(interactive "fFbrowse file in other window: ")
(find-file-other-window fn)
(eval-current-buffer)
(or forms--mode-setup (forms-mode t)))
(defun forms-exit (query)
"Normal exit from Forms mode. Modified buffers are saved."
1991-05-20 20:35:19 +00:00
(interactive "P")
(forms--exit query t))
(defun forms-exit-no-save (query)
"Exit from Forms mode without saving buffers."
1991-05-20 20:35:19 +00:00
(interactive "P")
(forms--exit query nil))
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
;;; Navigating commands
(defun forms-next-record (arg)
"Advance to the ARGth following record."
(interactive "P")
(forms-jump-record (+ forms--current-record (prefix-numeric-value arg)) t))
(defun forms-prev-record (arg)
"Advance to the ARGth previous record."
(interactive "P")
(forms-jump-record (- forms--current-record (prefix-numeric-value arg)) t))
(defun forms-jump-record (arg &optional relative)
"Jump to a random record."
(interactive "NRecord number: ")
;; Verify that the record number is within range.
1991-05-20 20:35:19 +00:00
(if (or (> arg forms--total-records)
(<= arg 0))
(progn
(beep)
;; Don't give the message if just paging.
1991-05-20 20:35:19 +00:00
(if (not relative)
(message "Record number %d out of range 1..%d"
arg forms--total-records))
)
;; Flush.
1991-05-20 20:35:19 +00:00
(forms--checkmod)
;; Calculate displacement.
1991-05-20 20:35:19 +00:00
(let ((disp (- arg forms--current-record))
(cur forms--current-record))
;; `forms--show-record' needs it now.
1991-05-20 20:35:19 +00:00
(setq forms--current-record arg)
;; Get the record and show it.
1991-05-20 20:35:19 +00:00
(forms--show-record
(save-excursion
(set-buffer forms--file-buffer)
(beginning-of-line)
;; Move, and adjust the amount if needed (shouldn't happen).
1991-05-20 20:35:19 +00:00
(if relative
(if (zerop disp)
nil
(setq cur (+ cur disp (- (forward-line disp)))))
(setq cur (+ cur disp (- (goto-line arg)))))
(forms--get-record)))
;; This shouldn't happen.
1991-05-20 20:35:19 +00:00
(if (/= forms--current-record cur)
(progn
(setq forms--current-record cur)
(beep)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(message "Stuck at record %d" cur))))))
1991-05-20 20:35:19 +00:00
(defun forms-first-record ()
"Jump to first record."
(interactive)
(forms-jump-record 1))
(defun forms-last-record ()
"Jump to last record.
As a side effect: re-calculates the number of records in the data file."
1991-05-20 20:35:19 +00:00
(interactive)
(let
((numrec
(save-excursion
(set-buffer forms--file-buffer)
(count-lines (point-min) (point-max)))))
(if (= numrec forms--total-records)
nil
(beep)
(setq forms--total-records numrec)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(message "Warning: number of records changed to %d" forms--total-records)))
1991-05-20 20:35:19 +00:00
(forms-jump-record forms--total-records))
1993-06-12 20:53:59 +00:00
1991-05-20 20:35:19 +00:00
;;; Other commands
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(defun forms-toggle-read-only (arg)
"Toggles read-only mode of a forms mode buffer.
With an argument, enables read-only mode if the argument is positive.
Otherwise enables edit mode if the visited file is writeable."
1991-05-20 20:35:19 +00:00
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(interactive "P")
(if (if arg
;; Negative arg means switch it off.
(<= (prefix-numeric-value arg) 0)
;; No arg means toggle.
forms-read-only)
;; Enable edit mode, if possible.
(let ((ro forms-read-only))
(if (save-excursion
(set-buffer forms--file-buffer)
buffer-read-only)
(progn
(setq forms-read-only t)
(message "No write access to \"%s\"" forms-file)
(beep))
(setq forms-read-only nil))
(if (equal ro forms-read-only)
nil
(forms-mode)))
;; Enable view mode.
(if forms-read-only
1991-05-20 20:35:19 +00:00
nil
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(forms--checkmod) ; sync
(setq forms-read-only t)
1991-05-20 20:35:19 +00:00
(forms-mode))))
;; Sample:
1991-07-01 18:06:13 +00:00
;; (defun my-new-record-filter (the-fields)
1991-05-20 20:35:19 +00:00
;; ;; numbers are relative to 1
;; (aset the-fields 4 (current-time-string))
;; (aset the-fields 6 (user-login-name))
;; the-list)
1991-07-01 18:06:13 +00:00
;; (setq forms-new-record-filter 'my-new-record-filter)
1991-05-20 20:35:19 +00:00
(defun forms-insert-record (arg)
"Create a new record before the current one.
With ARG: store the record after the current one.
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
If `forms-new-record-filter' contains the name of a function,
it is called to fill (some of) the fields with default values."
1991-05-20 20:35:19 +00:00
(interactive "P")
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(if forms-read-only
(error ""))
1991-05-20 20:35:19 +00:00
(let ((ln (if arg (1+ forms--current-record) forms--current-record))
the-list the-record)
(forms--checkmod)
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(if forms-new-record-filter
1991-05-20 20:35:19 +00:00
;; As a service to the user, we add a zeroth element so she
;; can use the same indices as in the forms definition.
(let ((the-fields (make-vector (1+ forms-number-of-fields) "")))
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(setq the-fields (funcall forms-new-record-filter the-fields))
1991-05-20 20:35:19 +00:00
(setq the-list (cdr (append the-fields nil))))
(setq the-list (make-list forms-number-of-fields "")))
(setq the-record
(mapconcat
'identity
the-list
forms-field-sep))
(save-excursion
(set-buffer forms--file-buffer)
(goto-line ln)
(open-line 1)
(insert the-record)
(beginning-of-line))
(setq forms--current-record ln))
(setq forms--total-records (1+ forms--total-records))
(forms-jump-record forms--current-record))
(defun forms-delete-record (arg)
"Deletes a record. With a prefix argument: don't ask."
1991-05-20 20:35:19 +00:00
(interactive "P")
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(if forms-read-only
(error ""))
1991-05-20 20:35:19 +00:00
(forms--checkmod)
(if (or arg
(y-or-n-p "Really delete this record? "))
(let ((ln forms--current-record))
(save-excursion
(set-buffer forms--file-buffer)
(goto-line ln)
;; Use delete-region instead of kill-region, to avoid
;; adding junk to the kill-ring.
(delete-region (save-excursion (beginning-of-line) (point))
(save-excursion (end-of-line) (1+ (point)))))
1991-05-20 20:35:19 +00:00
(setq forms--total-records (1- forms--total-records))
(if (> forms--current-record forms--total-records)
(setq forms--current-record forms--total-records))
(forms-jump-record forms--current-record)))
(message ""))
(defun forms-search (regexp)
"Search REGEXP in file buffer."
(interactive
(list (read-string (concat "Search for"
(if forms--search-regexp
(concat " ("
forms--search-regexp
")"))
": "))))
(if (equal "" regexp)
(setq regexp forms--search-regexp))
(forms--checkmod)
(let (the-line the-record here
(fld-sep forms-field-sep))
(if (save-excursion
(set-buffer forms--file-buffer)
(setq here (point))
(end-of-line)
(if (null (re-search-forward regexp nil t))
(progn
(goto-char here)
(message (concat "\"" regexp "\" not found."))
nil)
(setq the-record (forms--get-record))
(setq the-line (1+ (count-lines (point-min) (point))))))
(progn
(setq forms--current-record the-line)
(forms--show-record the-record)
(re-search-forward regexp nil t))))
(setq forms--search-regexp regexp))
(defun forms-revert-buffer (&optional arg noconfirm)
"Reverts current form to un-modified."
(interactive "P")
(if (or noconfirm
(yes-or-no-p "Revert form to unmodified? "))
(progn
(set-buffer-modified-p nil)
(forms-jump-record forms--current-record))))
(defun forms-next-field (arg)
"Jump to ARG-th next field."
(interactive "p")
(let ((i 0)
(here (point))
there
(cnt 0))
(if (zerop arg)
(setq cnt 1)
(setq cnt (+ cnt arg)))
(if (catch 'done
(while (< i (length forms--markers))
1991-05-20 20:35:19 +00:00
(if (or (null (setq there (aref forms--markers i)))
(<= there here))
nil
(if (<= (setq cnt (1- cnt)) 0)
(progn
(goto-char there)
(throw 'done t))))
(setq i (1+ i))))
nil
(goto-char (aref forms--markers 0)))))
1991-07-01 18:06:13 +00:00
Version 2.3. Documentation: `forms-forms-scroll' and `forms-forms-jump' now default to nil. `forms-new-record-filter' and `forms-modified-record-filter' cannot be redefined as functions. Commands and keymaps are changed. Add function key defs. (forms-version): Docstring includes full RCS id. (forms-forms-scroll): Defaults to nil. (forms-forms-jump): Defaults to nil. (forms-mode-edit-map, forms-mode-ro-map): Additional keymaps for edit mode and read-only mode. (forms--new-record-filter, forms--modified-record-filter): Deleted. (forms-mode): Docstring now includes the key bindings, since both edit mode and read-only mode must be supported. Changed `forms-new-record-filter' and `forms-modified-record-filter' semantics: the variable must point to a function and may not be defined as a function anymore. Use three keymaps: `forms-mode-map' (C-c commands), `forms-mode-edit-map' (normal mode) and `forms-mode-ro-map' (read-only mode). The maps are not buffer local. Changed the text of error messages to be more descriptive, and onsistent with the documentation. Moved setting up write-file-hooks and revert-buffer-function to function `forms--change-commands'. (forms--process-format-list): Changed error messages to be more descriptive. (forms--set-keymaps): Setup the three keymaps. (forms--mode-commands): Use new command key bindings. (forms--mode-commands1): New helper function for `forms--mode-commands'. (forms--change-commands): Handle setup of local-write-file-hooks and revert-buffer-function. (forms--help): Show new command bindings. (forms--show-record): Replaced `forms--modified-record-filter' by `forms-modified-record-filter'. (forms-jump-record): Changed error message. (forms-toggle-read-only): New function, replaces `forms-view-mode' and `forms-edit-mode'. (forms-view-mode, forms-edit-mode): Deleted. (forms-insert-record): Replaced `forms--new-record-filter' by `forms-new-record-filter'. (forms-insert-record, forms-delete-record): Disallow in read-only mode. (forms-prev-field): New function.
1993-09-27 02:19:46 +00:00
(defun forms-prev-field (arg)
"Jump to ARG-th previous field."
(interactive "p")
(let ((i (length forms--markers))
(here (point))
there
(cnt 0))
(if (zerop arg)
(setq cnt 1)
(setq cnt (+ cnt arg)))
(if (catch 'done
(while (> i 0)
(setq i ( 1- i))
(if (or (null (setq there (aref forms--markers i)))
(>= there here))
nil
(if (<= (setq cnt (1- cnt)) 0)
(progn
(goto-char there)
(throw 'done t))))))
nil
(goto-char (aref forms--markers (1- (length forms--markers)))))))
1991-07-01 18:06:13 +00:00
;;;
;;; Special service
;;;
(defun forms-enumerate (the-fields)
"Take a quoted list of symbols, and set their values to sequential numbers.
The first symbol gets number 1, the second 2 and so on.
It returns the higest number.
1991-07-01 18:06:13 +00:00
Usage: (setq forms-number-of-fields
(forms-enumerate
'(field1 field2 field2 ...)))"
(let ((the-index 0))
(while the-fields
(setq the-index (1+ the-index))
(let ((el (car-safe the-fields)))
(setq the-fields (cdr-safe the-fields))
(set el the-index)))
the-index))
1993-06-12 20:53:59 +00:00
1991-07-01 18:06:13 +00:00
;;; Debugging
1991-07-01 18:06:13 +00:00
(defvar forms--debug nil
"*Enables forms-mode debugging if not nil.")
(defun forms--debug (&rest args)
"Internal debugging routine."
1991-07-01 18:06:13 +00:00
(if forms--debug
(let ((ret nil))
(while args
(let ((el (car-safe args)))
(setq args (cdr-safe args))
(if (stringp el)
(setq ret (concat ret el))
(setq ret (concat ret (prin1-to-string el) " = "))
(if (boundp el)
(let ((vel (eval el)))
(setq ret (concat ret (prin1-to-string vel) "\n")))
(setq ret (concat ret "<unbound>" "\n")))
(if (fboundp el)
(setq ret (concat ret (prin1-to-string (symbol-function el))
"\n"))))))
(save-excursion
(set-buffer (get-buffer-create "*forms-mode debug*"))
(if (zerop (buffer-size))
(emacs-lisp-mode))
1991-07-01 18:06:13 +00:00
(goto-char (point-max))
(insert ret)))))
1993-06-12 20:53:59 +00:00
;;; forms.el ends here.