> Rather than increment CHARS_MODIFF separately, > it should copy the value from MODIFF. > That way, values of CHARS_MODIFF will be comparable with values > that were copied from MODIFF. Yes, but it will deprive you of eventually introducing a variable SAVE_CHARS_MODIFF and tell whether an insertion/deletion occurred since the last save because CHARS_MODIFF > SAVE_CHARS_MODIFF. > Also, instead of setting CHARS_MODIFF explicitly in each place that > modifies the buffer, modify_region could set it from MODIFF, and > changing text properties could save and restore it to prevent it from > being incremented. That means changes in fewer places, and no need > for each place that modifies the buffer to know about CHARS_MODIFF. Perhaps the cleanest solution would be to equip modify_region with an additional parameter, say preserve_chars_modiff, and do everything in modify_region. In the attached patch I tried to follow your suggestions.