comparison src/insdel.c @ 203:850242ba4a81 r20-3b28

Import from CVS: tag r20-3b28
author cvs
date Mon, 13 Aug 2007 10:02:21 +0200
parents 3d6bfa290dbd
children 78478c60bfcd
comparison
equal deleted inserted replaced
202:61eefc8fc970 203:850242ba4a81
2800 /* We do not have to adjust the Mule data; we just replaced a 2800 /* We do not have to adjust the Mule data; we just replaced a
2801 character with another of the same number of bytes. */ 2801 character with another of the same number of bytes. */
2802 } 2802 }
2803 else 2803 else
2804 { 2804 {
2805 /* must implement as deletion followed by insertion. */ 2805 /*
2806 * Must implement as deletion followed by insertion.
2807 *
2808 * Make a note to move point forward later in the one situation
2809 * where it is needed, a delete/insert one position behind
2810 * point. Point will drift backward by one position and stay
2811 * there otherwise.
2812 */
2813 int movepoint = (pos == BUF_PT (b) - 1);
2814
2806 buffer_delete_range (b, pos, pos + 1, 0); 2815 buffer_delete_range (b, pos, pos + 1, 0);
2807 /* Defensive steps in case the before-change-functions fuck around */ 2816 /* Defensive steps in case the before-change-functions fuck around */
2808 if (!BUFFER_LIVE_P (b)) 2817 if (!BUFFER_LIVE_P (b))
2809 /* Bad bad pre-change function. */ 2818 /* Bad bad pre-change function. */
2810 return; 2819 return;
2816 if (pos >= BUF_ZV (b)) 2825 if (pos >= BUF_ZV (b))
2817 pos = BUF_ZV (b) - 1; 2826 pos = BUF_ZV (b) - 1;
2818 if (pos < BUF_BEGV (b)) 2827 if (pos < BUF_BEGV (b))
2819 /* no more characters in buffer! */ 2828 /* no more characters in buffer! */
2820 return; 2829 return;
2821 buffer_insert_string_1 (b, pos, newstr, Qnil, 0, newlen, 0); 2830 /*
2831 * -1 as the pos argument means to move point forward with the
2832 * insertion, which we must do if the deletion moved point
2833 * backward so that it now equals the insertion point.
2834 */
2835 buffer_insert_string_1 (b, (movepoint ? -1 : pos),
2836 newstr, Qnil, 0, newlen, 0);
2822 } 2837 }
2823 } 2838 }
2824 2839
2825 2840
2826 /************************************************************************/ 2841 /************************************************************************/