changeset 3568:3ee951a22a80

(Fforward_comment): Set point to where scan stops, thus moving acros whitespace. When moving fwd, treat Sendcomment as whitespace; likewise for Scomment when moving back. (scan_sexps_forward): New arg COMMENTSTOP. (Fparse_partial_sexp): Likewise.
author Richard M. Stallman <rms@gnu.org>
date Tue, 08 Jun 1993 06:12:08 +0000
parents 2ca5f216e445
children 8399d8e4ad22
files src/syntax.c
diffstat 1 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/syntax.c	Tue Jun 08 05:25:19 1993 +0000
+++ b/src/syntax.c	Tue Jun 08 06:12:08 1993 +0000
@@ -565,8 +565,8 @@
 
 DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0,
   "Move forward across up to N comments.  If N is negative, move backward.\n\
-Set point to the far end of the last comment found.\n\
 Stop scanning if we find something other than a comment or whitespace.\n\
+Set point to where scanning stops.\n\
 If N comments are found as expected, with nothing except whitespace\n\
 between them, return t; otherwise return nil.")
   (count)
@@ -587,11 +587,9 @@
   QUIT;
 
   from = PT;
-  found = from;
 
   while (count1 > 0)
     {
-      found = from;
       stop = ZV;
       while (from < stop)
 	{
@@ -619,7 +617,7 @@
 		  if (from == stop)
 		    {
 		      immediate_quit = 0;
-		      SET_PT (found);
+		      SET_PT (from);
 		      return Qnil;
 		    }
 		  c = FETCH_CHAR (from);
@@ -641,10 +639,10 @@
 	      /* We have skipped one comment.  */
 	      break;
 	    }
-	  else if (code != Swhitespace)
+	  else if (code != Swhitespace && code != Sendcomment)
 	    {
 	      immediate_quit = 0;
-	      SET_PT (found);
+	      SET_PT (from - 1);
 	      return Qnil;
 	    }
 	}
@@ -655,8 +653,6 @@
 
   while (count1 < 0)
     {
-      found = from;
-
       stop = BEGV;
       while (from > stop)
 	{
@@ -696,7 +692,7 @@
 		      if (from == stop)
 			{
 			  immediate_quit = 0;
-			  SET_PT (found);
+			  SET_PT (from);
 			  return Qnil;
 			}
 		      from--;
@@ -817,10 +813,10 @@
 		  }
 	      }
 	    }
-	  else if (code != Swhitespace || quoted)
+	  else if ((code != Swhitespace && code != Scomment) || quoted)
 	    {
 	      immediate_quit = 0;
-	      SET_PT (found);
+	      SET_PT (from + 1);
 	      return Qnil;
 	    }
 	}
@@ -1321,13 +1317,16 @@
 /* Parse forward from FROM to END,
    assuming that FROM has state OLDSTATE (nil means FROM is start of function),
    and return a description of the state of the parse at END.
-   If STOPBEFORE is nonzero, stop at the start of an atom.  */
+   If STOPBEFORE is nonzero, stop at the start of an atom.
+   If COMMENTSTOP is nonzero, stop at the start of a comment.  */
 
-scan_sexps_forward (stateptr, from, end, targetdepth, stopbefore, oldstate)
+scan_sexps_forward (stateptr, from, end, targetdepth,
+		    stopbefore, oldstate, commentstop)
      struct lisp_parse_state *stateptr;
      register int from;
      int end, targetdepth, stopbefore;
      Lisp_Object oldstate;
+     int commentstop;
 {
   struct lisp_parse_state state;
 
@@ -1467,6 +1466,8 @@
 	  state.incomment = 1;
 	  state.comstart = from;
 	startincomment:
+	  if (commentstop)
+	    goto done;
 	  while (1)
 	    {
 	      if (from == end) goto done;
@@ -1568,7 +1569,7 @@
    for make-docfile to see.  We cannot put this in the real DEFUN
    due to limits in the Unix cpp.
 
-DEFUN ("parse-partial-sexp", Ffoo, Sfoo, 2, 5, 0,
+DEFUN ("parse-partial-sexp", Ffoo, Sfoo, 2, 6, 0,
   "Parse Lisp syntax starting at FROM until TO; return status of parse at TO.\n\
 Parsing stops at TO or when certain criteria are met;\n\
  point is set to where parsing stops.\n\
@@ -1590,14 +1591,15 @@
  any character that starts a sexp.\n\
 Fifth arg STATE is a seven-list like what this function returns.\n\
 It is used to initialize the state of the parse.  Its second and third
-elements are ignored.")
-  (from, to, targetdepth, stopbefore, state)
+elements are ignored.
+Sixth args COMMENTSTOP non-nil means stop at the start of a comment.")
+  (from, to, targetdepth, stopbefore, state, commentstop)
 */
 
-DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 5, 0,
+DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 6, 0,
   0 /* See immediately above */)
-  (from, to, targetdepth, stopbefore, oldstate)
-     Lisp_Object from, to, targetdepth, stopbefore, oldstate;
+  (from, to, targetdepth, stopbefore, oldstate, commentstop)
+     Lisp_Object from, to, targetdepth, stopbefore, oldstate, commentstop;
 {
   struct lisp_parse_state state;
   int target;
@@ -1612,7 +1614,8 @@
 
   validate_region (&from, &to);
   scan_sexps_forward (&state, XINT (from), XINT (to),
-		      target, !NILP (stopbefore), oldstate);
+		      target, !NILP (stopbefore), oldstate,
+		      !NILP (commentstop));
 
   SET_PT (state.location);