aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorKenichi Handa2004-11-30 08:07:11 +0000
committerKenichi Handa2004-11-30 08:07:11 +0000
commit2a47931bdbc9fe78f9c777180c7011dc4f52e373 (patch)
tree71b2554313baff81304efd684823f8bee44a54e8 /src/coding.c
parentf9439896895305bf8e0b13ff46b59b3a1deb29c0 (diff)
downloademacs-2a47931bdbc9fe78f9c777180c7011dc4f52e373.tar.gz
emacs-2a47931bdbc9fe78f9c777180c7011dc4f52e373.zip
(Vcode_conversion_workbuf_name): New variable.
(syms_of_coding): Initialize and staticpro it. (set_conversion_work_buffer): New function. (run_pre_post_conversion_on_str): Use it. (run_pre_write_conversin_on_c_str): New function.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c110
1 files changed, 93 insertions, 17 deletions
diff --git a/src/coding.c b/src/coding.c
index b521d100989..93a18d1cd9c 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6008,6 +6008,37 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
6008 return 0; 6008 return 0;
6009} 6009}
6010 6010
6011/* Name (or base name) of work buffer for code conversion. */
6012static Lisp_Object Vcode_conversion_workbuf_name;
6013
6014/* Set the current buffer to the working buffer prepared for
6015 code-conversion. MULTIBYTE specifies the multibyteness of the
6016 buffer. */
6017
6018static struct buffer *
6019set_conversion_work_buffer (multibyte)
6020 int multibyte;
6021{
6022 Lisp_Object buffer;
6023 struct buffer *buf;
6024
6025 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
6026 buf = XBUFFER (buffer);
6027 delete_all_overlays (buf);
6028 buf->directory = current_buffer->directory;
6029 buf->read_only = Qnil;
6030 buf->filename = Qnil;
6031 buf->undo_list = Qt;
6032 eassert (buf->overlays_before == NULL);
6033 eassert (buf->overlays_after == NULL);
6034 set_buffer_internal (buf);
6035 if (BEG != BEGV || Z != ZV)
6036 Fwiden ();
6037 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
6038 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6039 return buf;
6040}
6041
6011Lisp_Object 6042Lisp_Object
6012run_pre_post_conversion_on_str (str, coding, encodep) 6043run_pre_post_conversion_on_str (str, coding, encodep)
6013 Lisp_Object str; 6044 Lisp_Object str;
@@ -6017,7 +6048,6 @@ run_pre_post_conversion_on_str (str, coding, encodep)
6017 int count = SPECPDL_INDEX (); 6048 int count = SPECPDL_INDEX ();
6018 struct gcpro gcpro1, gcpro2; 6049 struct gcpro gcpro1, gcpro2;
6019 int multibyte = STRING_MULTIBYTE (str); 6050 int multibyte = STRING_MULTIBYTE (str);
6020 Lisp_Object buffer;
6021 struct buffer *buf; 6051 struct buffer *buf;
6022 Lisp_Object old_deactivate_mark; 6052 Lisp_Object old_deactivate_mark;
6023 6053
@@ -6028,25 +6058,10 @@ run_pre_post_conversion_on_str (str, coding, encodep)
6028 old_deactivate_mark = Vdeactivate_mark; 6058 old_deactivate_mark = Vdeactivate_mark;
6029 GCPRO2 (str, old_deactivate_mark); 6059 GCPRO2 (str, old_deactivate_mark);
6030 6060
6031 buffer = Fget_buffer_create (build_string (" *code-converting-work*"));
6032 buf = XBUFFER (buffer);
6033
6034 delete_all_overlays (buf);
6035 buf->directory = current_buffer->directory;
6036 buf->read_only = Qnil;
6037 buf->filename = Qnil;
6038 buf->undo_list = Qt;
6039 eassert (buf->overlays_before == NULL);
6040 eassert (buf->overlays_after == NULL);
6041
6042 set_buffer_internal (buf);
6043 /* Don't let Ferase_buffer stumble due to text props. */
6044 specbind (Qinhibit_read_only, Qt);
6045 /* We must insert the contents of STR as is without 6061 /* We must insert the contents of STR as is without
6046 unibyte<->multibyte conversion. For that, we adjust the 6062 unibyte<->multibyte conversion. For that, we adjust the
6047 multibyteness of the working buffer to that of STR. */ 6063 multibyteness of the working buffer to that of STR. */
6048 Ferase_buffer (); 6064 set_conversion_work_buffer (multibyte);
6049 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6050 6065
6051 insert_from_string (str, 0, 0, 6066 insert_from_string (str, 0, 0,
6052 SCHARS (str), SBYTES (str), 0); 6067 SCHARS (str), SBYTES (str), 0);
@@ -6067,6 +6082,64 @@ run_pre_post_conversion_on_str (str, coding, encodep)
6067 return unbind_to (count, str); 6082 return unbind_to (count, str);
6068} 6083}
6069 6084
6085
6086/* Run pre-write-conversion function of CODING on NCHARS/NBYTES
6087 text in *STR. *SIZE is the allocated bytes for STR. As it
6088 is intended that this function is called from encode_terminal_code,
6089 the pre-write-conversion function is run by safe_call and thus
6090 "Error during redisplay: ..." is logged when an error occurs.
6091
6092 Store the resulting text in *STR and set CODING->produced_char and
6093 CODING->produced to the number of characters and bytes
6094 respectively. If the size of *STR is too small, enlarge it by
6095 xrealloc and update *STR and *SIZE. */
6096
6097void
6098run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding)
6099 unsigned char **str;
6100 int *size, nchars, nbytes;
6101 struct coding_system *coding;
6102{
6103 struct gcpro gcpro1, gcpro2;
6104 struct buffer *cur = current_buffer;
6105 Lisp_Object old_deactivate_mark, old_last_coding_system_used;
6106 Lisp_Object args[3];
6107
6108 /* It is not crucial to specbind this. */
6109 old_deactivate_mark = Vdeactivate_mark;
6110 old_last_coding_system_used = Vlast_coding_system_used;
6111 GCPRO2 (old_deactivate_mark, old_last_coding_system_used);
6112
6113 /* We must insert the contents of STR as is without
6114 unibyte<->multibyte conversion. For that, we adjust the
6115 multibyteness of the working buffer to that of STR. */
6116 set_conversion_work_buffer (coding->src_multibyte);
6117 insert_1_both (*str, nchars, nbytes, 0, 0, 0);
6118 UNGCPRO;
6119 inhibit_pre_post_conversion = 1;
6120 args[0] = coding->pre_write_conversion;
6121 args[1] = make_number (BEG);
6122 args[2] = make_number (Z);
6123 safe_call (3, args);
6124 inhibit_pre_post_conversion = 0;
6125 Vdeactivate_mark = old_deactivate_mark;
6126 Vlast_coding_system_used = old_last_coding_system_used;
6127 coding->produced_char = Z - BEG;
6128 coding->produced = Z_BYTE - BEG_BYTE;
6129 if (coding->produced > *size)
6130 {
6131 *size = coding->produced;
6132 *str = xrealloc (*str, *size);
6133 }
6134 if (BEG < GPT && GPT < Z)
6135 move_gap (BEG);
6136 bcopy (BEG_ADDR, *str, coding->produced);
6137 coding->src_multibyte
6138 = ! NILP (current_buffer->enable_multibyte_characters);
6139 set_buffer_internal (cur);
6140}
6141
6142
6070Lisp_Object 6143Lisp_Object
6071decode_coding_string (str, coding, nocopy) 6144decode_coding_string (str, coding, nocopy)
6072 Lisp_Object str; 6145 Lisp_Object str;
@@ -7545,6 +7618,9 @@ init_coding_once ()
7545void 7618void
7546syms_of_coding () 7619syms_of_coding ()
7547{ 7620{
7621 staticpro (&Vcode_conversion_workbuf_name);
7622 Vcode_conversion_workbuf_name = build_string (" *code-conversion-work*");
7623
7548 Qtarget_idx = intern ("target-idx"); 7624 Qtarget_idx = intern ("target-idx");
7549 staticpro (&Qtarget_idx); 7625 staticpro (&Qtarget_idx);
7550 7626