45 |
#include "window.h" |
#include "window.h" |
46 |
#include "commands.h" |
#include "commands.h" |
47 |
#include "buffer.h" |
#include "buffer.h" |
48 |
#include "charset.h" |
#include "character.h" |
49 |
#include "region-cache.h" |
#include "region-cache.h" |
50 |
#include "indent.h" |
#include "indent.h" |
51 |
#include "blockinput.h" |
#include "blockinput.h" |
186 |
static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *)); |
static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *)); |
187 |
static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT)); |
static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT)); |
188 |
|
|
189 |
|
extern char * emacs_strerror P_ ((int)); |
190 |
|
|
191 |
/* For debugging; temporary. See set_buffer_internal. */ |
/* For debugging; temporary. See set_buffer_internal. */ |
192 |
/* Lisp_Object Qlisp_mode, Vcheck_symbol; */ |
/* Lisp_Object Qlisp_mode, Vcheck_symbol; */ |
2079 |
doc: /* Set the multibyte flag of the current buffer to FLAG. |
doc: /* Set the multibyte flag of the current buffer to FLAG. |
2080 |
If FLAG is t, this makes the buffer a multibyte buffer. |
If FLAG is t, this makes the buffer a multibyte buffer. |
2081 |
If FLAG is nil, this makes the buffer a single-byte buffer. |
If FLAG is nil, this makes the buffer a single-byte buffer. |
2082 |
The buffer contents remain unchanged as a sequence of bytes |
In these cases, the buffer contents remain unchanged as a sequence of |
2083 |
but the contents viewed as characters do change. */) |
bytes but the contents viewed as characters do change. |
2084 |
|
If FLAG is `to', this makes the buffer a multibyte buffer by changing |
2085 |
|
all eight-bit bytes to eight-bit characters. */) |
2086 |
(flag) |
(flag) |
2087 |
Lisp_Object flag; |
Lisp_Object flag; |
2088 |
{ |
{ |
2152 |
p = GAP_END_ADDR; |
p = GAP_END_ADDR; |
2153 |
stop = Z; |
stop = Z; |
2154 |
} |
} |
2155 |
if (MULTIBYTE_STR_AS_UNIBYTE_P (p, bytes)) |
if (ASCII_BYTE_P (*p)) |
2156 |
p += bytes, pos += bytes; |
p++, pos++; |
2157 |
else |
else if (CHAR_BYTE8_HEAD_P (*p)) |
2158 |
{ |
{ |
2159 |
c = STRING_CHAR (p, stop - pos); |
c = STRING_CHAR_AND_LENGTH (p, stop - pos, bytes); |
2160 |
/* Delete all bytes for this 8-bit character but the |
/* Delete all bytes for this 8-bit character but the |
2161 |
last one, and change the last one to the charcter |
last one, and change the last one to the charcter |
2162 |
code. */ |
code. */ |
2171 |
zv -= bytes; |
zv -= bytes; |
2172 |
stop = Z; |
stop = Z; |
2173 |
} |
} |
2174 |
|
else |
2175 |
|
{ |
2176 |
|
bytes = BYTES_BY_CHAR_HEAD (*p); |
2177 |
|
p += bytes, pos += bytes; |
2178 |
|
} |
2179 |
} |
} |
2180 |
if (narrowed) |
if (narrowed) |
2181 |
Fnarrow_to_region (make_number (begv), make_number (zv)); |
Fnarrow_to_region (make_number (begv), make_number (zv)); |
2184 |
{ |
{ |
2185 |
int pt = PT; |
int pt = PT; |
2186 |
int pos, stop; |
int pos, stop; |
2187 |
unsigned char *p; |
unsigned char *p, *pend; |
2188 |
|
|
2189 |
/* Be sure not to have a multibyte sequence striding over the GAP. |
/* Be sure not to have a multibyte sequence striding over the GAP. |
2190 |
Ex: We change this: "...abc\201 _GAP_ \241def..." |
Ex: We change this: "...abc\302 _GAP_ \241def..." |
2191 |
to: "...abc _GAP_ \201\241def..." */ |
to: "...abc _GAP_ \302\241def..." */ |
2192 |
|
|
2193 |
if (GPT_BYTE > 1 && GPT_BYTE < Z_BYTE |
if (EQ (flag, Qt) |
2194 |
|
&& GPT_BYTE > 1 && GPT_BYTE < Z_BYTE |
2195 |
&& ! CHAR_HEAD_P (*(GAP_END_ADDR))) |
&& ! CHAR_HEAD_P (*(GAP_END_ADDR))) |
2196 |
{ |
{ |
2197 |
unsigned char *p = GPT_ADDR - 1; |
unsigned char *p = GPT_ADDR - 1; |
2210 |
pos = BEG; |
pos = BEG; |
2211 |
stop = GPT; |
stop = GPT; |
2212 |
p = BEG_ADDR; |
p = BEG_ADDR; |
2213 |
|
pend = GPT_ADDR; |
2214 |
while (1) |
while (1) |
2215 |
{ |
{ |
2216 |
int bytes; |
int bytes; |
2220 |
if (pos == Z) |
if (pos == Z) |
2221 |
break; |
break; |
2222 |
p = GAP_END_ADDR; |
p = GAP_END_ADDR; |
2223 |
|
pend = Z_ADDR; |
2224 |
stop = Z; |
stop = Z; |
2225 |
} |
} |
2226 |
|
|
2227 |
if (UNIBYTE_STR_AS_MULTIBYTE_P (p, stop - pos, bytes)) |
if (ASCII_BYTE_P (*p)) |
2228 |
|
p++, pos++; |
2229 |
|
else if (EQ (flag, Qt) && (bytes = MULTIBYTE_LENGTH (p, pend)) > 0) |
2230 |
p += bytes, pos += bytes; |
p += bytes, pos += bytes; |
2231 |
else |
else |
2232 |
{ |
{ |
2233 |
unsigned char tmp[MAX_MULTIBYTE_LENGTH]; |
unsigned char tmp[MAX_MULTIBYTE_LENGTH]; |
2234 |
|
int c; |
2235 |
|
|
2236 |
bytes = CHAR_STRING (*p, tmp); |
c = BYTE8_TO_CHAR (*p); |
2237 |
|
bytes = CHAR_STRING (c, tmp); |
2238 |
*p = tmp[0]; |
*p = tmp[0]; |
2239 |
TEMP_SET_PT_BOTH (pos + 1, pos + 1); |
TEMP_SET_PT_BOTH (pos + 1, pos + 1); |
2240 |
bytes--; |
bytes--; |
2248 |
zv += bytes; |
zv += bytes; |
2249 |
if (pos <= pt) |
if (pos <= pt) |
2250 |
pt += bytes; |
pt += bytes; |
2251 |
|
pend = Z_ADDR; |
2252 |
stop = Z; |
stop = Z; |
2253 |
} |
} |
2254 |
} |
} |
3757 |
end = OVERLAY_END (overlay); |
end = OVERLAY_END (overlay); |
3758 |
if (OVERLAY_POSITION (end) < b->overlay_center) |
if (OVERLAY_POSITION (end) < b->overlay_center) |
3759 |
{ |
{ |
3760 |
if (b->overlays_after) |
XOVERLAY (overlay)->next = b->overlays_after; |
3761 |
XOVERLAY (overlay)->next = b->overlays_after; |
b->overlays_after = XOVERLAY (overlay); |
|
b->overlays_after = XOVERLAY (overlay); |
|
3762 |
} |
} |
3763 |
else |
else |
3764 |
{ |
{ |
3765 |
if (b->overlays_before) |
XOVERLAY (overlay)->next = b->overlays_before; |
3766 |
XOVERLAY (overlay)->next = b->overlays_before; |
b->overlays_before = XOVERLAY (overlay); |
|
b->overlays_before = XOVERLAY (overlay); |
|
3767 |
} |
} |
3768 |
|
|
3769 |
/* This puts it in the right list, and in the right order. */ |
/* This puts it in the right list, and in the right order. */ |