diff options
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 108 |
1 files changed, 93 insertions, 15 deletions
diff --git a/src/coding.c b/src/coding.c index 58fc587570a..3ddd7ea957d 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -6004,6 +6004,37 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace) | |||
| 6004 | return 0; | 6004 | return 0; |
| 6005 | } | 6005 | } |
| 6006 | 6006 | ||
| 6007 | /* Name (or base name) of work buffer for code conversion. */ | ||
| 6008 | static Lisp_Object Vcode_conversion_workbuf_name; | ||
| 6009 | |||
| 6010 | /* Set the current buffer to the working buffer prepared for | ||
| 6011 | code-conversion. MULTIBYTE specifies the multibyteness of the | ||
| 6012 | buffer. */ | ||
| 6013 | |||
| 6014 | static struct buffer * | ||
| 6015 | set_conversion_work_buffer (multibyte) | ||
| 6016 | int multibyte; | ||
| 6017 | { | ||
| 6018 | Lisp_Object buffer; | ||
| 6019 | struct buffer *buf; | ||
| 6020 | |||
| 6021 | buffer = Fget_buffer_create (Vcode_conversion_workbuf_name); | ||
| 6022 | buf = XBUFFER (buffer); | ||
| 6023 | delete_all_overlays (buf); | ||
| 6024 | buf->directory = current_buffer->directory; | ||
| 6025 | buf->read_only = Qnil; | ||
| 6026 | buf->filename = Qnil; | ||
| 6027 | buf->undo_list = Qt; | ||
| 6028 | eassert (buf->overlays_before == NULL); | ||
| 6029 | eassert (buf->overlays_after == NULL); | ||
| 6030 | set_buffer_internal (buf); | ||
| 6031 | if (BEG != BEGV || Z != ZV) | ||
| 6032 | Fwiden (); | ||
| 6033 | del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0); | ||
| 6034 | buf->enable_multibyte_characters = multibyte ? Qt : Qnil; | ||
| 6035 | return buf; | ||
| 6036 | } | ||
| 6037 | |||
| 6007 | Lisp_Object | 6038 | Lisp_Object |
| 6008 | run_pre_post_conversion_on_str (str, coding, encodep) | 6039 | run_pre_post_conversion_on_str (str, coding, encodep) |
| 6009 | Lisp_Object str; | 6040 | Lisp_Object str; |
| @@ -6013,7 +6044,6 @@ run_pre_post_conversion_on_str (str, coding, encodep) | |||
| 6013 | int count = SPECPDL_INDEX (); | 6044 | int count = SPECPDL_INDEX (); |
| 6014 | struct gcpro gcpro1, gcpro2; | 6045 | struct gcpro gcpro1, gcpro2; |
| 6015 | int multibyte = STRING_MULTIBYTE (str); | 6046 | int multibyte = STRING_MULTIBYTE (str); |
| 6016 | Lisp_Object buffer; | ||
| 6017 | struct buffer *buf; | 6047 | struct buffer *buf; |
| 6018 | Lisp_Object old_deactivate_mark; | 6048 | Lisp_Object old_deactivate_mark; |
| 6019 | 6049 | ||
| @@ -6024,23 +6054,10 @@ run_pre_post_conversion_on_str (str, coding, encodep) | |||
| 6024 | old_deactivate_mark = Vdeactivate_mark; | 6054 | old_deactivate_mark = Vdeactivate_mark; |
| 6025 | GCPRO2 (str, old_deactivate_mark); | 6055 | GCPRO2 (str, old_deactivate_mark); |
| 6026 | 6056 | ||
| 6027 | buffer = Fget_buffer_create (build_string (" *code-converting-work*")); | ||
| 6028 | buf = XBUFFER (buffer); | ||
| 6029 | |||
| 6030 | delete_all_overlays (buf); | ||
| 6031 | buf->directory = current_buffer->directory; | ||
| 6032 | buf->read_only = Qnil; | ||
| 6033 | buf->filename = Qnil; | ||
| 6034 | buf->undo_list = Qt; | ||
| 6035 | eassert (buf->overlays_before == NULL); | ||
| 6036 | eassert (buf->overlays_after == NULL); | ||
| 6037 | |||
| 6038 | set_buffer_internal (buf); | ||
| 6039 | /* We must insert the contents of STR as is without | 6057 | /* We must insert the contents of STR as is without |
| 6040 | unibyte<->multibyte conversion. For that, we adjust the | 6058 | unibyte<->multibyte conversion. For that, we adjust the |
| 6041 | multibyteness of the working buffer to that of STR. */ | 6059 | multibyteness of the working buffer to that of STR. */ |
| 6042 | Ferase_buffer (); | 6060 | set_conversion_work_buffer (multibyte); |
| 6043 | buf->enable_multibyte_characters = multibyte ? Qt : Qnil; | ||
| 6044 | 6061 | ||
| 6045 | insert_from_string (str, 0, 0, | 6062 | insert_from_string (str, 0, 0, |
| 6046 | SCHARS (str), SBYTES (str), 0); | 6063 | SCHARS (str), SBYTES (str), 0); |
| @@ -6061,6 +6078,64 @@ run_pre_post_conversion_on_str (str, coding, encodep) | |||
| 6061 | return unbind_to (count, str); | 6078 | return unbind_to (count, str); |
| 6062 | } | 6079 | } |
| 6063 | 6080 | ||
| 6081 | |||
| 6082 | /* Run pre-write-conversion function of CODING on NCHARS/NBYTES | ||
| 6083 | text in *STR. *SIZE is the allocated bytes for STR. As it | ||
| 6084 | is intended that this function is called from encode_terminal_code, | ||
| 6085 | the pre-write-conversion function is run by safe_call and thus | ||
| 6086 | "Error during redisplay: ..." is logged when an error occurs. | ||
| 6087 | |||
| 6088 | Store the resulting text in *STR and set CODING->produced_char and | ||
| 6089 | CODING->produced to the number of characters and bytes | ||
| 6090 | respectively. If the size of *STR is too small, enlarge it by | ||
| 6091 | xrealloc and update *STR and *SIZE. */ | ||
| 6092 | |||
| 6093 | void | ||
| 6094 | run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding) | ||
| 6095 | unsigned char **str; | ||
| 6096 | int *size, nchars, nbytes; | ||
| 6097 | struct coding_system *coding; | ||
| 6098 | { | ||
| 6099 | struct gcpro gcpro1, gcpro2; | ||
| 6100 | struct buffer *cur = current_buffer; | ||
| 6101 | Lisp_Object old_deactivate_mark, old_last_coding_system_used; | ||
| 6102 | Lisp_Object args[3]; | ||
| 6103 | |||
| 6104 | /* It is not crucial to specbind this. */ | ||
| 6105 | old_deactivate_mark = Vdeactivate_mark; | ||
| 6106 | old_last_coding_system_used = Vlast_coding_system_used; | ||
| 6107 | GCPRO2 (old_deactivate_mark, old_last_coding_system_used); | ||
| 6108 | |||
| 6109 | /* We must insert the contents of STR as is without | ||
| 6110 | unibyte<->multibyte conversion. For that, we adjust the | ||
| 6111 | multibyteness of the working buffer to that of STR. */ | ||
| 6112 | set_conversion_work_buffer (coding->src_multibyte); | ||
| 6113 | insert_1_both (*str, nchars, nbytes, 0, 0, 0); | ||
| 6114 | UNGCPRO; | ||
| 6115 | inhibit_pre_post_conversion = 1; | ||
| 6116 | args[0] = coding->pre_write_conversion; | ||
| 6117 | args[1] = make_number (BEG); | ||
| 6118 | args[2] = make_number (Z); | ||
| 6119 | safe_call (3, args); | ||
| 6120 | inhibit_pre_post_conversion = 0; | ||
| 6121 | Vdeactivate_mark = old_deactivate_mark; | ||
| 6122 | Vlast_coding_system_used = old_last_coding_system_used; | ||
| 6123 | coding->produced_char = Z - BEG; | ||
| 6124 | coding->produced = Z_BYTE - BEG_BYTE; | ||
| 6125 | if (coding->produced > *size) | ||
| 6126 | { | ||
| 6127 | *size = coding->produced; | ||
| 6128 | *str = xrealloc (*str, *size); | ||
| 6129 | } | ||
| 6130 | if (BEG < GPT && GPT < Z) | ||
| 6131 | move_gap (BEG); | ||
| 6132 | bcopy (BEG_ADDR, *str, coding->produced); | ||
| 6133 | coding->src_multibyte | ||
| 6134 | = ! NILP (current_buffer->enable_multibyte_characters); | ||
| 6135 | set_buffer_internal (cur); | ||
| 6136 | } | ||
| 6137 | |||
| 6138 | |||
| 6064 | Lisp_Object | 6139 | Lisp_Object |
| 6065 | decode_coding_string (str, coding, nocopy) | 6140 | decode_coding_string (str, coding, nocopy) |
| 6066 | Lisp_Object str; | 6141 | Lisp_Object str; |
| @@ -7539,6 +7614,9 @@ init_coding_once () | |||
| 7539 | void | 7614 | void |
| 7540 | syms_of_coding () | 7615 | syms_of_coding () |
| 7541 | { | 7616 | { |
| 7617 | staticpro (&Vcode_conversion_workbuf_name); | ||
| 7618 | Vcode_conversion_workbuf_name = build_string (" *code-conversion-work*"); | ||
| 7619 | |||
| 7542 | Qtarget_idx = intern ("target-idx"); | 7620 | Qtarget_idx = intern ("target-idx"); |
| 7543 | staticpro (&Qtarget_idx); | 7621 | staticpro (&Qtarget_idx); |
| 7544 | 7622 | ||