aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c
index 8ca1d19c4c3..de65884254f 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6578,6 +6578,37 @@ code_conversion_restore (arg)
6578 return Qnil; 6578 return Qnil;
6579} 6579}
6580 6580
6581/* Name (or base name) of work buffer for code conversion. */
6582static Lisp_Object Vcode_conversion_workbuf_name;
6583
6584/* Set the current buffer to the working buffer prepared for
6585 code-conversion. MULTIBYTE specifies the multibyteness of the
6586 buffer. */
6587
6588static struct buffer *
6589set_conversion_work_buffer (multibyte)
6590 int multibyte;
6591{
6592 Lisp_Object buffer;
6593 struct buffer *buf;
6594
6595 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
6596 buf = XBUFFER (buffer);
6597 delete_all_overlays (buf);
6598 buf->directory = current_buffer->directory;
6599 buf->read_only = Qnil;
6600 buf->filename = Qnil;
6601 buf->undo_list = Qt;
6602 eassert (buf->overlays_before == NULL);
6603 eassert (buf->overlays_after == NULL);
6604 set_buffer_internal (buf);
6605 if (BEG != BEGV || Z != ZV)
6606 Fwiden ();
6607 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
6608 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6609 return buf;
6610}
6611
6581Lisp_Object 6612Lisp_Object
6582code_conversion_save (with_work_buf, multibyte) 6613code_conversion_save (with_work_buf, multibyte)
6583 int with_work_buf, multibyte; 6614 int with_work_buf, multibyte;
@@ -6995,6 +7026,64 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6995} 7026}
6996 7027
6997 7028
7029
7030/* Run pre-write-conversion function of CODING on NCHARS/NBYTES
7031 text in *STR. *SIZE is the allocated bytes for STR. As it
7032 is intended that this function is called from encode_terminal_code,
7033 the pre-write-conversion function is run by safe_call and thus
7034 "Error during redisplay: ..." is logged when an error occurs.
7035
7036 Store the resulting text in *STR and set CODING->produced_char and
7037 CODING->produced to the number of characters and bytes
7038 respectively. If the size of *STR is too small, enlarge it by
7039 xrealloc and update *STR and *SIZE. */
7040
7041void
7042run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding)
7043 unsigned char **str;
7044 int *size, nchars, nbytes;
7045 struct coding_system *coding;
7046{
7047 struct gcpro gcpro1, gcpro2;
7048 struct buffer *cur = current_buffer;
7049 Lisp_Object old_deactivate_mark, old_last_coding_system_used;
7050 Lisp_Object args[3];
7051
7052 /* It is not crucial to specbind this. */
7053 old_deactivate_mark = Vdeactivate_mark;
7054 old_last_coding_system_used = Vlast_coding_system_used;
7055 GCPRO2 (old_deactivate_mark, old_last_coding_system_used);
7056
7057 /* We must insert the contents of STR as is without
7058 unibyte<->multibyte conversion. For that, we adjust the
7059 multibyteness of the working buffer to that of STR. */
7060 set_conversion_work_buffer (coding->src_multibyte);
7061 insert_1_both (*str, nchars, nbytes, 0, 0, 0);
7062 UNGCPRO;
7063 inhibit_pre_post_conversion = 1;
7064 args[0] = coding->pre_write_conversion;
7065 args[1] = make_number (BEG);
7066 args[2] = make_number (Z);
7067 safe_call (3, args);
7068 inhibit_pre_post_conversion = 0;
7069 Vdeactivate_mark = old_deactivate_mark;
7070 Vlast_coding_system_used = old_last_coding_system_used;
7071 coding->produced_char = Z - BEG;
7072 coding->produced = Z_BYTE - BEG_BYTE;
7073 if (coding->produced > *size)
7074 {
7075 *size = coding->produced;
7076 *str = xrealloc (*str, *size);
7077 }
7078 if (BEG < GPT && GPT < Z)
7079 move_gap (BEG);
7080 bcopy (BEG_ADDR, *str, coding->produced);
7081 coding->src_multibyte
7082 = ! NILP (current_buffer->enable_multibyte_characters);
7083 set_buffer_internal (cur);
7084}
7085
7086
6998Lisp_Object 7087Lisp_Object
6999preferred_coding_system () 7088preferred_coding_system ()
7000{ 7089{