annotate lisp/forms.el @ 3829:4130587b6ffc

* fileio.c (Fset_visited_file_modtime): We're only passing two arguments to the file name handler; use call2, not call3.
author Jim Blandy <jimb@redhat.com>
date Sat, 19 Jun 1993 01:04:50 +0000
parents c9f18a7140f9
children 93a7a7b97030
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
1 ;;; forms.el -- Forms mode: edit a file as a form to fill in.
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
2 ;;; Copyright (C) 1991, 1993 Free Software Foundation, Inc.
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
3
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
4 ;;; Author: Johan Vromans
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
5
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
6 ;; This file is part of GNU Emacs.
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
7
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
11 ;; any later version.
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
12
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
16 ;; GNU General Public License for more details.
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
17
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
18 ;; You should have received a copy of the GNU General Public License
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
21
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
22 ;;; Commentary:
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
23
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
24 ;;; Visit a file using a form.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
25 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
26 ;;; === Naming conventions
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
27 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
28 ;;; The names of all variables and functions start with 'form-'.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
29 ;;; Names which start with 'form--' are intended for internal use, and
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
30 ;;; should *NOT* be used from the outside.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
31 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
32 ;;; All variables are buffer-local, to enable multiple forms visits
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
33 ;;; simultaneously.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
34 ;;; Variable 'forms--mode-setup' is local to *ALL* buffers, for it
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
35 ;;; controls if forms-mode has been enabled in a buffer.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
36 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
37 ;;; === How it works ===
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
38 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
39 ;;; Forms mode means visiting a data file which is supposed to consist
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
40 ;;; of records each containing a number of fields. The records are
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
41 ;;; separated by a newline, the fields are separated by a user-defined
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
42 ;;; field separater (default: TAB).
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
43 ;;; When shown, a record is transferred to an emacs buffer and
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
44 ;;; presented using a user-defined form. One record is shown at a
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
45 ;;; time.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
46 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
47 ;;; Forms mode is a composite mode. It involves two files, and two
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
48 ;;; buffers.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
49 ;;; The first file, called the control file, defines the name of the
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
50 ;;; data file and the forms format. This file buffer will be used to
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
51 ;;; present the forms.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
52 ;;; The second file holds the actual data. The buffer of this file
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
53 ;;; will be buried, for it is never accessed directly.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
54 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
55 ;;; Forms mode is invoked using "forms-find-file control-file".
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
56 ;;; Alternativily forms-find-file-other-window can be used.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
57 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
58 ;;; You may also visit the control file, and switch to forms mode by hand
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
59 ;;; with M-x forms-mode .
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
60 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
61 ;;; Automatic mode switching is supported, so you may use "find-file"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
62 ;;; if you specify "-*- forms -*-" in the first line of the control file.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
63 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
64 ;;; The control file is visited, evaluated using
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
65 ;;; eval-current-buffer, and should set at least the following
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
66 ;;; variables:
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
67 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
68 ;;; forms-file [string] the name of the data file.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
69 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
70 ;;; forms-number-of-fields [integer]
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
71 ;;; The number of fields in each record.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
72 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
73 ;;; forms-format-list [list] formatting instructions.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
74 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
75 ;;; The forms-format-list should be a list, each element containing
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
76 ;;;
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
77 ;;; - a string, e.g. "hello" (which is inserted \"as is\"),
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
78 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
79 ;;; - an integer, denoting a field number. The contents of the field
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
80 ;;; are inserted at this point.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
81 ;;; The first field has number one.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
82 ;;;
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
83 ;;; - a function call, e.g. (insert "text"). This function call is
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
84 ;;; dynamically evaluated and should return a string. It should *NOT*
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
85 ;;; have side-effects on the forms being constructed.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
86 ;;; The current fields are available to the function in the variable
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
87 ;;; forms-fields, they should *NOT* be modified.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
88 ;;;
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
89 ;;; - a lisp symbol, that must evaluate to one of the above.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
90 ;;;
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
91 ;;; Optional variables which may be set in the control file:
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
92 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
93 ;;; forms-field-sep [string, default TAB]
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
94 ;;; The field separator used to separate the
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
95 ;;; fields in the data file. It may be a string.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
96 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
97 ;;; forms-read-only [bool, default nil]
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
98 ;;; 't' means that the data file is visited read-only.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
99 ;;; If no write access to the data file is
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
100 ;;; possible, read-only mode is enforced.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
101 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
102 ;;; forms-multi-line [string, default "^K"]
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
103 ;;; If non-null the records of the data file may
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
104 ;;; contain fields which span multiple lines in
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
105 ;;; the form.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
106 ;;; This variable denoted the separator character
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
107 ;;; to be used for this purpose. Upon display, all
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
108 ;;; occurrencies of this character are translated
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
109 ;;; to newlines. Upon storage they are translated
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
110 ;;; back to the separator.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
111 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
112 ;;; forms-forms-scroll [bool, default t]
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
113 ;;; If non-nil: redefine scroll-up/down to perform
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
114 ;;; forms-next/prev-field if in forms mode.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
115 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
116 ;;; forms-forms-jump [bool, default t]
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
117 ;;; If non-nil: redefine beginning/end-of-buffer
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
118 ;;; to performs forms-first/last-field if in
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
119 ;;; forms mode.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
120 ;;;
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
121 ;;; forms-new-record-filter [symbol, no default]
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
122 ;;; If defined: this should be the name of a
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
123 ;;; function that is called when a new
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
124 ;;; record is created. It can be used to fill in
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
125 ;;; the new record with default fields, for example.
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
126 ;;; Instead of the name of the function, it may
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
127 ;;; be the function itself.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
128 ;;;
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
129 ;;; forms-modified-record-filter [symbol, no default]
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
130 ;;; If defined: this should be the name of a
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
131 ;;; function that is called when a record has
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
132 ;;; been modified. It is called after the fields
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
133 ;;; are parsed. It can be used to register
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
134 ;;; modification dates, for example.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
135 ;;; Instead of the name of the function, it may
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
136 ;;; be the function itself.
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
137 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
138 ;;; After evaluating the control file, its buffer is cleared and used
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
139 ;;; for further processing.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
140 ;;; The data file (as designated by "forms-file") is visited in a buffer
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
141 ;;; (forms--file-buffer) which will not normally be shown.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
142 ;;; Great malfunctioning may be expected if this file/buffer is modified
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
143 ;;; outside of this package while it's being visited!
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
144 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
145 ;;; A record from the data file is transferred from the data file,
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
146 ;;; split into fields (into forms--the-record-list), and displayed using
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
147 ;;; the specs in forms-format-list.
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
148 ;;; A format routine 'forms--format' is built upon startup to format
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
149 ;;; the records.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
150 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
151 ;;; When a form is changed the record is updated as soon as this form
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
152 ;;; is left. The contents of the form are parsed using forms-format-list,
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
153 ;;; and the fields which are deduced from the form are modified. So,
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
154 ;;; fields not shown on the forms retain their origional values.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
155 ;;; The newly formed record and replaces the contents of the
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
156 ;;; old record in forms--file-buffer.
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
157 ;;; A parse routine 'forms--parser' is built upon startup to parse
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
158 ;;; the records.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
159 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
160 ;;; Two exit functions exist: forms-exit (which saves) and forms-exit-no-save
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
161 ;;; (which doesn't). However, if forms-exit-no-save is executed and the file
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
162 ;;; buffer has been modified, emacs will ask questions.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
163 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
164 ;;; Other functions are:
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
165 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
166 ;;; paging (forward, backward) by record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
167 ;;; jumping (first, last, random number)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
168 ;;; searching
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
169 ;;; creating and deleting records
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
170 ;;; reverting the form (NOT the file buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
171 ;;; switching edit <-> view mode v.v.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
172 ;;; jumping from field to field
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
173 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
174 ;;; As an documented side-effect: jumping to the last record in the
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
175 ;;; file (using forms-last-record) will adjust forms--total-records if
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
176 ;;; needed.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
177 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
178 ;;; Commands and keymaps:
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
179 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
180 ;;; A local keymap 'forms-mode-map' is used in the forms buffer.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
181 ;;; As conventional, this map can be accessed with C-c prefix.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
182 ;;; In read-only mode, the C-c prefix must be omitted.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
183 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
184 ;;; Default bindings:
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
185 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
186 ;;; \C-c forms-mode-map
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
187 ;;; TAB forms-next-field
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
188 ;;; SPC forms-next-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
189 ;;; < forms-first-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
190 ;;; > forms-last-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
191 ;;; ? describe-mode
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
192 ;;; d forms-delete-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
193 ;;; e forms-edit-mode
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
194 ;;; i forms-insert-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
195 ;;; j forms-jump-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
196 ;;; n forms-next-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
197 ;;; p forms-prev-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
198 ;;; q forms-exit
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
199 ;;; s forms-search
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
200 ;;; v forms-view-mode
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
201 ;;; x forms-exit-no-save
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
202 ;;; DEL forms-prev-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
203 ;;;
3827
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
204 ;;; The bindings of standard functions scroll-up, scroll-down,
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
205 ;;; beginning-of-buffer and end-of-buffer are locally replaced with
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
206 ;;; forms mode functions next/prev record and first/last
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
207 ;;; record. Buffer-local variables forms-forms-scroll and
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
208 ;;; forms-forms-jump (default: t) may be set to nil to inhibit
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
209 ;;; rebinding.
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
210 ;;;
3827
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
211 ;;; A local-write-file hook is defined to save the actual data file
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
212 ;;; instead of the buffer data, a revert-file-hook is defined to
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
213 ;;; revert a forms to original.
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
214 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
215 ;;; For convenience, TAB is always bound to forms-next-field, so you
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
216 ;;; don't need the C-c prefix for this command.
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
217
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
218 ;;; Code:
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
219
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
220 ;;; Global variables and constants
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
221
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
222 (provide 'forms) ;;; official
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
223 (provide 'forms-mode) ;;; for compatibility
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
224
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
225 (defconst forms-version "1.2.11"
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
226 "Version of forms-mode implementation.")
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
227
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
228 (defvar forms-mode-hooks nil
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
229 "Hook functions to be run upon entering Forms mode.")
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
230
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
231 ;;; Mandatory variables - must be set by evaluating the control file
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
232
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
233 (defvar forms-file nil
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
234 "Name of the file holding the data.")
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
235
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
236 (defvar forms-format-list nil
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
237 "List of formatting specifications.")
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
238
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
239 (defvar forms-number-of-fields nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
240 "Number of fields per record.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
241
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
242
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
243 ;;; Optional variables with default values
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
244
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
245 (defvar forms-field-sep "\t"
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
246 "Field separator character (default TAB).")
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
247
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
248 (defvar forms-read-only nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
249 "Read-only mode (defaults to the write access on the data file).")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
250
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
251 (defvar forms-multi-line "\C-k"
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
252 "Character to separate multi-line fields (default C-k)")
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
253
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
254 (defvar forms-forms-scroll t
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
255 "*Non-nil means replace scroll-up/down commands in Forms mode.
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
256 The replacement commands performs forms-next/prev-record.")
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
257
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
258 (defvar forms-forms-jump t
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
259 "*Non-nil means redefine beginning/end-of-buffer in Forms mode.
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
260 The replacement commands performs forms-first/last-record.")
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
261
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
262 ;;; Internal variables.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
263
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
264 (defvar forms--file-buffer nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
265 "Buffer which holds the file data")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
266
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
267 (defvar forms--total-records 0
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
268 "Total number of records in the data file.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
269
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
270 (defvar forms--current-record 0
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
271 "Number of the record currently on the screen.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
272
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
273 (defvar forms-mode-map nil ; yes - this one is global
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
274 "Keymap for form buffer.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
275
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
276 (defvar forms--markers nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
277 "Field markers in the screen.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
278
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
279 (defvar forms--number-of-markers 0
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
280 "Number of fields on screen.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
281
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
282 (defvar forms--the-record-list nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
283 "List of strings of the current record, as parsed from the file.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
284
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
285 (defvar forms--search-regexp nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
286 "Last regexp used by forms-search.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
287
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
288 (defvar forms--format nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
289 "Formatting routine.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
290
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
291 (defvar forms--parser nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
292 "Forms parser routine.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
293
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
294 (defvar forms--mode-setup nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
295 "Internal - keeps track of forms-mode being set-up.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
296 (make-variable-buffer-local 'forms--mode-setup)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
297
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
298 (defvar forms--new-record-filter nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
299 "Internal - set if a new record filter has been defined.")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
300
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
301 (defvar forms--modified-record-filter nil
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
302 "Internal - set if a modified record filter has been defined.")
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
303
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
304 (defvar forms--dynamic-text nil
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
305 "Internal - holds dynamic text to insert between fields.")
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
306
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
307 (defvar forms-fields nil
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
308 "List with fields of the current forms. First field has number 1.")
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
309
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
310 (defvar forms-new-record-filter
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
311 "The name of a function that is called when a new record is created.")
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
312
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
313 (defvar forms-modified-record-filter
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
314 "The name of a function that is called when a record has been modified.")
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
315
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
316 ;;; forms-mode
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
317 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
318 ;;; This is not a simple major mode, as usual. Therefore, forms-mode
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
319 ;;; takes an optional argument 'primary' which is used for the initial
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
320 ;;; set-up. Normal use would leave 'primary' to nil.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
321 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
322 ;;; A global buffer-local variable 'forms--mode-setup' has the same effect
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
323 ;;; but makes it possible to auto-invoke forms-mode using find-file.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
324 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
325 ;;; Note: although it seems logical to have (make-local-variable) executed
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
326 ;;; where the variable is first needed, I deliberately placed all calls
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
327 ;;; in the forms-mode function.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
328
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
329 (defun forms-mode (&optional primary)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
330 "Major mode to visit files in a field-structured manner using a form.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
331
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
332 Commands (prefix with C-c if not in read-only mode):
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
333 \\{forms-mode-map}"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
334
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
335 (interactive) ; no - 'primary' is not prefix arg
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
336
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
337 ;; Primary set-up: evaluate buffer and check if the mandatory
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
338 ;; variables have been set.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
339 (if (or primary (not forms--mode-setup))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
340 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
341 (kill-all-local-variables)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
342
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
343 ;; make mandatory variables
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
344 (make-local-variable 'forms-file)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
345 (make-local-variable 'forms-number-of-fields)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
346 (make-local-variable 'forms-format-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
347
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
348 ;; make optional variables
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
349 (make-local-variable 'forms-field-sep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
350 (make-local-variable 'forms-read-only)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
351 (make-local-variable 'forms-multi-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
352 (make-local-variable 'forms-forms-scroll)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
353 (make-local-variable 'forms-forms-jump)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
354 (fmakunbound 'forms-new-record-filter)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
355
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
356 ;; eval the buffer, should set variables
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
357 (eval-current-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
358
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
359 ;; check if the mandatory variables make sense.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
360 (or forms-file
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
361 (error "'forms-file' has not been set"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
362 (or forms-number-of-fields
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
363 (error "'forms-number-of-fields' has not been set"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
364 (or (> forms-number-of-fields 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
365 (error "'forms-number-of-fields' must be > 0")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
366 (or (stringp forms-field-sep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
367 (error "'forms-field-sep' is not a string"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
368 (if forms-multi-line
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
369 (if (and (stringp forms-multi-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
370 (eq (length forms-multi-line) 1))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
371 (if (string= forms-multi-line forms-field-sep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
372 (error "'forms-multi-line' is equal to 'forms-field-sep'"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
373 (error "'forms-multi-line' must be nil or a one-character string")))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
374
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
375 ;; validate and process forms-format-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
376 (make-local-variable 'forms--number-of-markers)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
377 (make-local-variable 'forms--markers)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
378 (forms--process-format-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
379
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
380 ;; build the formatter and parser
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
381 (make-local-variable 'forms--format)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
382 (forms--make-format)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
383 (make-local-variable 'forms--parser)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
384 (forms--make-parser)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
385
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
386 ;; check if record filters are defined
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
387 (make-local-variable 'forms--new-record-filter)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
388 (setq forms--new-record-filter
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
389 (cond
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
390 ((fboundp 'forms-new-record-filter)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
391 (symbol-function 'forms-new-record-filter))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
392 ((and (boundp 'forms-new-record-filter)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
393 (fboundp forms-new-record-filter))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
394 forms-new-record-filter)))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
395 (fmakunbound 'forms-new-record-filter)
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
396 (make-local-variable 'forms--modified-record-filter)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
397 (setq forms--modified-record-filter
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
398 (cond
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
399 ((fboundp 'forms-modified-record-filter)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
400 (symbol-function 'forms-modified-record-filter))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
401 ((and (boundp 'forms-modified-record-filter)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
402 (fboundp forms-modified-record-filter))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
403 forms-modified-record-filter)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
404 (fmakunbound 'forms-modified-record-filter)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
405
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
406 ;; dynamic text support
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
407 (make-local-variable 'forms--dynamic-text)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
408 (make-local-variable 'forms-fields)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
409
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
410 ;; prepare this buffer for further processing
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
411 (setq buffer-read-only nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
412
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
413 ;; prevent accidental overwrite of the control file and autosave
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
414 (setq buffer-file-name nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
415 (auto-save-mode nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
416
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
417 ;; and clean it
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
418 (erase-buffer)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
419
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
420 ;; Make more local variables
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
421 (make-local-variable 'forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
422 (make-local-variable 'forms--total-records)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
423 (make-local-variable 'forms--current-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
424 (make-local-variable 'forms--the-record-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
425 (make-local-variable 'forms--search-rexexp)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
426
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
427 ;; A bug in the current Emacs release prevents a keymap
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
428 ;; which is buffer-local from being used by 'describe-mode'.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
429 ;; Hence we'll leave it global.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
430 ;;(make-local-variable 'forms-mode-map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
431 (if forms-mode-map ; already defined
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
432 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
433 (setq forms-mode-map (make-keymap))
3827
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
434 (forms--mode-commands forms-mode-map))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
435
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
436 ;; find the data file
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
437 (setq forms--file-buffer (find-file-noselect forms-file))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
438
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
439 ;; count the number of records, and set see if it may be modified
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
440 (let (ro)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
441 (setq forms--total-records
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
442 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
443 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
444 (bury-buffer (current-buffer))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
445 (setq ro buffer-read-only)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
446 (count-lines (point-min) (point-max))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
447 (if ro
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
448 (setq forms-read-only t)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
449
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
450 ;; set the major mode indicator
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
451 (setq major-mode 'forms-mode)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
452 (setq mode-name "Forms")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
453 (make-local-variable 'minor-mode-alist) ; needed?
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
454 (forms--set-minor-mode)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
455 (forms--set-keymaps)
3827
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
456 (make-local-variable 'local-write-file-hooks)
4089cf0e3f06 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 3697
diff changeset
457 (forms--change-commands)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
458
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
459 (set-buffer-modified-p nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
460
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
461 ;; We have our own revert function - use it
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
462 (make-local-variable 'revert-buffer-function)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
463 (setq revert-buffer-function 'forms-revert-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
464
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
465 ;; setup the first (or current) record to show
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
466 (if (< forms--current-record 1)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
467 (setq forms--current-record 1))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
468 (forms-jump-record forms--current-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
469
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
470 ;; user customising
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
471 (run-hooks 'forms-mode-hooks)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
472
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
473 ;; be helpful
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
474 (forms--help)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
475
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
476 ;; initialization done
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
477 (setq forms--mode-setup t))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
478
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
479
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
480 ;;; forms-process-format-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
481 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
482 ;;; Validates forms-format-list.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
483 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
484 ;;; Sets forms--number-of-markers and forms--markers.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
485
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
486 (defun forms--process-format-list ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
487 "Validate forms-format-list and set some global variables."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
488
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
489 (forms--debug "forms-forms-list before 1st pass:\n"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
490 'forms-format-list)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
491
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
492 ;; it must be non-nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
493 (or forms-format-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
494 (error "'forms-format-list' has not been set"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
495 ;; it must be a list ...
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
496 (or (listp forms-format-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
497 (error "'forms-format-list' is not a list"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
498
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
499 (setq forms--number-of-markers 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
500
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
501 (let ((the-list forms-format-list) ; the list of format elements
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
502 (this-item 0) ; element in list
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
503 (field-num 0)) ; highest field number
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
504
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
505 (setq forms-format-list nil) ; gonna rebuild
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
506
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
507 (while the-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
508
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
509 (let ((el (car-safe the-list))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
510 (rem (cdr-safe the-list)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
511
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
512 ;; if it is a symbol, eval it first
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
513 (if (and (symbolp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
514 (boundp el))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
515 (setq el (eval el)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
516
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
517 (cond
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
518
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
519 ;; try string ...
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
520 ((stringp el)) ; string is OK
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
521
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
522 ;; try numeric ...
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
523 ((numberp el)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
524
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
525 (if (or (<= el 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
526 (> el forms-number-of-fields))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
527 (error
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
528 "Forms error: field number %d out of range 1..%d"
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
529 el forms-number-of-fields))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
530
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
531 (setq forms--number-of-markers (1+ forms--number-of-markers))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
532 (if (> el field-num)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
533 (setq field-num el)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
534
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
535 ;; try function
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
536 ((listp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
537 (or (fboundp (car-safe el))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
538 (error
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
539 "Forms error: not a function: %s"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
540 (prin1-to-string (car-safe el)))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
541
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
542 ;; else
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
543 (t
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
544 (error "Invalid element in 'forms-format-list': %s"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
545 (prin1-to-string el))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
546
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
547 ;; advance to next element of the list
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
548 (setq the-list rem)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
549 (setq forms-format-list
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
550 (append forms-format-list (list el) nil)))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
551
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
552 (forms--debug "forms-forms-list after 1st pass:\n"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
553 'forms-format-list)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
554
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
555 ;; concat adjacent strings
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
556 (setq forms-format-list (forms--concat-adjacent forms-format-list))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
557
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
558 (forms--debug "forms-forms-list after 2nd pass:\n"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
559 'forms-format-list
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
560 'forms--number-of-markers)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
561
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
562 (setq forms--markers (make-vector forms--number-of-markers nil)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
563
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
564
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
565
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
566 ;;; Build the format routine from forms-format-list.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
567 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
568 ;;; The format routine (forms--format) will look like
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
569 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
570 ;;; (lambda (arg)
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
571 ;;; (setq forms--dynamic-text nil)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
572 ;;; ;; "text: "
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
573 ;;; (insert "text: ")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
574 ;;; ;; 6
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
575 ;;; (aset forms--markers 0 (point-marker))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
576 ;;; (insert (elt arg 5))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
577 ;;; ;; "\nmore text: "
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
578 ;;; (insert "\nmore text: ")
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
579 ;;; ;; (tocol 40)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
580 ;;; (let ((the-dyntext (tocol 40)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
581 ;;; (insert the-dyntext)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
582 ;;; (setq forms--dynamic-text (append forms--dynamic-text
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
583 ;;; (list the-dyntext))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
584 ;;; ;; 9
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
585 ;;; (aset forms--markers 1 (point-marker))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
586 ;;; (insert (elt arg 8))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
587 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
588 ;;; ... )
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
589 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
590
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
591 (defun forms--make-format ()
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
592 "Generate format function for forms"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
593 (setq forms--format (forms--format-maker forms-format-list))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
594 (forms--debug 'forms--format))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
595
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
596 (defun forms--format-maker (the-format-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
597 "Returns the parser function for forms"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
598 (let ((the-marker 0))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
599 (` (lambda (arg)
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
600 (setq forms--dynamic-text nil)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
601 (,@ (apply 'append
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
602 (mapcar 'forms--make-format-elt the-format-list)))))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
603
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
604 (defun forms--make-format-elt (el)
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
605 (cond
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
606 ((stringp el)
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
607 (` ((insert (, el)))))
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
608 ((numberp el)
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
609 (prog1
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
610 (` ((aset forms--markers (, the-marker) (point-marker))
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
611 (insert (elt arg (, (1- el))))))
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
612 (setq the-marker (1+ the-marker))))
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
613 ((listp el)
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
614 (prog1
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
615 (` ((let ((the-dyntext (, el)))
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
616 (insert the-dyntext)
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
617 (setq forms--dynamic-text (append forms--dynamic-text
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
618 (list the-dyntext)))))
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
619 )))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
620
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
621 (defun forms--concat-adjacent (the-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
622 "Concatenate adjacent strings in the-list and return the resulting list"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
623 (if (consp the-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
624 (let ((the-rest (forms--concat-adjacent (cdr the-list))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
625 (if (and (stringp (car the-list)) (stringp (car the-rest)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
626 (cons (concat (car the-list) (car the-rest))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
627 (cdr the-rest))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
628 (cons (car the-list) the-rest)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
629 the-list))
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
630
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
631 ;;; forms--make-parser.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
632 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
633 ;;; Generate parse routine from forms-format-list.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
634 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
635 ;;; The parse routine (forms--parser) will look like (give or take
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
636 ;;; a few " " .
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
637 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
638 ;;; (lambda nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
639 ;;; (let (here)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
640 ;;; (goto-char (point-min))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
641 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
642 ;;; ;; "text: "
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
643 ;;; (if (not (looking-at "text: "))
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
644 ;;; (error "Parse error: cannot find \"text: \""))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
645 ;;; (forward-char 6) ; past "text: "
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
646 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
647 ;;; ;; 6
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
648 ;;; ;; "\nmore text: "
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
649 ;;; (setq here (point))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
650 ;;; (if (not (search-forward "\nmore text: " nil t nil))
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
651 ;;; (error "Parse error: cannot find \"\\nmore text: \""))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
652 ;;; (aset the-recordv 5 (buffer-substring here (- (point) 12)))
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
653 ;;;
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
654 ;;; ;; (tocol 40)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
655 ;;; (let ((the-dyntext (car-safe forms--dynamic-text)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
656 ;;; (if (not (looking-at (regexp-quote the-dyntext)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
657 ;;; (error "Parse error: not looking at \"%s\"" the-dyntext))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
658 ;;; (forward-char (length the-dyntext))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
659 ;;; (setq forms--dynamic-text (cdr-safe forms--dynamic-text)))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
660 ;;; ...
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
661 ;;; ;; final flush (due to terminator sentinel, see below)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
662 ;;; (aset the-recordv 7 (buffer-substring (point) (point-max)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
663 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
664
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
665 (defun forms--make-parser ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
666 "Generate parser function for forms"
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
667 (setq forms--parser (forms--parser-maker forms-format-list))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
668 (forms--debug 'forms--parser))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
669
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
670 (defun forms--parser-maker (the-format-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
671 "Returns the parser function for forms"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
672 (let ((the-field nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
673 (seen-text nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
674 the--format-list)
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
675 ;; add a terminator sentinel
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
676 (setq the--format-list (append the-format-list (list nil)))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
677 (` (lambda nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
678 (let (here)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
679 (goto-char (point-min))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
680 (,@ (apply 'append
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
681 (mapcar 'forms--make-parser-elt the--format-list))))))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
682
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
683 (defun forms--make-parser-elt (el)
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
684 (cond
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
685 ((stringp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
686 (prog1
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
687 (if the-field
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
688 (` ((setq here (point))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
689 (if (not (search-forward (, el) nil t nil))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
690 (error "Parse error: cannot find \"%s\"" (, el)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
691 (aset the-recordv (, (1- the-field))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
692 (buffer-substring here
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
693 (- (point) (, (length el)))))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
694 (` ((if (not (looking-at (, (regexp-quote el))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
695 (error "Parse error: not looking at \"%s\"" (, el)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
696 (forward-char (, (length el))))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
697 (setq seen-text t)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
698 (setq the-field nil)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
699 ((numberp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
700 (if the-field
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
701 (error "Cannot parse adjacent fields %d and %d"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
702 the-field el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
703 (setq the-field el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
704 nil))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
705 ((null el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
706 (if the-field
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
707 (` ((aset the-recordv (, (1- the-field))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
708 (buffer-substring (point) (point-max)))))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
709 ((listp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
710 (prog1
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
711 (if the-field
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
712 (` ((let ((here (point))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
713 (the-dyntext (car-safe forms--dynamic-text)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
714 (if (not (search-forward the-dyntext nil t nil))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
715 (error "Parse error: cannot find \"%s\"" the-dyntext))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
716 (aset the-recordv (, (1- the-field))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
717 (buffer-substring here
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
718 (- (point) (length the-dyntext))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
719 (setq forms--dynamic-text (cdr-safe forms--dynamic-text)))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
720 (` ((let ((the-dyntext (car-safe forms--dynamic-text)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
721 (if (not (looking-at (regexp-quote the-dyntext)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
722 (error "Parse error: not looking at \"%s\"" the-dyntext))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
723 (forward-char (length the-dyntext))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
724 (setq forms--dynamic-text (cdr-safe forms--dynamic-text))))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
725 (setq seen-text t)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
726 (setq the-field nil)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
727 ))
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
728
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
729
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
730 (defun forms--set-minor-mode ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
731 (setq minor-mode-alist
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
732 (if forms-read-only
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
733 " View"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
734 nil)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
735
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
736 (defun forms--set-keymaps ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
737 "Set the keymaps used in this mode."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
738
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
739 (if forms-read-only
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
740 (use-local-map forms-mode-map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
741 (use-local-map (make-sparse-keymap))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
742 (define-key (current-local-map) "\C-c" forms-mode-map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
743 (define-key (current-local-map) "\t" 'forms-next-field)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
744
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
745 (defun forms--mode-commands (map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
746 "Fill map with all commands."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
747 (define-key map "\t" 'forms-next-field)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
748 (define-key map " " 'forms-next-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
749 (define-key map "d" 'forms-delete-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
750 (define-key map "e" 'forms-edit-mode)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
751 (define-key map "i" 'forms-insert-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
752 (define-key map "j" 'forms-jump-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
753 (define-key map "n" 'forms-next-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
754 (define-key map "p" 'forms-prev-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
755 (define-key map "q" 'forms-exit)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
756 (define-key map "s" 'forms-search)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
757 (define-key map "v" 'forms-view-mode)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
758 (define-key map "x" 'forms-exit-no-save)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
759 (define-key map "<" 'forms-first-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
760 (define-key map ">" 'forms-last-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
761 (define-key map "?" 'describe-mode)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
762 (define-key map "\177" 'forms-prev-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
763 ; (define-key map "\C-c" map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
764 (define-key map "\e" 'ESC-prefix)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
765 (define-key map "\C-x" ctl-x-map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
766 (define-key map "\C-u" 'universal-argument)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
767 (define-key map "\C-h" help-map)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
768 )
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
769
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
770 ;;; Changed functions
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
771 ;;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
772 ;;; Emacs (as of 18.55) lacks the functionality of buffer-local
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
773 ;;; funtions. Therefore we save the original meaning of some handy
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
774 ;;; functions, and replace them with a wrapper.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
775
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
776 (defun forms--change-commands ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
777 "Localize some commands."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
778 ;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
779 ;; scroll-down -> forms-prev-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
780 ;; scroll-up -> forms-next-record
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
781 (if forms-forms-scroll
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
782 (progn
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
783 (substitute-key-definition 'scroll-up 'forms-next-record
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
784 (current-local-map)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
785 (current-global-map))
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
786 (substitute-key-definition 'scroll-down 'forms-prev-record
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
787 (current-local-map)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
788 (current-global-map))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
789 ;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
790 ;; beginning-of-buffer -> forms-first-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
791 ;; end-of-buffer -> forms-end-record
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
792 (if forms-forms-jump
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
793 (progn
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
794 (substitute-key-definition 'beginning-of-buffer 'forms-first-record
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
795 (current-local-map)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
796 (current-global-map))
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
797 (substitute-key-definition 'end-of-buffer 'forms-last-record
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
798 (current-local-map)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
799 (current-global-map))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
800 ;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
801 ;; save-buffer -> forms--save-buffer
3828
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
802 (add-hook 'local-write-file-hooks
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
803 (function
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
804 (lambda (nil)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
805 (forms--checkmod)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
806 (save-excursion
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
807 (set-buffer forms--file-buffer)
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
808 (save-buffer))
c9f18a7140f9 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 3827
diff changeset
809 t))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
810
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
811 (defun forms--help ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
812 "Initial help."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
813 ;; We should use
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
814 ;;(message (substitute-command-keys (concat
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
815 ;;"\\[forms-next-record]:next"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
816 ;;" \\[forms-prev-record]:prev"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
817 ;;" \\[forms-first-record]:first"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
818 ;;" \\[forms-last-record]:last"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
819 ;;" \\[describe-mode]:help"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
820 ;;" \\[forms-exit]:exit")))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
821 ;; but it's too slow ....
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
822 (if forms-read-only
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
823 (message "SPC:next DEL:prev <:first >:last ?:help q:exit")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
824 (message "C-c n:next C-c p:prev C-c <:first C-c >:last C-c ?:help C-c q:exit")))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
825
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
826 (defun forms--trans (subj arg rep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
827 "Translate in SUBJ all chars ARG into char REP. ARG and REP should
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
828 be single-char strings."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
829 (let ((i 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
830 (x (length subj))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
831 (re (regexp-quote arg))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
832 (k (string-to-char rep)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
833 (while (setq i (string-match re subj i))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
834 (aset subj i k)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
835 (setq i (1+ i)))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
836
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
837 (defun forms--exit (query &optional save)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
838 (let ((buf (buffer-name forms--file-buffer)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
839 (forms--checkmod)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
840 (if (and save
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
841 (buffer-modified-p forms--file-buffer))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
842 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
843 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
844 (save-buffer)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
845 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
846 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
847 (delete-auto-save-file-if-necessary)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
848 (kill-buffer (current-buffer)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
849 (if (get-buffer buf) ; not killed???
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
850 (if save
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
851 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
852 (beep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
853 (message "Problem saving buffers?")))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
854 (delete-auto-save-file-if-necessary)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
855 (kill-buffer (current-buffer)))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
856
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
857 (defun forms--get-record ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
858 "Fetch the current record from the file buffer."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
859 ;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
860 ;; This function is executed in the context of the forms--file-buffer.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
861 ;;
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
862 (or (bolp)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
863 (beginning-of-line nil))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
864 (let ((here (point)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
865 (prog2
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
866 (end-of-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
867 (buffer-substring here (point))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
868 (goto-char here))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
869
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
870 (defun forms--show-record (the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
871 "Format THE-RECORD according to forms-format-list,
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
872 and display it in the current buffer."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
873
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
874 ;; split the-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
875 (let (the-result
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
876 (start-pos 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
877 found-pos
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
878 (field-sep-length (length forms-field-sep)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
879 (if forms-multi-line
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
880 (forms--trans the-record forms-multi-line "\n"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
881 ;; add an extra separator (makes splitting easy)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
882 (setq the-record (concat the-record forms-field-sep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
883 (while (setq found-pos (string-match forms-field-sep the-record start-pos))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
884 (let ((ent (substring the-record start-pos found-pos)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
885 (setq the-result
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
886 (append the-result (list ent)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
887 (setq start-pos (+ field-sep-length found-pos))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
888 (setq forms--the-record-list the-result))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
889
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
890 (setq buffer-read-only nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
891 (erase-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
892
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
893 ;; verify the number of fields, extend forms--the-record-list if needed
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
894 (if (= (length forms--the-record-list) forms-number-of-fields)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
895 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
896 (beep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
897 (message "Record has %d fields instead of %d."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
898 (length forms--the-record-list) forms-number-of-fields)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
899 (if (< (length forms--the-record-list) forms-number-of-fields)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
900 (setq forms--the-record-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
901 (append forms--the-record-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
902 (make-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
903 (- forms-number-of-fields
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
904 (length forms--the-record-list))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
905 "")))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
906
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
907 ;; call the formatter function
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
908 (setq forms-fields (append (list nil) forms--the-record-list nil))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
909 (funcall forms--format forms--the-record-list)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
910
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
911 ;; prepare
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
912 (goto-char (point-min))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
913 (set-buffer-modified-p nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
914 (setq buffer-read-only forms-read-only)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
915 (setq mode-line-process
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
916 (concat " " forms--current-record "/" forms--total-records)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
917
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
918 (defun forms--parse-form ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
919 "Parse contents of form into list of strings."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
920 ;; The contents of the form are parsed, and a new list of strings
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
921 ;; is constructed.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
922 ;; A vector with the strings from the original record is
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
923 ;; constructed, which is updated with the new contents. Therefore
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
924 ;; fields which were not in the form are not modified.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
925 ;; Finally, the vector is transformed into a list for further processing.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
926
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
927 (let (the-recordv)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
928
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
929 ;; build the vector
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
930 (setq the-recordv (vconcat forms--the-record-list))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
931
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
932 ;; parse the form and update the vector
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
933 (let ((forms--dynamic-text forms--dynamic-text))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
934 (funcall forms--parser))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
935
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
936 (if forms--modified-record-filter
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
937 ;; As a service to the user, we add a zeroth element so she
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
938 ;; can use the same indices as in the forms definition.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
939 (let ((the-fields (vconcat [nil] the-recordv)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
940 (setq the-fields (funcall forms--modified-record-filter the-fields))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
941 (cdr (append the-fields nil)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
942
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
943 ;; transform to a list and return
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
944 (append the-recordv nil))))
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
945
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
946 (defun forms--update ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
947 "Update current record with contents of form. As a side effect: sets
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
948 forms--the-record-list ."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
949 (if forms-read-only
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
950 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
951 (message "Read-only buffer!")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
952 (beep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
953
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
954 (let (the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
955 ;; build new record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
956 (setq forms--the-record-list (forms--parse-form))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
957 (setq the-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
958 (mapconcat 'identity forms--the-record-list forms-field-sep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
959
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
960 ;; handle multi-line fields, if allowed
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
961 (if forms-multi-line
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
962 (forms--trans the-record "\n" forms-multi-line))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
963
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
964 ;; a final sanity check before updating
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
965 (if (string-match "\n" the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
966 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
967 (message "Multi-line fields in this record - update refused!")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
968 (beep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
969
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
970 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
971 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
972 ;; Insert something before kill-line is called. See kill-line
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
973 ;; doc. Bugfix provided by Ignatios Souvatzis.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
974 (insert "*")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
975 (beginning-of-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
976 (kill-line nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
977 (insert the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
978 (beginning-of-line))))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
979
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
980 (defun forms--checkmod ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
981 "Check if this form has been modified, and call forms--update if so."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
982 (if (buffer-modified-p nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
983 (let ((here (point)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
984 (forms--update)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
985 (set-buffer-modified-p nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
986 (goto-char here))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
987
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
988
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
989 ;;; Start and exit
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
990 (defun forms-find-file (fn)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
991 "Visit file FN in forms mode"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
992 (interactive "fForms file: ")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
993 (find-file-read-only fn)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
994 (or forms--mode-setup (forms-mode t)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
995
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
996 (defun forms-find-file-other-window (fn)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
997 "Visit file FN in form mode in other window"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
998 (interactive "fFbrowse file in other window: ")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
999 (find-file-other-window fn)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1000 (eval-current-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1001 (or forms--mode-setup (forms-mode t)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1002
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1003 (defun forms-exit (query)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1004 "Normal exit. Modified buffers are saved."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1005 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1006 (forms--exit query t))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1007
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1008 (defun forms-exit-no-save (query)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1009 "Exit without saving buffers."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1010 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1011 (forms--exit query nil))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1012
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
1013
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1014 ;;; Navigating commands
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1015
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1016 (defun forms-next-record (arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1017 "Advance to the ARGth following record."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1018 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1019 (forms-jump-record (+ forms--current-record (prefix-numeric-value arg)) t))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1020
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1021 (defun forms-prev-record (arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1022 "Advance to the ARGth previous record."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1023 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1024 (forms-jump-record (- forms--current-record (prefix-numeric-value arg)) t))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1025
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1026 (defun forms-jump-record (arg &optional relative)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1027 "Jump to a random record."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1028 (interactive "NRecord number: ")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1029
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1030 ;; verify that the record number is within range
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1031 (if (or (> arg forms--total-records)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1032 (<= arg 0))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1033 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1034 (beep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1035 ;; don't give the message if just paging
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1036 (if (not relative)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1037 (message "Record number %d out of range 1..%d"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1038 arg forms--total-records))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1039 )
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1040
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1041 ;; flush
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1042 (forms--checkmod)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1043
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1044 ;; calculate displacement
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1045 (let ((disp (- arg forms--current-record))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1046 (cur forms--current-record))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1047
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1048 ;; forms--show-record needs it now
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1049 (setq forms--current-record arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1050
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1051 ;; get the record and show it
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1052 (forms--show-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1053 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1054 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1055 (beginning-of-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1056
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1057 ;; move, and adjust the amount if needed (shouldn't happen)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1058 (if relative
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1059 (if (zerop disp)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1060 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1061 (setq cur (+ cur disp (- (forward-line disp)))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1062 (setq cur (+ cur disp (- (goto-line arg)))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1063
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1064 (forms--get-record)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1065
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1066 ;; this shouldn't happen
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1067 (if (/= forms--current-record cur)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1068 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1069 (setq forms--current-record cur)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1070 (beep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1071 (message "Stuck at record %d." cur))))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1072
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1073 (defun forms-first-record ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1074 "Jump to first record."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1075 (interactive)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1076 (forms-jump-record 1))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1077
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1078 (defun forms-last-record ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1079 "Jump to last record. As a side effect: re-calculates the number
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1080 of records in the data file."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1081 (interactive)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1082 (let
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1083 ((numrec
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1084 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1085 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1086 (count-lines (point-min) (point-max)))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1087 (if (= numrec forms--total-records)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1088 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1089 (beep)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1090 (setq forms--total-records numrec)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1091 (message "Number of records reset to %d." forms--total-records)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1092 (forms-jump-record forms--total-records))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1093
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
1094
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1095 ;;; Other commands
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1096 (defun forms-view-mode ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1097 "Visit buffer read-only."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1098 (interactive)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1099 (if forms-read-only
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1100 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1101 (forms--checkmod) ; sync
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1102 (setq forms-read-only t)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1103 (forms-mode)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1104
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1105 (defun forms-edit-mode ()
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1106 "Make form suitable for editing, if possible."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1107 (interactive)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1108 (let ((ro forms-read-only))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1109 (if (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1110 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1111 buffer-read-only)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1112 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1113 (setq forms-read-only t)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1114 (message "No write access to \"%s\"" forms-file)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1115 (beep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1116 (setq forms-read-only nil))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1117 (if (equal ro forms-read-only)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1118 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1119 (forms-mode))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1120
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1121 ;; Sample:
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1122 ;; (defun my-new-record-filter (the-fields)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1123 ;; ;; numbers are relative to 1
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1124 ;; (aset the-fields 4 (current-time-string))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1125 ;; (aset the-fields 6 (user-login-name))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1126 ;; the-list)
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1127 ;; (setq forms-new-record-filter 'my-new-record-filter)
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1128
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1129 (defun forms-insert-record (arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1130 "Create a new record before the current one. With ARG: store the
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1131 record after the current one.
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1132 If a function forms-new-record-filter is defined, or forms-new-record-filter
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1133 contains the name of a function, it is called to
276
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1134 fill (some of) the fields with default values."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1135 ; The above doc is not true, but for documentary purposes only
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1136
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1137 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1138
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1139 (let ((ln (if arg (1+ forms--current-record) forms--current-record))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1140 the-list the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1141
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1142 (forms--checkmod)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1143 (if forms--new-record-filter
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1144 ;; As a service to the user, we add a zeroth element so she
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1145 ;; can use the same indices as in the forms definition.
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1146 (let ((the-fields (make-vector (1+ forms-number-of-fields) "")))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1147 (setq the-fields (funcall forms--new-record-filter the-fields))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1148 (setq the-list (cdr (append the-fields nil))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1149 (setq the-list (make-list forms-number-of-fields "")))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1150
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1151 (setq the-record
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1152 (mapconcat
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1153 'identity
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1154 the-list
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1155 forms-field-sep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1156
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1157 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1158 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1159 (goto-line ln)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1160 (open-line 1)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1161 (insert the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1162 (beginning-of-line))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1163
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1164 (setq forms--current-record ln))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1165
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1166 (setq forms--total-records (1+ forms--total-records))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1167 (forms-jump-record forms--current-record))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1168
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1169 (defun forms-delete-record (arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1170 "Deletes a record. With ARG: don't ask."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1171 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1172 (forms--checkmod)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1173 (if (or arg
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1174 (y-or-n-p "Really delete this record? "))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1175 (let ((ln forms--current-record))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1176 (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1177 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1178 (goto-line ln)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1179 (kill-line 1))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1180 (setq forms--total-records (1- forms--total-records))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1181 (if (> forms--current-record forms--total-records)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1182 (setq forms--current-record forms--total-records))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1183 (forms-jump-record forms--current-record)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1184 (message ""))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1185
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1186 (defun forms-search (regexp)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1187 "Search REGEXP in file buffer."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1188 (interactive
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1189 (list (read-string (concat "Search for"
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1190 (if forms--search-regexp
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1191 (concat " ("
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1192 forms--search-regexp
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1193 ")"))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1194 ": "))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1195 (if (equal "" regexp)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1196 (setq regexp forms--search-regexp))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1197 (forms--checkmod)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1198
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1199 (let (the-line the-record here
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1200 (fld-sep forms-field-sep))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1201 (if (save-excursion
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1202 (set-buffer forms--file-buffer)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1203 (setq here (point))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1204 (end-of-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1205 (if (null (re-search-forward regexp nil t))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1206 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1207 (goto-char here)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1208 (message (concat "\"" regexp "\" not found."))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1209 nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1210 (setq the-record (forms--get-record))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1211 (setq the-line (1+ (count-lines (point-min) (point))))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1212 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1213 (setq forms--current-record the-line)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1214 (forms--show-record the-record)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1215 (re-search-forward regexp nil t))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1216 (setq forms--search-regexp regexp))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1217
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1218 (defun forms-revert-buffer (&optional arg noconfirm)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1219 "Reverts current form to un-modified."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1220 (interactive "P")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1221 (if (or noconfirm
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1222 (yes-or-no-p "Revert form to unmodified? "))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1223 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1224 (set-buffer-modified-p nil)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1225 (forms-jump-record forms--current-record))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1226
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1227 (defun forms-next-field (arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1228 "Jump to ARG-th next field."
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1229 (interactive "p")
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1230
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1231 (let ((i 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1232 (here (point))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1233 there
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1234 (cnt 0))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1235
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1236 (if (zerop arg)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1237 (setq cnt 1)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1238 (setq cnt (+ cnt arg)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1239
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1240 (if (catch 'done
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1241 (while (< i forms--number-of-markers)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1242 (if (or (null (setq there (aref forms--markers i)))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1243 (<= there here))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1244 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1245 (if (<= (setq cnt (1- cnt)) 0)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1246 (progn
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1247 (goto-char there)
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1248 (throw 'done t))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1249 (setq i (1+ i))))
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1250 nil
e7eb71cbf478 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1251 (goto-char (aref forms--markers 0)))))
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1252
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1253 ;;;
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1254 ;;; Special service
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1255 ;;;
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1256 (defun forms-enumerate (the-fields)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1257 "Take a quoted list of symbols, and set their values to the numbers
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1258 1, 2 and so on. Returns the higest number.
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1259
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1260 Usage: (setq forms-number-of-fields
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1261 (forms-enumerate
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1262 '(field1 field2 field2 ...)))"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1263
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1264 (let ((the-index 0))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1265 (while the-fields
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1266 (setq the-index (1+ the-index))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1267 (let ((el (car-safe the-fields)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1268 (setq the-fields (cdr-safe the-fields))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1269 (set el the-index)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1270 the-index))
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
1271
307
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1272 ;;; Debugging
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1273 ;;;
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1274 (defvar forms--debug nil
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1275 "*Enables forms-mode debugging if not nil.")
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1276
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1277 (defun forms--debug (&rest args)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1278 "Internal - debugging routine"
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1279 (if forms--debug
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1280 (let ((ret nil))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1281 (while args
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1282 (let ((el (car-safe args)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1283 (setq args (cdr-safe args))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1284 (if (stringp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1285 (setq ret (concat ret el))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1286 (setq ret (concat ret (prin1-to-string el) " = "))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1287 (if (boundp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1288 (let ((vel (eval el)))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1289 (setq ret (concat ret (prin1-to-string vel) "\n")))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1290 (setq ret (concat ret "<unbound>" "\n")))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1291 (if (fboundp el)
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1292 (setq ret (concat ret (prin1-to-string (symbol-function el))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1293 "\n"))))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1294 (save-excursion
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1295 (set-buffer (get-buffer-create "*forms-mode debug*"))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1296 (goto-char (point-max))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1297 (insert ret)))))
7fede845e304 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 276
diff changeset
1298
3697
994bb6dc9249 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 307
diff changeset
1299 ;;; forms.el ends here.