Update years in copyright notice; nfc.
[bpt/emacs.git] / src / insdel.c
index 7f10c2f..fd41603 100644 (file)
@@ -1,6 +1,6 @@
 /* Buffer insertion/deletion and gap motion for GNU Emacs.
-   Copyright (C) 1985, 86,93,94,95,97,98, 1999, 2000, 01, 2003
-   Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
+                 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -16,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 #include <config.h>
@@ -1745,17 +1745,21 @@ replace_range_2 (from, from_byte, to, to_byte, ins, inschars, insbytes, markers)
 
   /* Adjust markers for the deletion and the insertion.  */
   if (markers
-      && ! (nchars_del == 1 && inschars == 1))
+      && ! (nchars_del == 1 && inschars == 1 && nbytes_del == insbytes))
     adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del,
                                inschars, insbytes);
 
   offset_intervals (current_buffer, from, inschars - nchars_del);
 
   /* Relocate point as if it were a marker.  */
-  if (from < PT && nchars_del != inschars)
-    adjust_point ((from + inschars - (PT < to ? PT : to)),
-                 (from_byte + insbytes
-                  - (PT_BYTE < to_byte ? PT_BYTE : to_byte)));
+  if (from < PT && (nchars_del != inschars || nbytes_del != insbytes))
+    {
+      if (PT < to)
+       /* PT was within the deleted text.  Move it to FROM.  */
+       adjust_point (from - PT, from_byte - PT_BYTE);
+      else
+       adjust_point (inschars - nchars_del, insbytes - nbytes_del);
+    }
 
   if (insbytes == 0)
     evaporate_overlays (from);
@@ -2389,6 +2393,7 @@ void
 syms_of_insdel ()
 {
   staticpro (&combine_after_change_list);
+  staticpro (&combine_after_change_buffer);
   combine_after_change_list = Qnil;
   combine_after_change_buffer = Qnil;