comparison src/syntax.c @ 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 ef7d99920f81
children 507f64624555
comparison
equal deleted inserted replaced
3567:2ca5f216e445 3568:3ee951a22a80
563 return Qt; 563 return Qt;
564 } 564 }
565 565
566 DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0, 566 DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0,
567 "Move forward across up to N comments. If N is negative, move backward.\n\ 567 "Move forward across up to N comments. If N is negative, move backward.\n\
568 Set point to the far end of the last comment found.\n\
569 Stop scanning if we find something other than a comment or whitespace.\n\ 568 Stop scanning if we find something other than a comment or whitespace.\n\
569 Set point to where scanning stops.\n\
570 If N comments are found as expected, with nothing except whitespace\n\ 570 If N comments are found as expected, with nothing except whitespace\n\
571 between them, return t; otherwise return nil.") 571 between them, return t; otherwise return nil.")
572 (count) 572 (count)
573 Lisp_Object count; 573 Lisp_Object count;
574 { 574 {
585 585
586 immediate_quit = 1; 586 immediate_quit = 1;
587 QUIT; 587 QUIT;
588 588
589 from = PT; 589 from = PT;
590 found = from;
591 590
592 while (count1 > 0) 591 while (count1 > 0)
593 { 592 {
594 found = from;
595 stop = ZV; 593 stop = ZV;
596 while (from < stop) 594 while (from < stop)
597 { 595 {
598 c = FETCH_CHAR (from); 596 c = FETCH_CHAR (from);
599 code = SYNTAX (c); 597 code = SYNTAX (c);
617 while (1) 615 while (1)
618 { 616 {
619 if (from == stop) 617 if (from == stop)
620 { 618 {
621 immediate_quit = 0; 619 immediate_quit = 0;
622 SET_PT (found); 620 SET_PT (from);
623 return Qnil; 621 return Qnil;
624 } 622 }
625 c = FETCH_CHAR (from); 623 c = FETCH_CHAR (from);
626 if (SYNTAX (c) == Sendcomment 624 if (SYNTAX (c) == Sendcomment
627 && SYNTAX_COMMENT_STYLE (c) == comstyle) 625 && SYNTAX_COMMENT_STYLE (c) == comstyle)
639 { from++; break; } 637 { from++; break; }
640 } 638 }
641 /* We have skipped one comment. */ 639 /* We have skipped one comment. */
642 break; 640 break;
643 } 641 }
644 else if (code != Swhitespace) 642 else if (code != Swhitespace && code != Sendcomment)
645 { 643 {
646 immediate_quit = 0; 644 immediate_quit = 0;
647 SET_PT (found); 645 SET_PT (from - 1);
648 return Qnil; 646 return Qnil;
649 } 647 }
650 } 648 }
651 649
652 /* End of comment reached */ 650 /* End of comment reached */
653 count1--; 651 count1--;
654 } 652 }
655 653
656 while (count1 < 0) 654 while (count1 < 0)
657 { 655 {
658 found = from;
659
660 stop = BEGV; 656 stop = BEGV;
661 while (from > stop) 657 while (from > stop)
662 { 658 {
663 int quoted; 659 int quoted;
664 660
694 && SYNTAX_COMMENT_STYLE (c) == comstyle) 690 && SYNTAX_COMMENT_STYLE (c) == comstyle)
695 break; 691 break;
696 if (from == stop) 692 if (from == stop)
697 { 693 {
698 immediate_quit = 0; 694 immediate_quit = 0;
699 SET_PT (found); 695 SET_PT (from);
700 return Qnil; 696 return Qnil;
701 } 697 }
702 from--; 698 from--;
703 if (SYNTAX_COMSTART_SECOND (c) 699 if (SYNTAX_COMSTART_SECOND (c)
704 && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from)) 700 && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from))
815 /* We can't grok this as a comment; scan it normally. */ 811 /* We can't grok this as a comment; scan it normally. */
816 from = comment_end; 812 from = comment_end;
817 } 813 }
818 } 814 }
819 } 815 }
820 else if (code != Swhitespace || quoted) 816 else if ((code != Swhitespace && code != Scomment) || quoted)
821 { 817 {
822 immediate_quit = 0; 818 immediate_quit = 0;
823 SET_PT (found); 819 SET_PT (from + 1);
824 return Qnil; 820 return Qnil;
825 } 821 }
826 } 822 }
827 823
828 count1++; 824 count1++;
1319 } 1315 }
1320 1316
1321 /* Parse forward from FROM to END, 1317 /* Parse forward from FROM to END,
1322 assuming that FROM has state OLDSTATE (nil means FROM is start of function), 1318 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
1323 and return a description of the state of the parse at END. 1319 and return a description of the state of the parse at END.
1324 If STOPBEFORE is nonzero, stop at the start of an atom. */ 1320 If STOPBEFORE is nonzero, stop at the start of an atom.
1325 1321 If COMMENTSTOP is nonzero, stop at the start of a comment. */
1326 scan_sexps_forward (stateptr, from, end, targetdepth, stopbefore, oldstate) 1322
1323 scan_sexps_forward (stateptr, from, end, targetdepth,
1324 stopbefore, oldstate, commentstop)
1327 struct lisp_parse_state *stateptr; 1325 struct lisp_parse_state *stateptr;
1328 register int from; 1326 register int from;
1329 int end, targetdepth, stopbefore; 1327 int end, targetdepth, stopbefore;
1330 Lisp_Object oldstate; 1328 Lisp_Object oldstate;
1329 int commentstop;
1331 { 1330 {
1332 struct lisp_parse_state state; 1331 struct lisp_parse_state state;
1333 1332
1334 register enum syntaxcode code; 1333 register enum syntaxcode code;
1335 struct level { int last, prev; }; 1334 struct level { int last, prev; };
1465 1464
1466 case Scomment: 1465 case Scomment:
1467 state.incomment = 1; 1466 state.incomment = 1;
1468 state.comstart = from; 1467 state.comstart = from;
1469 startincomment: 1468 startincomment:
1469 if (commentstop)
1470 goto done;
1470 while (1) 1471 while (1)
1471 { 1472 {
1472 if (from == end) goto done; 1473 if (from == end) goto done;
1473 prev = FETCH_CHAR (from); 1474 prev = FETCH_CHAR (from);
1474 if (SYNTAX (prev) == Sendcomment 1475 if (SYNTAX (prev) == Sendcomment
1566 1567
1567 /* This comment supplies the doc string for parse-partial-sexp, 1568 /* This comment supplies the doc string for parse-partial-sexp,
1568 for make-docfile to see. We cannot put this in the real DEFUN 1569 for make-docfile to see. We cannot put this in the real DEFUN
1569 due to limits in the Unix cpp. 1570 due to limits in the Unix cpp.
1570 1571
1571 DEFUN ("parse-partial-sexp", Ffoo, Sfoo, 2, 5, 0, 1572 DEFUN ("parse-partial-sexp", Ffoo, Sfoo, 2, 6, 0,
1572 "Parse Lisp syntax starting at FROM until TO; return status of parse at TO.\n\ 1573 "Parse Lisp syntax starting at FROM until TO; return status of parse at TO.\n\
1573 Parsing stops at TO or when certain criteria are met;\n\ 1574 Parsing stops at TO or when certain criteria are met;\n\
1574 point is set to where parsing stops.\n\ 1575 point is set to where parsing stops.\n\
1575 If fifth arg STATE is omitted or nil,\n\ 1576 If fifth arg STATE is omitted or nil,\n\
1576 parsing assumes that FROM is the beginning of a function.\n\ 1577 parsing assumes that FROM is the beginning of a function.\n\
1588 in parentheses becomes equal to TARGETDEPTH.\n\ 1589 in parentheses becomes equal to TARGETDEPTH.\n\
1589 Fourth arg STOPBEFORE non-nil means stop when come to\n\ 1590 Fourth arg STOPBEFORE non-nil means stop when come to\n\
1590 any character that starts a sexp.\n\ 1591 any character that starts a sexp.\n\
1591 Fifth arg STATE is a seven-list like what this function returns.\n\ 1592 Fifth arg STATE is a seven-list like what this function returns.\n\
1592 It is used to initialize the state of the parse. Its second and third 1593 It is used to initialize the state of the parse. Its second and third
1593 elements are ignored.") 1594 elements are ignored.
1594 (from, to, targetdepth, stopbefore, state) 1595 Sixth args COMMENTSTOP non-nil means stop at the start of a comment.")
1596 (from, to, targetdepth, stopbefore, state, commentstop)
1595 */ 1597 */
1596 1598
1597 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 5, 0, 1599 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 6, 0,
1598 0 /* See immediately above */) 1600 0 /* See immediately above */)
1599 (from, to, targetdepth, stopbefore, oldstate) 1601 (from, to, targetdepth, stopbefore, oldstate, commentstop)
1600 Lisp_Object from, to, targetdepth, stopbefore, oldstate; 1602 Lisp_Object from, to, targetdepth, stopbefore, oldstate, commentstop;
1601 { 1603 {
1602 struct lisp_parse_state state; 1604 struct lisp_parse_state state;
1603 int target; 1605 int target;
1604 1606
1605 if (!NILP (targetdepth)) 1607 if (!NILP (targetdepth))
1610 else 1612 else
1611 target = -100000; /* We won't reach this depth */ 1613 target = -100000; /* We won't reach this depth */
1612 1614
1613 validate_region (&from, &to); 1615 validate_region (&from, &to);
1614 scan_sexps_forward (&state, XINT (from), XINT (to), 1616 scan_sexps_forward (&state, XINT (from), XINT (to),
1615 target, !NILP (stopbefore), oldstate); 1617 target, !NILP (stopbefore), oldstate,
1618 !NILP (commentstop));
1616 1619
1617 SET_PT (state.location); 1620 SET_PT (state.location);
1618 1621
1619 return Fcons (make_number (state.depth), 1622 return Fcons (make_number (state.depth),
1620 Fcons (state.prevlevelstart < 0 ? Qnil : make_number (state.prevlevelstart), 1623 Fcons (state.prevlevelstart < 0 ? Qnil : make_number (state.prevlevelstart),