comparison src/buffer.c @ 89483:2f877ed80fa6

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 08 Sep 2003 12:53:41 +0000
parents 375f2633d815 6ba025c9a3d1
children 68c22ea6027c
comparison
equal deleted inserted replaced
88123:375f2633d815 89483:2f877ed80fa6
43 #include "lisp.h" 43 #include "lisp.h"
44 #include "intervals.h" 44 #include "intervals.h"
45 #include "window.h" 45 #include "window.h"
46 #include "commands.h" 46 #include "commands.h"
47 #include "buffer.h" 47 #include "buffer.h"
48 #include "charset.h" 48 #include "character.h"
49 #include "region-cache.h" 49 #include "region-cache.h"
50 #include "indent.h" 50 #include "indent.h"
51 #include "blockinput.h" 51 #include "blockinput.h"
52 #include "keyboard.h" 52 #include "keyboard.h"
53 #include "keymap.h" 53 #include "keymap.h"
184 static void alloc_buffer_text P_ ((struct buffer *, size_t)); 184 static void alloc_buffer_text P_ ((struct buffer *, size_t));
185 static void free_buffer_text P_ ((struct buffer *b)); 185 static void free_buffer_text P_ ((struct buffer *b));
186 static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *)); 186 static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *));
187 static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT)); 187 static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT));
188 188
189 extern char * emacs_strerror P_ ((int));
189 190
190 /* For debugging; temporary. See set_buffer_internal. */ 191 /* For debugging; temporary. See set_buffer_internal. */
191 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 192 /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
192 193
193 void 194 void
2076 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte, Sset_buffer_multibyte, 2077 DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte, Sset_buffer_multibyte,
2077 1, 1, 0, 2078 1, 1, 0,
2078 doc: /* Set the multibyte flag of the current buffer to FLAG. 2079 doc: /* Set the multibyte flag of the current buffer to FLAG.
2079 If FLAG is t, this makes the buffer a multibyte buffer. 2080 If FLAG is t, this makes the buffer a multibyte buffer.
2080 If FLAG is nil, this makes the buffer a single-byte buffer. 2081 If FLAG is nil, this makes the buffer a single-byte buffer.
2081 The buffer contents remain unchanged as a sequence of bytes 2082 In these cases, the buffer contents remain unchanged as a sequence of
2082 but the contents viewed as characters do change. */) 2083 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. */)
2083 (flag) 2086 (flag)
2084 Lisp_Object flag; 2087 Lisp_Object flag;
2085 { 2088 {
2086 struct Lisp_Marker *tail, *markers; 2089 struct Lisp_Marker *tail, *markers;
2087 struct buffer *other; 2090 struct buffer *other;
2147 if (pos == Z) 2150 if (pos == Z)
2148 break; 2151 break;
2149 p = GAP_END_ADDR; 2152 p = GAP_END_ADDR;
2150 stop = Z; 2153 stop = Z;
2151 } 2154 }
2152 if (MULTIBYTE_STR_AS_UNIBYTE_P (p, bytes)) 2155 if (ASCII_BYTE_P (*p))
2153 p += bytes, pos += bytes; 2156 p++, pos++;
2154 else 2157 else if (CHAR_BYTE8_HEAD_P (*p))
2155 { 2158 {
2156 c = STRING_CHAR (p, stop - pos); 2159 c = STRING_CHAR_AND_LENGTH (p, stop - pos, bytes);
2157 /* Delete all bytes for this 8-bit character but the 2160 /* Delete all bytes for this 8-bit character but the
2158 last one, and change the last one to the charcter 2161 last one, and change the last one to the charcter
2159 code. */ 2162 code. */
2160 bytes--; 2163 bytes--;
2161 del_range_2 (pos, pos, pos + bytes, pos + bytes, 0); 2164 del_range_2 (pos, pos, pos + bytes, pos + bytes, 0);
2166 begv -= bytes; 2169 begv -= bytes;
2167 if (zv > pos) 2170 if (zv > pos)
2168 zv -= bytes; 2171 zv -= bytes;
2169 stop = Z; 2172 stop = Z;
2170 } 2173 }
2174 else
2175 {
2176 bytes = BYTES_BY_CHAR_HEAD (*p);
2177 p += bytes, pos += bytes;
2178 }
2171 } 2179 }
2172 if (narrowed) 2180 if (narrowed)
2173 Fnarrow_to_region (make_number (begv), make_number (zv)); 2181 Fnarrow_to_region (make_number (begv), make_number (zv));
2174 } 2182 }
2175 else 2183 else
2176 { 2184 {
2177 int pt = PT; 2185 int pt = PT;
2178 int pos, stop; 2186 int pos, stop;
2179 unsigned char *p; 2187 unsigned char *p, *pend;
2180 2188
2181 /* Be sure not to have a multibyte sequence striding over the GAP. 2189 /* Be sure not to have a multibyte sequence striding over the GAP.
2182 Ex: We change this: "...abc\201 _GAP_ \241def..." 2190 Ex: We change this: "...abc\302 _GAP_ \241def..."
2183 to: "...abc _GAP_ \201\241def..." */ 2191 to: "...abc _GAP_ \302\241def..." */
2184 2192
2185 if (GPT_BYTE > 1 && GPT_BYTE < Z_BYTE 2193 if (EQ (flag, Qt)
2194 && GPT_BYTE > 1 && GPT_BYTE < Z_BYTE
2186 && ! CHAR_HEAD_P (*(GAP_END_ADDR))) 2195 && ! CHAR_HEAD_P (*(GAP_END_ADDR)))
2187 { 2196 {
2188 unsigned char *p = GPT_ADDR - 1; 2197 unsigned char *p = GPT_ADDR - 1;
2189 2198
2190 while (! CHAR_HEAD_P (*p) && p > BEG_ADDR) p--; 2199 while (! CHAR_HEAD_P (*p) && p > BEG_ADDR) p--;
2199 /* Make the buffer contents valid as multibyte by converting 2208 /* Make the buffer contents valid as multibyte by converting
2200 8-bit characters to multibyte form. */ 2209 8-bit characters to multibyte form. */
2201 pos = BEG; 2210 pos = BEG;
2202 stop = GPT; 2211 stop = GPT;
2203 p = BEG_ADDR; 2212 p = BEG_ADDR;
2213 pend = GPT_ADDR;
2204 while (1) 2214 while (1)
2205 { 2215 {
2206 int bytes; 2216 int bytes;
2207 2217
2208 if (pos == stop) 2218 if (pos == stop)
2209 { 2219 {
2210 if (pos == Z) 2220 if (pos == Z)
2211 break; 2221 break;
2212 p = GAP_END_ADDR; 2222 p = GAP_END_ADDR;
2223 pend = Z_ADDR;
2213 stop = Z; 2224 stop = Z;
2214 } 2225 }
2215 2226
2216 if (UNIBYTE_STR_AS_MULTIBYTE_P (p, stop - pos, bytes)) 2227 if (ASCII_BYTE_P (*p))
2228 p++, pos++;
2229 else if (EQ (flag, Qt) && (bytes = MULTIBYTE_LENGTH (p, pend)) > 0)
2217 p += bytes, pos += bytes; 2230 p += bytes, pos += bytes;
2218 else 2231 else
2219 { 2232 {
2220 unsigned char tmp[MAX_MULTIBYTE_LENGTH]; 2233 unsigned char tmp[MAX_MULTIBYTE_LENGTH];
2221 2234 int c;
2222 bytes = CHAR_STRING (*p, tmp); 2235
2236 c = BYTE8_TO_CHAR (*p);
2237 bytes = CHAR_STRING (c, tmp);
2223 *p = tmp[0]; 2238 *p = tmp[0];
2224 TEMP_SET_PT_BOTH (pos + 1, pos + 1); 2239 TEMP_SET_PT_BOTH (pos + 1, pos + 1);
2225 bytes--; 2240 bytes--;
2226 insert_1_both (tmp + 1, bytes, bytes, 1, 0, 0); 2241 insert_1_both (tmp + 1, bytes, bytes, 1, 0, 0);
2227 /* Now the gap is after the just inserted data. */ 2242 /* Now the gap is after the just inserted data. */
2231 begv += bytes; 2246 begv += bytes;
2232 if (pos <= zv) 2247 if (pos <= zv)
2233 zv += bytes; 2248 zv += bytes;
2234 if (pos <= pt) 2249 if (pos <= pt)
2235 pt += bytes; 2250 pt += bytes;
2251 pend = Z_ADDR;
2236 stop = Z; 2252 stop = Z;
2237 } 2253 }
2238 } 2254 }
2239 2255
2240 if (pt != PT) 2256 if (pt != PT)
3739 3755
3740 /* Put the overlay on the wrong list. */ 3756 /* Put the overlay on the wrong list. */
3741 end = OVERLAY_END (overlay); 3757 end = OVERLAY_END (overlay);
3742 if (OVERLAY_POSITION (end) < b->overlay_center) 3758 if (OVERLAY_POSITION (end) < b->overlay_center)
3743 { 3759 {
3744 if (b->overlays_after) 3760 XOVERLAY (overlay)->next = b->overlays_after;
3745 XOVERLAY (overlay)->next = b->overlays_after; 3761 b->overlays_after = XOVERLAY (overlay);
3746 b->overlays_after = XOVERLAY (overlay);
3747 } 3762 }
3748 else 3763 else
3749 { 3764 {
3750 if (b->overlays_before) 3765 XOVERLAY (overlay)->next = b->overlays_before;
3751 XOVERLAY (overlay)->next = b->overlays_before; 3766 b->overlays_before = XOVERLAY (overlay);
3752 b->overlays_before = XOVERLAY (overlay);
3753 } 3767 }
3754 3768
3755 /* This puts it in the right list, and in the right order. */ 3769 /* This puts it in the right list, and in the right order. */
3756 recenter_overlay_lists (b, b->overlay_center); 3770 recenter_overlay_lists (b, b->overlay_center);
3757 3771