diff --git a/src/process.c b/src/process.c index 08cb810ec13..5db56692fe1 100644 --- a/src/process.c +++ b/src/process.c @@ -6112,6 +6112,11 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, ssize_t nbytes, struct coding_system *coding); +static void +read_and_insert_process_output (struct Lisp_Process *p, char *buf, + ssize_t nread, + struct coding_system *process_coding); + /* Read pending output from the process channel, starting with our buffered-ahead character if we have one. Yield number of decoded characters read, @@ -6227,7 +6232,10 @@ read_process_output (Lisp_Object proc, int channel) friends don't expect current-buffer to be changed from under them. */ record_unwind_current_buffer (); - read_and_dispose_of_process_output (p, chars, nbytes, coding); + if (p->filter == Qinternal_default_process_filter) + read_and_insert_process_output (p, chars, nbytes, coding); + else + read_and_dispose_of_process_output (p, chars, nbytes, coding); /* Handling the process output should not deactivate the mark. */ Vdeactivate_mark = odeactivate; @@ -6236,6 +6244,46 @@ read_process_output (Lisp_Object proc, int channel) return nbytes; } +static void read_and_insert_process_output (struct Lisp_Process *p, char *buf, + ssize_t nread, + struct coding_system *process_coding) +{ + if (!nread || NILP (p->buffer) || !BUFFER_LIVE_P (XBUFFER (p->buffer))) + ; + else if (NILP (BVAR (XBUFFER(p->buffer), enable_multibyte_characters)) + && ! CODING_MAY_REQUIRE_DECODING (process_coding)) + { + insert_1_both (buf, nread, nread, 0, 0, 0); + signal_after_change (PT - nread, 0, nread); + } + else + { /* We have to decode the input. */ + Lisp_Object curbuf; + int carryover = 0; + specpdl_ref count1 = SPECPDL_INDEX (); + + XSETBUFFER (curbuf, current_buffer); + /* We cannot allow after-change-functions be run + during decoding, because that might modify the + buffer, while we rely on process_coding.produced to + faithfully reflect inserted text until we + TEMP_SET_PT_BOTH below. */ + specbind (Qinhibit_modification_hooks, Qt); + decode_coding_c_string (process_coding, + (unsigned char *) buf, nread, curbuf); + unbind_to (count1, Qnil); + + TEMP_SET_PT_BOTH (PT + process_coding->produced_char, + PT_BYTE + process_coding->produced); + signal_after_change (PT - process_coding->produced_char, + 0, process_coding->produced_char); + carryover = process_coding->carryover_bytes; + if (carryover > 0) + memcpy (buf, process_coding->carryover, + process_coding->carryover_bytes); + } +} + static void read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, ssize_t nbytes,