changeset 19444:752afe97eaa4

(Fchars_in_region): Fix gap handling.
author Richard M. Stallman <rms@gnu.org>
date Wed, 20 Aug 1997 22:28:40 +0000
parents 39815ec1b9f8
children 94a54fbffb3e
files src/charset.c
diffstat 1 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/charset.c	Wed Aug 20 17:25:25 1997 +0000
+++ b/src/charset.c	Wed Aug 20 22:28:40 1997 +0000
@@ -897,8 +897,8 @@
 
 DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0,
   "Return number of characters between BEG and END.\n\
-When using multibyte characters, this is not the necessarily same as\n\
-(- END BEG); that subtraction gives you the number of bytes, which\n\
+When using multibyte characters, this is not the necessarily same\n\
+as (- END BEG); that subtraction gives you the number of bytes, which\n\
 may be more than the number of characters.")
   (beg, end)
      Lisp_Object beg, end;
@@ -911,25 +911,30 @@
   validate_region (&beg, &end);
 
   from = min (XFASTINT (beg), XFASTINT (end));
-  stop = to = max (XFASTINT (beg), XFASTINT (end));
+  to = max (XFASTINT (beg), XFASTINT (end));
   p = POS_ADDR (from);
-  endp = POS_ADDR (stop);
 
-  if (from < GPT && GPT < to)
-    stop = GPT;
+  if (from < GPT && GPT <= to)
+    {
+      stop = GPT;
+      endp = GPT_ADDR;
+    }
+  else
+    {
+      stop = to;
+      endp = POS_ADDR (stop);
+    }
 
   while (1)
     {
       if (p == endp)
 	{
-	  if (stop == GPT)
-	    {
-	      p = POS_ADDR (stop);
-	      stop = to;
-	      endp = POS_ADDR (stop);
-	    }
-	  else
+	  if (stop == to)
 	    break;
+
+	  p = POS_ADDR (stop);
+	  stop = to;
+	  endp = POS_ADDR (stop);
 	}
 
       if (*p == LEADING_CODE_COMPOSITION)