diff options
| author | Stefan Monnier | 2024-04-10 12:15:26 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2024-04-10 12:15:26 -0400 |
| commit | 36cb16556c60bf4e703764eefd4fb6668ccc37cc (patch) | |
| tree | 22ea5c9410cef797c7a9a50c8b1de934185d89e5 /src/coding.c | |
| parent | 15bafc04322e9c4e85a00fe593239935eb723b6e (diff) | |
| download | emacs-36cb16556c60bf4e703764eefd4fb6668ccc37cc.tar.gz emacs-36cb16556c60bf4e703764eefd4fb6668ccc37cc.zip | |
(en/decode_coding_object): Fix `after-change-functions`
For `en/decode-coding-string/region`, `after-change-functions`
were either not run at all, or run only after deleting the text
but not after inserting it.
* src/coding.c (decode_coding_object, encode_coding_object): Run the
after-change-functions after inserting the result.
* test/src/editfns-tests.el (sanity-check-change-functions-with-op):
New macro.
(sanity-check-change-functions-errors): New function.
(editfns-tests--before/after-change-functions): Use them to add
cases for `en/decode-coding-string/region`.
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/src/coding.c b/src/coding.c index c51ceb95475..b21f2ecf00a 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -8109,7 +8109,7 @@ decode_coding_object (struct coding_system *coding, | |||
| 8109 | set_buffer_internal (XBUFFER (src_object)); | 8109 | set_buffer_internal (XBUFFER (src_object)); |
| 8110 | if (from != GPT) | 8110 | if (from != GPT) |
| 8111 | move_gap_both (from, from_byte); | 8111 | move_gap_both (from, from_byte); |
| 8112 | if (EQ (src_object, dst_object)) | 8112 | if (BASE_EQ (src_object, dst_object)) |
| 8113 | { | 8113 | { |
| 8114 | struct Lisp_Marker *tail; | 8114 | struct Lisp_Marker *tail; |
| 8115 | 8115 | ||
| @@ -8121,8 +8121,9 @@ decode_coding_object (struct coding_system *coding, | |||
| 8121 | } | 8121 | } |
| 8122 | saved_pt = PT, saved_pt_byte = PT_BYTE; | 8122 | saved_pt = PT, saved_pt_byte = PT_BYTE; |
| 8123 | TEMP_SET_PT_BOTH (from, from_byte); | 8123 | TEMP_SET_PT_BOTH (from, from_byte); |
| 8124 | current_buffer->text->inhibit_shrinking = 1; | 8124 | current_buffer->text->inhibit_shrinking = true; |
| 8125 | del_range_both (from, from_byte, to, to_byte, 1); | 8125 | prepare_to_modify_buffer (from, to, NULL); |
| 8126 | del_range_2 (from, from_byte, to, to_byte, false); | ||
| 8126 | coding->src_pos = -chars; | 8127 | coding->src_pos = -chars; |
| 8127 | coding->src_pos_byte = -bytes; | 8128 | coding->src_pos_byte = -bytes; |
| 8128 | } | 8129 | } |
| @@ -8148,6 +8149,13 @@ decode_coding_object (struct coding_system *coding, | |||
| 8148 | } | 8149 | } |
| 8149 | else if (BUFFERP (dst_object)) | 8150 | else if (BUFFERP (dst_object)) |
| 8150 | { | 8151 | { |
| 8152 | if (!BASE_EQ (src_object, dst_object)) | ||
| 8153 | { | ||
| 8154 | struct buffer *current = current_buffer; | ||
| 8155 | set_buffer_internal (XBUFFER (dst_object)); | ||
| 8156 | prepare_to_modify_buffer (PT, PT, NULL); | ||
| 8157 | set_buffer_internal (current); | ||
| 8158 | } | ||
| 8151 | code_conversion_save (0, 0); | 8159 | code_conversion_save (0, 0); |
| 8152 | coding->dst_object = dst_object; | 8160 | coding->dst_object = dst_object; |
| 8153 | coding->dst_pos = BUF_PT (XBUFFER (dst_object)); | 8161 | coding->dst_pos = BUF_PT (XBUFFER (dst_object)); |
| @@ -8168,7 +8176,14 @@ decode_coding_object (struct coding_system *coding, | |||
| 8168 | decode_coding (coding); | 8176 | decode_coding (coding); |
| 8169 | 8177 | ||
| 8170 | if (BUFFERP (coding->dst_object)) | 8178 | if (BUFFERP (coding->dst_object)) |
| 8171 | set_buffer_internal (XBUFFER (coding->dst_object)); | 8179 | { |
| 8180 | set_buffer_internal (XBUFFER (coding->dst_object)); | ||
| 8181 | signal_after_change (coding->dst_pos, | ||
| 8182 | BASE_EQ (src_object, dst_object) ? to - from : 0, | ||
| 8183 | coding->produced_char); | ||
| 8184 | update_compositions (coding->dst_pos, | ||
| 8185 | coding->dst_pos + coding->produced_char, CHECK_ALL); | ||
| 8186 | } | ||
| 8172 | 8187 | ||
| 8173 | if (! NILP (CODING_ATTR_POST_READ (attrs))) | 8188 | if (! NILP (CODING_ATTR_POST_READ (attrs))) |
| 8174 | { | 8189 | { |
| @@ -8373,7 +8388,12 @@ encode_coding_object (struct coding_system *coding, | |||
| 8373 | if (same_buffer) | 8388 | if (same_buffer) |
| 8374 | { | 8389 | { |
| 8375 | saved_pt = PT, saved_pt_byte = PT_BYTE; | 8390 | saved_pt = PT, saved_pt_byte = PT_BYTE; |
| 8376 | coding->src_object = del_range_1 (from, to, 1, 1); | 8391 | /* Run 'prepare_to_modify_buffer' by hand because we don't want |
| 8392 | to run the after-change hooks yet. */ | ||
| 8393 | prepare_to_modify_buffer (from, to, &from); | ||
| 8394 | coding->src_object = del_range_2 (from, CHAR_TO_BYTE (from), | ||
| 8395 | to, CHAR_TO_BYTE (to), | ||
| 8396 | true); | ||
| 8377 | coding->src_pos = 0; | 8397 | coding->src_pos = 0; |
| 8378 | coding->src_pos_byte = 0; | 8398 | coding->src_pos_byte = 0; |
| 8379 | } | 8399 | } |
| @@ -8404,11 +8424,12 @@ encode_coding_object (struct coding_system *coding, | |||
| 8404 | { | 8424 | { |
| 8405 | struct buffer *current = current_buffer; | 8425 | struct buffer *current = current_buffer; |
| 8406 | 8426 | ||
| 8407 | set_buffer_temp (XBUFFER (dst_object)); | 8427 | set_buffer_internal (XBUFFER (dst_object)); |
| 8428 | prepare_to_modify_buffer (PT, PT, NULL); | ||
| 8408 | coding->dst_pos = PT; | 8429 | coding->dst_pos = PT; |
| 8409 | coding->dst_pos_byte = PT_BYTE; | 8430 | coding->dst_pos_byte = PT_BYTE; |
| 8410 | move_gap_both (coding->dst_pos, coding->dst_pos_byte); | 8431 | move_gap_both (coding->dst_pos, coding->dst_pos_byte); |
| 8411 | set_buffer_temp (current); | 8432 | set_buffer_internal (current); |
| 8412 | } | 8433 | } |
| 8413 | coding->dst_multibyte | 8434 | coding->dst_multibyte |
| 8414 | = ! NILP (BVAR (XBUFFER (dst_object), enable_multibyte_characters)); | 8435 | = ! NILP (BVAR (XBUFFER (dst_object), enable_multibyte_characters)); |
| @@ -8446,6 +8467,16 @@ encode_coding_object (struct coding_system *coding, | |||
| 8446 | xfree (coding->destination); | 8467 | xfree (coding->destination); |
| 8447 | } | 8468 | } |
| 8448 | } | 8469 | } |
| 8470 | else if (BUFFERP (coding->dst_object)) | ||
| 8471 | { | ||
| 8472 | struct buffer *current = current_buffer; | ||
| 8473 | set_buffer_internal (XBUFFER (dst_object)); | ||
| 8474 | signal_after_change (coding->dst_pos, same_buffer ? to - from : 0, | ||
| 8475 | coding->produced_char); | ||
| 8476 | update_compositions (coding->dst_pos, | ||
| 8477 | coding->dst_pos + coding->produced_char, CHECK_ALL); | ||
| 8478 | set_buffer_internal (current); | ||
| 8479 | } | ||
| 8449 | 8480 | ||
| 8450 | if (saved_pt >= 0) | 8481 | if (saved_pt >= 0) |
| 8451 | { | 8482 | { |
| @@ -9510,7 +9541,7 @@ not fully specified.) */) | |||
| 9510 | 9541 | ||
| 9511 | DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, | 9542 | DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
| 9512 | 3, 4, "r\nzCoding system: ", | 9543 | 3, 4, "r\nzCoding system: ", |
| 9513 | doc: /* Encode the current region using th specified coding system. | 9544 | doc: /* Encode the current region using the specified coding system. |
| 9514 | Interactively, prompt for the coding system to encode the region, and | 9545 | Interactively, prompt for the coding system to encode the region, and |
| 9515 | replace the region with the bytes that are the result of the encoding. | 9546 | replace the region with the bytes that are the result of the encoding. |
| 9516 | 9547 | ||