aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorKenichi Handa1999-10-18 01:36:35 +0000
committerKenichi Handa1999-10-18 01:36:35 +0000
commitb843d1aed4ea675ca01d63df16958e206a911d19 (patch)
treeffffa3f178514d22ed5c43fd5095f1eb11e8660c /src/coding.c
parent600f9d03904b78ced2cdbc4311668f354147e0a4 (diff)
downloademacs-b843d1aed4ea675ca01d63df16958e206a911d19.tar.gz
emacs-b843d1aed4ea675ca01d63df16958e206a911d19.zip
(code_convert_string): Add record_unwind_protect to
assure setting inhibit_pre_post_conversion back to zero. Take care of the multibyteness of the working buffer. (inhibit_pre_post_conversion): New variable. (setup_coding_system): If inhibit_pre_post_conversion is nonzero, ignore post-read-conversion and pre-write-conversion property of the coding system. (code_convert_region_unwind): New function. (code_convert_region): Set inhibit_pre_post_conversion to 1 while running pre-write-conversion and post-read-conversion. (code_convert_string): Likewise.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c79
1 files changed, 59 insertions, 20 deletions
diff --git a/src/coding.c b/src/coding.c
index 5a4a4c8c9a6..4bf0b2aea81 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -411,6 +411,12 @@ Lisp_Object Vcharset_revision_alist;
411/* Default coding systems used for process I/O. */ 411/* Default coding systems used for process I/O. */
412Lisp_Object Vdefault_process_coding_system; 412Lisp_Object Vdefault_process_coding_system;
413 413
414/* Global flag to tell that we can't call post-read-conversion and
415 pre-write-conversion functions. Usually the value is zero, but it
416 is set to 1 temporarily while such functions are running. This is
417 to avoid infinite recursive call. */
418static int inhibit_pre_post_conversion;
419
414 420
415/*** 2. Emacs internal format (emacs-mule) handlers ***/ 421/*** 2. Emacs internal format (emacs-mule) handlers ***/
416 422
@@ -2941,8 +2947,14 @@ setup_coding_system (coding_system, coding)
2941 `post-read-conversion', `pre-write-conversion', 2947 `post-read-conversion', `pre-write-conversion',
2942 `translation-table-for-decode', `translation-table-for-encode'. */ 2948 `translation-table-for-decode', `translation-table-for-encode'. */
2943 plist = XVECTOR (coding_spec)->contents[3]; 2949 plist = XVECTOR (coding_spec)->contents[3];
2944 coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion); 2950 /* Pre & post conversion functions should be disabled if
2945 coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion); 2951 inhibit_eol_conversion is nozero. This is the case that a code
2952 conversion function is called while those functions are running. */
2953 if (! inhibit_pre_post_conversion)
2954 {
2955 coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion);
2956 coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion);
2957 }
2946 val = Fplist_get (plist, Qtranslation_table_for_decode); 2958 val = Fplist_get (plist, Qtranslation_table_for_decode);
2947 if (SYMBOLP (val)) 2959 if (SYMBOLP (val))
2948 val = Fget (val, Qtranslation_table_for_decode); 2960 val = Fget (val, Qtranslation_table_for_decode);
@@ -4221,6 +4233,14 @@ static int shrink_conversion_region_threshhold = 1024;
4221 } \ 4233 } \
4222 } while (0) 4234 } while (0)
4223 4235
4236static Lisp_Object
4237code_convert_region_unwind (dummy)
4238 Lisp_Object dummy;
4239{
4240 inhibit_pre_post_conversion = 0;
4241 return Qnil;
4242}
4243
4224/* Decode (if ENCODEP is zero) or encode (if ENCODEP is nonzero) the 4244/* Decode (if ENCODEP is zero) or encode (if ENCODEP is nonzero) the
4225 text from FROM to TO (byte positions are FROM_BYTE and TO_BYTE) by 4245 text from FROM to TO (byte positions are FROM_BYTE and TO_BYTE) by
4226 coding system CODING, and return the status code of code conversion 4246 coding system CODING, and return the status code of code conversion
@@ -4345,9 +4365,18 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4345 new buffer. */ 4365 new buffer. */
4346 struct buffer *prev = current_buffer; 4366 struct buffer *prev = current_buffer;
4347 Lisp_Object new; 4367 Lisp_Object new;
4368 int count = specpdl_ptr - specpdl;
4348 4369
4370 record_unwind_protect (code_convert_region_unwind, Qnil);
4371 /* We should not call any more pre-write/post-read-conversion
4372 functions while this pre-write-conversion is running. */
4373 inhibit_pre_post_conversion = 1;
4349 call2 (coding->pre_write_conversion, 4374 call2 (coding->pre_write_conversion,
4350 make_number (from), make_number (to)); 4375 make_number (from), make_number (to));
4376 inhibit_pre_post_conversion = 0;
4377 /* Discard the unwind protect. */
4378 specpdl_ptr--;
4379
4351 if (current_buffer != prev) 4380 if (current_buffer != prev)
4352 { 4381 {
4353 len = ZV - BEGV; 4382 len = ZV - BEGV;
@@ -4626,11 +4655,19 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4626 if (! encodep && ! NILP (coding->post_read_conversion)) 4655 if (! encodep && ! NILP (coding->post_read_conversion))
4627 { 4656 {
4628 Lisp_Object val; 4657 Lisp_Object val;
4658 int count = specpdl_ptr - specpdl;
4629 4659
4630 if (from != PT) 4660 if (from != PT)
4631 TEMP_SET_PT_BOTH (from, from_byte); 4661 TEMP_SET_PT_BOTH (from, from_byte);
4632 prev_Z = Z; 4662 prev_Z = Z;
4663 record_unwind_protect (code_convert_region_unwind, Qnil);
4664 /* We should not call any more pre-write/post-read-conversion
4665 functions while this post-read-conversion is running. */
4666 inhibit_pre_post_conversion = 1;
4633 val = call1 (coding->post_read_conversion, make_number (inserted)); 4667 val = call1 (coding->post_read_conversion, make_number (inserted));
4668 inhibit_pre_post_conversion = 0;
4669 /* Discard the unwind protect. */
4670 specpdl_ptr--;
4634 CHECK_NUMBER (val, 0); 4671 CHECK_NUMBER (val, 0);
4635 inserted += Z - prev_Z; 4672 inserted += Z - prev_Z;
4636 } 4673 }
@@ -4671,34 +4708,34 @@ code_convert_string (str, coding, encodep, nocopy)
4671 int result; 4708 int result;
4672 4709
4673 saved_coding_symbol = Qnil; 4710 saved_coding_symbol = Qnil;
4674 if (encodep && !NILP (coding->pre_write_conversion) 4711 if ((encodep && !NILP (coding->pre_write_conversion)
4675 || !encodep && !NILP (coding->post_read_conversion)) 4712 || !encodep && !NILP (coding->post_read_conversion)))
4676 { 4713 {
4677 /* Since we have to call Lisp functions which assume target text 4714 /* Since we have to call Lisp functions which assume target text
4678 is in a buffer, after setting a temporary buffer, call 4715 is in a buffer, after setting a temporary buffer, call
4679 code_convert_region. */ 4716 code_convert_region. */
4680 int count = specpdl_ptr - specpdl; 4717 int count = specpdl_ptr - specpdl;
4681 struct buffer *prev = current_buffer; 4718 struct buffer *prev = current_buffer;
4719 int multibyte = STRING_MULTIBYTE (str);
4682 4720
4683 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 4721 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4722 record_unwind_protect (code_convert_region_unwind, Qnil);
4723 inhibit_pre_post_conversion = 1;
4724 GCPRO1 (str);
4684 temp_output_buffer_setup (" *code-converting-work*"); 4725 temp_output_buffer_setup (" *code-converting-work*");
4685 set_buffer_internal (XBUFFER (Vstandard_output)); 4726 set_buffer_internal (XBUFFER (Vstandard_output));
4686 if (encodep) 4727 /* We must insert the contents of STR as is without
4687 insert_from_string (str, 0, 0, to, to_byte, 0); 4728 unibyte<->multibyte conversion. For that, we adjust the
4688 else 4729 multibyteness of the working buffer to that of STR. */
4689 { 4730 Ferase_buffer (); /* for safety */
4690 /* We must insert the contents of STR as is without 4731 current_buffer->enable_multibyte_characters = multibyte ? Qt : Qnil;
4691 unibyte<->multibyte conversion. */ 4732 insert_from_string (str, 0, 0, to, to_byte, 0);
4692 current_buffer->enable_multibyte_characters = Qnil; 4733 UNGCPRO;
4693 insert_from_string (str, 0, 0, to_byte, to_byte, 0);
4694 current_buffer->enable_multibyte_characters = Qt;
4695 }
4696 code_convert_region (BEGV, BEGV_BYTE, ZV, ZV_BYTE, coding, encodep, 1); 4734 code_convert_region (BEGV, BEGV_BYTE, ZV, ZV_BYTE, coding, encodep, 1);
4697 if (encodep) 4735 /* Make a unibyte string if we are encoding, otherwise make a
4698 /* We must return the buffer contents as unibyte string. */ 4736 multibyte string. */
4699 current_buffer->enable_multibyte_characters = Qnil; 4737 Fset_buffer_multibyte (encodep ? Qnil : Qt);
4700 str = make_buffer_string (BEGV, ZV, 0); 4738 str = make_buffer_string (BEGV, ZV, 0);
4701 set_buffer_internal (prev);
4702 return unbind_to (count, str); 4739 return unbind_to (count, str);
4703 } 4740 }
4704 4741
@@ -5493,6 +5530,8 @@ init_coding_once ()
5493#else 5530#else
5494 system_eol_type = CODING_EOL_LF; 5531 system_eol_type = CODING_EOL_LF;
5495#endif 5532#endif
5533
5534 inhibit_pre_post_conversion = 0;
5496} 5535}
5497 5536
5498#ifdef emacs 5537#ifdef emacs