# HG changeset patch # User Kenichi Handa # Date 1285820914 -32400 # Node ID 4d672e9d91bfdcf323cace260e5a170a375b4bd0 # Parent bf3b8d29e99213aaf1db57e6a478a74857e32a54 Complement a coding system for encoding arguments and input to a process. diff -r bf3b8d29e992 -r 4d672e9d91bf src/ChangeLog --- a/src/ChangeLog Wed Sep 29 09:55:58 2010 +0900 +++ b/src/ChangeLog Thu Sep 30 13:28:34 2010 +0900 @@ -1,3 +1,19 @@ +2010-09-30 Kenichi Handa + + * coding.c (complement_process_encoding_system): New function. + + * coding.h (complement_process_encoding_system): Extern it. + + * callproc.c (Fcall_process): Complement the coding system for + encoding arguments. + (Fcall_process_region): Complement the coding system for encoding + the input to the process. + + * process.c (Fstart_process): Complement the coding system for + encoding arguments. + (send_process): Complement the coding system for encoding what + sent to the process. + 2010-09-29 Kenichi Handa * xfont.c (xfont_open): Fix setting of font->average_width from diff -r bf3b8d29e992 -r 4d672e9d91bf src/callproc.c --- a/src/callproc.c Wed Sep 29 09:55:58 2010 +0900 +++ b/src/callproc.c Thu Sep 30 13:28:34 2010 +0900 @@ -287,21 +287,16 @@ if (!NILP (Vcoding_system_for_write)) val = Vcoding_system_for_write; else if (! must_encode) - val = Qnil; + val = Qraw_text; else { args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); args2[0] = Qcall_process; for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; coding_systems = Ffind_operation_coding_system (nargs + 1, args2); - if (CONSP (coding_systems)) - val = XCDR (coding_systems); - else if (CONSP (Vdefault_process_coding_system)) - val = XCDR (Vdefault_process_coding_system); - else - val = Qnil; + val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil; } - val = coding_inherit_eol_type (val, Qnil); + val = complement_process_encoding_system (val); setup_coding_system (Fcheck_coding_system (val), &argument_coding); coding_attrs = CODING_ID_ATTRS (argument_coding.id); if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs))) @@ -954,20 +949,16 @@ if (!NILP (Vcoding_system_for_write)) val = Vcoding_system_for_write; else if (NILP (current_buffer->enable_multibyte_characters)) - val = Qnil; + val = Qraw_text; else { args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); args2[0] = Qcall_process_region; for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; coding_systems = Ffind_operation_coding_system (nargs + 1, args2); - if (CONSP (coding_systems)) - val = XCDR (coding_systems); - else if (CONSP (Vdefault_process_coding_system)) - val = XCDR (Vdefault_process_coding_system); - else - val = Qnil; + val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil; } + val = complement_process_encoding_system (val); { int count1 = SPECPDL_INDEX (); diff -r bf3b8d29e992 -r 4d672e9d91bf src/coding.c --- a/src/coding.c Wed Sep 29 09:55:58 2010 +0900 +++ b/src/coding.c Thu Sep 30 13:28:34 2010 +0900 @@ -6112,6 +6112,63 @@ return coding_system; } + +/* Check if text-conversion and eol-conversion of CODING_SYSTEM are + decided for writing to a process. If not, complement them, and + return a new coding system. */ + +Lisp_Object +complement_process_encoding_system (coding_system) + Lisp_Object coding_system; +{ + Lisp_Object spec, attrs, coding_type, eol_type; + + if (NILP (coding_system)) + coding_system = Qundecided; + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + coding_type = CODING_ATTR_TYPE (attrs); + eol_type = AREF (spec, 2); + + if (EQ (coding_type, Qundecided)) + { + /* We must decide the text-conversion part. */ + if (CONSP (Vdefault_process_coding_system)) + { + coding_system = XCDR (Vdefault_process_coding_system); + if (! NILP (coding_system)) + { + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + coding_type = CODING_ATTR_TYPE (attrs); + eol_type = AREF (spec, 2); + } + } + if (EQ (coding_type, Qundecided)) + { + coding_system = preferred_coding_system (); + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + coding_type = CODING_ATTR_TYPE (attrs); + eol_type = AREF (spec, 2); + } + if (EQ (coding_type, Qundecided)) + { + coding_system = Qraw_text; + coding_type = Qraw_text; + eol_type = Qnil; + } + } + if (NILP (eol_type) || VECTORP (eol_type)) + { + /* We must decide the eol-conversion part. */ + coding_system = coding_inherit_eol_type (coding_system, Qnil); + } + + return coding_system; +} + + /* Emacs has a mechanism to automatically detect a coding system if it is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, it's impossible to distinguish some coding systems accurately diff -r bf3b8d29e992 -r 4d672e9d91bf src/coding.h --- a/src/coding.h Wed Sep 29 09:55:58 2010 +0900 +++ b/src/coding.h Thu Sep 30 13:28:34 2010 +0900 @@ -707,6 +707,7 @@ int)); extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object)); extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object)); +extern Lisp_Object complement_process_encoding_system P_ ((Lisp_Object)); extern int decode_coding_gap P_ ((struct coding_system *, EMACS_INT, EMACS_INT)); diff -r bf3b8d29e992 -r 4d672e9d91bf src/process.c --- a/src/process.c Wed Sep 29 09:55:58 2010 +0900 +++ b/src/process.c Thu Sep 30 13:28:34 2010 +0900 @@ -1727,6 +1727,11 @@ val = XCDR (Vdefault_process_coding_system); } XPROCESS (proc)->encode_coding_system = val; + /* Note: At this momemnt, the above coding system may leave + text-conversion or eol-conversion unspecified. They will be + decided after we read output from the process and decode it by + some coding system, or just before we actually send a text to + the process. */ } @@ -1769,6 +1774,7 @@ tem = Fsubstring (tem, make_number (2), Qnil); { + Lisp_Object arg_encoding = Qnil; struct gcpro gcpro1; GCPRO1 (tem); @@ -1786,9 +1792,14 @@ tem = Fcons (args[i], tem); CHECK_STRING (XCAR (tem)); if (STRING_MULTIBYTE (XCAR (tem))) - XSETCAR (tem, - code_convert_string_norecord - (XCAR (tem), XPROCESS (proc)->encode_coding_system, 1)); + { + if (NILP (arg_encoding)) + arg_encoding = (complement_process_encoding_system + (XPROCESS (proc)->encode_coding_system)); + XSETCAR (tem, + code_convert_string_norecord + (XCAR (tem), arg_encoding, 1)); + } } UNGCPRO; @@ -5690,12 +5701,21 @@ && !NILP (XBUFFER (object)->enable_multibyte_characters)) || EQ (object, Qt)) { + p->encode_coding_system + = complement_process_encoding_system (p->encode_coding_system); if (!EQ (Vlast_coding_system_used, p->encode_coding_system)) - /* The coding system for encoding was changed to raw-text - because we sent a unibyte text previously. Now we are - sending a multibyte text, thus we must encode it by the - original coding system specified for the current process. */ - setup_coding_system (p->encode_coding_system, coding); + { + /* The coding system for encoding was changed to raw-text + because we sent a unibyte text previously. Now we are + sending a multibyte text, thus we must encode it by the + original coding system specified for the current process. + + Another reason we comming here is that the coding system + was just complemented and new one was returned by + complement_process_encoding_system. */ + setup_coding_system (p->encode_coding_system, coding); + Vlast_coding_system_used = p->encode_coding_system; + } coding->src_multibyte = 1; } else