Commit 98a7d268 authored by Kenichi Handa's avatar Kenichi Handa
Browse files

(decide_coding_unwind): Renamed from

(Finsert_file_contents): Make single unwind protect to call both
Vset_auto_coding_function and Ffind_operation_coding_system.
parent d506e713
...@@ -3288,22 +3288,44 @@ Lisp_Object Qfind_buffer_file_type; ...@@ -3288,22 +3288,44 @@ Lisp_Object Qfind_buffer_file_type;
#define READ_BUF_SIZE (64 << 10) #define READ_BUF_SIZE (64 << 10)
#endif #endif
/* This function is called when a function bound to extern void adjust_markers_for_delete P_ ((int, int, int, int));
Vset_auto_coding_function causes some error. At that time, a text
of a file has already been inserted in the current buffer, but, /* This function is called after Lisp functions to decide a coding
markers has not yet been adjusted. Thus we must adjust markers system are called, or when they cause an error. Before they are
here. We are sure that the buffer was empty before the text of the called, the current buffer is set unibyte and it contains only a
file was inserted. */ newly inserted text (thus the buffer was empty before the
The functions may set markers, overlays, text properties, or even
alter the buffer contents, change the current buffer.
Here, we reset all those changes by:
o set back the current buffer.
o move all markers and overlays to BEG.
o remove all text properties.
o set back the buffer multibyteness. */
static Lisp_Object static Lisp_Object
set_auto_coding_unwind (multibyte) decide_coding_unwind (unwind_data)
Lisp_Object multibyte; Lisp_Object unwind_data;
{ {
int inserted = Z_BYTE - BEG_BYTE; Lisp_Object multibyte, undo_list, buffer;
if (!NILP (multibyte)) multibyte = XCAR (unwind_data);
inserted = multibyte_chars_in_text (GPT_ADDR - inserted, inserted); unwind_data = XCDR (unwind_data);
adjust_after_insert (PT, PT_BYTE, Z, Z_BYTE, inserted); undo_list = XCAR (unwind_data);
buffer = XCDR (unwind_data);
if (current_buffer != XBUFFER (buffer))
set_buffer_internal (XBUFFER (buffer));
adjust_markers_for_delete (BEG, BEG_BYTE, Z, Z_BYTE);
adjust_overlays_for_delete (BEG, Z - BEG);
BUF_INTERVALS (current_buffer) = 0;
/* Now we are safe to change the buffer's multibyteness directly. */
current_buffer->enable_multibyte_characters = multibyte;
current_buffer->undo_list = undo_list;
return Qnil; return Qnil;
} }
...@@ -4061,27 +4083,26 @@ actually used.") ...@@ -4061,27 +4083,26 @@ actually used.")
val = Vcoding_system_for_read; val = Vcoding_system_for_read;
else else
{ {
if (inserted > 0 && ! NILP (Vset_auto_coding_function)) /* Since we are sure that the current buffer was empty
{ before the insertion, we can toggle
/* Since we are sure that the current buffer was enable-multibyte-characters directly here without taking
empty before the insertion, we can toggle care of marker adjustment and byte combining problem. By
enable-multibyte-characters directly here without this way, we can run Lisp program safely before decoding
taking care of marker adjustment and byte the inserted text. */
combining problem. */ Lisp_Object unwind_data;
Lisp_Object prev_multibyte;
int count = specpdl_ptr - specpdl; int count = specpdl_ptr - specpdl;
prev_multibyte = current_buffer->enable_multibyte_characters; unwind_data = Fcons (current_buffer->enable_multibyte_characters,
Fcons (current_buffer->undo_list,
Fcurrent_buffer ()));
current_buffer->enable_multibyte_characters = Qnil; current_buffer->enable_multibyte_characters = Qnil;
record_unwind_protect (set_auto_coding_unwind, current_buffer->undo_list = Qt;
prev_multibyte); record_unwind_protect (decide_coding_unwind, unwind_data);
if (inserted > 0 && ! NILP (Vset_auto_coding_function))
val = call2 (Vset_auto_coding_function, val = call2 (Vset_auto_coding_function,
filename, make_number (inserted)); filename, make_number (inserted));
/* Discard the unwind protect for recovering the
error of Vset_auto_coding_function. */
current_buffer->enable_multibyte_characters = prev_multibyte;
} }
if (NILP (val)) if (NILP (val))
...@@ -4096,6 +4117,9 @@ actually used.") ...@@ -4096,6 +4117,9 @@ actually used.")
if (CONSP (coding_systems)) if (CONSP (coding_systems))
val = XCAR (coding_systems); val = XCAR (coding_systems);
} }
unbind_to (count, Qnil);
inserted = Z_BYTE - BEG_BYTE;
} }
/* The following kludgy code is to avoid some compiler bug. /* The following kludgy code is to avoid some compiler bug.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment