@@ -746,6 +746,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
746
746
int carryover = 0 ;
747
747
bool display_on_the_fly = display_p ;
748
748
struct coding_system saved_coding = process_coding ;
749
+ ptrdiff_t prepared_pos = 0 ; /* prepare_to_modify_buffer was last
750
+ called here. */
749
751
750
752
while (1 )
751
753
{
@@ -773,22 +775,50 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
773
775
if (display_on_the_fly )
774
776
break ;
775
777
}
778
+ /* CHANGE FUNCTIONS
779
+ For each iteration of the enclosing while (1) loop which
780
+ yields data (i.e. nread > 0), before- and
781
+ after-change-functions are each invoked exactly once.
782
+ This is done directly from the current function only, by
783
+ calling prepare_to_modify_buffer and signal_after_change.
784
+ It is not done here by directing another function such as
785
+ insert_1_both to call them. The call to
786
+ prepare_to_modify_buffer follows this comment, and there
787
+ is one call to signal_after_change in each of the
788
+ branches of the next `else if'.
789
+
790
+ Exceptionally, the insertion into the buffer is aborted
791
+ at the call to del_range_2 ~45 lines further down, this
792
+ function removing the newly inserted data. At this stage
793
+ prepare_to_modify_buffer has been called, but
794
+ signal_after_change hasn't. A continue statement
795
+ restarts the enclosing while (1) loop. A second,
796
+ unwanted, call to `prepare_to_modify_buffer' is inhibited
797
+ by the test perpared_pos < PT. The data are inserted
798
+ again, and this time signal_after_change gets called,
799
+ balancing the previous call to prepare_to_modify_buffer. */
800
+ if ((prepared_pos < PT ) && nread )
801
+ {
802
+ prepare_to_modify_buffer (PT , PT , NULL );
803
+ prepared_pos = PT ;
804
+ }
776
805
777
806
/* Now NREAD is the total amount of data in the buffer. */
778
807
779
808
if (!nread )
780
809
;
781
810
else if (NILP (BVAR (current_buffer , enable_multibyte_characters ))
782
811
&& ! CODING_MAY_REQUIRE_DECODING (& process_coding ))
783
- insert_1_both (buf , nread , nread , 0 , 1 , 0 );
812
+ {
813
+ insert_1_both (buf , nread , nread , 0 , 0 , 0 );
814
+ signal_after_change (PT , 0 , nread );
815
+ }
784
816
else
785
817
{ /* We have to decode the input. */
786
818
Lisp_Object curbuf ;
787
819
ptrdiff_t count1 = SPECPDL_INDEX ();
788
820
789
821
XSETBUFFER (curbuf , current_buffer );
790
- /* FIXME: Call signal_after_change! */
791
- prepare_to_modify_buffer (PT , PT , NULL );
792
822
/* We cannot allow after-change-functions be run
793
823
during decoding, because that might modify the
794
824
buffer, while we rely on process_coding.produced to
@@ -824,6 +854,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
824
854
825
855
TEMP_SET_PT_BOTH (PT + process_coding .produced_char ,
826
856
PT_BYTE + process_coding .produced );
857
+ signal_after_change (PT , 0 , process_coding .produced_char );
827
858
carryover = process_coding .carryover_bytes ;
828
859
if (carryover > 0 )
829
860
memcpy (buf , process_coding .carryover ,
0 commit comments