annotate src/insdel.c @ 407:ed6218a7d4d3

Added tag r21-2-33 for changeset b8cc9ab3f761
author cvs
date Mon, 13 Aug 2007 11:17:10 +0200
parents b8cc9ab3f761
children de805c49cfc1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Buffer insertion/deletion and gap motion for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1991, 1992, 1993, 1994, 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* Synched up with: Mule 2.0, FSF 19.30. Diverges significantly. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* Overhauled by Ben Wing, December 1994, for Mule implementation. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 There are three possible ways to specify positions in a buffer. All
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 of these are one-based: the beginning of the buffer is position or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 index 1, and 0 is not a valid position.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
33
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 As a "buffer position" (typedef Bufpos):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 This is an index specifying an offset in characters from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 beginning of the buffer. Note that buffer positions are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 logically *between* characters, not on a character. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 difference between two buffer positions specifies the number of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 characters between those positions. Buffer positions are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 only kind of position externally visible to the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 As a "byte index" (typedef Bytind):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 This is an index over the bytes used to represent the characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 in the buffer. If there is no Mule support, this is identical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 to a buffer position, because each character is represented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 using one byte. However, with Mule support, many characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 require two or more bytes for their representation, and so a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 byte index may be greater than the corresponding buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 As a "memory index" (typedef Memind):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 This is the byte index adjusted for the gap. For positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 before the gap, this is identical to the byte index. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 positions after the gap, this is the byte index plus the gap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 size. There are two possible memory indices for the gap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 position; the memory index at the beginning of the gap should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 always be used, except in code that deals with manipulating the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 gap, where both indices may be seen. The address of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 character "at" (i.e. following) a particular position can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 obtained from the formula
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 buffer_start_address + memory_index(position) - 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 except in the case of characters at the gap position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Other typedefs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ===============
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 Emchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 -------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 This typedef represents a single Emacs character, which can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ASCII, ISO-8859, or some extended character, as would typically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 be used for Kanji. Note that the representation of a character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 as an Emchar is *not* the same as the representation of that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 same character in a string; thus, you cannot do the standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 C trick of passing a pointer to a character to a function that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 expects a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 An Emchar takes up 19 bits of representation and (for code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 compatibility and such) is compatible with an int. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 representation is visible on the Lisp level. The important
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 characteristics of the Emchar representation are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 -- values 0x00 - 0x7f represent ASCII.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 -- values 0x80 - 0xff represent the right half of ISO-8859-1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 -- values 0x100 and up represent all other characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 This means that Emchar values are upwardly compatible with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 the standard 8-bit representation of ASCII/ISO-8859-1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 Bufbyte:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 --------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 The data in a buffer or string is logically made up of Bufbyte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 objects, where a Bufbyte takes up the same amount of space as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 char. (It is declared differently, though, to catch invalid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 usages.) Strings stored using Bufbytes are said to be in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "internal format". The important characteristics of internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 format are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 -- ASCII characters are represented as a single Bufbyte,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 in the range 0 - 0x7f.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 -- All other characters are represented as a Bufbyte in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 the range 0x80 - 0x9f followed by one or more Bufbytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 in the range 0xa0 to 0xff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 This leads to a number of desirable properties:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 -- Given the position of the beginning of a character,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 you can find the beginning of the next or previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 character in constant time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 -- When searching for a substring or an ASCII character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 within the string, you need merely use standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 searching routines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 array of char:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 --------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Strings that go in or out of Emacs are in "external format",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 typedef'ed as an array of char or a char *. There is more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 than one external format (JIS, EUC, etc.) but they all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 have similar properties. They are modal encodings,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 which is to say that the meaning of particular bytes is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 not fixed but depends on what "mode" the string is currently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 in (e.g. bytes in the range 0 - 0x7f might be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 interpreted as ASCII, or as Hiragana, or as 2-byte Kanji,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 depending on the current mode). The mode starts out in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ASCII/ISO-8859-1 and is switched using escape sequences --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 for example, in the JIS encoding, 'ESC $ B' switches to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 mode where pairs of bytes in the range 0 - 0x7f
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 are interpreted as Kanji characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 External-formatted data is generally desirable for passing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 data between programs because it is upwardly compatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 with standard ASCII/ISO-8859-1 strings and may require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 less space than internal encodings such as the one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 described above. In addition, some encodings (e.g. JIS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 keep all characters (except the ESC used to switch modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 in the printing ASCII range 0x20 - 0x7e, which results in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 a much higher probability that the data will avoid being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 garbled in transmission. Externally-formatted data is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 generally not very convenient to work with, however, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 for this reason is usually converted to internal format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 before any work is done on the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 NOTE: filenames need to be in external format so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ISO-8859-1 characters come out correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 Charcount:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ----------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 This typedef represents a count of characters, such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 a character offset into a string or the number of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 characters between two positions in a buffer. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 difference between two Bufpos's is a Charcount, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 character positions in a string are represented using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 a Charcount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 Bytecount:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ----------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 Similar to a Charcount but represents a count of bytes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 The difference between two Bytind's is a Bytecount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
164
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Usage of the various representations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 =====================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Memory indices are used in low-level functions in insdel.c and for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 extent endpoints and marker positions. The reason for this is that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 this way, the extents and markers don't need to be updated for most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 insertions, which merely shrink the gap and don't move any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 characters around in memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (The beginning-of-gap memory index simplifies insertions w.r.t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 markers, because text usually gets inserted after markers. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 extents, it is merely for consistency, because text can get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 inserted either before or after an extent's endpoint depending on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 the open/closedness of the endpoint.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 Byte indices are used in other code that needs to be fast,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 such as the searching, redisplay, and extent-manipulation code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 Buffer positions are used in all other code. This is because this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 representation is easiest to work with (especially since Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 code always uses buffer positions), necessitates the fewest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 changes to existing code, and is the safest (e.g. if the text gets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 shifted underneath a buffer position, it will still point to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 character; if text is shifted under a byte index, it might point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 to the middle of a character, which would be bad).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Similarly, Charcounts are used in all code that deals with strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 except for code that needs to be fast, which used Bytecounts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Strings are always passed around internally using internal format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Conversions between external format are performed at the time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 that the data goes in or out of Emacs.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
197
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Working with the various representations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ========================================= */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 #include "lisp.h"
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
203 #include <limits.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 #include "redisplay.h"
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 203
diff changeset
212 #include "line-number.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 /* We write things this way because it's very important the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 MAX_BYTIND_GAP_SIZE_3 is a multiple of 3. (As it happens,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 65535 is a multiple of 3, but this may not always be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 case.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 #define MAX_BUFPOS_GAP_SIZE_3 (65535/3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 #define MAX_BYTIND_GAP_SIZE_3 (3 * MAX_BUFPOS_GAP_SIZE_3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 short three_to_one_table[1 + MAX_BYTIND_GAP_SIZE_3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 /* Various macros modelled along the lines of those in buffer.h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 Purposefully omitted from buffer.h because files other than this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 one should not be using them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 /* Address of beginning of buffer. This is an lvalue because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 BUFFER_ALLOC needs it to be. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 #define BUF_BEG_ADDR(buf) ((buf)->text->beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 /* Set the address of beginning of buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 #define SET_BUF_BEG_ADDR(buf, addr) do { (buf)->text->beg = (addr); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 /* Gap size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size + 0)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
237 #define BUF_END_GAP_SIZE(buf) ((buf)->text->end_gap_size + 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 /* Set gap size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 #define SET_BUF_GAP_SIZE(buf, value) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 do { (buf)->text->gap_size = (value); } while (0)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
241 #define SET_BUF_END_GAP_SIZE(buf, value) \
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
242 do { (buf)->text->end_gap_size = (value); } while (0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
244 /* Gap location. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 #define BI_BUF_GPT(buf) ((buf)->text->gpt + 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 #define BUF_GPT_ADDR(buf) (BUF_BEG_ADDR (buf) + BI_BUF_GPT (buf) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 /* Set gap location. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 #define SET_BI_BUF_GPT(buf, value) do { (buf)->text->gpt = (value); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
251 /* Set end of buffer. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 #define SET_BOTH_BUF_Z(buf, val, bival) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (buf)->text->z = (bival); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (buf)->text->bufz = (val); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
259 /* Under Mule, we maintain two sentinels in the buffer: one at the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
260 beginning of the gap, and one at the end of the buffer. This
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
261 allows us to move forward, examining bytes looking for the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
262 end of a character, and not worry about running off the end.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
263 We do not need corresponding sentinels when moving backwards
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
264 because we do not have to look past the beginning of a character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
265 to find the beginning of the character.
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 Every time we change the beginning of the gap, we have to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
268 call SET_GAP_SENTINEL().
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 Every time we change the total size (characters plus gap)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
271 of the buffer, we have to call SET_END_SENTINEL().
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
272 */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
273
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
274
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
275 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
276 # define GAP_CAN_HOLD_SIZE_P(buf, len) (BUF_GAP_SIZE (buf) >= (len) + 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
277 # define SET_GAP_SENTINEL(buf) (*BUF_GPT_ADDR (buf) = 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
278 # define BUF_END_SENTINEL_SIZE 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
279 # define SET_END_SENTINEL(buf) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
280 (*(BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + BI_BUF_Z (buf) - 1) = 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
281 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 # define GAP_CAN_HOLD_SIZE_P(buf, len) (BUF_GAP_SIZE (buf) >= (len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 # define SET_GAP_SENTINEL(buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 # define BUF_END_SENTINEL_SIZE 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 # define SET_END_SENTINEL(buf)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
286 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 /* Charcount/Bytecount conversion */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 /* Optimization. Do it. Live it. Love it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
295 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
296
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
297 /* We include the basic functions here that require no specific
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
298 knowledge of how data is Mule-encoded into a buffer other
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
299 than the basic (00 - 7F), (80 - 9F), (A0 - FF) scheme.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
300 Anything that requires more specific knowledge goes into
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
301 mule-charset.c. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
302
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
303 /* Given a pointer to a text string and a length in bytes, return
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
304 the equivalent length in characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
305
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
306 Charcount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
307 bytecount_to_charcount (const Bufbyte *ptr, Bytecount len)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
308 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
309 Charcount count = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
310 const Bufbyte *end = ptr + len;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
311
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
312 #if SIZEOF_LONG == 8
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
313 # define STRIDE_TYPE long
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
314 # define HIGH_BIT_MASK 0x8080808080808080UL
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
315 #elif SIZEOF_LONG_LONG == 8 && !(defined (i386) || defined (__i386__))
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
316 # define STRIDE_TYPE long long
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
317 # define HIGH_BIT_MASK 0x8080808080808080ULL
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
318 #elif SIZEOF_LONG == 4
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
319 # define STRIDE_TYPE long
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
320 # define HIGH_BIT_MASK 0x80808080UL
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
321 #else
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
322 # error Add support for 128-bit systems here
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
323 #endif
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
324
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
325 #define ALIGN_BITS ((EMACS_UINT) (ALIGNOF (STRIDE_TYPE) - 1))
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
326 #define ALIGN_MASK (~ ALIGN_BITS)
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
327 #define ALIGNED(ptr) ((((EMACS_UINT) ptr) & ALIGN_BITS) == 0)
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
328 #define STRIDE sizeof (STRIDE_TYPE)
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
329
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
330 while (ptr < end)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
331 {
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
332 if (BYTE_ASCII_P (*ptr))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
333 {
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
334 /* optimize for long stretches of ASCII */
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
335 if (! ALIGNED (ptr))
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
336 ptr++, count++;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
337 else
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
338 {
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
339 const unsigned STRIDE_TYPE *ascii_end =
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
340 (const unsigned STRIDE_TYPE *) ptr;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
341 /* This loop screams, because we can typically
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
342 detect ASCII characters 8 at a time. */
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
343 while ((const Bufbyte *) ascii_end + STRIDE <= end
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
344 && !(*ascii_end & HIGH_BIT_MASK))
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
345 ascii_end++;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
346 if ((Bufbyte *) ascii_end == ptr)
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
347 ptr++, count++;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
348 else
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
349 {
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
350 count += (Bufbyte *) ascii_end - ptr;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
351 ptr = (Bufbyte *) ascii_end;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
352 }
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
353 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
354 }
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
355 else
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
356 {
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
357 /* optimize for successive characters from the same charset */
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
358 Bufbyte leading_byte = *ptr;
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
359 size_t bytes = REP_BYTES_BY_FIRST_BYTE (leading_byte);
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
360 while ((ptr < end) && (*ptr == leading_byte))
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
361 ptr += bytes, count++;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
362 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
363 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
364
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
365 #ifdef ERROR_CHECK_BUFPOS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
366 /* Bomb out if the specified substring ends in the middle
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
367 of a character. Note that we might have already gotten
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
368 a core dump above from an invalid reference, but at least
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
369 we will get no farther than here. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
370 assert (ptr == end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
371 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
372
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
373 return count;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
374 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
375
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
376 /* Given a pointer to a text string and a length in characters, return
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
377 the equivalent length in bytes. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
378
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
379 Bytecount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
380 charcount_to_bytecount (const Bufbyte *ptr, Charcount len)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
381 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
382 const Bufbyte *newptr = ptr;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
383
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
384 while (len > 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
385 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
386 INC_CHARPTR (newptr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
387 len--;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
388 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
389 return newptr - ptr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
390 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
391
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
392 /* The next two functions are the actual meat behind the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
393 bufpos-to-bytind and bytind-to-bufpos conversions. Currently
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
394 the method they use is fairly unsophisticated; see buffer.h.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
395
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
396 Note that bufpos_to_bytind_func() is probably the most-called
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
397 function in all of XEmacs. Therefore, it must be FAST FAST FAST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
398 This is the reason why so much of the code is duplicated.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
399
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
400 Similar considerations apply to bytind_to_bufpos_func(), although
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
401 less so because the function is not called so often.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
402
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
403 #### At some point this should use a more sophisticated method;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
404 see buffer.h. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
405
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
406 static int not_very_random_number;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
407
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
408 Bytind
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
409 bufpos_to_bytind_func (struct buffer *buf, Bufpos x)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
410 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
411 Bufpos bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
412 Bufpos bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
413 Bytind bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
414 Bytind bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
415 int size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
416 int forward_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
417 Bytind retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
418 int diff_so_far;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
419 int add_to_cache = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
420
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
421 /* Check for some cached positions, for speed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
422 if (x == BUF_PT (buf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
423 return BI_BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
424 if (x == BUF_ZV (buf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
425 return BI_BUF_ZV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
426 if (x == BUF_BEGV (buf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
427 return BI_BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
428
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
429 bufmin = buf->text->mule_bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
430 bufmax = buf->text->mule_bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
431 bytmin = buf->text->mule_bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
432 bytmax = buf->text->mule_bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
433 size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
434
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
435 /* The basic idea here is that we shift the "known region" up or down
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
436 until it overlaps the specified position. We do this by moving
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
437 the upper bound of the known region up one character at a time,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
438 and moving the lower bound of the known region up as necessary
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
439 when the size of the character just seen changes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
440
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
441 We optimize this, however, by first shifting the known region to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
442 one of the cached points if it's close by. (We don't check BEG or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
443 Z, even though they're cached; most of the time these will be the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
444 same as BEGV and ZV, and when they're not, they're not likely
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
445 to be used.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
446
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
447 if (x > bufmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
448 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
449 Bufpos diffmax = x - bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
450 Bufpos diffpt = x - BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
451 Bufpos diffzv = BUF_ZV (buf) - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
452 /* #### This value could stand some more exploration. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
453 Charcount heuristic_hack = (bufmax - bufmin) >> 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
454
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
455 /* Check if the position is closer to PT or ZV than to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
456 end of the known region. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
457
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
458 if (diffpt < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
459 diffpt = -diffpt;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
460 if (diffzv < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
461 diffzv = -diffzv;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
462
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
463 /* But also implement a heuristic that favors the known region
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
464 over PT or ZV. The reason for this is that switching to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
465 PT or ZV will wipe out the knowledge in the known region,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
466 which might be annoying if the known region is large and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
467 PT or ZV is not that much closer than the end of the known
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
468 region. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
469
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
470 diffzv += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
471 diffpt += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
472 if (diffpt < diffmax && diffpt <= diffzv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
473 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
474 bufmax = bufmin = BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
475 bytmax = bytmin = BI_BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
476 /* We set the size to 1 even though it doesn't really
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
477 matter because the new known region contains no
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
478 characters. We do this because this is the most
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
479 likely size of the characters around the new known
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
480 region, and we avoid potential yuckiness that is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
481 done when size == 3. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
482 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
483 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
484 if (diffzv < diffmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
485 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
486 bufmax = bufmin = BUF_ZV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
487 bytmax = bytmin = BI_BUF_ZV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
488 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
489 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
490 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
491 #ifdef ERROR_CHECK_BUFPOS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
492 else if (x >= bufmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
493 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
494 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
495 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
496 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
497 Bufpos diffmin = bufmin - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
498 Bufpos diffpt = BUF_PT (buf) - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
499 Bufpos diffbegv = x - BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
500 /* #### This value could stand some more exploration. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
501 Charcount heuristic_hack = (bufmax - bufmin) >> 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
502
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
503 if (diffpt < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
504 diffpt = -diffpt;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
505 if (diffbegv < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
506 diffbegv = -diffbegv;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
507
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
508 /* But also implement a heuristic that favors the known region --
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
509 see above. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
510
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
511 diffbegv += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
512 diffpt += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
513
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
514 if (diffpt < diffmin && diffpt <= diffbegv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
515 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
516 bufmax = bufmin = BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
517 bytmax = bytmin = BI_BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
518 /* We set the size to 1 even though it doesn't really
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
519 matter because the new known region contains no
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
520 characters. We do this because this is the most
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
521 likely size of the characters around the new known
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
522 region, and we avoid potential yuckiness that is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
523 done when size == 3. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
524 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
525 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
526 if (diffbegv < diffmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
527 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
528 bufmax = bufmin = BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
529 bytmax = bytmin = BI_BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
530 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
531 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
532 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
533
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
534 diff_so_far = x > bufmax ? x - bufmax : bufmin - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
535 if (diff_so_far > 50)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
536 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
537 /* If we have to move more than a certain amount, then look
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
538 into our cache. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
539 int minval = INT_MAX;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
540 int found = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
541 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
542
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
543 add_to_cache = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
544 /* I considered keeping the positions ordered. This would speed
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
545 up this loop, but updating the cache would take longer, so
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
546 it doesn't seem like it would really matter. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
547 for (i = 0; i < 16; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
548 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
549 int diff = buf->text->mule_bufpos_cache[i] - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
550
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
551 if (diff < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
552 diff = -diff;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
553 if (diff < minval)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
554 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
555 minval = diff;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
556 found = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
557 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
558 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
559
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
560 if (minval < diff_so_far)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
561 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
562 bufmax = bufmin = buf->text->mule_bufpos_cache[found];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
563 bytmax = bytmin = buf->text->mule_bytind_cache[found];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
564 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
565 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
566 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
567
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
568 /* It's conceivable that the caching above could lead to X being
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
569 the same as one of the range edges. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
570 if (x >= bufmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
571 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
572 Bytind newmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
573 Bytecount newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
574
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
575 forward_p = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
576 while (x > bufmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
577 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
578 newmax = bytmax;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
579
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
580 INC_BYTIND (buf, newmax);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
581 newsize = newmax - bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
582 if (newsize != size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
583 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
584 bufmin = bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
585 bytmin = bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
586 size = newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
587 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
588 bytmax = newmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
589 bufmax++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
590 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
591 retval = bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
592
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
593 /* #### Should go past the found location to reduce the number
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
594 of times that this function is called */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
595 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
596 else /* x < bufmin */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
597 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
598 Bytind newmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
599 Bytecount newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
600
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
601 forward_p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
602 while (x < bufmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
603 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
604 newmin = bytmin;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
605
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
606 DEC_BYTIND (buf, newmin);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
607 newsize = bytmin - newmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
608 if (newsize != size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
609 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
610 bufmax = bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
611 bytmax = bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
612 size = newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
613 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
614 bytmin = newmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
615 bufmin--;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
616 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
617 retval = bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
618
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
619 /* #### Should go past the found location to reduce the number
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
620 of times that this function is called
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
621 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
622 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
623
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
624 /* If size is three, than we have to max sure that the range we
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
625 discovered isn't too large, because we use a fixed-length
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
626 table to divide by 3. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
627
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
628 if (size == 3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
629 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
630 int gap = bytmax - bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
631 buf->text->mule_three_p = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
632 buf->text->mule_shifter = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
633
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
634 if (gap > MAX_BYTIND_GAP_SIZE_3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
635 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
636 if (forward_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
637 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
638 bytmin = bytmax - MAX_BYTIND_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
639 bufmin = bufmax - MAX_BUFPOS_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
640 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
641 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
642 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
643 bytmax = bytmin + MAX_BYTIND_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
644 bufmax = bufmin + MAX_BUFPOS_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
645 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
646 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
647 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
648 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
649 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
650 buf->text->mule_three_p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
651 if (size == 4)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
652 buf->text->mule_shifter = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
653 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
654 buf->text->mule_shifter = size - 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
655 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
656
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
657 buf->text->mule_bufmin = bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
658 buf->text->mule_bufmax = bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
659 buf->text->mule_bytmin = bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
660 buf->text->mule_bytmax = bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
661
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
662 if (add_to_cache)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
663 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
664 int replace_loc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
665
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
666 /* We throw away a "random" cached value and replace it with
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
667 the new value. It doesn't actually have to be very random
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
668 at all, just evenly distributed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
669
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
670 #### It would be better to use a least-recently-used algorithm
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
671 or something that tries to space things out, but I'm not sure
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
672 it's worth it to go to the trouble of maintaining that. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
673 not_very_random_number += 621;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
674 replace_loc = not_very_random_number & 15;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
675 buf->text->mule_bufpos_cache[replace_loc] = x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
676 buf->text->mule_bytind_cache[replace_loc] = retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
677 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
678
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
679 return retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
680 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
681
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
682 /* The logic in this function is almost identical to the logic in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
683 the previous function. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
684
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
685 Bufpos
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
686 bytind_to_bufpos_func (struct buffer *buf, Bytind x)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
687 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
688 Bufpos bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
689 Bufpos bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
690 Bytind bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
691 Bytind bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
692 int size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
693 int forward_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
694 Bufpos retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
695 int diff_so_far;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
696 int add_to_cache = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
697
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
698 /* Check for some cached positions, for speed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
699 if (x == BI_BUF_PT (buf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
700 return BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
701 if (x == BI_BUF_ZV (buf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
702 return BUF_ZV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
703 if (x == BI_BUF_BEGV (buf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
704 return BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
705
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
706 bufmin = buf->text->mule_bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
707 bufmax = buf->text->mule_bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
708 bytmin = buf->text->mule_bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
709 bytmax = buf->text->mule_bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
710 size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
711
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
712 /* The basic idea here is that we shift the "known region" up or down
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
713 until it overlaps the specified position. We do this by moving
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
714 the upper bound of the known region up one character at a time,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
715 and moving the lower bound of the known region up as necessary
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
716 when the size of the character just seen changes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
717
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
718 We optimize this, however, by first shifting the known region to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
719 one of the cached points if it's close by. (We don't check BI_BEG or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
720 BI_Z, even though they're cached; most of the time these will be the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
721 same as BI_BEGV and BI_ZV, and when they're not, they're not likely
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
722 to be used.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
723
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
724 if (x > bytmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
725 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
726 Bytind diffmax = x - bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
727 Bytind diffpt = x - BI_BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
728 Bytind diffzv = BI_BUF_ZV (buf) - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
729 /* #### This value could stand some more exploration. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
730 Bytecount heuristic_hack = (bytmax - bytmin) >> 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
731
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
732 /* Check if the position is closer to PT or ZV than to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
733 end of the known region. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
734
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
735 if (diffpt < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
736 diffpt = -diffpt;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
737 if (diffzv < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
738 diffzv = -diffzv;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
739
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
740 /* But also implement a heuristic that favors the known region
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
741 over BI_PT or BI_ZV. The reason for this is that switching to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
742 BI_PT or BI_ZV will wipe out the knowledge in the known region,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
743 which might be annoying if the known region is large and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
744 BI_PT or BI_ZV is not that much closer than the end of the known
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
745 region. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
746
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
747 diffzv += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
748 diffpt += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
749 if (diffpt < diffmax && diffpt <= diffzv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
750 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
751 bufmax = bufmin = BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
752 bytmax = bytmin = BI_BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
753 /* We set the size to 1 even though it doesn't really
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
754 matter because the new known region contains no
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
755 characters. We do this because this is the most
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
756 likely size of the characters around the new known
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
757 region, and we avoid potential yuckiness that is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
758 done when size == 3. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
759 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
760 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
761 if (diffzv < diffmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
762 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
763 bufmax = bufmin = BUF_ZV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
764 bytmax = bytmin = BI_BUF_ZV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
765 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
766 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
767 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
768 #ifdef ERROR_CHECK_BUFPOS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
769 else if (x >= bytmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
770 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
771 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
772 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
773 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
774 Bytind diffmin = bytmin - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
775 Bytind diffpt = BI_BUF_PT (buf) - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
776 Bytind diffbegv = x - BI_BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
777 /* #### This value could stand some more exploration. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
778 Bytecount heuristic_hack = (bytmax - bytmin) >> 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
779
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
780 if (diffpt < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
781 diffpt = -diffpt;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
782 if (diffbegv < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
783 diffbegv = -diffbegv;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
784
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
785 /* But also implement a heuristic that favors the known region --
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
786 see above. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
787
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
788 diffbegv += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
789 diffpt += heuristic_hack;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
790
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
791 if (diffpt < diffmin && diffpt <= diffbegv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
792 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
793 bufmax = bufmin = BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
794 bytmax = bytmin = BI_BUF_PT (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
795 /* We set the size to 1 even though it doesn't really
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
796 matter because the new known region contains no
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
797 characters. We do this because this is the most
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
798 likely size of the characters around the new known
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
799 region, and we avoid potential yuckiness that is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
800 done when size == 3. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
801 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
802 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
803 if (diffbegv < diffmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
804 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
805 bufmax = bufmin = BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
806 bytmax = bytmin = BI_BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
807 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
808 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
809 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
810
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
811 diff_so_far = x > bytmax ? x - bytmax : bytmin - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
812 if (diff_so_far > 50)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
813 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
814 /* If we have to move more than a certain amount, then look
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
815 into our cache. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
816 int minval = INT_MAX;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
817 int found = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
818 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
819
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
820 add_to_cache = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
821 /* I considered keeping the positions ordered. This would speed
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
822 up this loop, but updating the cache would take longer, so
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
823 it doesn't seem like it would really matter. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
824 for (i = 0; i < 16; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
825 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
826 int diff = buf->text->mule_bytind_cache[i] - x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
827
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
828 if (diff < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
829 diff = -diff;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
830 if (diff < minval)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
831 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
832 minval = diff;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
833 found = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
834 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
835 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
836
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
837 if (minval < diff_so_far)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
838 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
839 bufmax = bufmin = buf->text->mule_bufpos_cache[found];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
840 bytmax = bytmin = buf->text->mule_bytind_cache[found];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
841 size = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
842 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
843 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
844
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
845 /* It's conceivable that the caching above could lead to X being
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
846 the same as one of the range edges. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
847 if (x >= bytmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
848 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
849 Bytind newmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
850 Bytecount newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
851
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
852 forward_p = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
853 while (x > bytmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
854 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
855 newmax = bytmax;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
856
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
857 INC_BYTIND (buf, newmax);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
858 newsize = newmax - bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
859 if (newsize != size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
860 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
861 bufmin = bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
862 bytmin = bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
863 size = newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
864 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
865 bytmax = newmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
866 bufmax++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
867 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
868 retval = bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
869
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
870 /* #### Should go past the found location to reduce the number
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
871 of times that this function is called */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
872 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
873 else /* x <= bytmin */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
874 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
875 Bytind newmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
876 Bytecount newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
877
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
878 forward_p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
879 while (x < bytmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
880 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
881 newmin = bytmin;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
882
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
883 DEC_BYTIND (buf, newmin);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
884 newsize = bytmin - newmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
885 if (newsize != size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
886 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
887 bufmax = bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
888 bytmax = bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
889 size = newsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
890 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
891 bytmin = newmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
892 bufmin--;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
893 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
894 retval = bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
895
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
896 /* #### Should go past the found location to reduce the number
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
897 of times that this function is called
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
898 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
899 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
900
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
901 /* If size is three, than we have to max sure that the range we
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
902 discovered isn't too large, because we use a fixed-length
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
903 table to divide by 3. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
904
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
905 if (size == 3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
906 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
907 int gap = bytmax - bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
908 buf->text->mule_three_p = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
909 buf->text->mule_shifter = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
910
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
911 if (gap > MAX_BYTIND_GAP_SIZE_3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
912 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
913 if (forward_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
914 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
915 bytmin = bytmax - MAX_BYTIND_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
916 bufmin = bufmax - MAX_BUFPOS_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
917 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
918 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
919 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
920 bytmax = bytmin + MAX_BYTIND_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
921 bufmax = bufmin + MAX_BUFPOS_GAP_SIZE_3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
922 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
923 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
924 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
925 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
926 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
927 buf->text->mule_three_p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
928 if (size == 4)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
929 buf->text->mule_shifter = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
930 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
931 buf->text->mule_shifter = size - 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
932 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
933
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
934 buf->text->mule_bufmin = bufmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
935 buf->text->mule_bufmax = bufmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
936 buf->text->mule_bytmin = bytmin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
937 buf->text->mule_bytmax = bytmax;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
938
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
939 if (add_to_cache)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
940 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
941 int replace_loc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
942
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
943 /* We throw away a "random" cached value and replace it with
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
944 the new value. It doesn't actually have to be very random
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
945 at all, just evenly distributed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
946
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
947 #### It would be better to use a least-recently-used algorithm
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
948 or something that tries to space things out, but I'm not sure
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
949 it's worth it to go to the trouble of maintaining that. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
950 not_very_random_number += 621;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
951 replace_loc = not_very_random_number & 15;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
952 buf->text->mule_bufpos_cache[replace_loc] = retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
953 buf->text->mule_bytind_cache[replace_loc] = x;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
954 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
955
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
956 return retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
957 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
958
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
959 /* Text of length BYTELENGTH and CHARLENGTH (in different units)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
960 was inserted at bufpos START. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
961
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
962 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
963 buffer_mule_signal_inserted_region (struct buffer *buf, Bufpos start,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
964 Bytecount bytelength,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
965 Charcount charlength)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
966 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
967 int size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
968 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
969
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
970 /* Adjust the cache of known positions. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
971 for (i = 0; i < 16; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
972 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
973
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
974 if (buf->text->mule_bufpos_cache[i] > start)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
975 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
976 buf->text->mule_bufpos_cache[i] += charlength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
977 buf->text->mule_bytind_cache[i] += bytelength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
978 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
979 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
980
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
981 if (start >= buf->text->mule_bufmax)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
982 return;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
983
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
984 /* The insertion is either before the known region, in which case
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
985 it shoves it forward; or within the known region, in which case
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
986 it shoves the end forward. (But it may make the known region
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
987 inconsistent, so we may have to shorten it.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
988
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
989 if (start <= buf->text->mule_bufmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
990 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
991 buf->text->mule_bufmin += charlength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
992 buf->text->mule_bufmax += charlength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
993 buf->text->mule_bytmin += bytelength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
994 buf->text->mule_bytmax += bytelength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
995 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
996 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
997 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
998 Bufpos end = start + charlength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
999 /* the insertion point divides the known region in two.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1000 Keep the longer half, at least, and expand into the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1001 inserted chunk as much as possible. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1002
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1003 if (start - buf->text->mule_bufmin > buf->text->mule_bufmax - start)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1004 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1005 Bytind bytestart = (buf->text->mule_bytmin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1006 + size * (start - buf->text->mule_bufmin));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1007 Bytind bytenew;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1008
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1009 while (start < end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1010 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1011 bytenew = bytestart;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1012 INC_BYTIND (buf, bytenew);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1013 if (bytenew - bytestart != size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1014 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1015 start++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1016 bytestart = bytenew;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1017 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1018 if (start != end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1019 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1020 buf->text->mule_bufmax = start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1021 buf->text->mule_bytmax = bytestart;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1022 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1023 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1024 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1025 buf->text->mule_bufmax += charlength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1026 buf->text->mule_bytmax += bytelength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1027 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1028 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1029 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1030 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1031 Bytind byteend = (buf->text->mule_bytmin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1032 + size * (start - buf->text->mule_bufmin)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1033 + bytelength);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1034 Bytind bytenew;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1035
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1036 buf->text->mule_bufmax += charlength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1037 buf->text->mule_bytmax += bytelength;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1038
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1039 while (end > start)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1040 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1041 bytenew = byteend;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1042 DEC_BYTIND (buf, bytenew);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1043 if (byteend - bytenew != size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1044 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1045 end--;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1046 byteend = bytenew;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1047 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1048 if (start != end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1049 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1050 buf->text->mule_bufmin = end;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1051 buf->text->mule_bytmin = byteend;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1052 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1053 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1054 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1055 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1056
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1057 /* Text from START to END (equivalent in Bytinds: from BI_START to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1058 BI_END) was deleted. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1059
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1060 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1061 buffer_mule_signal_deleted_region (struct buffer *buf, Bufpos start,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1062 Bufpos end, Bytind bi_start,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1063 Bytind bi_end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1064 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1065 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1066
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1067 /* Adjust the cache of known positions. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1068 for (i = 0; i < 16; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1069 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1070 /* After the end; gets shoved backward */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1071 if (buf->text->mule_bufpos_cache[i] > end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1072 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1073 buf->text->mule_bufpos_cache[i] -= end - start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1074 buf->text->mule_bytind_cache[i] -= bi_end - bi_start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1075 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1076 /* In the range; moves to start of range */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1077 else if (buf->text->mule_bufpos_cache[i] > start)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1078 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1079 buf->text->mule_bufpos_cache[i] = start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1080 buf->text->mule_bytind_cache[i] = bi_start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1081 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1082 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1083
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1084 /* We don't care about any text after the end of the known region. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1085
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1086 end = min (end, buf->text->mule_bufmax);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1087 bi_end = min (bi_end, buf->text->mule_bytmax);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1088 if (start >= end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1089 return;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1090
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1091 /* The end of the known region offsets by the total amount of deletion,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1092 since it's all before it. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1093
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1094 buf->text->mule_bufmax -= end - start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1095 buf->text->mule_bytmax -= bi_end - bi_start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1096
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1097 /* Now we don't care about any text after the start of the known region. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1098
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1099 end = min (end, buf->text->mule_bufmin);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1100 bi_end = min (bi_end, buf->text->mule_bytmin);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1101 if (start >= end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1102 return;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1103
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1104 buf->text->mule_bufmin -= end - start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1105 buf->text->mule_bytmin -= bi_end - bi_start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1106 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1107
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1108 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1109
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 #ifdef ERROR_CHECK_BUFPOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 bufpos_to_bytind (struct buffer *buf, Bufpos x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 Bytind retval = real_bufpos_to_bytind (buf, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ASSERT_VALID_BYTIND_UNSAFE (buf, retval);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 return retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 bytind_to_bufpos (struct buffer *buf, Bytind x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ASSERT_VALID_BYTIND_UNSAFE (buf, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 return real_bytind_to_bufpos (buf, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 #endif /* ERROR_CHECK_BUFPOS */
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 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 /* verifying buffer and string positions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 /* Functions below are tagged with either _byte or _char indicating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 whether they return byte or character positions. For a buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 a character position is a "Bufpos" and a byte position is a "Bytind".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 For strings, these are sometimes typed using "Charcount" and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 "Bytecount". */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 /* Flags for the functions below are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 GB_ALLOW_PAST_ACCESSIBLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1144 Allow positions to range over the entire buffer (BUF_BEG to BUF_Z),
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1145 rather than just the accessible portion (BUF_BEGV to BUF_ZV).
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1146 For strings, this flag has no effect.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 GB_COERCE_RANGE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1150 If the position is outside the allowable range, return the lower
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1151 or upper bound of the range, whichever is closer to the specified
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1152 position.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 GB_NO_ERROR_IF_BAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 If the position is outside the allowable range, return -1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 GB_NEGATIVE_FROM_END
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 If a value is negative, treat it as an offset from the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 Only applies to strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 The following additional flags apply only to the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 that return ranges:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 GB_ALLOW_NIL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 Either or both positions can be nil. If FROM is nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 FROM_OUT will contain the lower bound of the allowed range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 If TO is nil, TO_OUT will contain the upper bound of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 allowed range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 GB_CHECK_ORDER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 FROM must contain the lower bound and TO the upper bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 of the range. If the positions are reversed, an error is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 signalled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 The following is a combination flag:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 GB_HISTORICAL_STRING_BEHAVIOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 Equivalent to (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 /* Return a buffer position stored in a Lisp_Object. Full
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 error-checking is done on the position. Flags can be specified to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 control the behavior of out-of-range values. The default behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 is to require that the position is within the accessible part of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 the buffer (BEGV and ZV), and to signal an error if the position is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 out of range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 get_buffer_pos_char (struct buffer *b, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 Bufpos ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 Bufpos min_allowed, max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 CHECK_INT_COERCE_MARKER (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ind = XINT (pos);
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1203 min_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_BEG (b) : BUF_BEGV (b);
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 120
diff changeset
1204 max_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_Z (b) : BUF_ZV (b);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1205
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 if (ind < min_allowed || ind > max_allowed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 if (flags & GB_COERCE_RANGE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ind = ind < min_allowed ? min_allowed : max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 else if (flags & GB_NO_ERROR_IF_BAD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ind = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 XSETBUFFER (buffer, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 args_out_of_range (buffer, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 return ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 get_buffer_pos_byte (struct buffer *b, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 Bufpos bpos = get_buffer_pos_char (b, pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 if (bpos < 0) /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 return bufpos_to_bytind (b, bpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 /* Return a pair of buffer positions representing a range of text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 taken from a pair of Lisp_Objects. Full error-checking is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 done on the positions. Flags can be specified to control the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 behavior of out-of-range values. The default behavior is to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 allow the range bounds to be specified in either order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (however, FROM_OUT will always be the lower bound of the range
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 and TO_OUT the upper bound),to require that the positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 are within the accessible part of the buffer (BEGV and ZV),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 and to signal an error if the positions are out of range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 Bufpos *from_out, Bufpos *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 Bufpos min_allowed, max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 min_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 BUF_BEG (b) : BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 max_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 BUF_Z (b) : BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 if (NILP (from) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 *from_out = min_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 *from_out = get_buffer_pos_char (b, from, flags | GB_NO_ERROR_IF_BAD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 if (NILP (to) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 *to_out = max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 *to_out = get_buffer_pos_char (b, to, flags | GB_NO_ERROR_IF_BAD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 if ((*from_out < 0 || *to_out < 0) && !(flags & GB_NO_ERROR_IF_BAD))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 XSETBUFFER (buffer, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 args_out_of_range_3 (buffer, from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 if (*from_out >= 0 && *to_out >= 0 && *from_out > *to_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 if (flags & GB_CHECK_ORDER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 signal_simple_error_2 ("start greater than end", from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1277 Bufpos temp = *from_out;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 *from_out = *to_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 *to_out = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 Bytind *from_out, Bytind *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 Bufpos s, e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 get_buffer_range_char (b, from, to, &s, &e, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 if (s >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 *from_out = bufpos_to_bytind (b, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 else /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 *from_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 if (e >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 *to_out = bufpos_to_bytind (b, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 *to_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 static Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 get_string_pos_char_1 (Lisp_Object string, Lisp_Object pos, unsigned int flags,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 Charcount known_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 Charcount ccpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 Charcount min_allowed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 Charcount max_allowed = known_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 /* Computation of KNOWN_LENGTH is potentially expensive so we pass
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 it in. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 CHECK_INT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 ccpos = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 if (ccpos < 0 && flags & GB_NEGATIVE_FROM_END)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 ccpos += max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 if (ccpos < min_allowed || ccpos > max_allowed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 if (flags & GB_COERCE_RANGE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 ccpos = ccpos < min_allowed ? min_allowed : max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 else if (flags & GB_NO_ERROR_IF_BAD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 ccpos = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 args_out_of_range (string, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 return ccpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 get_string_pos_char (Lisp_Object string, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 return get_string_pos_char_1 (string, pos, flags,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1333 XSTRING_CHAR_LENGTH (string));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 get_string_pos_byte (Lisp_Object string, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 Charcount ccpos = get_string_pos_char (string, pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 if (ccpos < 0) /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 return -1;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1342 return charcount_to_bytecount (XSTRING_DATA (string), ccpos);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 get_string_range_char (Lisp_Object string, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 Charcount *from_out, Charcount *to_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 Charcount min_allowed = 0;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1351 Charcount max_allowed = XSTRING_CHAR_LENGTH (string);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 if (NILP (from) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 *from_out = min_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 *from_out = get_string_pos_char_1 (string, from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 flags | GB_NO_ERROR_IF_BAD,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 max_allowed);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 if (NILP (to) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 *to_out = max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 *to_out = get_string_pos_char_1 (string, to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 flags | GB_NO_ERROR_IF_BAD,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 max_allowed);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 if ((*from_out < 0 || *to_out < 0) && !(flags & GB_NO_ERROR_IF_BAD))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 args_out_of_range_3 (string, from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 if (*from_out >= 0 && *to_out >= 0 && *from_out > *to_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 if (flags & GB_CHECK_ORDER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 signal_simple_error_2 ("start greater than end", from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1376 Bufpos temp = *from_out;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 *from_out = *to_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 *to_out = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 get_string_range_byte (Lisp_Object string, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 Bytecount *from_out, Bytecount *to_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 Charcount s, e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 get_string_range_char (string, from, to, &s, &e, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 if (s >= 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1392 *from_out = charcount_to_bytecount (XSTRING_DATA (string), s);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 else /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 *from_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 if (e >= 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1396 *to_out = charcount_to_bytecount (XSTRING_DATA (string), e);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 *to_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1406 return STRINGP (object) ?
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1407 get_string_pos_char (object, pos, flags) :
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1408 get_buffer_pos_char (XBUFFER (object), pos, flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1415 return STRINGP (object) ?
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1416 get_string_pos_byte (object, pos, flags) :
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1417 get_buffer_pos_byte (XBUFFER (object), pos, flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 Lisp_Object to, Bufpos *from_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 Bufpos *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 get_string_range_char (object, from, to, from_out, to_out, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 else
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1428 get_buffer_range_char (XBUFFER (object), from, to, from_out, to_out, flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 Lisp_Object to, Bytind *from_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 Bytind *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 get_string_range_byte (object, from, to, from_out, to_out, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 else
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1439 get_buffer_range_byte (XBUFFER (object), from, to, from_out, to_out, flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 buffer_or_string_accessible_begin_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1445 return STRINGP (object) ? 0 : BUF_BEGV (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 buffer_or_string_accessible_end_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1451 return STRINGP (object) ?
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1452 XSTRING_CHAR_LENGTH (object) : BUF_ZV (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 buffer_or_string_accessible_begin_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1458 return STRINGP (object) ? 0 : BI_BUF_BEGV (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 buffer_or_string_accessible_end_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1464 return STRINGP (object) ?
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1465 XSTRING_LENGTH (object) : BI_BUF_ZV (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 buffer_or_string_absolute_begin_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1471 return STRINGP (object) ? 0 : BUF_BEG (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 buffer_or_string_absolute_end_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1477 return STRINGP (object) ?
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1478 XSTRING_CHAR_LENGTH (object) : BUF_Z (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 buffer_or_string_absolute_begin_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1484 return STRINGP (object) ? 0 : BI_BUF_BEG (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 buffer_or_string_absolute_end_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1490 return STRINGP (object) ?
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 151
diff changeset
1491 XSTRING_LENGTH (object) : BI_BUF_Z (XBUFFER (object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 /* point and marker adjustment */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 /* just_set_point() is the only place `PT' is an lvalue in all of emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 This function is called from set_buffer_point(), which is the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 that the SET_PT and BUF_SET_PT macros expand into, and from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 routines below that insert and delete text. (This is in cases where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 the point marker logically doesn't move but PT (being a byte index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 needs to get adjusted.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 /* Set point to a specified value. This is used only when the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 of point changes due to an insert or delete; it does not represent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 a conceptual change in point as a marker. In particular, point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 not crossing any interval boundaries, so there's no need to use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 usual SET_PT macro. In fact it would be incorrect to do so, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 either the old or the new value of point is out of synch with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 current set of intervals. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 /* This gets called more than enough to make the function call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 overhead a significant factor so we've turned it into a macro. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 #define JUST_SET_POINT(buf, bufpos, ind) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 buf->bufpt = (bufpos); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 buf->pt = (ind); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 /* Set a buffer's point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 set_buffer_point (struct buffer *buf, Bufpos bufpos, Bytind bytpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 assert (bytpos >= BI_BUF_BEGV (buf) && bytpos <= BI_BUF_ZV (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 if (bytpos == BI_BUF_PT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 JUST_SET_POINT (buf, bufpos, bytpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 MARK_POINT_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 assert (MARKERP (buf->point_marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 XMARKER (buf->point_marker)->memind =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 bytind_to_memind (buf, bytpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 /* FSF makes sure that PT is not being set within invisible text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 However, this is the wrong place for that check. The check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 should happen only at the next redisplay. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 /* Some old coder said:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 "If there were to be hooks which were run when point entered/left an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 extent, this would be the place to put them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 However, it's probably the case that such hooks should be implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 using a post-command-hook instead, to avoid running the hooks as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 result of intermediate motion inside of save-excursions, for example."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 I definitely agree with this. PT gets moved all over the place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 and it would be a Bad Thing for any hooks to get called, both for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 the reason above and because many callers are not prepared for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 a GC within this function. --ben
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 /* Do the correct marker-like adjustment on MPOS (see below). FROM, TO,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 and AMOUNT are as in adjust_markers(). If MPOS doesn't need to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 adjusted, nothing will happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 Memind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 do_marker_adjustment (Memind mpos, Memind from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 Memind to, Bytecount amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 if (amount > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 if (mpos > to && mpos < to + amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 mpos = to + amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 if (mpos > from + amount && mpos <= from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 mpos = from + amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 if (mpos > from && mpos <= to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 mpos += amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 return mpos;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1577 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 /* Do the following:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (1) Add `amount' to the position of every marker in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 whose current position is between `from' (exclusive) and `to' (inclusive).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (2) Also, any markers past the outside of that interval, in the direction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 of adjustment, are first moved back to the near end of the interval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 and then adjusted by `amount'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 This function is called in two different cases: when a region of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 characters adjacent to the gap is moved, causing the gap to shift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 to the other side of the region (in this case, `from' and `to'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 point to the old position of the region and there should be no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 markers affected by (2) because they would be inside the gap),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 or when a region of characters adjacent to the gap is wiped out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 causing the gap to increase to include the region (in this case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 `from' and `to' are the same, both pointing to the boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 between the gap and the deleted region, and there are no markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 affected by (1)).
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1598
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 The reason for the use of exclusive and inclusive is that markers at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 the gap always sit at the beginning, not at the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 adjust_markers (struct buffer *buf, Memind from, Memind to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 Bytecount amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1607 Lisp_Marker *m;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 for (m = BUF_MARKERS (buf); m; m = marker_next (m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 m->memind = do_marker_adjustment (m->memind, from, to, amount);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 /* Adjust markers whose insertion-type is t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 for an insertion of AMOUNT characters at POS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1619 Lisp_Marker *m;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 for (m = BUF_MARKERS (buf); m; m = marker_next (m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 if (m->insertion_type && m->memind == ind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 m->memind += amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 /* Routines for dealing with the gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 /* maximum amount of memory moved in a single chunk. Increasing this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 value improves gap-motion efficiency but decreases QUIT responsiveness
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 time. Was 32000 but today's processors are faster and files are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 bigger. --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 #define GAP_MOVE_CHUNK 300000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 /* Move the gap to POS, which is less than the current GPT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 gap_left (struct buffer *buf, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 Bufbyte *to, *from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 Bytind new_s1;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1647 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1648 Lisp_Object bufcons;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 from = BUF_GPT_ADDR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 to = from + BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 new_s1 = BI_BUF_GPT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 /* Now copy the characters. To move the gap down,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 copy characters up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 /* I gets number of characters left to copy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 i = new_s1 - pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 if (i == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 /* If a quit is requested, stop copying now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 Change POS to be where we have actually moved the gap to. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 pos = new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 if (i > GAP_MOVE_CHUNK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 i = GAP_MOVE_CHUNK;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1673
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1674 if (i >= 128)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 new_s1 -= i;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1677 from -= i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1678 to -= i;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 memmove (to, from, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 new_s1 -= i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 while (--i >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 *--to = *--from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 /* Adjust markers, and buffer data structure, to put the gap at POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 POS is where the loop above stopped, which may be what was specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 or may be where a quit was detected. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1692 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1693 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1694 adjust_markers (mbuf, pos, BI_BUF_GPT (mbuf), BUF_GAP_SIZE (mbuf));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1695 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1696 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1697 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1698 adjust_extents (make_buffer (mbuf), pos, BI_BUF_GPT (mbuf),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1699 BUF_GAP_SIZE (mbuf));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1700 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 SET_BI_BUF_GPT (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 #ifdef ERROR_CHECK_EXTENTS
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1704 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1705 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1706 sledgehammer_extent_check (make_buffer (mbuf));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1707 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 gap_right (struct buffer *buf, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 Bufbyte *to, *from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 Bytind new_s1;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1718 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1719 Lisp_Object bufcons;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 to = BUF_GPT_ADDR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 from = to + BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 new_s1 = BI_BUF_GPT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 /* Now copy the characters. To move the gap up,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 copy characters down. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 /* I gets number of characters left to copy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 i = pos - new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 if (i == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 /* If a quit is requested, stop copying now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 Change POS to be where we have actually moved the gap to. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 pos = new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 if (i > GAP_MOVE_CHUNK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 i = GAP_MOVE_CHUNK;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1744
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1745 if (i >= 128)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 new_s1 += i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 memmove (to, from, i);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1749 from += i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
1750 to += i;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 new_s1 += i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 while (--i >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 *to++ = *from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 int gsize = BUF_GAP_SIZE (buf);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1762 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1763 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1764 adjust_markers (mbuf, BI_BUF_GPT (mbuf) + gsize, pos + gsize, - gsize);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1765 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1766 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1767 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1768 adjust_extents (make_buffer (mbuf), BI_BUF_GPT (mbuf) + gsize,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1769 pos + gsize, - gsize);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1770 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 SET_BI_BUF_GPT (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 #ifdef ERROR_CHECK_EXTENTS
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1774 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1775 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1776 sledgehammer_extent_check (make_buffer (mbuf));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
1777 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1780 if (pos == BI_BUF_Z (buf))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1781 {
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1782 /* merge gap with end gap */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1783
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1784 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + BUF_END_GAP_SIZE (buf));
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1785 SET_BUF_END_GAP_SIZE (buf, 0);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1786 SET_END_SENTINEL (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1787 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1788
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 /* Move gap to position `pos'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 Note that this can quit! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 move_gap (struct buffer *buf, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 if (! BUF_BEG_ADDR (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 if (pos < BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 gap_left (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 else if (pos > BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 gap_right (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1806 /* Merge the end gap into the gap */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1807
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1808 static void
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1809 merge_gap_with_end_gap (struct buffer *buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1810 {
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1811 Lisp_Object tem;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1812 Bytind real_gap_loc;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1813 Bytecount old_gap_size;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1814 Bytecount increment;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1815
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1816 increment = BUF_END_GAP_SIZE (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1817 SET_BUF_END_GAP_SIZE (buf, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1818
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1819 if (increment > 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1820 {
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1821 /* Prevent quitting in move_gap. */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1822 tem = Vinhibit_quit;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1823 Vinhibit_quit = Qt;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1824
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1825 real_gap_loc = BI_BUF_GPT (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1826 old_gap_size = BUF_GAP_SIZE (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1827
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1828 /* Pretend the end gap is the gap */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1829 SET_BI_BUF_GPT (buf, BI_BUF_Z (buf) + BUF_GAP_SIZE (buf));
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1830 SET_BUF_GAP_SIZE (buf, increment);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1831
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1832 /* Move the new gap down to be consecutive with the end of the old one.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1833 This adjusts the markers properly too. */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1834 gap_left (buf, real_gap_loc + old_gap_size);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1835
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1836 /* Now combine the two into one large gap. */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1837 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1838 SET_BI_BUF_GPT (buf, real_gap_loc);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1839 SET_GAP_SENTINEL (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1840
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1841 /* We changed the total size of the buffer (including gap),
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1842 so we need to fix up the end sentinel. */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1843 SET_END_SENTINEL (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1844
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1845 Vinhibit_quit = tem;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1846 }
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1847 }
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1848
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 /* Make the gap INCREMENT bytes longer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 make_gap (struct buffer *buf, Bytecount increment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 Bufbyte *result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 Bytind real_gap_loc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 Bytecount old_gap_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 /* If we have to get more space, get enough to last a while. We use
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1860 a geometric progression that saves on realloc space. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 increment += 2000 + ((BI_BUF_Z (buf) - BI_BUF_BEG (buf)) / 8);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1863 if (increment > BUF_END_GAP_SIZE (buf))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1864 {
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1865 /* Don't allow a buffer size that won't fit in an int
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1866 even if it will fit in a Lisp integer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1867 That won't work because so many places use `int'. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1868
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1869 if (BUF_Z (buf) - BUF_BEG (buf) + BUF_GAP_SIZE (buf) + increment
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
1870 > EMACS_INT_MAX)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1871 error ("Maximum buffer size exceeded");
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1872
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1873 result = BUFFER_REALLOC (buf->text->beg,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1874 BI_BUF_Z (buf) - BI_BUF_BEG (buf) +
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1875 BUF_GAP_SIZE (buf) + increment +
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1876 BUF_END_SENTINEL_SIZE);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1877 if (result == 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1878 memory_full ();
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1879
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1880 SET_BUF_BEG_ADDR (buf, result);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1881 }
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1882 else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1883 increment = BUF_END_GAP_SIZE (buf);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1884
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 /* Prevent quitting in move_gap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 tem = Vinhibit_quit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 Vinhibit_quit = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 real_gap_loc = BI_BUF_GPT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 old_gap_size = BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 /* Call the newly allocated space a gap at the end of the whole space. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 SET_BI_BUF_GPT (buf, BI_BUF_Z (buf) + BUF_GAP_SIZE (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 SET_BUF_GAP_SIZE (buf, increment);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1896 SET_BUF_END_GAP_SIZE (buf, 0);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
1897
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 /* Move the new gap down to be consecutive with the end of the old one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 This adjusts the markers properly too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 gap_left (buf, real_gap_loc + old_gap_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 /* Now combine the two into one large gap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 SET_BI_BUF_GPT (buf, real_gap_loc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 /* We changed the total size of the buffer (including gap),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 so we need to fix up the end sentinel. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 SET_END_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 Vinhibit_quit = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 /* Before/after-change processing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 /* Those magic changes ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 buffer_signal_changed_region (struct buffer *buf, Bufpos start,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 /* The changed region is recorded as the number of unchanged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 characters from the beginning and from the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 buffer. This obviates much of the need of shifting the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 region around to compensate for insertions and deletions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 if (buf->changes->begin_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 buf->changes->begin_unchanged > start - BUF_BEG (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 buf->changes->begin_unchanged = start - BUF_BEG (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 if (buf->changes->end_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 buf->changes->end_unchanged > BUF_Z (buf) - end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 buf->changes->end_unchanged = BUF_Z (buf) - end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 buffer_extent_signal_changed_region (struct buffer *buf, Bufpos start,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 if (buf->changes->begin_extent_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 buf->changes->begin_extent_unchanged > start - BUF_BEG (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 buf->changes->begin_extent_unchanged = start - BUF_BEG (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 if (buf->changes->end_extent_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 buf->changes->end_extent_unchanged > BUF_Z (buf) - end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 buf->changes->end_extent_unchanged = BUF_Z (buf) - end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 buffer_reset_changes (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 buf->changes->begin_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 buf->changes->end_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 buf->changes->begin_extent_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 buf->changes->end_extent_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 buf->changes->newline_was_deleted = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 Bufpos new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1964
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 /* Call the after-change-functions according to the changes made so far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 and treat all further changes as single until the outermost
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 multiple change exits. This is called when the outermost multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 change exits and when someone is trying to make a change that violates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 the constraints specified in begin_multiple_change(), typically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 when nested multiple-change sessions occur. (There are smarter ways of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 dealing with nested multiple changes, but these rarely occur so there's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 probably no point in it.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 /* #### This needs to keep track of what actually changed and only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 call the after-change functions on that region. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 cancel_multiple_change (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 /* Call the after-change-functions except when they've already been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 called or when there were no changes made to the buffer at all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 if (buf->text->changes->mc_begin != 0 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 buf->text->changes->mc_begin_signaled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 Bufpos real_mc_begin = buf->text->changes->mc_begin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 buf->text->changes->mc_begin = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 signal_after_change (buf, real_mc_begin, buf->text->changes->mc_orig_end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 buf->text->changes->mc_new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 buf->text->changes->mc_begin = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 /* this is an unwind_protect, to ensure that the after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 get called even in a non-local exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 multiple_change_finish_up (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 struct buffer *buf = XBUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 /* #### I don't know whether or not it should even be possible to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 get here with a dead buffer (though given how it is called I can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 see how it might be). In any case, there isn't time before 19.14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 to find out. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 buf->text->changes->in_multiple_change = 0; /* do this first so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 errors in the after-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 functions don't mess things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 cancel_multiple_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 /* Call this function when you're about to make a number of buffer changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 that should be considered a single change. (e.g. `replace-match' calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 this.) You need to specify the START and END of the region that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 going to be changed so that the before-change-functions are called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 with the correct arguments. The after-change region is calculated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 automatically, however, and if changes somehow or other happen outside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 of the specified region, that will also be handled correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 begin_multiple_change() returns a number (actually a specpdl depth)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2031 that you must pass to end_multiple_change() when you are done.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2032
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2033 FSF Emacs 20 implements a similar feature, accessible from Lisp
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2034 through a `combine-after-change-calls' special form, which is
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2035 essentially equivalent to this function. We should consider
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2036 whether we want to introduce a similar Lisp form. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2037
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 int count = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 if (buf->text->changes->in_multiple_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 if (buf->text->changes->mc_begin != 0 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (start < buf->text->changes->mc_begin ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 end > buf->text->changes->mc_new_end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 cancel_multiple_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 buf->text->changes->mc_begin = start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 buf->text->changes->mc_orig_end = buf->text->changes->mc_new_end = end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 buf->text->changes->mc_begin_signaled = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 record_unwind_protect (multiple_change_finish_up, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 buf->text->changes->in_multiple_change++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 /* We don't call before-change-functions until signal_before_change()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 is called, in case there is a read-only or other error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 return count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 end_multiple_change (struct buffer *buf, int count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 assert (buf->text->changes->in_multiple_change > 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 buf->text->changes->in_multiple_change--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 if (!buf->text->changes->in_multiple_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 static int inside_change_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 change_function_restore (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2081 /* We should first reset the variable and then change the buffer,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2082 because Fset_buffer() can throw. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2083 inside_change_hook = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2084 if (XBUFFER (buffer) != current_buffer)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2085 Fset_buffer (buffer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 static int in_first_change;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 first_change_hook_restore (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2094 in_first_change = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 Fset_buffer (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 /* Signal an initial modification to the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 signal_first_change (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 Lisp_Object buffer;
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
2106 XSETBUFFER (buffer, current_buffer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 if (!in_first_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2110 if (!NILP (symbol_value_in_buffer (Qfirst_change_hook, buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 record_unwind_protect (first_change_hook_restore, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 set_buffer_internal (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 in_first_change = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 run_hook (Qfirst_change_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 /* Signal a change to the buffer immediately before it happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 START and END are the bounds of the text to be changed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 signal_before_change (struct buffer *buf, Bufpos start, Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 /* This function can GC */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2129 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2130 Lisp_Object bufcons;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 if (!inside_change_hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2134 Lisp_Object buffer;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2135 int speccount;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2136
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 /* Are we in a multiple-change session? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 if (buf->text->changes->in_multiple_change &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 buf->text->changes->mc_begin != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 /* If we're violating the constraints of the session,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 call the after-change-functions as necessary for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 changes already made and treat further changes as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 single. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 if (start < buf->text->changes->mc_begin ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 end > buf->text->changes->mc_new_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 cancel_multiple_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 /* Do nothing if this is not the first change in the session. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 else if (buf->text->changes->mc_begin_signaled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 /* First time through; call the before-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 specifying the entire region to be changed. (Note that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 we didn't call before-change-functions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 begin_multiple_change() because the buffer might be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 read-only, etc.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 start = buf->text->changes->mc_begin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 end = buf->text->changes->mc_new_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 /* If buffer is unmodified, run a special hook for that case. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 if (BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf))
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2165 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2166 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2167 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2168 signal_first_change (mbuf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2169 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2170 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 /* Now in any case run the before-change-functions if any. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2173 speccount = specpdl_depth ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2174 record_unwind_protect (change_function_restore, Fcurrent_buffer ());
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2175 inside_change_hook = 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2177 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2179 XSETBUFFER (buffer, mbuf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2180 if (!NILP (symbol_value_in_buffer (Qbefore_change_functions, buffer))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2181 /* Obsolete, for compatibility */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2182 || !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer)))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2183 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2184 set_buffer_internal (buf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2185 va_run_hook_with_args (Qbefore_change_functions, 2,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2186 make_int (start), make_int (end));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2187 /* Obsolete, for compatibility */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2188 va_run_hook_with_args (Qbefore_change_function, 2,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2189 make_int (start), make_int (end));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2190 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2191 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2192
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2193 /* Make sure endpoints remain valid. before-change-functions
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2194 might have modified the buffer. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2195 if (start < BUF_BEGV (buf)) start = BUF_BEGV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2196 if (start > BUF_ZV (buf)) start = BUF_ZV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2197 if (end < BUF_BEGV (buf)) end = BUF_BEGV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2198 if (end > BUF_ZV (buf)) end = BUF_ZV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2199
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2200 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2201 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2202 XSETBUFFER (buffer, mbuf);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2203 report_extent_modification (buffer, start, end, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2205 unbind_to (speccount, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 /* Only now do we indicate that the before-change-functions have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 been called, in case some function throws out. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 buf->text->changes->mc_begin_signaled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 /* Signal a change immediately after it happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 START is the bufpos of the start of the changed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 ORIG_END is the bufpos of the end of the before-changed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 NEW_END is the bufpos of the end of the after-changed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 Bufpos new_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 /* This function can GC */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2224 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2225 Lisp_Object bufcons;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2226
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2227 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2228 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2229 /* always do this. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2230 buffer_signal_changed_region (mbuf, start, new_end);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2231 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2232 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2233 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2234 /* #### This seems inefficient. Wouldn't it be better to just
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2235 keep one cache per base buffer? */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2236 font_lock_maybe_update_syntactic_caches (mbuf, start, orig_end, new_end);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2237 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 if (!inside_change_hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2241 Lisp_Object buffer;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2242 int speccount;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2243
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 if (buf->text->changes->in_multiple_change &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 buf->text->changes->mc_begin != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 assert (start >= buf->text->changes->mc_begin &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 start <= buf->text->changes->mc_new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 assert (orig_end >= buf->text->changes->mc_begin &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 orig_end <= buf->text->changes->mc_new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 buf->text->changes->mc_new_end += new_end - orig_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 return; /* after-change-functions signalled when all changes done */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2255 speccount = specpdl_depth ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2256 record_unwind_protect (change_function_restore, Fcurrent_buffer ());
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2257 inside_change_hook = 1;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2258 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2260 XSETBUFFER (buffer, mbuf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2261
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2262 if (!NILP (symbol_value_in_buffer (Qafter_change_functions, buffer))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2263 /* Obsolete, for compatibility */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2264 || !NILP (symbol_value_in_buffer (Qafter_change_function, buffer)))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2265 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2266 set_buffer_internal (buf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2267 /* The actual after-change functions take slightly
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2268 different arguments than what we were passed. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2269 va_run_hook_with_args (Qafter_change_functions, 3,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2270 make_int (start), make_int (new_end),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2271 make_int (orig_end - start));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2272 /* Obsolete, for compatibility */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2273 va_run_hook_with_args (Qafter_change_function, 3,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2274 make_int (start), make_int (new_end),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2275 make_int (orig_end - start));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2276 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2277 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2278
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2279 /* Make sure endpoints remain valid. after-change-functions
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2280 might have modified the buffer. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2281 if (start < BUF_BEGV (buf)) start = BUF_BEGV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2282 if (start > BUF_ZV (buf)) start = BUF_ZV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2283 if (new_end < BUF_BEGV (buf)) new_end = BUF_BEGV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2284 if (new_end > BUF_ZV (buf)) new_end = BUF_ZV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2285 if (orig_end < BUF_BEGV (buf)) orig_end = BUF_BEGV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2286 if (orig_end > BUF_ZV (buf)) orig_end = BUF_ZV (buf);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2287
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2288 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2289 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2290 XSETBUFFER (buffer, mbuf);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2291 report_extent_modification (buffer, start, new_end, 1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2293 unbind_to (speccount, Qnil); /* sets inside_change_hook back to 0 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 /* Call this if you're about to change the region of BUFFER from START
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 to END. This checks the read-only properties of the region, calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 the necessary modification hooks, and warns the next redisplay that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 it should pay attention to that area. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 prepare_to_modify_buffer (struct buffer *buf, Bufpos start, Bufpos end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 int lockit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 /* This function can GC */
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2307 /* dmoore - This function can also kill the buffer buf, the current
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2308 buffer, and do anything it pleases. So if you call it, be
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2309 careful. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2310 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2311 Lisp_Object buffer, bufcons;
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2312 struct gcpro gcpro1;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2313
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2314 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2315 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2316 barf_if_buffer_read_only (mbuf, start, end);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2317 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 /* if this is the first modification, see about locking the buffer's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 file */
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2321 XSETBUFFER (buffer, buf);
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2322 GCPRO1 (buffer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 if (!NILP (buf->filename) && lockit &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 #ifdef CLASH_DETECTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 if (!NILP (buf->file_truename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 /* Make binding buffer-file-name to nil effective. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 lock_file (buf->file_truename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 /* At least warn if this file has changed on disk since it was visited.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 if (NILP (Fverify_visited_file_modtime (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 && !NILP (Ffile_exists_p (buf->filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 call1_in_buffer (buf, intern ("ask-user-about-supersession-threat"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 buf->filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 #endif /* not CLASH_DETECTION */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 }
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2338 UNGCPRO;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2339
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2340 /* #### dmoore - is this reasonable in case of buf being killed above? */
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2341 if (!BUFFER_LIVE_P (buf))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 98
diff changeset
2342 return;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 signal_before_change (buf, start, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 #ifdef REGION_CACHE_NEEDS_WORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 if (buf->newline_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 invalidate_region_cache (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 buf->newline_cache,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 start - BUF_BEG (buf), BUF_Z (buf) - end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 if (buf->width_run_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 invalidate_region_cache (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 buf->width_run_cache,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 start - BUF_BEG (buf), BUF_Z (buf) - end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 #if 0 /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 Vdeactivate_mark = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2361 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2362 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2363 mbuf->point_before_scroll = Qnil;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2364 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 /* Insertion of strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2373 fixup_internal_substring (const Bufbyte *nonreloc, Lisp_Object reloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 Bytecount offset, Bytecount *len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 assert ((nonreloc && NILP (reloc)) || (!nonreloc && STRINGP (reloc)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 if (*len < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 if (nonreloc)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2381 *len = strlen ((const char *) nonreloc) - offset;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 else
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2383 *len = XSTRING_LENGTH (reloc) - offset;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 }
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 219
diff changeset
2385 #ifdef ERROR_CHECK_BUFPOS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 assert (*len >= 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 if (STRINGP (reloc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2389 assert (offset >= 0 && offset <= XSTRING_LENGTH (reloc));
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2390 assert (offset + *len <= XSTRING_LENGTH (reloc));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 }
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 219
diff changeset
2392 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 /* Insert a string into BUF at Bufpos POS. The string data comes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 from one of two sources: constant, non-relocatable data (specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 in NONRELOC), or a Lisp string object (specified in RELOC), which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 is relocatable and may have extent data that needs to be copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 into the buffer. OFFSET and LENGTH specify the substring of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 data that is actually to be inserted. As a special case, if POS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 is -1, insert the string at point and move point to the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 Normally, markers at the insertion point end up before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 inserted string. If INSDEL_BEFORE_MARKERS is set in flags, however,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 they end up after the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 INSDEL_NO_LOCKING is kludgy and is used when insert-file-contents is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 visiting a new file; it inhibits the locking checks normally done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 before modifying a buffer. Similar checks were already done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 in the higher-level Lisp functions calling insert-file-contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 buffer_insert_string_1 (struct buffer *buf, Bufpos pos,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2415 const Bufbyte *nonreloc, Lisp_Object reloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 Bytecount offset, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 Bytind ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 Charcount cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 int move_point = 0;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2424 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2425 Lisp_Object bufcons;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 /* Defensive steps just in case a buffer gets deleted and a calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 function doesn't notice it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 fixup_internal_substring (nonreloc, reloc, offset, &length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 if (pos == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 pos = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 move_point = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 /* #### See the comment in print_internal(). If this buffer is marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 as translatable, then Fgettext() should be called on obj if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 is a string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 /* Make sure that point-max won't exceed the size of an emacs int. */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2447 if ((length + BUF_Z (buf)) > EMACS_INT_MAX)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2448 error ("Maximum buffer size exceeded");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2450 /* theoretically not necessary -- caller should GCPRO.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2451 #### buffer_insert_from_buffer_1() doesn't! */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 GCPRO1 (reloc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 prepare_to_modify_buffer (buf, pos, pos, !(flags & INSDEL_NO_LOCKING));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 /* Defensive steps in case the before-change-functions fuck around */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 modified the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 if (pos < BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 pos = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 if (pos > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 pos = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 /* string may have been relocated up to this point */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 if (STRINGP (reloc))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2473 nonreloc = XSTRING_DATA (reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 ind = bufpos_to_bytind (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 cclen = bytecount_to_charcount (nonreloc + offset, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 if (ind != BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 /* #### if debug-on-quit is invoked and the user changes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 buffer, bad things can happen. This is a rampant problem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 in Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 move_gap (buf, ind); /* may QUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 if (! GAP_CAN_HOLD_SIZE_P (buf, length))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2484 {
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2485 if (BUF_END_GAP_SIZE (buf) >= length)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2486 merge_gap_with_end_gap (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2487 else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2488 make_gap (buf, length - BUF_GAP_SIZE (buf));
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2489 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 203
diff changeset
2491 insert_invalidate_line_number_cache (buf, pos, nonreloc + offset, length);
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 203
diff changeset
2492
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2493 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2494 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2495 record_insert (mbuf, pos, cclen);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2496 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2497
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 BUF_MODIFF (buf)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 MARK_BUFFERS_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 /* string may have been relocated up to this point */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 if (STRINGP (reloc))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2503 nonreloc = XSTRING_DATA (reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 memcpy (BUF_GPT_ADDR (buf), nonreloc + offset, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 SET_BI_BUF_GPT (buf, BI_BUF_GPT (buf) + length);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2509 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2510 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2511 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) + cclen, BI_BUF_ZV (mbuf) + length);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2512 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 SET_BOTH_BUF_Z (buf, BUF_Z (buf) + cclen, BI_BUF_Z (buf) + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2516 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2517 buffer_mule_signal_inserted_region (buf, pos, length, cclen);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2518 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2519
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2520 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2521 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2522 process_extents_for_insertion (make_buffer (mbuf), ind, length);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2523 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2524
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2525 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2526 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2527 /* We know the gap is at IND so the cast is OK. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2528 adjust_markers_for_insert (mbuf, (Memind) ind, length);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2529 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 /* Point logically doesn't move, but may need to be adjusted because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 it's a byte index. point-marker doesn't change because it's a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 memory index. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2534 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2535 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2536 if (BI_BUF_PT (mbuf) > ind)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2537 JUST_SET_POINT (mbuf, BUF_PT (mbuf) + cclen,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2538 BI_BUF_PT (mbuf) + length);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2539 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 /* Well, point might move. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 if (move_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 BI_BUF_SET_PT (buf, ind + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 if (STRINGP (reloc))
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2546 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2547 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2548 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2549 splice_in_string_extents (reloc, mbuf, ind, length, offset);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2550 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2551 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 if (flags & INSDEL_BEFORE_MARKERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2555 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2556 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2557 /* ind - 1 is correct because the FROM argument is exclusive.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2558 I formerly used DEC_BYTIND() but that caused problems at the
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2559 beginning of the buffer. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2560 adjust_markers (mbuf, ind - 1, ind, length);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2561 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 signal_after_change (buf, pos, pos, pos + cclen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 return cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 /* The following functions are interfaces onto the above function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 for inserting particular sorts of data. In all the functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 BUF and POS specify the buffer and location where the insertion is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 to take place. (If POS is -1, text is inserted at point and point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 moves forward past the text.) FLAGS is as above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 buffer_insert_raw_string_1 (struct buffer *buf, Bufpos pos,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2580 const Bufbyte *nonreloc, Bytecount length,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 return buffer_insert_string_1 (buf, pos, nonreloc, Qnil, 0, length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 buffer_insert_lisp_string_1 (struct buffer *buf, Bufpos pos, Lisp_Object str,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 /* This function can GC */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2593 #ifdef ERROR_CHECK_TYPECHECK
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 assert (STRINGP (str));
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2595 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 return buffer_insert_string_1 (buf, pos, 0, str, 0,
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2597 XSTRING_LENGTH (str),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 /* Insert the null-terminated string S (in external format). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 Charcount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2604 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, const char *s,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 /* This function can GC */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2608 const char *translated = GETTEXT (s);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
2609 return buffer_insert_string_1 (buf, pos, (const Bufbyte *) translated, Qnil,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 0, strlen (translated), flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 buffer_insert_emacs_char_1 (struct buffer *buf, Bufpos pos, Emchar ch,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 Bufbyte str[MAX_EMCHAR_LEN];
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2619 Bytecount len = set_charptr_emchar (str, ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 return buffer_insert_string_1 (buf, pos, str, Qnil, 0, len, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 buffer_insert_c_char_1 (struct buffer *buf, Bufpos pos, char c,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 return buffer_insert_emacs_char_1 (buf, pos, (Emchar) (unsigned char) c,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2631
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 buffer_insert_from_buffer_1 (struct buffer *buf, Bufpos pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 struct buffer *buf2, Bufpos pos2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 Charcount length, int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 Lisp_Object str = make_string_from_buffer (buf2, pos2, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 return buffer_insert_string_1 (buf, pos, 0, str, 0,
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2640 XSTRING_LENGTH (str), flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 /* Deletion of ranges */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 /* Delete characters in buffer from FROM up to (but not including) TO. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 buffer_delete_range (struct buffer *buf, Bufpos from, Bufpos to, int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 Charcount numdel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 Bytind bi_from, bi_to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 Bytecount bc_numdel;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 274
diff changeset
2657 EMACS_INT shortage;
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2658 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2659 Lisp_Object bufcons;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 /* Defensive steps just in case a buffer gets deleted and a calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 function doesn't notice it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 /* Make args be valid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 if (from < BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 from = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 if (to > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 to = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 if ((numdel = to - from) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 prepare_to_modify_buffer (buf, from, to, !(flags & INSDEL_NO_LOCKING));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 /* Defensive steps in case the before-change-functions fuck around */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 modified the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 if (from < BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 from = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 if (to > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 to = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 if ((numdel = to - from) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 /* Redisplay needs to know if a newline was in the deleted region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 If we've already marked the changed region as having a deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 newline there is no use in performing the check. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 if (!buf->changes->newline_was_deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 scan_buffer (buf, '\n', from, to, 1, &shortage, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 if (!shortage)
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2697 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2698 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2699 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2700 mbuf->changes->newline_was_deleted = 1;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2701 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2702 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 bi_from = bufpos_to_bytind (buf, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 bi_to = bufpos_to_bytind (buf, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 bc_numdel = bi_to - bi_from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 203
diff changeset
2709 delete_invalidate_line_number_cache (buf, from, to);
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 203
diff changeset
2710
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2711 if (to == BUF_Z (buf) &&
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2712 bi_from > BI_BUF_GPT (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 {
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2714 /* avoid moving the gap just to delete from the bottom. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2715
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2716 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2717 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2718 record_delete (mbuf, from, numdel);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2719 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2720 BUF_MODIFF (buf)++;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2721 MARK_BUFFERS_CHANGED;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2722
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2723 /* #### Point used to be modified here, but this causes problems
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2724 with MULE, as point is used to calculate bytinds, and if the
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2725 offset in bc_numdel causes point to move to a non first-byte
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2726 location, causing some other function to throw an assertion
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2727 in ASSERT_VALID_BYTIND. I've moved the code to right after
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2728 the other movements and adjustments, but before the gap is
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2729 moved. -- jh 970813 */
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2730
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2731 /* Detach any extents that are completely within the range [FROM, TO],
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2732 if the extents are detachable.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2733
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2734 This must come AFTER record_delete(), so that the appropriate
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2735 extents will be present to be recorded, and BEFORE the gap
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2736 size is increased, as otherwise we will be confused about
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2737 where the extents end. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2738 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2739 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2740 process_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to, 0);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2741 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2742
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2743 /* Relocate all markers pointing into the new, larger gap to
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2744 point at the end of the text before the gap. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2745 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2746 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2747 adjust_markers (mbuf,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2748 (bi_to + BUF_GAP_SIZE (mbuf)),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2749 (bi_to + BUF_GAP_SIZE (mbuf)),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2750 (- bc_numdel));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2751 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2752
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2753 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2754 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2755 /* Relocate any extent endpoints just like markers. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2756 adjust_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2757 BUF_GAP_SIZE (mbuf), bc_numdel, 0);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2758 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2759
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2760 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2761 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2762 /* Relocate point as if it were a marker. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2763 if (bi_from < BI_BUF_PT (mbuf))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2764 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2765 if (BI_BUF_PT (mbuf) < bi_to)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2766 JUST_SET_POINT (mbuf, from, bi_from);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2767 else
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2768 JUST_SET_POINT (mbuf, BUF_PT (mbuf) - numdel,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2769 BI_BUF_PT (mbuf) - bc_numdel);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2770 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2771 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2772
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2773 SET_BUF_END_GAP_SIZE (buf, BUF_END_GAP_SIZE (buf) + bc_numdel);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2774
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2775 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2776 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2777 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) - numdel,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2778 BI_BUF_ZV (mbuf) - bc_numdel);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2779 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2780 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2781 SET_GAP_SENTINEL (buf);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2783 else
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2784 {
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2785 /* Make sure the gap is somewhere in or next to what we are deleting. */
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2786 if (bi_to < BI_BUF_GPT (buf))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2787 gap_left (buf, bi_to);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2788 if (bi_from > BI_BUF_GPT (buf))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2789 gap_right (buf, bi_from);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2790
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2791 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2792 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2793 record_delete (mbuf, from, numdel);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2794 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2795 BUF_MODIFF (buf)++;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2796 MARK_BUFFERS_CHANGED;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2797
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2798 /* #### Point used to be modified here, but this causes problems
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2799 with MULE, as point is used to calculate bytinds, and if the
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2800 offset in bc_numdel causes point to move to a non first-byte
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2801 location, causing some other function to throw an assertion
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2802 in ASSERT_VALID_BYTIND. I've moved the code to right after
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2803 the other movements and adjustments, but before the gap is
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2804 moved. -- jh 970813 */
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2805
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2806 /* Detach any extents that are completely within the range [FROM, TO],
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2807 if the extents are detachable.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2808
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2809 This must come AFTER record_delete(), so that the appropriate extents
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2810 will be present to be recorded, and BEFORE the gap size is increased,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2811 as otherwise we will be confused about where the extents end. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2812 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2813 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2814 process_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to, 0);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2815 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2816
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2817 /* Relocate all markers pointing into the new, larger gap to
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2818 point at the end of the text before the gap. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2819 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2820 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2821 adjust_markers (mbuf,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2822 (bi_to + BUF_GAP_SIZE (mbuf)),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2823 (bi_to + BUF_GAP_SIZE (mbuf)),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2824 (- bc_numdel - BUF_GAP_SIZE (mbuf)));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2825 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2826
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2827 /* Relocate any extent endpoints just like markers. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2828 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2829 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2830 adjust_extents_for_deletion (make_buffer (mbuf), bi_from, bi_to,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2831 BUF_GAP_SIZE (mbuf),
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2832 bc_numdel, BUF_GAP_SIZE (mbuf));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2833 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2834
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2835 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 167
diff changeset
2836 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2837 /* Relocate point as if it were a marker. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2838 if (bi_from < BI_BUF_PT (mbuf))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2839 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2840 if (BI_BUF_PT (mbuf) < bi_to)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2841 JUST_SET_POINT (mbuf, from, bi_from);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2842 else
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2843 JUST_SET_POINT (mbuf, BUF_PT (mbuf) - numdel,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2844 BI_BUF_PT (mbuf) - bc_numdel);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2845 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 167
diff changeset
2846 }
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 167
diff changeset
2847
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2848 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + bc_numdel);
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2849 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2850 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2851 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) - numdel,
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2852 BI_BUF_ZV (mbuf) - bc_numdel);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2853 }
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2854 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2855 SET_BI_BUF_GPT (buf, bi_from);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2856 SET_GAP_SENTINEL (buf);
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2857 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2859 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2860 buffer_mule_signal_deleted_region (buf, from, to, bi_from, bi_to);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2861 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2862
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 #ifdef ERROR_CHECK_EXTENTS
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2864 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2865 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2866 sledgehammer_extent_check (make_buffer (mbuf));
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2867 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 signal_after_change (buf, from, to, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 /* Replacement of characters */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 /* Replace the character at POS in buffer B with CH. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 void
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2881 buffer_replace_char (struct buffer *buf, Bufpos pos, Emchar ch,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 int not_real_change, int force_lock_check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 Bufbyte curstr[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 Bufbyte newstr[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 Bytecount curlen, newlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 /* Defensive steps just in case a buffer gets deleted and a calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 function doesn't notice it. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2891 if (!BUFFER_LIVE_P (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2894 curlen = BUF_CHARPTR_COPY_CHAR (buf, pos, curstr);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 newlen = set_charptr_emchar (newstr, ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 if (curlen == newlen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2899 struct buffer *mbuf;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2900 Lisp_Object bufcons;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2901
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 /* then we can just replace the text. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2903 prepare_to_modify_buffer (buf, pos, pos + 1,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 !not_real_change || force_lock_check);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 /* Defensive steps in case the before-change-functions fuck around */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2906 if (!BUFFER_LIVE_P (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 modified the buffer. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2912 if (pos < BUF_BEGV (buf))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2913 pos = BUF_BEGV (buf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2914 if (pos >= BUF_ZV (buf))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2915 pos = BUF_ZV (buf) - 1;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2916 if (pos < BUF_BEGV (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 /* no more characters in buffer! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2920 if (BUF_FETCH_CHAR (buf, pos) == '\n')
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2921 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2922 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2923 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2924 mbuf->changes->newline_was_deleted = 1;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2925 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2926 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 MARK_BUFFERS_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 if (!not_real_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2930 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2931 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2932 record_change (mbuf, pos, 1);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2933 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2934 BUF_MODIFF (buf)++;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 }
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2936 memcpy (BUF_BYTE_ADDRESS (buf, pos), newstr, newlen);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2937
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2938 signal_after_change (buf, pos, pos + 1, pos + 1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2939
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2940 /* We do not have to adjust the Mule data; we just replaced a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2941 character with another of the same number of bytes. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2945 /*
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2946 * Must implement as deletion followed by insertion.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2947 *
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2948 * Make a note to move point forward later in the one situation
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2949 * where it is needed, a delete/insert one position behind
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2950 * point. Point will drift backward by one position and stay
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2951 * there otherwise.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2952 */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2953 int movepoint = (pos == BUF_PT (buf) - 1);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2954
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2955 buffer_delete_range (buf, pos, pos + 1, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 /* Defensive steps in case the before-change-functions fuck around */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2957 if (!BUFFER_LIVE_P (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 modified the buffer. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2963 if (pos < BUF_BEGV (buf))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2964 pos = BUF_BEGV (buf);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2965 if (pos >= BUF_ZV (buf))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2966 pos = BUF_ZV (buf) - 1;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2967 if (pos < BUF_BEGV (buf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 /* no more characters in buffer! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 return;
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2970 /*
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2971 * -1 as the pos argument means to move point forward with the
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2972 * insertion, which we must do if the deletion moved point
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2973 * backward so that it now equals the insertion point.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2974 */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
2975 buffer_insert_string_1 (buf, (movepoint ? -1 : pos),
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
2976 newstr, Qnil, 0, newlen, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 /* Other functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 /* Make a string from a buffer. This needs to take into account the gap,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 and add any necessary extents from the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2988 static Lisp_Object
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2989 make_string_from_buffer_1 (struct buffer *buf, Bufpos pos, Charcount length,
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2990 int no_extents)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 /* This function can GC */
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2993 Bytind bi_ind = bufpos_to_bytind (buf, pos);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2994 Bytecount bi_len = bufpos_to_bytind (buf, pos + length) - bi_ind;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2995 Lisp_Object val = make_uninit_string (bi_len);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
2996
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 GCPRO1 (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3000 if (!no_extents)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3001 add_string_extents (val, buf, bi_ind, bi_len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 Bytecount len1 = BI_BUF_GPT (buf) - bi_ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 Bufbyte *start1 = BI_BUF_BYTE_ADDRESS (buf, bi_ind);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
3006 Bufbyte *dest = XSTRING_DATA (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 if (len1 < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 /* Completely after gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 memcpy (dest, start1, bi_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 else if (bi_len <= len1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 /* Completely before gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 memcpy (dest, start1, bi_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 /* Spans gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 Bytind pos2 = bi_ind + len1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 Bufbyte *start2 = BI_BUF_BYTE_ADDRESS (buf, pos2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 memcpy (dest, start1, len1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 memcpy (dest + len1, start2, bi_len - len1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3033 Lisp_Object
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3034 make_string_from_buffer (struct buffer *buf, Bufpos pos, Charcount length)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3035 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3036 return make_string_from_buffer_1 (buf, pos, length, 0);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3037 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3038
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3039 Lisp_Object
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3040 make_string_from_buffer_no_extents (struct buffer *buf, Bufpos pos,
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3041 Charcount length)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3042 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3043 return make_string_from_buffer_1 (buf, pos, length, 1);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3044 }
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
3045
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 barf_if_buffer_read_only (struct buffer *buf, Bufpos from, Bufpos to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3049 Lisp_Object buffer;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 Lisp_Object iro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 back:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 iro = (buf == current_buffer ? Vinhibit_read_only :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 symbol_value_in_buffer (Qinhibit_read_only, buffer));
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3056 if (!LISTP (iro))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 if (NILP (iro) && !NILP (buf->read_only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 Fsignal (Qbuffer_read_only, (list1 (buffer)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 goto back;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 if (from > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 if (to < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 to = from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 verify_extent_modification (buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 bufpos_to_bytind (buf, from),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 bufpos_to_bytind (buf, to),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 iro);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3075 find_charsets_in_bufbyte_string (unsigned char *charsets, const Bufbyte *str,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 Bytecount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3078 #ifndef MULE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 /* Telescope this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 charsets[0] = 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3081 #else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3082 const Bufbyte *strend = str + len;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3083 memset (charsets, 0, NUM_LEADING_BYTES);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3084
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3085 /* #### SJT doesn't like this. */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3086 if (len == 0)
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3087 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3088 charsets[XCHARSET_LEADING_BYTE (Vcharset_ascii) - 128] = 1;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3089 return;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3090 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3091
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3092 while (str < strend)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3093 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3094 charsets[CHAR_LEADING_BYTE (charptr_emchar (str)) - 128] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3095 INC_CHARPTR (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3096 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3097 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3101 find_charsets_in_emchar_string (unsigned char *charsets, const Emchar *str,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 Charcount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3104 #ifndef MULE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 /* Telescope this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 charsets[0] = 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3107 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3108 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3109
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3110 memset (charsets, 0, NUM_LEADING_BYTES);
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3111
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3112 /* #### SJT doesn't like this. */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3113 if (len == 0)
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3114 {
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3115 charsets[XCHARSET_LEADING_BYTE (Vcharset_ascii) - 128] = 1;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3116 return;
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3117 }
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 400
diff changeset
3118
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3119 for (i = 0; i < len; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3120 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3121 charsets[CHAR_LEADING_BYTE (str[i]) - 128] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3122 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3123 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3127 bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 int cols = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3130 const Bufbyte *end = str + len;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 while (str < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3134 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3135 Emchar ch = charptr_emchar (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3136 cols += XCHARSET_COLUMNS (CHAR_CHARSET (ch));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3137 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 cols++;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3139 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 INC_CHARPTR (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 return cols;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3147 emchar_string_displayed_columns (const Emchar *str, Charcount len)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3149 #ifdef MULE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 int cols = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 for (i = 0; i < len; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 return cols;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3157 #else /* not MULE */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3158 return len;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3159 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 /* NOTE: Does not reset the Dynarr. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3165 convert_bufbyte_string_into_emchar_dynarr (const Bufbyte *str, Bytecount len,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3166 Emchar_dynarr *dyn)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3168 const Bufbyte *strend = str + len;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 while (str < strend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 Emchar ch = charptr_emchar (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 Dynarr_add (dyn, ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 INC_CHARPTR (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
3178 Charcount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3179 convert_bufbyte_string_into_emchar_string (const Bufbyte *str, Bytecount len,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 Emchar *arr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3182 const Bufbyte *strend = str + len;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 Charcount newlen = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 while (str < strend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 Emchar ch = charptr_emchar (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 arr[newlen++] = ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 INC_CHARPTR (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 return newlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 /* Convert an array of Emchars into the equivalent string representation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 Store into the given Bufbyte dynarr. Does not reset the dynarr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 Does not add a terminating zero. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3199 Bufbyte_dynarr *dyn)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 for (i = 0; i < nels; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 167
diff changeset
3206 Bytecount len = set_charptr_emchar (str, arr[i]);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 Dynarr_add_many (dyn, str, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 /* Convert an array of Emchars into the equivalent string representation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 Malloc the space needed for this and return it. If LEN_OUT is not a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 NULL pointer, store into LEN_OUT the number of Bufbytes in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 malloc()ed string. Note that the actual number of Bufbytes allocated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 is one more than this: the returned string is zero-terminated. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 Bufbyte *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 Bytecount *len_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 /* Damn zero-termination. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 Bufbyte *str = (Bufbyte *) alloca (nels * MAX_EMCHAR_LEN + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 Bufbyte *strorig = str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 Bytecount len;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3225
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 for (i = 0; i < nels; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 str += set_charptr_emchar (str, arr[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 *str = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 len = str - strorig;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3232 str = (Bufbyte *) xmalloc (1 + len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 memcpy (str, strorig, 1 + len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 if (len_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 *len_out = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 return str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3245 reinit_vars_of_insdel (void)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 inside_change_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 in_first_change = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 three_to_one_table[i] = i / 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3257 vars_of_insdel (void)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3258 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3259 reinit_vars_of_insdel ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3260 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3261
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
3262 void
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
3263 init_buffer_text (struct buffer *b)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
3265 if (!b->base_buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 SET_BUF_GAP_SIZE (b, 20);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 167
diff changeset
3268 BUFFER_ALLOC (b->text->beg, BUF_GAP_SIZE (b) + BUF_END_SENTINEL_SIZE);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 if (! BUF_BEG_ADDR (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 memory_full ();
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
3271
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
3272 SET_BUF_END_GAP_SIZE (b, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 SET_BI_BUF_GPT (b, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 SET_BOTH_BUF_Z (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 SET_GAP_SENTINEL (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 SET_END_SENTINEL (b);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3277 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3278 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3279 int i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3280
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3281 b->text->mule_bufmin = b->text->mule_bufmax = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3282 b->text->mule_bytmin = b->text->mule_bytmax = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3283 b->text->mule_shifter = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3284 b->text->mule_three_p = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3285
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3286 for (i = 0; i < 16; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3287 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3288 b->text->mule_bufpos_cache[i] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3289 b->text->mule_bytind_cache[i] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3290 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3291 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 167
diff changeset
3292 #endif /* MULE */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
3293 b->text->line_number_cache = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 BUF_MODIFF (b) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 BUF_SAVE_MODIFF (b) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 JUST_SET_POINT (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 SET_BOTH_BUF_BEGV (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 SET_BOTH_BUF_ZV (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3302 b->text->changes = xnew_and_zero (struct buffer_text_change_data);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 JUST_SET_POINT (b, BUF_PT (b->base_buffer), BI_BUF_PT (b->base_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 SET_BOTH_BUF_BEGV (b, BUF_BEGV (b->base_buffer),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 BI_BUF_BEGV (b->base_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 SET_BOTH_BUF_ZV (b, BUF_ZV (b->base_buffer),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 BI_BUF_ZV (b->base_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3313 b->changes = xnew_and_zero (struct each_buffer_change_data);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 BUF_FACECHANGE (b) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 #ifdef REGION_CACHE_NEEDS_WORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 b->newline_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 b->width_run_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 b->width_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 void
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
3324 uninit_buffer_text (struct buffer *b)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 286
diff changeset
3326 if (!b->base_buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 BUFFER_FREE (b->text->beg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 xfree (b->text->changes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 xfree (b->changes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 #ifdef REGION_CACHE_NEEDS_WORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 if (b->newline_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 free_region_cache (b->newline_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 b->newline_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 if (b->width_run_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 free_region_cache (b->width_run_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 b->width_run_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 b->width_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 }