aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa1999-12-06 04:46:51 +0000
committerKenichi Handa1999-12-06 04:46:51 +0000
commit98a7d2683c0b7c7605c2cefd5f3e6292e410514f (patch)
tree32e458a6f1cd9518f7b44d61ab151e5a224ab57c /src
parentd506e713fb368475825e20df902946f98c0f3a06 (diff)
downloademacs-98a7d2683c0b7c7605c2cefd5f3e6292e410514f.tar.gz
emacs-98a7d2683c0b7c7605c2cefd5f3e6292e410514f.zip
(decide_coding_unwind): Renamed from
set_auto_coding_unwind. (Finsert_file_contents): Make single unwind protect to call both Vset_auto_coding_function and Ffind_operation_coding_system.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c80
1 files changed, 52 insertions, 28 deletions
diff --git a/src/fileio.c b/src/fileio.c
index eafb1e61840..b6c1e4d5510 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3288,22 +3288,44 @@ Lisp_Object Qfind_buffer_file_type;
3288#define READ_BUF_SIZE (64 << 10) 3288#define READ_BUF_SIZE (64 << 10)
3289#endif 3289#endif
3290 3290
3291/* This function is called when a function bound to 3291extern void adjust_markers_for_delete P_ ((int, int, int, int));
3292 Vset_auto_coding_function causes some error. At that time, a text 3292
3293 of a file has already been inserted in the current buffer, but, 3293/* This function is called after Lisp functions to decide a coding
3294 markers has not yet been adjusted. Thus we must adjust markers 3294 system are called, or when they cause an error. Before they are
3295 here. We are sure that the buffer was empty before the text of the 3295 called, the current buffer is set unibyte and it contains only a
3296 file was inserted. */ 3296 newly inserted text (thus the buffer was empty before the
3297 insertion).
3298
3299 The functions may set markers, overlays, text properties, or even
3300 alter the buffer contents, change the current buffer.
3301
3302 Here, we reset all those changes by:
3303 o set back the current buffer.
3304 o move all markers and overlays to BEG.
3305 o remove all text properties.
3306 o set back the buffer multibyteness. */
3297 3307
3298static Lisp_Object 3308static Lisp_Object
3299set_auto_coding_unwind (multibyte) 3309decide_coding_unwind (unwind_data)
3300 Lisp_Object multibyte; 3310 Lisp_Object unwind_data;
3301{ 3311{
3302 int inserted = Z_BYTE - BEG_BYTE; 3312 Lisp_Object multibyte, undo_list, buffer;
3303 3313
3304 if (!NILP (multibyte)) 3314 multibyte = XCAR (unwind_data);
3305 inserted = multibyte_chars_in_text (GPT_ADDR - inserted, inserted); 3315 unwind_data = XCDR (unwind_data);
3306 adjust_after_insert (PT, PT_BYTE, Z, Z_BYTE, inserted); 3316 undo_list = XCAR (unwind_data);
3317 buffer = XCDR (unwind_data);
3318
3319 if (current_buffer != XBUFFER (buffer))
3320 set_buffer_internal (XBUFFER (buffer));
3321 adjust_markers_for_delete (BEG, BEG_BYTE, Z, Z_BYTE);
3322 adjust_overlays_for_delete (BEG, Z - BEG);
3323 BUF_INTERVALS (current_buffer) = 0;
3324 TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
3325
3326 /* Now we are safe to change the buffer's multibyteness directly. */
3327 current_buffer->enable_multibyte_characters = multibyte;
3328 current_buffer->undo_list = undo_list;
3307 3329
3308 return Qnil; 3330 return Qnil;
3309} 3331}
@@ -4061,27 +4083,26 @@ actually used.")
4061 val = Vcoding_system_for_read; 4083 val = Vcoding_system_for_read;
4062 else 4084 else
4063 { 4085 {
4064 if (inserted > 0 && ! NILP (Vset_auto_coding_function)) 4086 /* Since we are sure that the current buffer was empty
4065 { 4087 before the insertion, we can toggle
4066 /* Since we are sure that the current buffer was 4088 enable-multibyte-characters directly here without taking
4067 empty before the insertion, we can toggle 4089 care of marker adjustment and byte combining problem. By
4068 enable-multibyte-characters directly here without 4090 this way, we can run Lisp program safely before decoding
4069 taking care of marker adjustment and byte 4091 the inserted text. */
4070 combining problem. */ 4092 Lisp_Object unwind_data;
4071 Lisp_Object prev_multibyte;
4072 int count = specpdl_ptr - specpdl; 4093 int count = specpdl_ptr - specpdl;
4073 4094
4074 prev_multibyte = current_buffer->enable_multibyte_characters; 4095 unwind_data = Fcons (current_buffer->enable_multibyte_characters,
4096 Fcons (current_buffer->undo_list,
4097 Fcurrent_buffer ()));
4075 current_buffer->enable_multibyte_characters = Qnil; 4098 current_buffer->enable_multibyte_characters = Qnil;
4076 record_unwind_protect (set_auto_coding_unwind, 4099 current_buffer->undo_list = Qt;
4077 prev_multibyte); 4100 record_unwind_protect (decide_coding_unwind, unwind_data);
4101
4102 if (inserted > 0 && ! NILP (Vset_auto_coding_function))
4103 {
4078 val = call2 (Vset_auto_coding_function, 4104 val = call2 (Vset_auto_coding_function,
4079 filename, make_number (inserted)); 4105 filename, make_number (inserted));
4080 /* Discard the unwind protect for recovering the
4081 error of Vset_auto_coding_function. */
4082 specpdl_ptr--;
4083 current_buffer->enable_multibyte_characters = prev_multibyte;
4084 TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
4085 } 4106 }
4086 4107
4087 if (NILP (val)) 4108 if (NILP (val))
@@ -4096,6 +4117,9 @@ actually used.")
4096 if (CONSP (coding_systems)) 4117 if (CONSP (coding_systems))
4097 val = XCAR (coding_systems); 4118 val = XCAR (coding_systems);
4098 } 4119 }
4120
4121 unbind_to (count, Qnil);
4122 inserted = Z_BYTE - BEG_BYTE;
4099 } 4123 }
4100 4124
4101 /* The following kludgy code is to avoid some compiler bug. 4125 /* The following kludgy code is to avoid some compiler bug.