summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa <handa@m17n.org>2004-11-30 08:07:11 +0000
committerKenichi Handa <handa@m17n.org>2004-11-30 08:07:11 +0000
commit2a47931bdbc9fe78f9c777180c7011dc4f52e373 (patch)
tree71b2554313baff81304efd684823f8bee44a54e8 /src
parentf9439896895305bf8e0b13ff46b59b3a1deb29c0 (diff)
downloademacs-2a47931bdbc9fe78f9c777180c7011dc4f52e373.tar.gz
(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')
-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)
return 0;
}
+/* Name (or base name) of work buffer for code conversion. */
+static Lisp_Object Vcode_conversion_workbuf_name;
+
+/* Set the current buffer to the working buffer prepared for
+ code-conversion. MULTIBYTE specifies the multibyteness of the
+ buffer. */
+
+static struct buffer *
+set_conversion_work_buffer (multibyte)
+ int multibyte;
+{
+ Lisp_Object buffer;
+ struct buffer *buf;
+
+ buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
+ buf = XBUFFER (buffer);
+ delete_all_overlays (buf);
+ buf->directory = current_buffer->directory;
+ buf->read_only = Qnil;
+ buf->filename = Qnil;
+ buf->undo_list = Qt;
+ eassert (buf->overlays_before == NULL);
+ eassert (buf->overlays_after == NULL);
+ set_buffer_internal (buf);
+ if (BEG != BEGV || Z != ZV)
+ Fwiden ();
+ del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
+ buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
+ return buf;
+}
+
Lisp_Object
run_pre_post_conversion_on_str (str, coding, encodep)
Lisp_Object str;
@@ -6017,7 +6048,6 @@ run_pre_post_conversion_on_str (str, coding, encodep)
int count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2;
int multibyte = STRING_MULTIBYTE (str);
- Lisp_Object buffer;
struct buffer *buf;
Lisp_Object old_deactivate_mark;
@@ -6028,25 +6058,10 @@ run_pre_post_conversion_on_str (str, coding, encodep)
old_deactivate_mark = Vdeactivate_mark;
GCPRO2 (str, old_deactivate_mark);
- buffer = Fget_buffer_create (build_string (" *code-converting-work*"));
- buf = XBUFFER (buffer);
-
- delete_all_overlays (buf);
- buf->directory = current_buffer->directory;
- buf->read_only = Qnil;
- buf->filename = Qnil;
- buf->undo_list = Qt;
- eassert (buf->overlays_before == NULL);
- eassert (buf->overlays_after == NULL);
-
- set_buffer_internal (buf);
- /* Don't let Ferase_buffer stumble due to text props. */
- specbind (Qinhibit_read_only, Qt);
/* We must insert the contents of STR as is without
unibyte<->multibyte conversion. For that, we adjust the
multibyteness of the working buffer to that of STR. */
- Ferase_buffer ();
- buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
+ set_conversion_work_buffer (multibyte);
insert_from_string (str, 0, 0,
SCHARS (str), SBYTES (str), 0);
@@ -6067,6 +6082,64 @@ run_pre_post_conversion_on_str (str, coding, encodep)
return unbind_to (count, str);
}
+
+/* Run pre-write-conversion function of CODING on NCHARS/NBYTES
+ text in *STR. *SIZE is the allocated bytes for STR. As it
+ is intended that this function is called from encode_terminal_code,
+ the pre-write-conversion function is run by safe_call and thus
+ "Error during redisplay: ..." is logged when an error occurs.
+
+ Store the resulting text in *STR and set CODING->produced_char and
+ CODING->produced to the number of characters and bytes
+ respectively. If the size of *STR is too small, enlarge it by
+ xrealloc and update *STR and *SIZE. */
+
+void
+run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding)
+ unsigned char **str;
+ int *size, nchars, nbytes;
+ struct coding_system *coding;
+{
+ struct gcpro gcpro1, gcpro2;
+ struct buffer *cur = current_buffer;
+ Lisp_Object old_deactivate_mark, old_last_coding_system_used;
+ Lisp_Object args[3];
+
+ /* It is not crucial to specbind this. */
+ old_deactivate_mark = Vdeactivate_mark;
+ old_last_coding_system_used = Vlast_coding_system_used;
+ GCPRO2 (old_deactivate_mark, old_last_coding_system_used);
+
+ /* We must insert the contents of STR as is without
+ unibyte<->multibyte conversion. For that, we adjust the
+ multibyteness of the working buffer to that of STR. */
+ set_conversion_work_buffer (coding->src_multibyte);
+ insert_1_both (*str, nchars, nbytes, 0, 0, 0);
+ UNGCPRO;
+ inhibit_pre_post_conversion = 1;
+ args[0] = coding->pre_write_conversion;
+ args[1] = make_number (BEG);
+ args[2] = make_number (Z);
+ safe_call (3, args);
+ inhibit_pre_post_conversion = 0;
+ Vdeactivate_mark = old_deactivate_mark;
+ Vlast_coding_system_used = old_last_coding_system_used;
+ coding->produced_char = Z - BEG;
+ coding->produced = Z_BYTE - BEG_BYTE;
+ if (coding->produced > *size)
+ {
+ *size = coding->produced;
+ *str = xrealloc (*str, *size);
+ }
+ if (BEG < GPT && GPT < Z)
+ move_gap (BEG);
+ bcopy (BEG_ADDR, *str, coding->produced);
+ coding->src_multibyte
+ = ! NILP (current_buffer->enable_multibyte_characters);
+ set_buffer_internal (cur);
+}
+
+
Lisp_Object
decode_coding_string (str, coding, nocopy)
Lisp_Object str;
@@ -7545,6 +7618,9 @@ init_coding_once ()
void
syms_of_coding ()
{
+ staticpro (&Vcode_conversion_workbuf_name);
+ Vcode_conversion_workbuf_name = build_string (" *code-conversion-work*");
+
Qtarget_idx = intern ("target-idx");
staticpro (&Qtarget_idx);