annotate src/insdel.c @ 442:abe6d1db359e r21-2-36

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