annotate src/insdel.c @ 22:8fc7fe29b841 r19-15b94

Import from CVS: tag r19-15b94
author cvs
date Mon, 13 Aug 2007 08:50:29 +0200
parents 9ee227acff29
children 7e54bd776075
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Buffer insertion/deletion and gap motion for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1991, 1992, 1993, 1994, 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* Synched up with: Mule 2.0, FSF 19.30. Diverges significantly. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* Overhauled by Ben Wing, December 1994, for Mule implementation. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 There are three possible ways to specify positions in a buffer. All
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 of these are one-based: the beginning of the buffer is position or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 index 1, and 0 is not a valid position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 As a "buffer position" (typedef Bufpos):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 This is an index specifying an offset in characters from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 beginning of the buffer. Note that buffer positions are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 logically *between* characters, not on a character. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 difference between two buffer positions specifies the number of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 characters between those positions. Buffer positions are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 only kind of position externally visible to the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 As a "byte index" (typedef Bytind):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 This is an index over the bytes used to represent the characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 in the buffer. If there is no Mule support, this is identical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 to a buffer position, because each character is represented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 using one byte. However, with Mule support, many characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 require two or more bytes for their representation, and so a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 byte index may be greater than the corresponding buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 As a "memory index" (typedef Memind):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 This is the byte index adjusted for the gap. For positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 before the gap, this is identical to the byte index. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 positions after the gap, this is the byte index plus the gap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 size. There are two possible memory indices for the gap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 position; the memory index at the beginning of the gap should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 always be used, except in code that deals with manipulating the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 gap, where both indices may be seen. The address of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 character "at" (i.e. following) a particular position can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 obtained from the formula
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 buffer_start_address + memory_index(position) - 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 except in the case of characters at the gap position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Other typedefs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ===============
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 Emchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 -------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 This typedef represents a single Emacs character, which can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ASCII, ISO-8859, or some extended character, as would typically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 be used for Kanji. Note that the representation of a character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 as an Emchar is *not* the same as the representation of that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 same character in a string; thus, you cannot do the standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 C trick of passing a pointer to a character to a function that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 expects a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 An Emchar takes up 19 bits of representation and (for code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 compatibility and such) is compatible with an int. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 representation is visible on the Lisp level. The important
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 characteristics of the Emchar representation are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 -- values 0x00 - 0x7f represent ASCII.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 -- values 0x80 - 0xff represent the right half of ISO-8859-1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 -- values 0x100 and up represent all other characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 This means that Emchar values are upwardly compatible with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 the standard 8-bit representation of ASCII/ISO-8859-1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 Bufbyte:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 --------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 The data in a buffer or string is logically made up of Bufbyte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 objects, where a Bufbyte takes up the same amount of space as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 char. (It is declared differently, though, to catch invalid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 usages.) Strings stored using Bufbytes are said to be in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "internal format". The important characteristics of internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 format are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 -- ASCII characters are represented as a single Bufbyte,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 in the range 0 - 0x7f.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 -- All other characters are represented as a Bufbyte in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 the range 0x80 - 0x9f followed by one or more Bufbytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 in the range 0xa0 to 0xff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 This leads to a number of desirable properties:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 -- Given the position of the beginning of a character,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 you can find the beginning of the next or previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 character in constant time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 -- When searching for a substring or an ASCII character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 within the string, you need merely use standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 searching routines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 array of char:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 --------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Strings that go in or out of Emacs are in "external format",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 typedef'ed as an array of char or a char *. There is more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 than one external format (JIS, EUC, etc.) but they all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 have similar properties. They are modal encodings,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 which is to say that the meaning of particular bytes is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 not fixed but depends on what "mode" the string is currently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 in (e.g. bytes in the range 0 - 0x7f might be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 interpreted as ASCII, or as Hiragana, or as 2-byte Kanji,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 depending on the current mode). The mode starts out in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ASCII/ISO-8859-1 and is switched using escape sequences --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 for example, in the JIS encoding, 'ESC $ B' switches to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 mode where pairs of bytes in the range 0 - 0x7f
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 are interpreted as Kanji characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 External-formatted data is generally desirable for passing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 data between programs because it is upwardly compatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 with standard ASCII/ISO-8859-1 strings and may require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 less space than internal encodings such as the one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 described above. In addition, some encodings (e.g. JIS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 keep all characters (except the ESC used to switch modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 in the printing ASCII range 0x20 - 0x7e, which results in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 a much higher probability that the data will avoid being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 garbled in transmission. Externally-formatted data is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 generally not very convenient to work with, however, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 for this reason is usually converted to internal format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 before any work is done on the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 NOTE: filenames need to be in external format so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ISO-8859-1 characters come out correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 Charcount:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ----------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 This typedef represents a count of characters, such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 a character offset into a string or the number of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 characters between two positions in a buffer. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 difference between two Bufpos's is a Charcount, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 character positions in a string are represented using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 a Charcount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 Bytecount:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ----------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 Similar to a Charcount but represents a count of bytes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 The difference between two Bytind's is a Bytecount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Usage of the various representations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 =====================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Memory indices are used in low-level functions in insdel.c and for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 extent endpoints and marker positions. The reason for this is that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 this way, the extents and markers don't need to be updated for most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 insertions, which merely shrink the gap and don't move any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 characters around in memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (The beginning-of-gap memory index simplifies insertions w.r.t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 markers, because text usually gets inserted after markers. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 extents, it is merely for consistency, because text can get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 inserted either before or after an extent's endpoint depending on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 the open/closedness of the endpoint.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 Byte indices are used in other code that needs to be fast,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 such as the searching, redisplay, and extent-manipulation code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 Buffer positions are used in all other code. This is because this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 representation is easiest to work with (especially since Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 code always uses buffer positions), necessitates the fewest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 changes to existing code, and is the safest (e.g. if the text gets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 shifted underneath a buffer position, it will still point to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 character; if text is shifted under a byte index, it might point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 to the middle of a character, which would be bad).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Similarly, Charcounts are used in all code that deals with strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 except for code that needs to be fast, which used Bytecounts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Strings are always passed around internally using internal format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Conversions between external format are performed at the time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 that the data goes in or out of Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Working with the various representations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ========================================= */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #include "redisplay.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 /* We write things this way because it's very important the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 MAX_BYTIND_GAP_SIZE_3 is a multiple of 3. (As it happens,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 65535 is a multiple of 3, but this may not always be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 case.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 #define MAX_BUFPOS_GAP_SIZE_3 (65535/3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #define MAX_BYTIND_GAP_SIZE_3 (3 * MAX_BUFPOS_GAP_SIZE_3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 short three_to_one_table[1 + MAX_BYTIND_GAP_SIZE_3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 /* Various macros modelled along the lines of those in buffer.h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Purposefully omitted from buffer.h because files other than this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 one should not be using them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 /* Address of beginning of buffer. This is an lvalue because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 BUFFER_ALLOC needs it to be. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 #define BUF_BEG_ADDR(buf) ((buf)->text->beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 /* Set the address of beginning of buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 #define SET_BUF_BEG_ADDR(buf, addr) do { (buf)->text->beg = (addr); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 /* Gap size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size + 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 /* Set gap size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 #define SET_BUF_GAP_SIZE(buf, value) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 do { (buf)->text->gap_size = (value); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 /* Gap location. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 #define BI_BUF_GPT(buf) ((buf)->text->gpt + 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #define BUF_GPT_ADDR(buf) (BUF_BEG_ADDR (buf) + BI_BUF_GPT (buf) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 /* Set gap location. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 #define SET_BI_BUF_GPT(buf, value) do { (buf)->text->gpt = (value); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 /* Set end of buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 #define SET_BOTH_BUF_Z(buf, val, bival) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (buf)->text->z = (bival); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (buf)->text->bufz = (val); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 # define GAP_CAN_HOLD_SIZE_P(buf, len) (BUF_GAP_SIZE (buf) >= (len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 # define SET_GAP_SENTINEL(buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 # define BUF_END_SENTINEL_SIZE 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 # define SET_END_SENTINEL(buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 /* Charcount/Bytecount conversion */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 /* Optimization. Do it. Live it. Love it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 #ifdef ERROR_CHECK_BUFPOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 bufpos_to_bytind (struct buffer *buf, Bufpos x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 Bytind retval = real_bufpos_to_bytind (buf, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ASSERT_VALID_BYTIND_UNSAFE (buf, retval);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 return retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 bytind_to_bufpos (struct buffer *buf, Bytind x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ASSERT_VALID_BYTIND_UNSAFE (buf, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 return real_bytind_to_bufpos (buf, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 #endif /* ERROR_CHECK_BUFPOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 /* verifying buffer and string positions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 /* Functions below are tagged with either _byte or _char indicating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 whether they return byte or character positions. For a buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 a character position is a "Bufpos" and a byte position is a "Bytind".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 For strings, these are sometimes typed using "Charcount" and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "Bytecount". */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 /* Flags for the functions below are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 GB_ALLOW_PAST_ACCESSIBLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 The allowable range for the position is the entire buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (BEG and Z), rather than the accessible portion. For strings,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 this flag has no effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 GB_COERCE_RANGE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 If the position is outside the allowable range, return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 the lower or upper bound of the range, whichever is closer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 to the specified position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 GB_NO_ERROR_IF_BAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 If the position is outside the allowable range, return -1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 GB_NEGATIVE_FROM_END
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 If a value is negative, treat it as an offset from the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Only applies to strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 The following additional flags apply only to the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 that return ranges:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 GB_ALLOW_NIL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 Either or both positions can be nil. If FROM is nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 FROM_OUT will contain the lower bound of the allowed range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 If TO is nil, TO_OUT will contain the upper bound of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 allowed range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 GB_CHECK_ORDER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 FROM must contain the lower bound and TO the upper bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 of the range. If the positions are reversed, an error is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 signalled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 The following is a combination flag:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 GB_HISTORICAL_STRING_BEHAVIOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 Equivalent to (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 /* Return a buffer position stored in a Lisp_Object. Full
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 error-checking is done on the position. Flags can be specified to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 control the behavior of out-of-range values. The default behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 is to require that the position is within the accessible part of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 the buffer (BEGV and ZV), and to signal an error if the position is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 out of range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 get_buffer_pos_char (struct buffer *b, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 Bufpos ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 Bufpos min_allowed, max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 CHECK_INT_COERCE_MARKER (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ind = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 min_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 BUF_BEG (b) : BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 max_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 BUF_Z (b) : BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (ind < min_allowed || ind > max_allowed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 if (flags & GB_COERCE_RANGE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ind = ind < min_allowed ? min_allowed : max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 else if (flags & GB_NO_ERROR_IF_BAD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ind = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 XSETBUFFER (buffer, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 args_out_of_range (buffer, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 return ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 get_buffer_pos_byte (struct buffer *b, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 Bufpos bpos = get_buffer_pos_char (b, pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (bpos < 0) /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 return bufpos_to_bytind (b, bpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 /* Return a pair of buffer positions representing a range of text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 taken from a pair of Lisp_Objects. Full error-checking is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 done on the positions. Flags can be specified to control the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 behavior of out-of-range values. The default behavior is to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 allow the range bounds to be specified in either order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (however, FROM_OUT will always be the lower bound of the range
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 and TO_OUT the upper bound),to require that the positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 are within the accessible part of the buffer (BEGV and ZV),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 and to signal an error if the positions are out of range.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 Bufpos *from_out, Bufpos *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 Bufpos min_allowed, max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 min_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 BUF_BEG (b) : BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 max_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 BUF_Z (b) : BUF_ZV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 if (NILP (from) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 *from_out = min_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 *from_out = get_buffer_pos_char (b, from, flags | GB_NO_ERROR_IF_BAD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 if (NILP (to) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 *to_out = max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 *to_out = get_buffer_pos_char (b, to, flags | GB_NO_ERROR_IF_BAD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 if ((*from_out < 0 || *to_out < 0) && !(flags & GB_NO_ERROR_IF_BAD))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 XSETBUFFER (buffer, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 args_out_of_range_3 (buffer, from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 if (*from_out >= 0 && *to_out >= 0 && *from_out > *to_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (flags & GB_CHECK_ORDER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 signal_simple_error_2 ("start greater than end", from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 Bufpos temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 temp = *from_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 *from_out = *to_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 *to_out = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Bytind *from_out, Bytind *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 Bufpos s, e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 get_buffer_range_char (b, from, to, &s, &e, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 if (s >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 *from_out = bufpos_to_bytind (b, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 else /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 *from_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 if (e >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 *to_out = bufpos_to_bytind (b, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 *to_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 static Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 get_string_pos_char_1 (Lisp_Object string, Lisp_Object pos, unsigned int flags,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 Charcount known_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 Charcount ccpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 Charcount min_allowed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Charcount max_allowed = known_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 /* Computation of KNOWN_LENGTH is potentially expensive so we pass
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 it in. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 CHECK_INT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ccpos = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 if (ccpos < 0 && flags & GB_NEGATIVE_FROM_END)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ccpos += max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 if (ccpos < min_allowed || ccpos > max_allowed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 if (flags & GB_COERCE_RANGE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ccpos = ccpos < min_allowed ? min_allowed : max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 else if (flags & GB_NO_ERROR_IF_BAD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ccpos = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 args_out_of_range (string, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 return ccpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 get_string_pos_char (Lisp_Object string, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 return get_string_pos_char_1 (string, pos, flags,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 string_char_length (XSTRING (string)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 get_string_pos_byte (Lisp_Object string, Lisp_Object pos, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 Charcount ccpos = get_string_pos_char (string, pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 if (ccpos < 0) /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 return -1;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
503 return charcount_to_bytecount (XSTRING_DATA (string), ccpos);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 get_string_range_char (Lisp_Object string, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 Charcount *from_out, Charcount *to_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 Charcount min_allowed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 Charcount max_allowed = string_char_length (XSTRING (string));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 if (NILP (from) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 *from_out = min_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 *from_out = get_string_pos_char_1 (string, from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 flags | GB_NO_ERROR_IF_BAD,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 max_allowed);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if (NILP (to) && (flags & GB_ALLOW_NIL))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 *to_out = max_allowed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 *to_out = get_string_pos_char_1 (string, to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 flags | GB_NO_ERROR_IF_BAD,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 max_allowed);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 if ((*from_out < 0 || *to_out < 0) && !(flags & GB_NO_ERROR_IF_BAD))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 args_out_of_range_3 (string, from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 if (*from_out >= 0 && *to_out >= 0 && *from_out > *to_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 if (flags & GB_CHECK_ORDER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 signal_simple_error_2 ("start greater than end", from, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 Bufpos temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 temp = *from_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 *from_out = *to_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 *to_out = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 get_string_range_byte (Lisp_Object string, Lisp_Object from, Lisp_Object to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 Bytecount *from_out, Bytecount *to_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 Charcount s, e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 get_string_range_char (string, from, to, &s, &e, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 if (s >= 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
555 *from_out = charcount_to_bytecount (XSTRING_DATA (string), s);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 else /* could happen with GB_NO_ERROR_IF_BAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 *from_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 if (e >= 0)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
559 *to_out = charcount_to_bytecount (XSTRING_DATA (string), e);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 *to_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 return get_string_pos_char (object, pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 return get_buffer_pos_char (XBUFFER (object), pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 return get_string_pos_byte (object, pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 return get_buffer_pos_byte (XBUFFER (object), pos, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 Lisp_Object to, Bufpos *from_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 Bufpos *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 get_string_range_char (object, from, to, from_out, to_out, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 get_buffer_range_char (XBUFFER (object), from, to, from_out, to_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 Lisp_Object to, Bytind *from_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 Bytind *to_out, unsigned int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 get_string_range_byte (object, from, to, from_out, to_out, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 get_buffer_range_byte (XBUFFER (object), from, to, from_out, to_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 buffer_or_string_accessible_begin_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 return BUF_BEGV (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 buffer_or_string_accessible_end_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 return string_char_length (XSTRING (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 return BUF_ZV (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 buffer_or_string_accessible_begin_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 return BI_BUF_BEGV (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 buffer_or_string_accessible_end_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 if (STRINGP (object))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
637 return XSTRING_LENGTH (object);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 return BI_BUF_ZV (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 buffer_or_string_absolute_begin_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 return BUF_BEG (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 buffer_or_string_absolute_end_char (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 return string_char_length (XSTRING (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 return BUF_Z (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 buffer_or_string_absolute_begin_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 if (STRINGP (object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 return BI_BUF_BEG (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 Bytind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 buffer_or_string_absolute_end_byte (Lisp_Object object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 if (STRINGP (object))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
669 return XSTRING_LENGTH (object);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 return BI_BUF_Z (XBUFFER (object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 /* point and marker adjustment */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 /* just_set_point() is the only place `PT' is an lvalue in all of emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 This function is called from set_buffer_point(), which is the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 that the SET_PT and BUF_SET_PT macros expand into, and from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 routines below that insert and delete text. (This is in cases where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 the point marker logically doesn't move but PT (being a byte index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 needs to get adjusted.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 /* Set point to a specified value. This is used only when the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 of point changes due to an insert or delete; it does not represent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 a conceptual change in point as a marker. In particular, point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 not crossing any interval boundaries, so there's no need to use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 usual SET_PT macro. In fact it would be incorrect to do so, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 either the old or the new value of point is out of synch with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 current set of intervals. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 /* This gets called more than enough to make the function call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 overhead a significant factor so we've turned it into a macro. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 #define JUST_SET_POINT(buf, bufpos, ind) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 buf->bufpt = (bufpos); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 buf->pt = (ind); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 /* Set a buffer's point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 set_buffer_point (struct buffer *buf, Bufpos bufpos, Bytind bytpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 assert (bytpos >= BI_BUF_BEGV (buf) && bytpos <= BI_BUF_ZV (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 if (bytpos == BI_BUF_PT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 JUST_SET_POINT (buf, bufpos, bytpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 MARK_POINT_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 assert (MARKERP (buf->point_marker));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 XMARKER (buf->point_marker)->memind =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 bytind_to_memind (buf, bytpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 /* FSF makes sure that PT is not being set within invisible text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 However, this is the wrong place for that check. The check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 should happen only at the next redisplay. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 /* Some old coder said:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 "If there were to be hooks which were run when point entered/left an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 extent, this would be the place to put them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 However, it's probably the case that such hooks should be implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 using a post-command-hook instead, to avoid running the hooks as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 result of intermediate motion inside of save-excursions, for example."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 I definitely agree with this. PT gets moved all over the place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 and it would be a Bad Thing for any hooks to get called, both for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 the reason above and because many callers are not prepared for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 a GC within this function. --ben
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 /* Do the correct marker-like adjustment on MPOS (see below). FROM, TO,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 and AMOUNT are as in adjust_markers(). If MPOS doesn't need to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 adjusted, nothing will happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 Memind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 do_marker_adjustment (Memind mpos, Memind from,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 Memind to, Bytecount amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 if (amount > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 if (mpos > to && mpos < to + amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 mpos = to + amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 if (mpos > from + amount && mpos <= from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 mpos = from + amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 if (mpos > from && mpos <= to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 mpos += amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 return mpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 /* Do the following:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (1) Add `amount' to the position of every marker in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 whose current position is between `from' (exclusive) and `to' (inclusive).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (2) Also, any markers past the outside of that interval, in the direction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 of adjustment, are first moved back to the near end of the interval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 and then adjusted by `amount'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 This function is called in two different cases: when a region of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 characters adjacent to the gap is moved, causing the gap to shift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 to the other side of the region (in this case, `from' and `to'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 point to the old position of the region and there should be no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 markers affected by (2) because they would be inside the gap),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 or when a region of characters adjacent to the gap is wiped out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 causing the gap to increase to include the region (in this case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 `from' and `to' are the same, both pointing to the boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 between the gap and the deleted region, and there are no markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 affected by (1)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 The reason for the use of exclusive and inclusive is that markers at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 the gap always sit at the beginning, not at the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 adjust_markers (struct buffer *buf, Memind from, Memind to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 Bytecount amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 for (m = BUF_MARKERS (buf); m; m = marker_next (m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 m->memind = do_marker_adjustment (m->memind, from, to, amount);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 /* Adjust markers whose insertion-type is t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 for an insertion of AMOUNT characters at POS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 struct Lisp_Marker *m;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 for (m = BUF_MARKERS (buf); m; m = marker_next (m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 if (m->insertion_type && m->memind == ind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 m->memind += amount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 /* Routines for dealing with the gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 /* XEmacs requires an ANSI C compiler, and it damn well better have a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 working memmove() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 #define GAP_USE_BCOPY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 #ifdef BCOPY_UPWARD_SAFE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 # undef BCOPY_UPWARD_SAFE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 #ifdef BCOPY_DOWNWARD_SAFE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 # undef BCOPY_DOWNWARD_SAFE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 #define BCOPY_UPWARD_SAFE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 #define BCOPY_DOWNWARD_SAFE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 /* maximum amount of memory moved in a single chunk. Increasing this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 value improves gap-motion efficiency but decreases QUIT responsiveness
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 time. Was 32000 but today's processors are faster and files are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 bigger. --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 #define GAP_MOVE_CHUNK 300000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 /* Move the gap to POS, which is less than the current GPT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 gap_left (struct buffer *buf, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 Bufbyte *to, *from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 Bytind new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 from = BUF_GPT_ADDR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 to = from + BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 new_s1 = BI_BUF_GPT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 /* Now copy the characters. To move the gap down,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 copy characters up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 /* I gets number of characters left to copy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 i = new_s1 - pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 if (i == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 /* If a quit is requested, stop copying now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 Change POS to be where we have actually moved the gap to. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 pos = new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 if (i > GAP_MOVE_CHUNK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 i = GAP_MOVE_CHUNK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 #ifdef GAP_USE_BCOPY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 if (i >= 128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 /* bcopy is safe if the two areas of memory do not overlap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 or on systems where bcopy is always safe for moving upward. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 && (BCOPY_UPWARD_SAFE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 || to - from >= 128))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 /* If overlap is not safe, avoid it by not moving too many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 characters at once. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 if (!BCOPY_UPWARD_SAFE && i > to - from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 i = to - from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 new_s1 -= i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 from -= i, to -= i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 memmove (to, from, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 new_s1 -= i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 while (--i >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 *--to = *--from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 /* Adjust markers, and buffer data structure, to put the gap at POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 POS is where the loop above stopped, which may be what was specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 or may be where a quit was detected. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 adjust_markers (buf, pos, BI_BUF_GPT (buf), BUF_GAP_SIZE (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 adjust_extents (make_buffer (buf), pos, BI_BUF_GPT (buf),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 BUF_GAP_SIZE (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 SET_BI_BUF_GPT (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 #ifdef ERROR_CHECK_EXTENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 sledgehammer_extent_check (make_buffer (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 gap_right (struct buffer *buf, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 Bufbyte *to, *from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 Bytind new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 to = BUF_GPT_ADDR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 from = to + BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 new_s1 = BI_BUF_GPT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 /* Now copy the characters. To move the gap up,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 copy characters down. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 /* I gets number of characters left to copy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 i = pos - new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 if (i == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 /* If a quit is requested, stop copying now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 Change POS to be where we have actually moved the gap to. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 pos = new_s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 if (i > GAP_MOVE_CHUNK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 i = GAP_MOVE_CHUNK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 #ifdef GAP_USE_BCOPY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 if (i >= 128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 /* bcopy is safe if the two areas of memory do not overlap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 or on systems where bcopy is always safe for moving downward. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 && (BCOPY_DOWNWARD_SAFE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 || from - to >= 128))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 /* If overlap is not safe, avoid it by not moving too many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 characters at once. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 if (!BCOPY_DOWNWARD_SAFE && i > from - to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 i = from - to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 new_s1 += i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 memmove (to, from, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 from += i, to += i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 new_s1 += i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 while (--i >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 *to++ = *from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 int gsize = BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 adjust_markers (buf, BI_BUF_GPT (buf) + gsize, pos + gsize, - gsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 adjust_extents (make_buffer (buf), BI_BUF_GPT (buf) + gsize, pos + gsize,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 - gsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 SET_BI_BUF_GPT (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 #ifdef ERROR_CHECK_EXTENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 sledgehammer_extent_check (make_buffer (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 /* Move gap to position `pos'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 Note that this can quit! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 move_gap (struct buffer *buf, Bytind pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 if (! BUF_BEG_ADDR (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 if (pos < BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 gap_left (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 else if (pos > BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 gap_right (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 /* Make the gap INCREMENT bytes longer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 make_gap (struct buffer *buf, Bytecount increment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 Bufbyte *result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 Bytind real_gap_loc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 Bytecount old_gap_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 /* If we have to get more space, get enough to last a while. We use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 a geometric progession that saves on realloc space. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 increment += 2000 + ((BI_BUF_Z (buf) - BI_BUF_BEG (buf)) / 8);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 /* Don't allow a buffer size that won't fit in an int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 even if it will fit in a Lisp integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 That won't work because so many places use `int'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 if (BUF_Z (buf) - BUF_BEG (buf) + BUF_GAP_SIZE (buf) + increment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 >= ((unsigned) 1 << (min (INTBITS, VALBITS) - 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 error ("Buffer exceeds maximum size");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 result = BUFFER_REALLOC (buf->text->beg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 BI_BUF_Z (buf) - BI_BUF_BEG (buf) +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 BUF_GAP_SIZE (buf) + increment +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 BUF_END_SENTINEL_SIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 if (result == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 SET_BUF_BEG_ADDR (buf, result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 /* Prevent quitting in move_gap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 tem = Vinhibit_quit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 Vinhibit_quit = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 real_gap_loc = BI_BUF_GPT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 old_gap_size = BUF_GAP_SIZE (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 /* Call the newly allocated space a gap at the end of the whole space. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 SET_BI_BUF_GPT (buf, BI_BUF_Z (buf) + BUF_GAP_SIZE (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 SET_BUF_GAP_SIZE (buf, increment);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 /* Move the new gap down to be consecutive with the end of the old one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 This adjusts the markers properly too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 gap_left (buf, real_gap_loc + old_gap_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 /* Now combine the two into one large gap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 SET_BI_BUF_GPT (buf, real_gap_loc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 /* We changed the total size of the buffer (including gap),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 so we need to fix up the end sentinel. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 SET_END_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 Vinhibit_quit = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 /* Before/after-change processing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 /* Those magic changes ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 buffer_signal_changed_region (struct buffer *buf, Bufpos start,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 /* The changed region is recorded as the number of unchanged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 characters from the beginning and from the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 buffer. This obviates much of the need of shifting the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 region around to compensate for insertions and deletions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 if (buf->changes->begin_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 buf->changes->begin_unchanged > start - BUF_BEG (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 buf->changes->begin_unchanged = start - BUF_BEG (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 if (buf->changes->end_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 buf->changes->end_unchanged > BUF_Z (buf) - end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 buf->changes->end_unchanged = BUF_Z (buf) - end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 buffer_extent_signal_changed_region (struct buffer *buf, Bufpos start,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 if (buf->changes->begin_extent_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 buf->changes->begin_extent_unchanged > start - BUF_BEG (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 buf->changes->begin_extent_unchanged = start - BUF_BEG (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 if (buf->changes->end_extent_unchanged < 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 buf->changes->end_extent_unchanged > BUF_Z (buf) - end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 buf->changes->end_extent_unchanged = BUF_Z (buf) - end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 buffer_reset_changes (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 buf->changes->begin_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 buf->changes->end_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 buf->changes->begin_extent_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 buf->changes->end_extent_unchanged = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 buf->changes->newline_was_deleted = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 Bufpos new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 /* Call the after-change-functions according to the changes made so far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 and treat all further changes as single until the outermost
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 multiple change exits. This is called when the outermost multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 change exits and when someone is trying to make a change that violates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 the constraints specified in begin_multiple_change(), typically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 when nested multiple-change sessions occur. (There are smarter ways of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 dealing with nested multiple changes, but these rarely occur so there's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 probably no point in it.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 /* #### This needs to keep track of what actually changed and only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 call the after-change functions on that region. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 cancel_multiple_change (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 /* Call the after-change-functions except when they've already been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 called or when there were no changes made to the buffer at all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 if (buf->text->changes->mc_begin != 0 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 buf->text->changes->mc_begin_signaled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 Bufpos real_mc_begin = buf->text->changes->mc_begin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 buf->text->changes->mc_begin = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 signal_after_change (buf, real_mc_begin, buf->text->changes->mc_orig_end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 buf->text->changes->mc_new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 buf->text->changes->mc_begin = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 /* this is an unwind_protect, to ensure that the after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 get called even in a non-local exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 multiple_change_finish_up (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 struct buffer *buf = XBUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 /* #### I don't know whether or not it should even be possible to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 get here with a dead buffer (though given how it is called I can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 see how it might be). In any case, there isn't time before 19.14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 to find out. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 buf->text->changes->in_multiple_change = 0; /* do this first so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 errors in the after-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 functions don't mess things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 cancel_multiple_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 /* Call this function when you're about to make a number of buffer changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 that should be considered a single change. (e.g. `replace-match' calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 this.) You need to specify the START and END of the region that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 going to be changed so that the before-change-functions are called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 with the correct arguments. The after-change region is calculated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 automatically, however, and if changes somehow or other happen outside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 of the specified region, that will also be handled correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 begin_multiple_change() returns a number (actually a specpdl depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 that you must pass to end_multiple_change() when you are done. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 int count = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 if (buf->text->changes->in_multiple_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 if (buf->text->changes->mc_begin != 0 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (start < buf->text->changes->mc_begin ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 end > buf->text->changes->mc_new_end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 cancel_multiple_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 buf->text->changes->mc_begin = start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 buf->text->changes->mc_orig_end = buf->text->changes->mc_new_end = end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 buf->text->changes->mc_begin_signaled = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 record_unwind_protect (multiple_change_finish_up, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 buf->text->changes->in_multiple_change++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 /* We don't call before-change-functions until signal_before_change()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 is called, in case there is a read-only or other error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 return count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 end_multiple_change (struct buffer *buf, int count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 assert (buf->text->changes->in_multiple_change > 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 buf->text->changes->in_multiple_change--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 if (!buf->text->changes->in_multiple_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 static int inside_change_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 change_function_restore (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 Fset_buffer (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 inside_change_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 static int in_first_change;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 first_change_hook_restore (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 Fset_buffer (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 in_first_change = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 /* Signal an initial modification to the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 signal_first_change (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 if (!in_first_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 if (!preparing_for_armageddon &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 !NILP (symbol_value_in_buffer (Qfirst_change_hook, buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 record_unwind_protect (first_change_hook_restore, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 set_buffer_internal (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 in_first_change = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 run_hook (Qfirst_change_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 /* Signal a change to the buffer immediately before it happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 START and END are the bounds of the text to be changed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 signal_before_change (struct buffer *buf, Bufpos start, Bufpos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 if (!inside_change_hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 /* Are we in a multiple-change session? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 if (buf->text->changes->in_multiple_change &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 buf->text->changes->mc_begin != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 /* If we're violating the constraints of the session,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 call the after-change-functions as necessary for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 changes already made and treat further changes as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 single. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 if (start < buf->text->changes->mc_begin ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 end > buf->text->changes->mc_new_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 cancel_multiple_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 /* Do nothing if this is not the first change in the session. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 else if (buf->text->changes->mc_begin_signaled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 /* First time through; call the before-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 specifying the entire region to be changed. (Note that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 we didn't call before-change-functions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 begin_multiple_change() because the buffer might be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 read-only, etc.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 start = buf->text->changes->mc_begin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 end = buf->text->changes->mc_new_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 /* If buffer is unmodified, run a special hook for that case. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 if (BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 signal_first_change (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 /* Now in any case run the before-change-functions if any. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 if (!preparing_for_armageddon &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (!NILP (symbol_value_in_buffer (Qbefore_change_functions, buffer)) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 /* Obsolete, for compatibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 record_unwind_protect (change_function_restore, Fcurrent_buffer ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 set_buffer_internal (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 inside_change_hook = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 va_run_hook_with_args (Qbefore_change_functions, 2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 make_int (start), make_int (end));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 /* Obsolete, for compatibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 va_run_hook_with_args (Qbefore_change_function, 2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 make_int (start), make_int (end));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 /* Only now do we indicate that the before-change-functions have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 been called, in case some function throws out. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 buf->text->changes->mc_begin_signaled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 /* #### At this point we should map over extents calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 modification-hooks, insert-before-hooks and insert-after-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 of relevant extents */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 /* Signal a change immediately after it happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 START is the bufpos of the start of the changed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 ORIG_END is the bufpos of the end of the before-changed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 NEW_END is the bufpos of the end of the after-changed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 signal_after_change (struct buffer *buf, Bufpos start, Bufpos orig_end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 Bufpos new_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 /* always do this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 buffer_signal_changed_region (buf, start, new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 font_lock_maybe_update_syntactic_caches (buf, start, orig_end, new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 if (!inside_change_hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 if (buf->text->changes->in_multiple_change &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 buf->text->changes->mc_begin != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 assert (start >= buf->text->changes->mc_begin &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 start <= buf->text->changes->mc_new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 assert (orig_end >= buf->text->changes->mc_begin &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 orig_end <= buf->text->changes->mc_new_end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 buf->text->changes->mc_new_end += new_end - orig_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 return; /* after-change-functions signalled when all changes done */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 if (!preparing_for_armageddon &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (!NILP (symbol_value_in_buffer (Qafter_change_functions, buffer)) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 /* Obsolete, for compatibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 !NILP (symbol_value_in_buffer (Qafter_change_function, buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 record_unwind_protect (change_function_restore, Fcurrent_buffer ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 set_buffer_internal (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 inside_change_hook = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 /* The actual after-change functions take slightly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 different arguments than what we were passed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 va_run_hook_with_args (Qafter_change_functions, 3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 make_int (start), make_int (new_end),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 make_int (orig_end - start));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 /* Obsolete, for compatibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 va_run_hook_with_args (Qafter_change_function, 3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 make_int (start), make_int (new_end),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 make_int (orig_end - start));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 /* #### At this point we should map over extents calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 some sort of modification hooks of relevant extents */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 /* Call this if you're about to change the region of BUFFER from START
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 to END. This checks the read-only properties of the region, calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 the necessary modification hooks, and warns the next redisplay that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 it should pay attention to that area. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 prepare_to_modify_buffer (struct buffer *buf, Bufpos start, Bufpos end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 int lockit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 barf_if_buffer_read_only (buf, start, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 /* if this is the first modification, see about locking the buffer's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 if (!NILP (buf->filename) && lockit &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 #ifdef CLASH_DETECTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 if (!NILP (buf->file_truename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 /* Make binding buffer-file-name to nil effective. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 lock_file (buf->file_truename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 /* At least warn if this file has changed on disk since it was visited.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 if (NILP (Fverify_visited_file_modtime (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 && !NILP (Ffile_exists_p (buf->filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 call1_in_buffer (buf, intern ("ask-user-about-supersession-threat"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 buf->filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 #endif /* not CLASH_DETECTION */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 signal_before_change (buf, start, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 #ifdef REGION_CACHE_NEEDS_WORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 if (buf->newline_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 invalidate_region_cache (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 buf->newline_cache,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 start - BUF_BEG (buf), BUF_Z (buf) - end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 if (buf->width_run_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 invalidate_region_cache (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 buf->width_run_cache,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 start - BUF_BEG (buf), BUF_Z (buf) - end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 #if 0 /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 Vdeactivate_mark = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 buf->point_before_scroll = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 /* BUF_MODIFF (buf)++; -- should be done by callers (insert, delete range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 else record_first_change isn't called */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 /* Insertion of strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 fixup_internal_substring (CONST Bufbyte *nonreloc, Lisp_Object reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 Bytecount offset, Bytecount *len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 assert ((nonreloc && NILP (reloc)) || (!nonreloc && STRINGP (reloc)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 if (*len < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 if (nonreloc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 *len = strlen ((CONST char *) nonreloc) - offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 else
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1438 *len = XSTRING_LENGTH (reloc) - offset;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 assert (*len >= 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 if (STRINGP (reloc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1443 assert (offset >= 0 && offset <= XSTRING_LENGTH (reloc));
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1444 assert (offset + *len <= XSTRING_LENGTH (reloc));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 /* Insert a string into BUF at Bufpos POS. The string data comes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 from one of two sources: constant, non-relocatable data (specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 in NONRELOC), or a Lisp string object (specified in RELOC), which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 is relocatable and may have extent data that needs to be copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 into the buffer. OFFSET and LENGTH specify the substring of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 data that is actually to be inserted. As a special case, if POS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 is -1, insert the string at point and move point to the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 Normally, markers at the insertion point end up before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 inserted string. If INSDEL_BEFORE_MARKERS is set in flags, however,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 they end up after the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 INSDEL_NO_LOCKING is kludgy and is used when insert-file-contents is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 visiting a new file; it inhibits the locking checks normally done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 before modifying a buffer. Similar checks were already done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 in the higher-level Lisp functions calling insert-file-contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 buffer_insert_string_1 (struct buffer *buf, Bufpos pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 CONST Bufbyte *nonreloc, Lisp_Object reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 Bytecount offset, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 Bytind ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 Charcount cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 int move_point = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 /* Defensive steps just in case a buffer gets deleted and a calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 function doesn't notice it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 fixup_internal_substring (nonreloc, reloc, offset, &length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 if (pos == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 pos = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 move_point = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 /* #### See the comment in print_internal(). If this buffer is marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 as translatable, then Fgettext() should be called on obj if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 is a string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 /* Make sure that point-max won't exceed the size of an emacs int. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 Lisp_Object temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 XSETINT (temp, (int) (length + BUF_Z (buf)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 if ((int) (length + BUF_Z (buf)) != XINT (temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 error ("maximum buffer size exceeded");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 /* theoretically not necessary -- caller should GCPRO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 GCPRO1 (reloc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 prepare_to_modify_buffer (buf, pos, pos, !(flags & INSDEL_NO_LOCKING));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 /* Defensive steps in case the before-change-functions fuck around */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 modified the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 if (pos < BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 pos = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 if (pos > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 pos = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 /* string may have been relocated up to this point */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 if (STRINGP (reloc))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1528 nonreloc = XSTRING_DATA (reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 ind = bufpos_to_bytind (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 cclen = bytecount_to_charcount (nonreloc + offset, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 if (ind != BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 /* #### if debug-on-quit is invoked and the user changes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 buffer, bad things can happen. This is a rampant problem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 in Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 move_gap (buf, ind); /* may QUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 if (! GAP_CAN_HOLD_SIZE_P (buf, length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 make_gap (buf, length - BUF_GAP_SIZE (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 record_insert (buf, pos, cclen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 BUF_MODIFF (buf)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 MARK_BUFFERS_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 /* string may have been relocated up to this point */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 if (STRINGP (reloc))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1547 nonreloc = XSTRING_DATA (reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 memcpy (BUF_GPT_ADDR (buf), nonreloc + offset, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 SET_BI_BUF_GPT (buf, BI_BUF_GPT (buf) + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) + cclen, BI_BUF_ZV (buf) + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 SET_BOTH_BUF_Z (buf, BUF_Z (buf) + cclen, BI_BUF_Z (buf) + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 process_extents_for_insertion (make_buffer (buf), ind, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 /* We know the gap is at IND so the cast is OK. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 adjust_markers_for_insert (buf, (Memind) ind, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 /* Point logically doesn't move, but may need to be adjusted because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 it's a byte index. point-marker doesn't change because it's a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 memory index. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 if (BI_BUF_PT (buf) > ind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 JUST_SET_POINT (buf, BUF_PT (buf) + cclen, BI_BUF_PT (buf) + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 /* Well, point might move. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 if (move_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 BI_BUF_SET_PT (buf, ind + length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 if (STRINGP (reloc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 splice_in_string_extents (reloc, buf, ind, length, offset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 if (flags & INSDEL_BEFORE_MARKERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 /* ind - 1 is correct because the FROM argument is exclusive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 I formerly used DEC_BYTIND() but that caused problems at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 beginning of the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 adjust_markers (buf, ind - 1, ind, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 signal_after_change (buf, pos, pos, pos + cclen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 return cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 /* The following functions are interfaces onto the above function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 for inserting particular sorts of data. In all the functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 BUF and POS specify the buffer and location where the insertion is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 to take place. (If POS is -1, text is inserted at point and point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 moves forward past the text.) FLAGS is as above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 buffer_insert_raw_string_1 (struct buffer *buf, Bufpos pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 CONST Bufbyte *nonreloc, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 return buffer_insert_string_1 (buf, pos, nonreloc, Qnil, 0, length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 buffer_insert_lisp_string_1 (struct buffer *buf, Bufpos pos, Lisp_Object str,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 assert (STRINGP (str));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 return buffer_insert_string_1 (buf, pos, 0, str, 0,
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1613 XSTRING_LENGTH (str),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 /* Insert the null-terminated string S (in external format). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 CONST char *translated = GETTEXT (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 0, strlen (translated), flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 buffer_insert_emacs_char_1 (struct buffer *buf, Bufpos pos, Emchar ch,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 len = set_charptr_emchar (str, ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 return buffer_insert_string_1 (buf, pos, str, Qnil, 0, len, flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 buffer_insert_c_char_1 (struct buffer *buf, Bufpos pos, char c,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 return buffer_insert_emacs_char_1 (buf, pos, (Emchar) (unsigned char) c,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 flags);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 buffer_insert_from_buffer_1 (struct buffer *buf, Bufpos pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 struct buffer *buf2, Bufpos pos2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 Charcount length, int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 Lisp_Object str = make_string_from_buffer (buf2, pos2, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 return buffer_insert_string_1 (buf, pos, 0, str, 0,
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1659 XSTRING_LENGTH (str), flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 /* Deletion of ranges */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 /* Delete characters in buffer from FROM up to (but not including) TO. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 buffer_delete_range (struct buffer *buf, Bufpos from, Bufpos to, int flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 Charcount numdel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 Bytind bi_from, bi_to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 Bytecount bc_numdel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 int shortage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 Lisp_Object bufobj = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 /* Defensive steps just in case a buffer gets deleted and a calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 function doesn't notice it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 /* Make args be valid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 if (from < BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 from = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 if (to > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 to = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 if ((numdel = to - from) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 prepare_to_modify_buffer (buf, from, to, !(flags & INSDEL_NO_LOCKING));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 /* Defensive steps in case the before-change-functions fuck around */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 if (!BUFFER_LIVE_P (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 modified the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 if (from < BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 from = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 if (to > BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 to = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 if ((numdel = to - from) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 XSETBUFFER (bufobj, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 /* Redisplay needs to know if a newline was in the deleted region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 If we've already marked the changed region as having a deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 newline there is no use in performing the check. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 if (!buf->changes->newline_was_deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 scan_buffer (buf, '\n', from, to, 1, &shortage, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 if (!shortage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 buf->changes->newline_was_deleted = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 bi_from = bufpos_to_bytind (buf, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 bi_to = bufpos_to_bytind (buf, to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 bc_numdel = bi_to - bi_from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 /* Make sure the gap is somewhere in or next to what we are deleting. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 if (bi_to < BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 gap_left (buf, bi_to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 if (bi_from > BI_BUF_GPT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 gap_right (buf, bi_from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 record_delete (buf, from, numdel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 BUF_MODIFF (buf)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 MARK_BUFFERS_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 /* Relocate point as if it were a marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 if (bi_from < BI_BUF_PT (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 if (BI_BUF_PT (buf) < bi_to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 JUST_SET_POINT (buf, from, bi_from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 JUST_SET_POINT (buf, BUF_PT (buf) - numdel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 BI_BUF_PT (buf) - bc_numdel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 /* Detach any extents that are completely within the range [FROM, TO],
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 if the extents are detachable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 This must come AFTER record_delete(), so that the appropriate extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 will be present to be recorded, and BEFORE the gap size is increased,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 as otherwise we will be confused about where the extents end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 process_extents_for_deletion (bufobj, bi_from, bi_to, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 /* Relocate all markers pointing into the new, larger gap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 to point at the end of the text before the gap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 adjust_markers (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (bi_to + BUF_GAP_SIZE (buf)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (bi_to + BUF_GAP_SIZE (buf)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (- bc_numdel - BUF_GAP_SIZE (buf)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 /* Relocate any extent endpoints just like markers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 adjust_extents_for_deletion (bufobj, bi_from, bi_to, BUF_GAP_SIZE (buf),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 bc_numdel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + bc_numdel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 SET_BOTH_BUF_ZV (buf, BUF_ZV (buf) - numdel, BI_BUF_ZV (buf) - bc_numdel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BI_BUF_Z (buf) - bc_numdel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 SET_BI_BUF_GPT (buf, bi_from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 SET_GAP_SENTINEL (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 #ifdef ERROR_CHECK_EXTENTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 sledgehammer_extent_check (bufobj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 signal_after_change (buf, from, to, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 /* Replacement of characters */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 /* Replace the character at POS in buffer B with CH. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 buffer_replace_char (struct buffer *b, Bufpos pos, Emchar ch,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 int not_real_change, int force_lock_check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 Bufbyte curstr[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 Bufbyte newstr[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 Bytecount curlen, newlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 /* Defensive steps just in case a buffer gets deleted and a calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 function doesn't notice it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 if (!BUFFER_LIVE_P (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 curlen = BUF_CHARPTR_COPY_CHAR (b, pos, curstr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 newlen = set_charptr_emchar (newstr, ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 if (curlen == newlen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 /* then we can just replace the text. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 prepare_to_modify_buffer (b, pos, pos + 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 !not_real_change || force_lock_check);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 /* Defensive steps in case the before-change-functions fuck around */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 if (!BUFFER_LIVE_P (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 modified the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 if (pos < BUF_BEGV (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 pos = BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 if (pos >= BUF_ZV (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 pos = BUF_ZV (b) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 if (pos < BUF_BEGV (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 /* no more characters in buffer! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 if (BUF_FETCH_CHAR (b, pos) == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 b->changes->newline_was_deleted = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 MARK_BUFFERS_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 if (!not_real_change)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 record_change (b, pos, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 BUF_MODIFF (b)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 memcpy (BUF_BYTE_ADDRESS (b, pos), newstr, newlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 signal_after_change (b, pos, pos + 1, pos + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 /* must implement as deletion followed by insertion. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 buffer_delete_range (b, pos, pos + 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 /* Defensive steps in case the before-change-functions fuck around */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 if (!BUFFER_LIVE_P (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 /* Bad bad pre-change function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 /* Make args be valid again. prepare_to_modify_buffer() might have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 modified the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 if (pos < BUF_BEGV (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 pos = BUF_BEGV (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 if (pos >= BUF_ZV (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 pos = BUF_ZV (b) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 if (pos < BUF_BEGV (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 /* no more characters in buffer! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 buffer_insert_string_1 (b, pos, newstr, Qnil, 0, newlen, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 /* Other functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 /* Make a string from a buffer. This needs to take into account the gap,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 and add any necessary extents from the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 make_string_from_buffer (struct buffer *buf, Bufpos pos, Charcount length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 Bytind bi_ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 Bytecount bi_len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 bi_ind = bufpos_to_bytind (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 bi_len = bufpos_to_bytind (buf, pos + length) - bi_ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 val = make_uninit_string (bi_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 GCPRO1 (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 add_string_extents (val, buf, bi_ind, bi_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 Bytecount len1 = BI_BUF_GPT (buf) - bi_ind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 Bufbyte *start1 = BI_BUF_BYTE_ADDRESS (buf, bi_ind);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1881 Bufbyte *dest = XSTRING_DATA (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 if (len1 < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 /* Completely after gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 memcpy (dest, start1, bi_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 else if (bi_len <= len1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 /* Completely before gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 memcpy (dest, start1, bi_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 /* Spans gap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 Bytind pos2 = bi_ind + len1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 Bufbyte *start2 = BI_BUF_BYTE_ADDRESS (buf, pos2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 memcpy (dest, start1, len1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 memcpy (dest + len1, start2, bi_len - len1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 barf_if_buffer_read_only (struct buffer *buf, Bufpos from, Bufpos to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 Lisp_Object buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 Lisp_Object iro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 XSETBUFFER (buffer, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 back:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 iro = (buf == current_buffer ? Vinhibit_read_only :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 symbol_value_in_buffer (Qinhibit_read_only, buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 if (!NILP (iro) && !CONSP (iro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 if (NILP (iro) && !NILP (buf->read_only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 Fsignal (Qbuffer_read_only, (list1 (buffer)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 goto back;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 if (from > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 if (to < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 to = from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 verify_extent_modification (buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 bufpos_to_bytind (buf, from),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 bufpos_to_bytind (buf, to),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 iro);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 find_charsets_in_bufbyte_string (unsigned char *charsets, CONST Bufbyte *str,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 Bytecount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 /* Telescope this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 charsets[0] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 find_charsets_in_emchar_string (unsigned char *charsets, CONST Emchar *str,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 Charcount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 /* Telescope this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 charsets[0] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 int cols = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 CONST Bufbyte *end = str + len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 while (str < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 cols++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 INC_CHARPTR (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 return cols;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 emchar_string_displayed_columns (CONST Emchar *str, Charcount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 int cols = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 for (i = 0; i < len; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 return cols;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 /* NOTE: Does not reset the Dynarr. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, Bytecount len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 emchar_dynarr *dyn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 CONST Bufbyte *strend = str + len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 while (str < strend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 Emchar ch = charptr_emchar (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 Dynarr_add (dyn, ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 INC_CHARPTR (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, Bytecount len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 Emchar *arr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 CONST Bufbyte *strend = str + len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 Charcount newlen = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 while (str < strend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 Emchar ch = charptr_emchar (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 arr[newlen++] = ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 INC_CHARPTR (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 return newlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 /* Convert an array of Emchars into the equivalent string representation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 Store into the given Bufbyte dynarr. Does not reset the dynarr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 Does not add a terminating zero. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 bufbyte_dynarr *dyn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 for (i = 0; i < nels; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 len = set_charptr_emchar (str, arr[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 Dynarr_add_many (dyn, str, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 /* Convert an array of Emchars into the equivalent string representation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 Malloc the space needed for this and return it. If LEN_OUT is not a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 NULL pointer, store into LEN_OUT the number of Bufbytes in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 malloc()ed string. Note that the actual number of Bufbytes allocated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 is one more than this: the returned string is zero-terminated. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 Bufbyte *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 Bytecount *len_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 /* Damn zero-termination. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 Bufbyte *str = (Bufbyte *) alloca (nels * MAX_EMCHAR_LEN + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 Bufbyte *strorig = str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 for (i = 0; i < nels; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 str += set_charptr_emchar (str, arr[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 *str = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 len = str - strorig;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 str = xmalloc (1 + len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 memcpy (str, strorig, 1 + len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 if (len_out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 *len_out = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 return str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 vars_of_insdel (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 inside_change_hook = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 in_first_change = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 three_to_one_table[i] = i / 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 init_buffer_text (struct buffer *b, int indirect_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 if (!indirect_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 SET_BUF_GAP_SIZE (b, 20);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (void) BUFFER_ALLOC (b->text->beg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 BUF_GAP_SIZE (b) + BUF_END_SENTINEL_SIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 if (! BUF_BEG_ADDR (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 SET_BI_BUF_GPT (b, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 SET_BOTH_BUF_Z (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 SET_GAP_SENTINEL (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 SET_END_SENTINEL (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 BUF_MODIFF (b) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 BUF_SAVE_MODIFF (b) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 JUST_SET_POINT (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 SET_BOTH_BUF_BEGV (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 SET_BOTH_BUF_ZV (b, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 b->text->changes =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (struct buffer_text_change_data *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 xmalloc (sizeof (*b->text->changes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 memset (b->text->changes, 0, sizeof (*b->text->changes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 JUST_SET_POINT (b, BUF_PT (b->base_buffer), BI_BUF_PT (b->base_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 SET_BOTH_BUF_BEGV (b, BUF_BEGV (b->base_buffer),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 BI_BUF_BEGV (b->base_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 SET_BOTH_BUF_ZV (b, BUF_ZV (b->base_buffer),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 BI_BUF_ZV (b->base_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 b->changes =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (struct each_buffer_change_data *) xmalloc (sizeof (*b->changes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 memset (b->changes, 0, sizeof (*b->changes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 BUF_FACECHANGE (b) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 #ifdef REGION_CACHE_NEEDS_WORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 b->newline_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 b->width_run_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 b->width_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 uninit_buffer_text (struct buffer *b, int indirect_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 if (!indirect_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 BUFFER_FREE (b->text->beg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 xfree (b->text->changes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 xfree (b->changes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 #ifdef REGION_CACHE_NEEDS_WORK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 if (b->newline_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 free_region_cache (b->newline_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 b->newline_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 if (b->width_run_cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 free_region_cache (b->width_run_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 b->width_run_cache = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 b->width_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 }