"Insert before markers" in read_and_insert_process_output properly
* src/coding.c (setup_coding_system): Initialize it. (produce_chars, encode_coding, decode_coding_gap): Obey it in insert_from_gap calls. (encode_string_utf_8, decode_string_utf_8): Update the other calls to insert_from_gap to have one new argument (false). * src/coding.h: New field insert_before_markers. * src/decompress.c (Fzlib_decompress_region): Here too. * src/insdel.c (insert_from_gap): Accept new argument BEFORE_MARKERS (bug#71525) and pass it through to adjust_markers_for_insert. * src/lisp.h: Update prototype. * src/process.c (read_and_insert_process_output): Set process_coding->insert_before_markers instead of calling adjust_markers_for_insert.
This commit is contained in:
parent
08e38818f6
commit
a8d5c5fd87
6 changed files with 28 additions and 14 deletions
13
src/coding.c
13
src/coding.c
|
@ -5698,6 +5698,7 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding)
|
|||
coding->default_char = XFIXNUM (CODING_ATTR_DEFAULT_CHAR (attrs));
|
||||
coding->carryover_bytes = 0;
|
||||
coding->raw_destination = 0;
|
||||
coding->insert_before_markers = 0;
|
||||
|
||||
coding_type = CODING_ATTR_TYPE (attrs);
|
||||
if (EQ (coding_type, Qundecided))
|
||||
|
@ -7209,7 +7210,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
|
|||
|
||||
produced = dst - (coding->destination + coding->produced);
|
||||
if (BUFFERP (coding->dst_object) && produced_chars > 0)
|
||||
insert_from_gap (produced_chars, produced, 0);
|
||||
insert_from_gap (produced_chars, produced, 0,
|
||||
coding->insert_before_markers);
|
||||
coding->produced += produced;
|
||||
coding->produced_char += produced_chars;
|
||||
return carryover;
|
||||
|
@ -7814,7 +7816,8 @@ encode_coding (struct coding_system *coding)
|
|||
} while (coding->consumed_char < coding->src_chars);
|
||||
|
||||
if (BUFFERP (coding->dst_object) && coding->produced_char > 0)
|
||||
insert_from_gap (coding->produced_char, coding->produced, 0);
|
||||
insert_from_gap (coding->produced_char, coding->produced, 0,
|
||||
coding->insert_before_markers);
|
||||
|
||||
SAFE_FREE ();
|
||||
}
|
||||
|
@ -8008,7 +8011,7 @@ decode_coding_gap (struct coding_system *coding, ptrdiff_t bytes)
|
|||
}
|
||||
coding->produced = bytes;
|
||||
coding->produced_char = chars;
|
||||
insert_from_gap (chars, bytes, 1);
|
||||
insert_from_gap (chars, bytes, 1, coding->insert_before_markers);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -9980,7 +9983,7 @@ encode_string_utf_8 (Lisp_Object string, Lisp_Object buffer,
|
|||
struct buffer *oldb = current_buffer;
|
||||
|
||||
current_buffer = XBUFFER (buffer);
|
||||
insert_from_gap (outbytes, outbytes, false);
|
||||
insert_from_gap (outbytes, outbytes, false, false);
|
||||
current_buffer = oldb;
|
||||
}
|
||||
return val;
|
||||
|
@ -10290,7 +10293,7 @@ decode_string_utf_8 (Lisp_Object string, const char *str, ptrdiff_t str_len,
|
|||
struct buffer *oldb = current_buffer;
|
||||
|
||||
current_buffer = XBUFFER (buffer);
|
||||
insert_from_gap (outchars, outbytes, false);
|
||||
insert_from_gap (outchars, outbytes, false, false);
|
||||
current_buffer = oldb;
|
||||
}
|
||||
return val;
|
||||
|
|
|
@ -428,6 +428,10 @@ struct coding_system
|
|||
/* Set to true if charbuf contains an annotation. */
|
||||
bool_bf annotated : 1;
|
||||
|
||||
/* True to insert before markers in the output buffer,
|
||||
if `dst_object' is a buffer. */
|
||||
bool_bf insert_before_markers : 1;
|
||||
|
||||
/* Used internally in coding.c. See the comment of detect_ascii. */
|
||||
unsigned eol_seen : 3;
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ This function can be called only in unibyte buffers. */)
|
|||
inflate_status = inflate (&stream, Z_NO_FLUSH);
|
||||
pos_byte += avail_in - stream.avail_in;
|
||||
decompressed = avail_out - stream.avail_out;
|
||||
insert_from_gap (decompressed, decompressed, 0);
|
||||
insert_from_gap (decompressed, decompressed, 0, false);
|
||||
unwind_data.nbytes += decompressed;
|
||||
maybe_quit ();
|
||||
}
|
||||
|
|
12
src/insdel.c
12
src/insdel.c
|
@ -1129,10 +1129,15 @@ insert_from_gap_1 (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
|
|||
|
||||
/* Insert a sequence of NCHARS chars which occupy NBYTES bytes
|
||||
starting at GAP_END_ADDR - NBYTES (if text_at_gap_tail) and at
|
||||
GPT_ADDR (if not text_at_gap_tail). */
|
||||
GPT_ADDR (if not text_at_gap_tail).
|
||||
|
||||
If BEFORE_MARKERS is true, insert before markers. At the moment the
|
||||
only high-level callers of this functionality is
|
||||
read_and_insert_process_output in process.c. */
|
||||
|
||||
void
|
||||
insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
|
||||
insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail,
|
||||
bool before_markers)
|
||||
{
|
||||
ptrdiff_t ins_charpos = GPT, ins_bytepos = GPT_BYTE;
|
||||
|
||||
|
@ -1151,7 +1156,8 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
|
|||
insert_from_gap_1 (nchars, nbytes, text_at_gap_tail);
|
||||
|
||||
adjust_markers_for_insert (ins_charpos, ins_bytepos,
|
||||
ins_charpos + nchars, ins_bytepos + nbytes, false);
|
||||
ins_charpos + nchars, ins_bytepos + nbytes,
|
||||
before_markers);
|
||||
|
||||
if (buffer_intervals (current_buffer))
|
||||
{
|
||||
|
|
|
@ -4371,8 +4371,8 @@ extern void insert (const char *, ptrdiff_t);
|
|||
extern void insert_and_inherit (const char *, ptrdiff_t);
|
||||
extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
|
||||
bool, bool, bool);
|
||||
extern void insert_from_gap_1 (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
|
||||
extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
|
||||
extern void insert_from_gap_1 (ptrdiff_t, ptrdiff_t, bool);
|
||||
extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool, bool);
|
||||
extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
|
||||
ptrdiff_t, ptrdiff_t, bool);
|
||||
extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool);
|
||||
|
|
|
@ -6406,6 +6406,9 @@ read_and_insert_process_output (struct Lisp_Process *p, char *buf,
|
|||
if (NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters))
|
||||
&& ! CODING_MAY_REQUIRE_DECODING (process_coding))
|
||||
{
|
||||
/* For compatibility with the long-standing behavior of
|
||||
internal-default-process-filter we insert before markers,
|
||||
both here and in the 'else' branch. */
|
||||
insert_1_both (buf, nread, nread, 0, 0, 1);
|
||||
signal_after_change (PT - nread, 0, nread);
|
||||
}
|
||||
|
@ -6415,6 +6418,7 @@ read_and_insert_process_output (struct Lisp_Process *p, char *buf,
|
|||
specpdl_ref count1 = SPECPDL_INDEX ();
|
||||
|
||||
XSETBUFFER (curbuf, current_buffer);
|
||||
process_coding->insert_before_markers = true;
|
||||
/* We cannot allow after-change-functions be run
|
||||
during decoding, because that might modify the
|
||||
buffer, while we rely on process_coding.produced to
|
||||
|
@ -6423,9 +6427,6 @@ read_and_insert_process_output (struct Lisp_Process *p, char *buf,
|
|||
specbind (Qinhibit_modification_hooks, Qt);
|
||||
decode_coding_c_string (process_coding,
|
||||
(unsigned char *) buf, nread, curbuf);
|
||||
adjust_markers_for_insert (PT, PT_BYTE,
|
||||
PT + process_coding->produced_char,
|
||||
PT_BYTE + process_coding->produced, true);
|
||||
unbind_to (count1, Qnil);
|
||||
|
||||
read_process_output_set_last_coding_system (p, process_coding);
|
||||
|
|
Loading…
Add table
Reference in a new issue