annotate lisp/utils/forms.el @ 70:131b0175ea99 r20-0b30

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