aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/buffer.c b/src/buffer.c
index cf125559f76..c18e3ad8ddf 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -43,7 +43,7 @@ extern int errno;
43#include "window.h" 43#include "window.h"
44#include "commands.h" 44#include "commands.h"
45#include "buffer.h" 45#include "buffer.h"
46#include "charset.h" 46#include "character.h"
47#include "region-cache.h" 47#include "region-cache.h"
48#include "indent.h" 48#include "indent.h"
49#include "blockinput.h" 49#include "blockinput.h"
@@ -177,6 +177,7 @@ static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Ove
177static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT)); 177static void modify_overlay P_ ((struct buffer *, EMACS_INT, EMACS_INT));
178static Lisp_Object buffer_lisp_local_variables P_ ((struct buffer *)); 178static Lisp_Object buffer_lisp_local_variables P_ ((struct buffer *));
179 179
180extern char * emacs_strerror P_ ((int));
180 181
181/* For debugging; temporary. See set_buffer_internal. */ 182/* For debugging; temporary. See set_buffer_internal. */
182/* Lisp_Object Qlisp_mode, Vcheck_symbol; */ 183/* Lisp_Object Qlisp_mode, Vcheck_symbol; */
@@ -2208,8 +2209,10 @@ DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte, Sset_buffer_multibyte,
2208 doc: /* Set the multibyte flag of the current buffer to FLAG. 2209 doc: /* Set the multibyte flag of the current buffer to FLAG.
2209If FLAG is t, this makes the buffer a multibyte buffer. 2210If FLAG is t, this makes the buffer a multibyte buffer.
2210If FLAG is nil, this makes the buffer a single-byte buffer. 2211If FLAG is nil, this makes the buffer a single-byte buffer.
2211The buffer contents remain unchanged as a sequence of bytes 2212In these cases, the buffer contents remain unchanged as a sequence of
2212but the contents viewed as characters do change. 2213bytes but the contents viewed as characters do change.
2214If FLAG is `to', this makes the buffer a multibyte buffer by changing
2215all eight-bit bytes to eight-bit characters.
2213If the multibyte flag was really changed, undo information of the 2216If the multibyte flag was really changed, undo information of the
2214current buffer is cleared. */) 2217current buffer is cleared. */)
2215 (flag) 2218 (flag)
@@ -2283,11 +2286,11 @@ current buffer is cleared. */)
2283 p = GAP_END_ADDR; 2286 p = GAP_END_ADDR;
2284 stop = Z; 2287 stop = Z;
2285 } 2288 }
2286 if (MULTIBYTE_STR_AS_UNIBYTE_P (p, bytes)) 2289 if (ASCII_BYTE_P (*p))
2287 p += bytes, pos += bytes; 2290 p++, pos++;
2288 else 2291 else if (CHAR_BYTE8_HEAD_P (*p))
2289 { 2292 {
2290 c = STRING_CHAR (p, stop - pos); 2293 c = STRING_CHAR_AND_LENGTH (p, stop - pos, bytes);
2291 /* Delete all bytes for this 8-bit character but the 2294 /* Delete all bytes for this 8-bit character but the
2292 last one, and change the last one to the charcter 2295 last one, and change the last one to the charcter
2293 code. */ 2296 code. */
@@ -2302,6 +2305,11 @@ current buffer is cleared. */)
2302 zv -= bytes; 2305 zv -= bytes;
2303 stop = Z; 2306 stop = Z;
2304 } 2307 }
2308 else
2309 {
2310 bytes = BYTES_BY_CHAR_HEAD (*p);
2311 p += bytes, pos += bytes;
2312 }
2305 } 2313 }
2306 if (narrowed) 2314 if (narrowed)
2307 Fnarrow_to_region (make_number (begv), make_number (zv)); 2315 Fnarrow_to_region (make_number (begv), make_number (zv));
@@ -2310,13 +2318,14 @@ current buffer is cleared. */)
2310 { 2318 {
2311 int pt = PT; 2319 int pt = PT;
2312 int pos, stop; 2320 int pos, stop;
2313 unsigned char *p; 2321 unsigned char *p, *pend;
2314 2322
2315 /* Be sure not to have a multibyte sequence striding over the GAP. 2323 /* Be sure not to have a multibyte sequence striding over the GAP.
2316 Ex: We change this: "...abc\201 _GAP_ \241def..." 2324 Ex: We change this: "...abc\302 _GAP_ \241def..."
2317 to: "...abc _GAP_ \201\241def..." */ 2325 to: "...abc _GAP_ \302\241def..." */
2318 2326
2319 if (GPT_BYTE > 1 && GPT_BYTE < Z_BYTE 2327 if (EQ (flag, Qt)
2328 && GPT_BYTE > 1 && GPT_BYTE < Z_BYTE
2320 && ! CHAR_HEAD_P (*(GAP_END_ADDR))) 2329 && ! CHAR_HEAD_P (*(GAP_END_ADDR)))
2321 { 2330 {
2322 unsigned char *p = GPT_ADDR - 1; 2331 unsigned char *p = GPT_ADDR - 1;
@@ -2335,6 +2344,7 @@ current buffer is cleared. */)
2335 pos = BEG; 2344 pos = BEG;
2336 stop = GPT; 2345 stop = GPT;
2337 p = BEG_ADDR; 2346 p = BEG_ADDR;
2347 pend = GPT_ADDR;
2338 while (1) 2348 while (1)
2339 { 2349 {
2340 int bytes; 2350 int bytes;
@@ -2344,16 +2354,21 @@ current buffer is cleared. */)
2344 if (pos == Z) 2354 if (pos == Z)
2345 break; 2355 break;
2346 p = GAP_END_ADDR; 2356 p = GAP_END_ADDR;
2357 pend = Z_ADDR;
2347 stop = Z; 2358 stop = Z;
2348 } 2359 }
2349 2360
2350 if (UNIBYTE_STR_AS_MULTIBYTE_P (p, stop - pos, bytes)) 2361 if (ASCII_BYTE_P (*p))
2362 p++, pos++;
2363 else if (EQ (flag, Qt) && (bytes = MULTIBYTE_LENGTH (p, pend)) > 0)
2351 p += bytes, pos += bytes; 2364 p += bytes, pos += bytes;
2352 else 2365 else
2353 { 2366 {
2354 unsigned char tmp[MAX_MULTIBYTE_LENGTH]; 2367 unsigned char tmp[MAX_MULTIBYTE_LENGTH];
2368 int c;
2355 2369
2356 bytes = CHAR_STRING (*p, tmp); 2370 c = BYTE8_TO_CHAR (*p);
2371 bytes = CHAR_STRING (c, tmp);
2357 *p = tmp[0]; 2372 *p = tmp[0];
2358 TEMP_SET_PT_BOTH (pos + 1, pos + 1); 2373 TEMP_SET_PT_BOTH (pos + 1, pos + 1);
2359 bytes--; 2374 bytes--;
@@ -2367,6 +2382,7 @@ current buffer is cleared. */)
2367 zv += bytes; 2382 zv += bytes;
2368 if (pos <= pt) 2383 if (pos <= pt)
2369 pt += bytes; 2384 pt += bytes;
2385 pend = Z_ADDR;
2370 stop = Z; 2386 stop = Z;
2371 } 2387 }
2372 } 2388 }
@@ -2874,7 +2890,7 @@ overlay_touches_p (pos)
2874 int endpos; 2890 int endpos;
2875 2891
2876 XSETMISC (overlay ,tail); 2892 XSETMISC (overlay ,tail);
2877 if (!GC_OVERLAYP (overlay)) 2893 if (!OVERLAYP (overlay))
2878 abort (); 2894 abort ();
2879 2895
2880 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 2896 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
@@ -2889,7 +2905,7 @@ overlay_touches_p (pos)
2889 int startpos; 2905 int startpos;
2890 2906
2891 XSETMISC (overlay, tail); 2907 XSETMISC (overlay, tail);
2892 if (!GC_OVERLAYP (overlay)) 2908 if (!OVERLAYP (overlay))
2893 abort (); 2909 abort ();
2894 2910
2895 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 2911 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));