annotate lisp/utils/forms.el @ 30:ec9a17fef872 r19-15b98

Import from CVS: tag r19-15b98
author cvs
date Mon, 13 Aug 2007 08:52:29 +0200
parents b82b59fe008d
children 56c54cf7c5b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1 ;;; forms.el --- Forms mode: edit a file as a form to fill in
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
3 ;; Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
5 ;; Author: Johan Vromans <jvromans@squirrel.nl>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Version: Revision: 2.10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; hacked on by jwz for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
25 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
27 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
31 ;; Visit a file using a form.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
32 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
33 ;; === Naming conventions
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
34 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
35 ;; The names of all variables and functions start with 'forms-'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
36 ;; Names which start with 'forms--' are intended for internal use, and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
37 ;; should *NOT* be used from the outside.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
38 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
39 ;; All variables are buffer-local, to enable multiple forms visits
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
40 ;; simultaneously.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
41 ;; Variable `forms--mode-setup' is local to *ALL* buffers, for it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
42 ;; controls if forms-mode has been enabled in a buffer.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
43 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
44 ;; === How it works ===
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
45 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
46 ;; Forms mode means visiting a data file which is supposed to consist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
47 ;; of records each containing a number of fields. The records are
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
48 ;; separated by a newline, the fields are separated by a user-defined
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
49 ;; field separator (default: TAB).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
50 ;; When shown, a record is transferred to an Emacs buffer and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
51 ;; presented using a user-defined form. One record is shown at a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
52 ;; time.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
53 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
54 ;; Forms mode is a composite mode. It involves two files, and two
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
55 ;; buffers.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
56 ;; The first file, called the control file, defines the name of the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
57 ;; data file and the forms format. This file buffer will be used to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
58 ;; present the forms.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
59 ;; The second file holds the actual data. The buffer of this file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
60 ;; will be buried, for it is never accessed directly.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
61 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
62 ;; Forms mode is invoked using M-x forms-find-file control-file .
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
63 ;; Alternatively `forms-find-file-other-window' can be used.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
64 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
65 ;; You may also visit the control file, and switch to forms mode by hand
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
66 ;; with M-x forms-mode .
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
67 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
68 ;; Automatic mode switching is supported if you specify
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
69 ;; "-*- forms -*-" in the first line of the control file.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
70 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
71 ;; The control file is visited, evaluated using `eval-current-buffer',
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
72 ;; and should set at least the following variables:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
73 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
74 ;; forms-file [string]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
75 ;; The name of the data file.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
76 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
77 ;; forms-number-of-fields [integer]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
78 ;; The number of fields in each record.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
79 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
80 ;; forms-format-list [list]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
81 ;; Formatting instructions.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
82 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
83 ;; `forms-format-list' should be a list, each element containing
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
84 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
85 ;; - a string, e.g. "hello". The string is inserted in the forms
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
86 ;; "as is".
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
87 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
88 ;; - an integer, denoting a field number.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
89 ;; The contents of this field are inserted at this point.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
90 ;; Fields are numbered starting with number one.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
91 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
92 ;; - a function call, e.g. (insert "text").
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
93 ;; This function call is dynamically evaluated and should return a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
94 ;; string. It should *NOT* have side-effects on the forms being
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
95 ;; constructed. The current fields are available to the function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
96 ;; in the variable `forms-fields', they should *NOT* be modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
97 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
98 ;; - a lisp symbol, that must evaluate to one of the above.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
99 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
100 ;; Optional variables which may be set in the control file:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
101 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
102 ;; forms-field-sep [string, default TAB]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
103 ;; The field separator used to separate the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
104 ;; fields in the data file. It may be a string.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
105 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
106 ;; forms-read-only [bool, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
107 ;; Non-nil means that the data file is visited
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
108 ;; read-only (view mode) as opposed to edit mode.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
109 ;; If no write access to the data file is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
110 ;; possible, view mode is enforced.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
111 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
112 ;; forms-check-number-of-fields [bool, default t]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
113 ;; If non-nil, a warning will be issued whenever
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
114 ;; a record is found that does not have the number
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
115 ;; of fields specified by `forms-number-of-fields'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
116 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
117 ;; forms-multi-line [string, default "^K"]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
118 ;; If non-null the records of the data file may
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
119 ;; contain fields that can span multiple lines in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
120 ;; the form.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
121 ;; This variable denotes the separator character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
122 ;; to be used for this purpose. Upon display, all
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
123 ;; occurrences of this character are translated
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
124 ;; to newlines. Upon storage they are translated
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
125 ;; back to the separator character.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
126 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
127 ;; forms-forms-scroll [bool, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
128 ;; Non-nil means: rebind locally the commands that
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
129 ;; perform `scroll-up' or `scroll-down' to use
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
130 ;; `forms-next-field' resp. `forms-prev-field'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
131 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
132 ;; forms-forms-jump [bool, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
133 ;; Non-nil means: rebind locally the commands that
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
134 ;; perform `beginning-of-buffer' or `end-of-buffer'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
135 ;; to perform `forms-first-field' and `forms-last-field'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
136 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
137 ;; forms-insert-after [bool, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
138 ;; Non-nil means: inserts of new records go after
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
139 ;; current record, also initial position is at last
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
140 ;; record.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
141 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
142 ;; forms-read-file-filter [symbol, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
143 ;; If not nil: this should be the name of a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
144 ;; function that is called after the forms data file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
145 ;; has been read. It can be used to transform
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
146 ;; the contents of the file into a format more suitable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
147 ;; for forms-mode processing.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
148 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
149 ;; forms-write-file-filter [symbol, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
150 ;; If not nil: this should be the name of a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
151 ;; function that is called before the forms data file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
152 ;; is written (saved) to disk. It can be used to undo
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
153 ;; the effects of `forms-read-file-filter', if any.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
154 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
155 ;; forms-new-record-filter [symbol, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
156 ;; If not nil: this should be the name of a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
157 ;; function that is called when a new
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
158 ;; record is created. It can be used to fill in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
159 ;; the new record with default fields, for example.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
160 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
161 ;; forms-modified-record-filter [symbol, default nil]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
162 ;; If not nil: this should be the name of a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
163 ;; function that is called when a record has
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
164 ;; been modified. It is called after the fields
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
165 ;; are parsed. It can be used to register
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
166 ;; modification dates, for example.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
167 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
168 ;; forms-use-extents [bool, see text for default]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
169 ;; forms-use-text-properties [bool, see text for default]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
170 ;; These variables control if forms mode should use
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
171 ;; text properties or extents to protect the form text
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
172 ;; from being modified (using text-property `read-only').
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
173 ;; Also, the read-write fields are shown using a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
174 ;; distinct face, if possible.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
175 ;; As of emacs 19.29, the `intangible' text property
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
176 ;; is used to prevent moving into read-only fields.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
177 ;; This variable defaults to t if running Emacs 19
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
178 ;; with text properties.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
179 ;; The default face to show read-write fields is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
180 ;; copied from face `region'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
181 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
182 ;; forms-ro-face [symbol, default 'default]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
183 ;; This is the face that is used to show
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
184 ;; read-only text on the screen.If used, this
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
185 ;; variable should be set to a symbol that is a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
186 ;; valid face.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
187 ;; E.g.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
188 ;; (make-face 'my-face)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
189 ;; (setq forms-ro-face 'my-face)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
190 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
191 ;; forms-rw-face [symbol, default 'region]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
192 ;; This is the face that is used to show
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
193 ;; read-write text on the screen.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
194 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
195 ;; After evaluating the control file, its buffer is cleared and used
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
196 ;; for further processing.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
197 ;; The data file (as designated by `forms-file') is visited in a buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
198 ;; `forms--file-buffer' which will not normally be shown.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
199 ;; Great malfunctioning may be expected if this file/buffer is modified
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
200 ;; outside of this package while it is being visited!
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
201 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
202 ;; Normal operation is to transfer one line (record) from the data file,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
203 ;; split it into fields (into `forms--the-record-list'), and display it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
204 ;; using the specs in `forms-format-list'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
205 ;; A format routine `forms--format' is built upon startup to format
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
206 ;; the records according to `forms-format-list'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
207 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
208 ;; When a form is changed the record is updated as soon as this form
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
209 ;; is left. The contents of the form are parsed using information
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
210 ;; obtained from `forms-format-list', and the fields which are
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
211 ;; deduced from the form are modified. Fields not shown on the forms
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
212 ;; retain their original values. The newly formed record then
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
213 ;; replaces the contents of the old record in `forms--file-buffer'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
214 ;; A parse routine `forms--parser' is built upon startup to parse
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
215 ;; the records.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
216 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
217 ;; Two exit functions exist: `forms-exit' and `forms-exit-no-save'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
218 ;; `forms-exit' saves the data to the file, if modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
219 ;; `forms-exit-no-save` does not. However, if `forms-exit-no-save'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
220 ;; is executed and the file buffer has been modified, Emacs will ask
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
221 ;; questions anyway.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
222 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
223 ;; Other functions provided by forms mode are:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
224 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
225 ;; paging (forward, backward) by record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
226 ;; jumping (first, last, random number)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
227 ;; searching
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
228 ;; creating and deleting records
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
229 ;; reverting the form (NOT the file buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
230 ;; switching edit <-> view mode v.v.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
231 ;; jumping from field to field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
232 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
233 ;; As an documented side-effect: jumping to the last record in the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
234 ;; file (using forms-last-record) will adjust forms--total-records if
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
235 ;; needed.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
236 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
237 ;; The forms buffer can be in on eof two modes: edit mode or view
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
238 ;; mode. View mode is a read-only mode, you cannot modify the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
239 ;; contents of the buffer.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
240 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
241 ;; Edit mode commands:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
242 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
243 ;; TAB forms-next-field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
244 ;; \C-c TAB forms-next-field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
245 ;; \C-c < forms-first-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
246 ;; \C-c > forms-last-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
247 ;; \C-c ? describe-mode
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
248 ;; \C-c \C-k forms-delete-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
249 ;; \C-c \C-q forms-toggle-read-only
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
250 ;; \C-c \C-o forms-insert-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
251 ;; \C-c \C-l forms-jump-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
252 ;; \C-c \C-n forms-next-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
253 ;; \C-c \C-p forms-prev-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
254 ;; \C-c \C-r forms-search-backward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
255 ;; \C-c \C-s forms-search-forward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
256 ;; \C-c \C-x forms-exit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
257 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
258 ;; Read-only mode commands:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
259 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
260 ;; SPC forms-next-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
261 ;; DEL forms-prev-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
262 ;; ? describe-mode
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
263 ;; \C-q forms-toggle-read-only
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
264 ;; l forms-jump-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
265 ;; n forms-next-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
266 ;; p forms-prev-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
267 ;; r forms-search-backward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
268 ;; s forms-search-forward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
269 ;; x forms-exit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
270 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
271 ;; Of course, it is also possible to use the \C-c prefix to obtain the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
272 ;; same command keys as in edit mode.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
273 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
274 ;; The following bindings are available, independent of the mode:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
275 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
276 ;; [next] forms-next-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
277 ;; [prior] forms-prev-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
278 ;; [begin] forms-first-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
279 ;; [end] forms-last-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
280 ;; [S-TAB] forms-prev-field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
281 ;; [backtab] forms-prev-field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
282 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
283 ;; For convenience, TAB is always bound to `forms-next-field', so you
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
284 ;; don't need the C-c prefix for this command.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
285 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
286 ;; As mentioned above (see `forms-forms-scroll' and `forms-forms-jump')
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
287 ;; the bindings of standard functions `scroll-up', `scroll-down',
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
288 ;; `beginning-of-buffer' and `end-of-buffer' can be locally replaced with
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
289 ;; forms mode functions next/prev record and first/last
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
290 ;; record.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
291 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
292 ;; `local-write-file hook' is defined to save the actual data file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
293 ;; instead of the buffer data, `revert-file-hook' is defined to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
294 ;; revert a forms to original.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;;; Global variables and constants:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (provide 'forms) ;;; official
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (provide 'forms-mode) ;;; for compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
303 (defconst forms-version (substring "$Revision: 1.1.1.2 $" 11 -2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 "The version number of forms-mode (as string). The complete RCS id is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
306 $Id: forms.el,v 1.1.1.2 1996/12/18 03:54:04 steve Exp $")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar forms-mode-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "Hook functions to be run upon entering Forms mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;;; Mandatory variables - must be set by evaluating the control file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (defvar forms-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 "Name of the file holding the data.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defvar forms-format-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "List of formatting specifications.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (defvar forms-number-of-fields nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 "Number of fields per record.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;;; Optional variables with default values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
324 (defvar forms-check-number-of-fields t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
325 "*If non-nil, warn about records with wrong number of fields.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
326
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defvar forms-field-sep "\t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 "Field separator character (default TAB).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defvar forms-read-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 "Non-nil means: visit the file in view (read-only) mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 \(Defaults to the write access on the data file).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defvar forms-multi-line "\C-k"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 "If not nil: use this character to separate multi-line fields (default C-k).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defvar forms-forms-scroll nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 "*Non-nil means replace scroll-up/down commands in Forms mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 The replacement commands performs forms-next/prev-record.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defvar forms-forms-jump nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 "*Non-nil means redefine beginning/end-of-buffer in Forms mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 The replacement commands performs forms-first/last-record.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (defvar forms-read-file-filter nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "The name of a function that is called after reading the data file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 This can be used to change the contents of the file to something more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 suitable for forms processing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (defvar forms-write-file-filter nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 "The name of a function that is called before writing the data file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 This can be used to undo the effects of form-read-file-hook.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (defvar forms-new-record-filter nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 "The name of a function that is called when a new record is created.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (defvar forms-modified-record-filter nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 "The name of a function that is called when a record has been modified.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (defvar forms-fields nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "List with fields of the current forms. First field has number 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 This variable is for use by the filter routines only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 The contents may NOT be modified.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (defvar forms-use-extents (fboundp 'set-extent-property) ; XEmacs 19.9+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 "*Non-nil means: use XEmacs/Lucid Emacs extents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 Defaults to t if this emacs is capable of handling text properties.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defvar forms-use-text-properties (and (fboundp 'set-text-properties)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
370 (not forms-use-extents)) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 "*Non-nil means: use emacs-19 text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 Defaults to t if this emacs is capable of handling text properties.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
374 (defvar forms-insert-after nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
375 "*Non-nil means: inserts of new records go after current record.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
376 Also, initial position is at last record.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
377
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (defvar forms-ro-face (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 'forms-label-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 'default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 "The face (a symbol) that is used to display read-only text on the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defvar forms-rw-face (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 'forms-field-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 'region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "The face (a symbol) that is used to display read-write text on the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;;; Internal variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (defvar forms--lemacs-p (string-match "XEmacs" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (defvar forms--file-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 "Buffer which holds the file data")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (defvar forms--total-records 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 "Total number of records in the data file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defvar forms--current-record 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 "Number of the record currently on the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defvar forms-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 "Keymap for form buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (defvar forms-mode-ro-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 "Keymap for form buffer in view mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (defvar forms-mode-edit-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 "Keymap for form buffer in edit mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (defvar forms--markers nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 "Field markers in the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (defvar forms--dyntexts nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 "Dynamic texts (resulting from function calls) on the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (defvar forms--the-record-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 "List of strings of the current record, as parsed from the file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defvar forms--search-regexp nil
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
418 "Last regexp used by forms-search functions.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defvar forms--format nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 "Formatting routine.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (defvar forms--parser nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 "Forms parser routine.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (defvar forms--mode-setup nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 "To keep track of forms-mode being set-up.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (make-variable-buffer-local 'forms--mode-setup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (defvar forms--dynamic-text nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 "Array that holds dynamic texts to insert between fields.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (defvar forms--elements nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 "Array with the order in which the fields are displayed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (defvar forms--ro-face nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 "Face used to represent read-only data on the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (defvar forms--rw-face nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 "Face used to represent read-write data on the screen.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (defun forms-mode (&optional primary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 "Major mode to visit files in a field-structured manner using a form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Commands: Equivalent keys in read-only mode:
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
447 TAB forms-next-field TAB
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
448 \\C-c TAB forms-next-field
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
449 \\C-c < forms-first-record <
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
450 \\C-c > forms-last-record >
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
451 \\C-c ? describe-mode ?
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
452 \\C-c \\C-k forms-delete-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
453 \\C-c \\C-q forms-toggle-read-only q
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
454 \\C-c \\C-o forms-insert-record
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
455 \\C-c \\C-l forms-jump-record l
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
456 \\C-c \\C-n forms-next-record n
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
457 \\C-c \\C-p forms-prev-record p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
458 \\C-c \\C-r forms-search-backward r
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
459 \\C-c \\C-s forms-search-forward s
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
460 \\C-c \\C-x forms-exit x
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
461 "
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;; This is not a simple major mode, as usual. Therefore, forms-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; takes an optional argument `primary' which is used for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; initial set-up. Normal use would leave `primary' to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; A global buffer-local variable `forms--mode-setup' has the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; effect but makes it possible to auto-invoke forms-mode using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; `find-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; Note: although it seems logical to have `make-local-variable'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; executed where the variable is first needed, I have deliberately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; placed all calls in this function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;; Primary set-up: evaluate buffer and check if the mandatory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; variables have been set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (if (or primary (not forms--mode-setup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;;(message "forms: setting up...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; Make mandatory variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (make-local-variable 'forms-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (make-local-variable 'forms-number-of-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (make-local-variable 'forms-format-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; Make optional variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (make-local-variable 'forms-field-sep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (make-local-variable 'forms-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (make-local-variable 'forms-multi-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (make-local-variable 'forms-forms-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (make-local-variable 'forms-forms-jump)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
492 (make-local-variable 'forms-insert-after)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; (make-local-variable 'forms-use-text-properties)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;; Filter functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (make-local-variable 'forms-read-file-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (make-local-variable 'forms-write-file-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (make-local-variable 'forms-new-record-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (make-local-variable 'forms-modified-record-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;; Make sure no filters exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq forms-read-file-filter nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (setq forms-write-file-filter nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (setq forms-new-record-filter nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (setq forms-modified-record-filter nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
507 (if forms--lemacs-p ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; forms-field-face defaults to bold.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; forms-label-face defaults to no attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; (inherit from default.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (make-face 'forms-field-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (make-face 'forms-label-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (if (face-differs-from-default-p 'forms-field-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (copy-face 'bold 'forms-field-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;;(set-face-underline-p 'forms-field-face t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;; If running Emacs 19 under X, setup faces to show read-only and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;; read-write fields.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (if (fboundp 'make-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (make-local-variable 'forms-ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (make-local-variable 'forms-rw-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; eval the buffer, should set variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;;(message "forms: processing control file...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;; If enable-local-eval is not set to t the user is asked first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (if (or (eq enable-local-eval t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (concat "Evaluate lisp code in buffer "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (buffer-name) " to display forms ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (eval-current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (error "`enable-local-eval' inhibits buffer evaluation"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;; Check if the mandatory variables make sense.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (or forms-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 "'forms-file' has not been set")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ;; Check forms-field-sep first, since it can be needed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; construct a default format list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (or (stringp forms-field-sep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 "'forms-field-sep' is not a string")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (if forms-number-of-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (or (and (numberp forms-number-of-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (> forms-number-of-fields 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 "'forms-number-of-fields' must be a number > 0")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (or (null forms-format-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 "'forms-number-of-fields' has not been set"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (or forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (forms--intuit-from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (if forms-multi-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (if (and (stringp forms-multi-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (eq (length forms-multi-line) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (if (string= forms-multi-line forms-field-sep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 "'forms-multi-line' is equal to 'forms-field-sep'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 "'forms-multi-line' must be nil or a one-character string"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; (or (fboundp 'set-text-properties)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ;; (setq forms-use-text-properties nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ;; Validate and process forms-format-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ;;(message "forms: pre-processing format list...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (forms--process-format-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ;; Build the formatter and parser.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;;(message "forms: building formatter...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (make-local-variable 'forms--format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (make-local-variable 'forms--markers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (make-local-variable 'forms--dyntexts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (make-local-variable 'forms--elements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;;(message "forms: building parser...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (forms--make-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (make-local-variable 'forms--parser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (forms--make-parser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;;(message "forms: building parser... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; Check if record filters are defined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (if (and forms-new-record-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (not (fboundp forms-new-record-filter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 "'forms-new-record-filter' is not a function")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (if (and forms-modified-record-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (not (fboundp forms-modified-record-filter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 "'forms-modified-record-filter' is not a function")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ;; The filters acces the contents of the forms using `forms-fields'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (make-local-variable 'forms-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;; Dynamic text support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (make-local-variable 'forms--dynamic-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ;; Prevent accidental overwrite of the control file and autosave.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
605 (set-visited-file-name nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;; Prepare this buffer for further processing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 ;;(message "forms: setting up... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;; initialization done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (setq forms--mode-setup t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 ;; Copy desired faces to the actual variables used by the forms formatter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (if (fboundp 'make-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (make-local-variable 'forms--ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (make-local-variable 'forms--rw-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (if forms-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (setq forms--ro-face forms-ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (setq forms--rw-face forms-ro-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (setq forms--ro-face forms-ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (setq forms--rw-face forms-rw-face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; Make more local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (make-local-variable 'forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (make-local-variable 'forms--total-records)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (make-local-variable 'forms--current-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (make-local-variable 'forms--the-record-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (make-local-variable 'forms--search-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ; The keymaps are global, so multiple forms mode buffers can share them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;(make-local-variable 'forms-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 ;(make-local-variable 'forms-mode-ro-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ;(make-local-variable 'forms-mode-edit-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (if forms-mode-map ; already defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;;(message "forms: building keymap...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (forms--mode-commands)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;;(message "forms: building keymap... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
647 ;; set the major mode indicator
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
648 (setq major-mode 'forms-mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
649 (setq mode-name "Forms")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
650
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 ;; find the data file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (setq forms--file-buffer (find-file-noselect forms-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; Pre-transform.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (let ((read-file-filter forms-read-file-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (write-file-filter forms-write-file-filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (if read-file-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (set-buffer forms--file-buffer)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
660 (let ((inhibit-read-only t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
661 (file-modified (buffer-modified-p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
662 (run-hooks 'read-file-filter)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
663 (if (not file-modified) (set-buffer-modified-p nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (if write-file-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (make-variable-buffer-local 'local-write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (setq local-write-file-hooks (list write-file-filter)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (if write-file-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (make-variable-buffer-local 'local-write-file-hooks)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
672 ;; (setq local-write-file-hooks (list write-file-filter))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
673 (add-hook 'local-write-file-hooks 'write-file-filter)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;; count the number of records, and set see if it may be modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (let (ro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (setq forms--total-records
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ;;(message "forms: counting records...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (bury-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (setq ro buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (count-lines (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 ;;(message "forms: counting records... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (if ro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (setq forms-read-only t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 ;;(message "forms: proceeding setup...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ;; Since we aren't really implementing a minor mode, we hack the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; directly to get the text " View " into forms-read-only form buffers. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ;; that reason, this variable must be buffer only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (make-local-variable 'minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (setq minor-mode-alist (list (list 'forms-read-only " View")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ;;(message "forms: proceeding setup (keymaps)...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (forms--set-keymaps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ;;(message "forms: proceeding setup (commands)...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (forms--change-commands)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 ;;(message "forms: proceeding setup (buffer)...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (if (= forms--total-records 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ;;(message "forms: proceeding setup (new file)...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 "GNU Emacs Forms Mode version " forms-version "\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (file-exists-p forms-file)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
713 (concat "No records available in file `" forms-file "'\n\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
714 (format "Creating new file `%s'\nwith %d field%s per record\n\n"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 forms-file forms-number-of-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (if (= 1 forms-number-of-fields) "" "s")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 "Use " (substitute-command-keys "\\[forms-insert-record]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 " to create new records.\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (setq forms--current-record 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (set-buffer-modified-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ;; setup the first (or current) record to show
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (if (< forms--current-record 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (setq forms--current-record 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (forms-jump-record forms--current-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
729 (if forms-insert-after
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
730 (forms-last-record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
731 (forms-first-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
732
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;; user customising
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;;(message "forms: proceeding setup (user hooks)...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (run-hooks 'forms-mode-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;;(message "forms: setting up... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;; be helpful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (forms--help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (defun forms--process-format-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; Validate `forms-format-list' and set some global variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;; Symbols in the list are evaluated, and consecutive strings are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; concatenated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; Array `forms--elements' is constructed that contains the order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;; of the fields on the display. This array is used by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ;; `forms--parser-using-text-properties' to extract the fields data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 ;; from the form on the screen.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
750 ;; Upon completion, `forms-format-list' is guaranteed correct, so
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;; `forms--make-format' and `forms--make-parser' do not need to perform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 ;; any checks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; Verify that `forms-format-list' is not nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (or forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 "'forms-format-list' has not been set")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; It must be a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (or (listp forms-format-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (error (concat "Forms control file error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 "'forms-format-list' is not a list")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; Assume every field is painted once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; `forms--elements' will grow if needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (setq forms--elements (make-vector forms-number-of-fields nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (let ((the-list forms-format-list) ; the list of format elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (this-item 0) ; element in list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (prev-item nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (field-num 0)) ; highest field number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (setq forms-format-list nil) ; gonna rebuild
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (while the-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (let ((el (car-safe the-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (rem (cdr-safe the-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 ;; If it is a symbol, eval it first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (if (and (symbolp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (boundp el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (setq el (eval el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ;; Try string ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ((stringp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (if (stringp prev-item) ; try to concatenate strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (setq prev-item (concat prev-item el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (if prev-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (setq forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (append forms-format-list (list prev-item) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (setq prev-item el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 ;; Try numeric ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ((numberp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;; Validate range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (if (or (<= el 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (> el forms-number-of-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (error (concat "Forms format error: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 "field number %d out of range 1..%d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 el forms-number-of-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ;; Store forms order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (if (> field-num (length forms--elements))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (setq forms--elements (vconcat forms--elements (1- el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (aset forms--elements field-num (1- el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (setq field-num (1+ field-num))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (if prev-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (setq forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (append forms-format-list (list prev-item) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (setq prev-item el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 ;; Try function ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ((listp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 ;; Validate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (or (fboundp (car-safe el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (error (concat "Forms format error: "
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
822 "not a function %S")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
823 (car-safe el)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;; Shift.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (if prev-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (setq forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (append forms-format-list (list prev-item) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (setq prev-item el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 ;; else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (error (concat "Forms format error: "
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
834 "invalid element %S")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
835 el)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; Advance to next element of the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (setq the-list rem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;; Append last item.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (if prev-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (setq forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (append forms-format-list (list prev-item) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;; Append a newline if the last item is a field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 ;; This prevents parsing problems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ;; Also it makes it possible to insert an empty last field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (if (numberp prev-item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (setq forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (append forms-format-list (list "\n") nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (forms--debug 'forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 'forms--elements))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ;; Special treatment for read-only segments. (FSF19 only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ;; If text is inserted between two read-only segments, it inherits the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ;; read-only properties. This is not what we want.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;; To solve this, read-only segments get the `insert-in-front-hooks'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 ;; property set with a function that temporarily switches the properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 ;; of the first character of the segment to read-write, so the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 ;; text gets the right properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; The `post-command-hook' is used to restore the original properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (defvar forms--iif-start nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 "Record start of modification command.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (defvar forms--iif-properties nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 "Original properties of the character being overridden.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (defun forms--iif-hook (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 "`insert-in-front-hooks' function for read-only segments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;; Note start location. By making it a marker that points one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 ;; character beyond the actual location, it is guaranteed to move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 ;; correctly if text is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (or forms--iif-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (setq forms--iif-start (copy-marker (1+ (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 ;; Check if there is special treatment required.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (if (or (<= forms--iif-start 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (get-text-property (- forms--iif-start 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 'read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;; Fetch current properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (setq forms--iif-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (text-properties-at (1- forms--iif-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 ;; Replace them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (1- forms--iif-start) forms--iif-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (list 'face forms--rw-face 'front-sticky '(face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 ;; Enable `post-command-hook' to restore the properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (setq post-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (append (list 'forms--iif-post-command-hook) post-command-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 ;; No action needed. Clear marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (setq forms--iif-start nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (defun forms--iif-post-command-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 "`post-command-hook' function for read-only segments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ;; Disable `post-command-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (setq post-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (delq 'forms--iif-hook-post-command-hook post-command-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 ;; Restore properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (if forms--iif-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (1- forms--iif-start) forms--iif-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 forms--iif-properties)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ;; Cleanup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (setq forms--iif-start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (defvar forms--marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (defvar forms--dyntext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (defun forms--make-format ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 "Generate `forms--format' using the information in `forms-format-list'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;; The real work is done using a mapcar of `forms--make-format-elt' on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;; `forms-format-list'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 ;; This function sets up the necessary environment, and decides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; which function to mapcar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (let ((forms--marker 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (forms--dyntext 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 forms--format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (if forms-use-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (` (lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (,@ (apply 'append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (mapcar 'forms--make-format-elt-using-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 forms-format-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ;; Prevent insertion before the first text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (,@ (if (numberp (car forms-format-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 '((add-text-properties (point-min) (1+ (point-min))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
943 '(front-sticky (read-only intangible))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ;; Prevent insertion after the last text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (remove-text-properties (1- (point)) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 '(rear-nonsticky)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (setq forms--iif-start nil)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
948 (if forms-use-extents ; XEmacs version
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (` (lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (,@ (apply 'append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (mapcar 'forms--make-format-elt-using-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 forms-format-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 ;; After creating all the extents, set their endpoint behavior.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ;; We can't do this when creating the extents, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 ;; otherwise the text we insert for the labels would be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 ;; interpreted as user input, and would alter the endpoints
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 ;; of the previous extents we created (the text-entry fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ;; would be extended by the following static-text areas.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (lambda (extent ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ((not (extent-property extent 'forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ;; it's not one of ours; leave it alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 ((not (extent-property extent 'read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;; text-entry fields should be [closed,closed] so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;; characters at either boundary go into them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (set-extent-property extent 'end-open nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 ;; Read-only fields should be (open,open) so that a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;; read-only error isn't signalled when characters are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;; inserted adjascent to them. However, the very first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;; label should be [closed,open) so that one can't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 ;; insert text at point-min before the first label,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 ;; and the very last should be (open,closed] for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 ;; same reason.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 ((= (point-min) (extent-start-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (set-extent-property extent 'start-open nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (set-extent-property extent 'end-open t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ((= (point-max) (extent-end-position extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (set-extent-property extent 'start-open t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (set-extent-property extent 'end-open nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (set-extent-property extent 'start-open t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (set-extent-property extent 'end-open t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 ;; return nil to continue mapping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (current-buffer) (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (` (lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (,@ (apply 'append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (mapcar 'forms--make-format-elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 forms-format-list))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 ;; We have tallied the number of markers and dynamic texts,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 ;; so we can allocate the arrays now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (setq forms--markers (make-vector forms--marker nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (setq forms--dyntexts (make-vector forms--dyntext nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (forms--debug 'forms--format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (defun forms--make-format-elt-using-text-properties (el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 "Helper routine to generate format function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ;; The format routine `forms--format' will look like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ;; ;; preamble
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; (lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;; (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ;; ;; A string, e.g. "text: ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;; (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ;; (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ;; (progn (insert "text: ") (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ;; (list 'face forms--ro-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ;; 'read-only 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;; 'insert-in-front-hooks 'forms--iif-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;; 'rear-nonsticky '(read-only face insert-in-front-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; ;; A field, e.g. 6.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;; (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; (aset forms--markers 0 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ;; (insert (elt arg 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;; (or (= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;; (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;; here (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;; (list 'face forms--rw-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 ;; 'front-sticky '(face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ;; ;; Another string, e.g. "\nmore text: ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ;; (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ;; (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 ;; (progn (insert "\nmore text: ") (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 ;; (list 'face forms--ro-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 ;; 'read-only 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ;; 'insert-in-front-hooks 'forms--iif-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;; 'rear-nonsticky '(read-only face insert-in-front-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 ;; ;; A function, e.g. (tocol 40).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;; (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;; (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 ;; (insert (aset forms--dyntexts 0 (tocol 40)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;; (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;; (list 'face forms--ro-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ;; 'read-only 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 ;; 'insert-in-front-hooks 'forms--iif-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 ;; 'rear-nonsticky '(read-only face insert-in-front-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 ;; ;; Prevent insertion before the first text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 ;; (add-text-properties (point-min) (1+ (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ;; '(front-sticky (read-only))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;; ;; Prevent insertion after the last text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; (remove-text-properties (1- (point)) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 ;; '(rear-nonsticky)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ;; ;; wrap up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ;; (setq forms--iif-start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 ;; ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 ((stringp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (` ((set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (point) ; start at point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (progn ; until after insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (insert (, el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (list 'face forms--ro-face ; read-only appearance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 'read-only (,@ (list (1+ forms--marker)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1071 'intangible t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 'insert-in-front-hooks '(forms--iif-hook)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1073 'rear-nonsticky '(face read-only insert-in-front-hooks
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1074 intangible))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ((numberp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (` ((let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (aset forms--markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (, (prog1 forms--marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (setq forms--marker (1+ forms--marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (insert (elt arg (, (1- el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (or (= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 here (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (list 'face forms--rw-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 'front-sticky '(face))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 ((listp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (` ((set-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (insert (aset forms--dyntexts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (, (prog1 forms--dyntext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (setq forms--dyntext (1+ forms--dyntext))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (, el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (list 'face forms--ro-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 'read-only (,@ (list (1+ forms--marker)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1100 'intangible t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 'insert-in-front-hooks '(forms--iif-hook)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1102 'rear-nonsticky '(read-only face insert-in-front-hooks
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1103 intangible))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 ;; end of cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1108 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (defun forms--make-format-elt-using-extents (el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 "Helper routine to generate format function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;; The format routine `forms--format' will look like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 ;; ;; preamble
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 ;; (lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; ;; A string, e.g. "text: ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 ;; (let ((extent (make-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 ;; (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ;; (progn (insert "text: ") (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ;; (set-extent-face extent forms--ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 ;; (set-extent-property extent 'read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; (set-extent-property extent 'forms t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ;; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 ;; ;; A field, e.g. 6.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 ;; (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 ;; (aset forms--markers 0 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 ;; (insert (elt arg 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 ;; (if (= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 ;; nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 ;; (let ((extent (make-extent here (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 ;; (set-extent-face extent forms--rw-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 ;; (set-extent-property extent 'forms t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ;; )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; ;; A function, e.g. (tocol 40).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ;; (let ((extent (make-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 ;; (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 ;; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 ;; (insert (aset forms--dyntexts 0 (tocol 40)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;; (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;; (set-extent-face extent forms--ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 ;; (set-extent-property extent 'read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 ;; (set-extent-property extent 'forms t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 ;; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ;; ;; wrap up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 ;; (setq forms--iif-start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 ;; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 ((stringp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (` ((let ((extent (make-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (point) ; start at point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (progn ; until after insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (insert (, el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (set-extent-face extent forms--ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (set-extent-property extent 'forms t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (set-extent-property extent 'read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ((numberp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (` ((let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (aset forms--markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (, (prog1 forms--marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (setq forms--marker (1+ forms--marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (insert (elt arg (, (1- el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (if (= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (let ((extent (make-extent here (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (set-extent-face extent forms--rw-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (set-extent-property extent 'forms t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 ((listp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (` ((let ((extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (make-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (insert (aset forms--dyntexts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (, (prog1 forms--dyntext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (setq forms--dyntext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (1+ forms--dyntext))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (, el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (set-extent-face extent forms--ro-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (set-extent-property extent 'forms t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (set-extent-property extent 'read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;; end of cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (defun forms--make-format-elt (el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 "Helper routine to generate format function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 ;; If we're not using text properties, the format routine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ;; `forms--format' will look like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ;; (lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;; ;; a string, e.g. "text: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 ;; (insert "text: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ;; ;; a field, e.g. 6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 ;; (aset forms--markers 0 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ;; (insert (elt arg 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 ;; ;; another string, e.g. "\nmore text: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ;; (insert "\nmore text: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 ;; ;; a function, e.g. (tocol 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 ;; (insert (aset forms--dyntexts 0 (tocol 40)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 ;; ... )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 ((stringp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (` ((insert (, el)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ((numberp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (` ((aset forms--markers (, forms--marker) (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (insert (elt arg (, (1- el))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (setq forms--marker (1+ forms--marker))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 ((listp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (` ((insert (aset forms--dyntexts (, forms--dyntext) (, el)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (setq forms--dyntext (1+ forms--dyntext))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (defvar forms--field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (defvar forms--recordv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (defvar forms--seen-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (defun forms--make-parser ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 "Generate `forms--parser' from the information in `forms-format-list'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; If we can use text properties, we simply set it to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 ;; `forms--parser-using-text-properties'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 ;; Otherwise, the function is constructed using a mapcar of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ;; `forms--make-parser-elt on `forms-format-list'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 forms--parser
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (if forms-use-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (function forms--parser-using-text-properties)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (let ((forms--field nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (forms--seen-text nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (forms--dyntext 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 ;; Note: we add a nil element to the list passed to `mapcar',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 ;; see `forms--make-parser-elt' for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (` (lambda nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (let (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (,@ (apply 'append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 'forms--make-parser-elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (append forms-format-list (list nil)))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (forms--debug 'forms--parser))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (defun forms--parser-using-text-properties ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 "Extract field info from forms when using text properties."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ;; Using text properties, we can simply jump to the markers, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 ;; extract the information up to the following read-only segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 here there)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (while (< i (length forms--markers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (goto-char (setq here (aref forms--markers i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (if (get-text-property here 'read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (aset forms--recordv (aref forms--elements i) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (if (setq there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (next-single-property-change here 'read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (aset forms--recordv (aref forms--elements i)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1276 (buffer-substring-no-properties here there))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (aset forms--recordv (aref forms--elements i)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1278 (buffer-substring-no-properties here (point-max)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (setq i (1+ i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (defun forms--make-parser-elt (el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 "Helper routine to generate forms parser function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 ;; The parse routine will look like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 ;; (lambda nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 ;; (let (here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 ;; (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 ;; ;; "text: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 ;; (if (not (looking-at "text: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 ;; (error "Parse error: cannot find \"text: \""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ;; (forward-char 6) ; past "text: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ;; ;; 6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ;; ;; "\nmore text: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ;; (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 ;; (if (not (search-forward "\nmore text: " nil t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; (error "Parse error: cannot find \"\\nmore text: \""))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1300 ;; (aset forms--recordv 5 (buffer-substring-no-properties here (- (point) 12)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 ;; ;; (tocol 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 ;; (let ((forms--dyntext (car-safe forms--dynamic-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 ;; (if (not (looking-at (regexp-quote forms--dyntext)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 ;; (error "Parse error: not looking at \"%s\"" forms--dyntext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 ;; (forward-char (length forms--dyntext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 ;; (setq forms--dynamic-text (cdr-safe forms--dynamic-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 ;; ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 ;; ;; final flush (due to terminator sentinel, see below)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1310 ;; (aset forms--recordv 7 (buffer-substring-no-properties (point) (point-max)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 ((stringp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (if forms--field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (` ((setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (if (not (search-forward (, el) nil t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (error "Parse error: cannot find \"%s\"" (, el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (aset forms--recordv (, (1- forms--field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (buffer-substring here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (- (point) (, (length el)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (` ((if (not (looking-at (, (regexp-quote el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (error "Parse error: not looking at \"%s\"" (, el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (forward-char (, (length el))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (setq forms--seen-text t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (setq forms--field nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 ((numberp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (if forms--field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (error "Cannot parse adjacent fields %d and %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 forms--field el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (setq forms--field el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 ((null el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (if forms--field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (` ((aset forms--recordv (, (1- forms--field))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1336 (buffer-substring-no-properties (point) (point-max)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 ((listp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (if forms--field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (` ((let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (forms--dyntext (aref forms--dyntexts (, forms--dyntext))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (if (not (search-forward forms--dyntext nil t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (error "Parse error: cannot find \"%s\"" forms--dyntext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (aset forms--recordv (, (1- forms--field))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1345 (buffer-substring-no-properties here
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (- (point) (length forms--dyntext)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (` ((let ((forms--dyntext (aref forms--dyntexts (, forms--dyntext))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (if (not (looking-at (regexp-quote forms--dyntext)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (error "Parse error: not looking at \"%s\"" forms--dyntext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (forward-char (length forms--dyntext))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (setq forms--dyntext (1+ forms--dyntext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (setq forms--seen-text t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (setq forms--field nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (defun forms--intuit-from-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 "Get number of fields and a default form using the data file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 ;; If `forms-number-of-fields' is not set, get it from the data file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (if (null forms-number-of-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 ;; Need a file to do this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (if (not (file-exists-p forms-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (error "Need existing file or explicit 'forms-number-of-records'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ;; Visit the file and extract the first record.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (setq forms--file-buffer (find-file-noselect forms-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (let ((read-file-filter forms-read-file-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (the-record))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (setq the-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (run-hooks 'read-file-filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (forms--get-record)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 ;; This may be overkill, but try to avoid interference with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 ;; the normal processing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (kill-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 ;; Count the number of fields in `the-record'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (let (the-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (start-pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 found-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (field-sep-length (length forms-field-sep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (setq forms-number-of-fields 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (while (setq found-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (string-match forms-field-sep the-record start-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (setq forms-number-of-fields (1+ forms-number-of-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (setq start-pos (+ field-sep-length found-pos))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 ;; Construct default format list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (setq forms-format-list (list "Forms file \"" forms-file "\".\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (let ((i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (while (<= (setq i (1+ i)) forms-number-of-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (setq forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (append forms-format-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (list (format "%4d: " i) i "\n"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (defun forms--set-keymaps ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 "Set the keymaps used in this mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (use-local-map (if forms-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 forms-mode-ro-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 forms-mode-edit-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (defun forms--mode-commands ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 "Fill the Forms mode keymaps."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 ;; `forms-mode-map' is always accessible via \C-c prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (setq forms-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (define-key forms-mode-map "\t" 'forms-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (define-key forms-mode-map "\C-k" 'forms-delete-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (define-key forms-mode-map "\C-q" 'forms-toggle-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (define-key forms-mode-map "\C-o" 'forms-insert-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (define-key forms-mode-map "\C-l" 'forms-jump-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (define-key forms-mode-map "\C-n" 'forms-next-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (define-key forms-mode-map "\C-p" 'forms-prev-record)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1421 (define-key forms-mode-map "\C-r" 'forms-search-backward)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1422 (define-key forms-mode-map "\C-s" 'forms-search-forward)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (define-key forms-mode-map "\C-x" 'forms-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (define-key forms-mode-map "<" 'forms-first-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (define-key forms-mode-map ">" 'forms-last-record)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1426 (define-key forms-mode-map "?" 'describe-mode) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (define-key forms-mode-map "\C-?" 'forms-prev-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 ;; `forms-mode-ro-map' replaces the local map when in read-only mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (setq forms-mode-ro-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (suppress-keymap forms-mode-ro-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (define-key forms-mode-ro-map "\C-c" forms-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (define-key forms-mode-ro-map "\t" 'forms-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (define-key forms-mode-ro-map "q" 'forms-toggle-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (define-key forms-mode-ro-map "l" 'forms-jump-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (define-key forms-mode-ro-map "n" 'forms-next-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (define-key forms-mode-ro-map "p" 'forms-prev-record)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1438 (define-key forms-mode-ro-map "r" 'forms-search-backward)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1439 (define-key forms-mode-ro-map "s" 'forms-search-forward)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (define-key forms-mode-ro-map "x" 'forms-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (define-key forms-mode-ro-map "<" 'forms-first-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (define-key forms-mode-ro-map ">" 'forms-last-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (define-key forms-mode-ro-map "?" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (define-key forms-mode-ro-map " " 'forms-next-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (forms--mode-commands1 forms-mode-ro-map)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1446 (forms--mode-menu-ro forms-mode-ro-map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 ;; This is the normal, local map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (setq forms-mode-edit-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (define-key forms-mode-edit-map "\t" 'forms-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (define-key forms-mode-edit-map "\C-c" forms-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (forms--mode-commands1 forms-mode-edit-map)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1453 (forms--mode-menu-edit forms-mode-edit-map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1456 (defun forms--mode-menu-ro (map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1457 ;;; Menu initialisation
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1458 ; (define-key map [menu-bar] (make-sparse-keymap))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1459 (define-key map [menu-bar forms]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1460 (cons "Forms" (make-sparse-keymap "Forms")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1461 (define-key map [menu-bar forms menu-forms-exit]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1462 '("Exit Forms Mode" . forms-exit))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1463 (define-key map [menu-bar forms menu-forms-sep1]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1464 '("----"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1465 (define-key map [menu-bar forms menu-forms-save]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1466 '("Save Data" . forms-save-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1467 (define-key map [menu-bar forms menu-forms-print]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1468 '("Print Data" . forms-print))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1469 (define-key map [menu-bar forms menu-forms-describe]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1470 '("Describe Mode" . describe-mode))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1471 (define-key map [menu-bar forms menu-forms-toggle-ro]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1472 '("Toggle View/Edit" . forms-toggle-read-only))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1473 (define-key map [menu-bar forms menu-forms-jump-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1474 '("Jump" . forms-jump-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1475 (define-key map [menu-bar forms menu-forms-search-backward]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1476 '("Search Backward" . forms-search-backward))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1477 (define-key map [menu-bar forms menu-forms-search-forward]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1478 '("Search Forward" . forms-search-forward))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1479 (define-key map [menu-bar forms menu-forms-delete-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1480 '("Delete" . forms-delete-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1481 (define-key map [menu-bar forms menu-forms-insert-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1482 '("Insert" . forms-insert-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1483 (define-key map [menu-bar forms menu-forms-sep2]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1484 '("----"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1485 (define-key map [menu-bar forms menu-forms-last-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1486 '("Last Record" . forms-last-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1487 (define-key map [menu-bar forms menu-forms-first-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1488 '("First Record" . forms-first-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1489 (define-key map [menu-bar forms menu-forms-prev-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1490 '("Previous Record" . forms-prev-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1491 (define-key map [menu-bar forms menu-forms-next-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1492 '("Next Record" . forms-next-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1493 (define-key map [menu-bar forms menu-forms-sep3]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1494 '("----"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1495 (define-key map [menu-bar forms menu-forms-prev-field]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1496 '("Previous Field" . forms-prev-field))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1497 (define-key map [menu-bar forms menu-forms-next-field]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1498 '("Next Field" . forms-next-field))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1499 (put 'forms-insert-record 'menu-enable '(not forms-read-only))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1500 (put 'forms-delete-record 'menu-enable '(not forms-read-only))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1501 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1502 (defun forms--mode-menu-edit (map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1503 ;;; Menu initialisation
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1504 ; (define-key map [menu-bar] (make-sparse-keymap))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1505 (define-key map [menu-bar forms]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1506 (cons "Forms" (make-sparse-keymap "Forms")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1507 (define-key map [menu-bar forms menu-forms-edit--exit]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1508 '("Exit" . forms-exit))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1509 (define-key map [menu-bar forms menu-forms-edit-sep1]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1510 '("----"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1511 (define-key map [menu-bar forms menu-forms-edit-save]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1512 '("Save Data" . forms-save-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1513 (define-key map [menu-bar forms menu-forms-edit-print]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1514 '("Print Data" . forms-print))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1515 (define-key map [menu-bar forms menu-forms-edit-describe]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1516 '("Describe Mode" . describe-mode))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1517 (define-key map [menu-bar forms menu-forms-edit-toggle-ro]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1518 '("Toggle View/Edit" . forms-toggle-read-only))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1519 (define-key map [menu-bar forms menu-forms-edit-jump-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1520 '("Jump" . forms-jump-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1521 (define-key map [menu-bar forms menu-forms-edit-search-backward]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1522 '("Search Backward" . forms-search-backward))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1523 (define-key map [menu-bar forms menu-forms-edit-search-forward]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1524 '("Search Forward" . forms-search-forward))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1525 (define-key map [menu-bar forms menu-forms-edit-delete-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1526 '("Delete" . forms-delete-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1527 (define-key map [menu-bar forms menu-forms-edit-insert-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1528 '("Insert" . forms-insert-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1529 (define-key map [menu-bar forms menu-forms-edit-sep2]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1530 '("----"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1531 (define-key map [menu-bar forms menu-forms-edit-last-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1532 '("Last Record" . forms-last-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1533 (define-key map [menu-bar forms menu-forms-edit-first-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1534 '("First Record" . forms-first-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1535 (define-key map [menu-bar forms menu-forms-edit-prev-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1536 '("Previous Record" . forms-prev-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1537 (define-key map [menu-bar forms menu-forms-edit-next-record]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1538 '("Next Record" . forms-next-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1539 (define-key map [menu-bar forms menu-forms-edit-sep3]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1540 '("----"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1541 (define-key map [menu-bar forms menu-forms-edit-prev-field]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1542 '("Previous Field" . forms-prev-field))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1543 (define-key map [menu-bar forms menu-forms-edit-next-field]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1544 '("Next Field" . forms-next-field))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1545 (put 'forms-insert-record 'menu-enable '(not forms-read-only))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1546 (put 'forms-delete-record 'menu-enable '(not forms-read-only))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1547 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1548
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1549 (defun forms--mode-commands1 (map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 "Helper routine to define keys."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1551 (if forms--lemacs-p ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (define-key map [tab] 'forms-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (define-key map [(shift tab)] 'forms-prev-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (define-key map [TAB] 'forms-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (define-key map [S-tab] 'forms-prev-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (define-key map [next] 'forms-next-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (define-key map [prior] 'forms-prev-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (define-key map [begin] 'forms-first-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (define-key map [last] 'forms-last-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (define-key map [backtab] 'forms-prev-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ;;; Changed functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (defun forms--change-commands ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 "Localize some commands for Forms mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 ;; scroll-down -> forms-prev-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 ;; scroll-up -> forms-next-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (if forms-forms-scroll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (substitute-key-definition 'scroll-up 'forms-next-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (current-local-map)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1575 ;;(current-global-map) ; FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (substitute-key-definition 'scroll-down 'forms-prev-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (current-local-map)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1579 ;;(current-global-map) ; FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 ;; beginning-of-buffer -> forms-first-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 ;; end-of-buffer -> forms-end-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (if forms-forms-jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (substitute-key-definition 'beginning-of-buffer 'forms-first-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (current-local-map)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1588 ;;(current-global-map) ; FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (substitute-key-definition 'end-of-buffer 'forms-last-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (current-local-map)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1592 ;;(current-global-map) ;FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; Save buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (local-set-key "\C-x\C-s" 'forms-save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 ;; We have our own revert function - use it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (make-local-variable 'revert-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (setq revert-buffer-function 'forms--revert-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (defun forms--help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 "Initial help for Forms mode."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1606 (message "%s" (substitute-command-keys (concat
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 "\\[forms-next-record]:next"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 " \\[forms-prev-record]:prev"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 " \\[forms-first-record]:first"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 " \\[forms-last-record]:last"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 " \\[describe-mode]:help"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (defun forms--trans (subj arg rep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 "Translate in SUBJ all chars ARG into char REP. ARG and REP should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 be single-char strings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (x (length subj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (re (regexp-quote arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (k (string-to-char rep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (while (setq i (string-match re subj i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (aset subj i k)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (setq i (1+ i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (defun forms--exit (query &optional save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 "Internal exit from forms mode function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (let ((buf (buffer-name forms--file-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (forms--checkmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (if (and save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (buffer-modified-p forms--file-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (forms-save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (delete-auto-save-file-if-necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (kill-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (if (get-buffer buf) ; not killed???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (if save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (message "Problem saving buffers?")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (delete-auto-save-file-if-necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (kill-buffer (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (defun forms--get-record ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 "Fetch the current record from the file buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; This function is executed in the context of the `forms--file-buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (or (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (beginning-of-line nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (end-of-line)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1654 (buffer-substring-no-properties here (point))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (defun forms--show-record (the-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 "Format THE-RECORD and display it in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 ;; Split the-record.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (let (the-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (start-pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 found-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (field-sep-length (length forms-field-sep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (if forms-multi-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (forms--trans the-record forms-multi-line "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ;; Add an extra separator (makes splitting easy).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (setq the-record (concat the-record forms-field-sep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (while (setq found-pos (string-match forms-field-sep the-record start-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (let ((ent (substring the-record start-pos found-pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (setq the-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (append the-result (list ent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (setq start-pos (+ field-sep-length found-pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (setq forms--the-record-list the-result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (if forms-use-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (set-text-properties (point-min) (point-max) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 ;; Verify the number of fields, extend forms--the-record-list if needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (if (= (length forms--the-record-list) forms-number-of-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 nil
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1685 (if (null forms-check-number-of-fields)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1686 nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1687 (beep)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1688 (message "Warning: this record has %d fields instead of %d"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1689 (length forms--the-record-list) forms-number-of-fields))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (if (< (length forms--the-record-list) forms-number-of-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (setq forms--the-record-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (append forms--the-record-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (make-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (- forms-number-of-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (length forms--the-record-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 ;; Call the formatter function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (setq forms-fields (append (list nil) forms--the-record-list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 (funcall forms--format forms--the-record-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ;; Prepare.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 (setq buffer-read-only forms-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (setq mode-line-process
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1707 (concat " " forms--current-record "/" forms--total-records)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (defun forms--parse-form ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 "Parse contents of form into list of strings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 ;; The contents of the form are parsed, and a new list of strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 ;; is constructed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 ;; A vector with the strings from the original record is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 ;; constructed, which is updated with the new contents. Therefore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 ;; fields which were not in the form are not modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 ;; Finally, the vector is transformed into a list for further processing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (let (forms--recordv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 ;; Build the vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (setq forms--recordv (vconcat forms--the-record-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 ;; Parse the form and update the vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (let ((forms--dynamic-text forms--dynamic-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (funcall forms--parser))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (if forms-modified-record-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 ;; As a service to the user, we add a zeroth element so she
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 ;; can use the same indices as in the forms definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (let ((the-fields (vconcat [nil] forms--recordv)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (setq the-fields (funcall forms-modified-record-filter the-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (cdr (append the-fields nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 ;; Transform to a list and return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 (append forms--recordv nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (defun forms--update ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 "Update current record with contents of form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 As a side effect: sets `forms--the-record-list'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (if forms-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (message "Read-only buffer!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (let (the-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 ;; Build new record.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (setq forms--the-record-list (forms--parse-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (setq the-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (mapconcat 'identity forms--the-record-list forms-field-sep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (if (string-match (regexp-quote forms-field-sep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (mapconcat 'identity forms--the-record-list ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (error "Field separator occurs in record - update refused!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 ;; Handle multi-line fields, if allowed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (if forms-multi-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (forms--trans the-record "\n" forms-multi-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 ;; A final sanity check before updating.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (if (string-match "\n" the-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (message "Multi-line fields in this record - update refused!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 ;; Use delete-region instead of kill-region, to avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 ;; adding junk to the kill-ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (delete-region (save-excursion (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (save-excursion (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (insert the-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (beginning-of-line))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (defun forms--checkmod ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 "Check if this form has been modified, and call forms--update if so."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (if (buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (forms--update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 ;;; Start and exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (defun forms-find-file (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 "Visit a file in Forms mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (interactive "fForms file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (let ((enable-local-eval t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (enable-local-variables t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (find-file-read-only fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (or forms--mode-setup (forms-mode t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (defun forms-find-file-other-window (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 "Visit a file in Forms mode in other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (interactive "fFbrowse file in other window: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (let ((enable-local-eval t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (enable-local-variables t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (find-file-other-window fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (or forms--mode-setup (forms-mode t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (defun forms-exit (query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 "Normal exit from Forms mode. Modified buffers are saved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (forms--exit query t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (defun forms-exit-no-save (query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 "Exit from Forms mode without saving buffers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (forms--exit query nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ;;; Navigating commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (defun forms-next-record (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 "Advance to the ARGth following record."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (forms-jump-record (+ forms--current-record (prefix-numeric-value arg)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (defun forms-prev-record (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 "Advance to the ARGth previous record."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (forms-jump-record (- forms--current-record (prefix-numeric-value arg)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (defun forms-jump-record (arg &optional relative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 "Jump to a random record."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (interactive "NRecord number: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 ;; Verify that the record number is within range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (if (or (> arg forms--total-records)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (<= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 ;; Don't give the message if just paging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (if (not relative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (message "Record number %d out of range 1..%d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 arg forms--total-records))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 ;; Flush.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (forms--checkmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 ;; Calculate displacement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (let ((disp (- arg forms--current-record))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (cur forms--current-record))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 ;; `forms--show-record' needs it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (setq forms--current-record arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;; Get the record and show it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (forms--show-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 ;; Move, and adjust the amount if needed (shouldn't happen).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (if relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (if (zerop disp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (setq cur (+ cur disp (- (forward-line disp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (setq cur (+ cur disp (- (goto-line arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (forms--get-record)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 ;; This shouldn't happen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (if (/= forms--current-record cur)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (setq forms--current-record cur)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (message "Stuck at record %d" cur))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (defun forms-first-record ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 "Jump to first record."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (forms-jump-record 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (defun forms-last-record ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 "Jump to last record.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 As a side effect: re-calculates the number of records in the data file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ((numrec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (count-lines (point-min) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (if (= numrec forms--total-records)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (setq forms--total-records numrec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (message "Warning: number of records changed to %d" forms--total-records)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (forms-jump-record forms--total-records))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ;;; Other commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (defun forms-toggle-read-only (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 "Toggles read-only mode of a forms mode buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 With an argument, enables read-only mode if the argument is positive.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1898 Otherwise enables edit mode if the visited file is writable."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (if (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 ;; Negative arg means switch it off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (<= (prefix-numeric-value arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 ;; No arg means toggle.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 forms-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 ;; Enable edit mode, if possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (let ((ro forms-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (setq forms-read-only t)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1915 (message "No write access to `%s'" forms-file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (setq forms-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (if (equal ro forms-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (forms-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 ;; Enable view mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (if forms-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (forms--checkmod) ; sync
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (setq forms-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (forms-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 ;; Sample:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 ;; (defun my-new-record-filter (the-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 ;; ;; numbers are relative to 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 ;; (aset the-fields 4 (current-time-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 ;; (aset the-fields 6 (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 ;; the-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 ;; (setq forms-new-record-filter 'my-new-record-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (defun forms-insert-record (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 "Create a new record before the current one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 With ARG: store the record after the current one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 If `forms-new-record-filter' contains the name of a function,
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1941 it is called to fill (some of) the fields with default values.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1942 If `forms-insert-after is non-nil, the default behavior is to insert
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1943 after the current record."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (if forms-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1950 (let (ln the-list the-record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1951
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1952 (if (or (and arg forms-insert-after)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1953 (and (not arg) (not forms-insert-after)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1954 (setq ln forms--current-record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
1955 (setq ln (1+ forms--current-record)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (forms--checkmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (if forms-new-record-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 ;; As a service to the user, we add a zeroth element so she
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 ;; can use the same indices as in the forms definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (let ((the-fields (make-vector (1+ forms-number-of-fields) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (setq the-fields (funcall forms-new-record-filter the-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (setq the-list (cdr (append the-fields nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (setq the-list (make-list forms-number-of-fields "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (setq the-record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 the-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 forms-field-sep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (goto-line ln)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (open-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (insert the-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (setq forms--current-record ln))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (setq forms--total-records (1+ forms--total-records))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (forms-jump-record forms--current-record))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (defun forms-delete-record (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 "Deletes a record. With a prefix argument: don't ask."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (if forms-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (forms--checkmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 (if (or arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 (y-or-n-p "Really delete this record? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (let ((ln forms--current-record))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (goto-line ln)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 ;; Use delete-region instead of kill-region, to avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 ;; adding junk to the kill-ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (progn (beginning-of-line 2) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (setq forms--total-records (1- forms--total-records))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (if (> forms--current-record forms--total-records)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (setq forms--current-record forms--total-records))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (forms-jump-record forms--current-record)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 (message ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2008 (defun forms-search-forward (regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2009 "Search forward for record containing REGEXP."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (interactive
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2011 (list (read-string (concat "Search forward for"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (if forms--search-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (concat " ("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 forms--search-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 ")"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 ": "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (if (equal "" regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (setq regexp forms--search-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (forms--checkmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (let (the-line the-record here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (fld-sep forms-field-sep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (if (null (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (goto-char here)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2030 (message "\"%s\" not found" regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2031 nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2032 (setq the-record (forms--get-record))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2033 (setq the-line (1+ (count-lines (point-min) (point))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2034 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2035 (setq forms--current-record the-line)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2036 (forms--show-record the-record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2037 (re-search-forward regexp nil t))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2038 (setq forms--search-regexp regexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2039
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2040 (defun forms-search-backward (regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2041 "Search backward for record containing REGEXP."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2042 (interactive
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2043 (list (read-string (concat "Search backward for"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2044 (if forms--search-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2045 (concat " ("
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2046 forms--search-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2047 ")"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2048 ": "))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2049 (if (equal "" regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2050 (setq regexp forms--search-regexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2051 (forms--checkmod)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2052
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2053 (let (the-line the-record here
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2054 (fld-sep forms-field-sep))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2055 (if (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2056 (set-buffer forms--file-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2057 (setq here (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2058 (beginning-of-line)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2059 (if (null (re-search-backward regexp nil t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2060 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2061 (goto-char here)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2062 (message "\"%s\" not found" regexp)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (setq the-record (forms--get-record))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (setq the-line (1+ (count-lines (point-min) (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (setq forms--current-record the-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (forms--show-record the-record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (re-search-forward regexp nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (setq forms--search-regexp regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (defun forms-save-buffer (&optional args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 "Forms mode replacement for save-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 It saves the data buffer instead of the forms buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 Calls `forms-write-file-filter' before writing out the data."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (forms--checkmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (let ((read-file-filter forms-read-file-filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (set-buffer forms--file-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (save-buffer args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (if read-file-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (run-hooks 'read-file-filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (set-buffer-modified-p nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (defun forms--revert-buffer (&optional arg noconfirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 "Reverts current form to un-modified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (if (or noconfirm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (yes-or-no-p "Revert form to unmodified? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (forms-jump-record forms--current-record))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (defun forms-next-field (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 "Jump to ARG-th next field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 there
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2104 (cnt 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2105 (inhibit-point-motion-hooks t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (if (zerop arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (setq cnt 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (setq cnt (+ cnt arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (if (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (while (< i (length forms--markers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (if (or (null (setq there (aref forms--markers i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (<= there here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (if (<= (setq cnt (1- cnt)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (goto-char there)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (throw 'done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (goto-char (aref forms--markers 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 (defun forms-prev-field (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 "Jump to ARG-th previous field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (let ((i (length forms--markers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 there
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2131 (cnt 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2132 (inhibit-point-motion-hooks t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (if (zerop arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (setq cnt 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (setq cnt (+ cnt arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (if (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (while (> i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (setq i ( 1- i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (if (or (null (setq there (aref forms--markers i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (>= there here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (if (<= (setq cnt (1- cnt)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (goto-char there)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (throw 'done t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (goto-char (aref forms--markers (1- (length forms--markers)))))))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2150
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2151 (defun forms-print ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2152 "Send the records to the printer with 'print-buffer', one record per page."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2153 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2154 (let ((inhibit-read-only t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2155 (save-record forms--current-record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2156 (nb-record 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2157 (record nil))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2158 (while (<= nb-record forms--total-records)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2159 (forms-jump-record nb-record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2160 (setq record (buffer-string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2161 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2162 (set-buffer (get-buffer-create "*forms-print*"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2163 (goto-char (buffer-end 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2164 (insert record)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2165 (setq buffer-read-only nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2166 (if (< nb-record forms--total-records)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2167 (insert "\n \n")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2168 (setq nb-record (1+ nb-record)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2169 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2170 (set-buffer "*forms-print*")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2171 (print-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2172 (set-buffer-modified-p nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2173 (kill-buffer (current-buffer)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2174 (forms-jump-record save-record)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2175
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 ;;; Special service
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (defun forms-enumerate (the-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 "Take a quoted list of symbols, and set their values to sequential numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 The first symbol gets number 1, the second 2 and so on.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
2182 It returns the highest number.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 Usage: (setq forms-number-of-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (forms-enumerate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 '(field1 field2 field2 ...)))"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (let ((the-index 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (while the-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (setq the-index (1+ the-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (let ((el (car-safe the-fields)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (setq the-fields (cdr-safe the-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (set el the-index)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 the-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 ;;; Debugging
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (defvar forms--debug nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 "*Enables forms-mode debugging if not nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (defun forms--debug (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 "Internal debugging routine."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (if forms--debug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (let ((ret nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (let ((el (car-safe args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (setq args (cdr-safe args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (if (stringp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (setq ret (concat ret el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (setq ret (concat ret (prin1-to-string el) " = "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (if (boundp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (let ((vel (eval el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (setq ret (concat ret (prin1-to-string vel) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (setq ret (concat ret "<unbound>" "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (if (fboundp el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (setq ret (concat ret (prin1-to-string (symbol-function el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 "\n"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (set-buffer (get-buffer-create "*forms-mode debug*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (if (zerop (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (emacs-lisp-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (insert ret)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 ;;; forms.el ends here.