aboutsummaryrefslogtreecommitdiffstats
path: root/src/syntax.c
diff options
context:
space:
mode:
authorJoakim Verona2010-08-27 10:58:44 +0200
committerJoakim Verona2010-08-27 10:58:44 +0200
commit362120833bcbbaea94976b6701633e2ed75f6051 (patch)
tree632690a24a934bb51a32303add5172d63b6b9e00 /src/syntax.c
parent1800c4865b15a9e1154bf1f03d87d1aaf750a527 (diff)
parent1a868076f51b5d6f1cf78117463e6f9c614551ec (diff)
downloademacs-362120833bcbbaea94976b6701633e2ed75f6051.tar.gz
emacs-362120833bcbbaea94976b6701633e2ed75f6051.zip
merge from trunk, fix conflicts
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c398
1 files changed, 226 insertions, 172 deletions
diff --git a/src/syntax.c b/src/syntax.c
index 4741fa260d2..f0a7dca42dc 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -34,6 +34,60 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
34 34
35#include "syntax.h" 35#include "syntax.h"
36#include "intervals.h" 36#include "intervals.h"
37#include "category.h"
38
39/* Then there are seven single-bit flags that have the following meanings:
40 1. This character is the first of a two-character comment-start sequence.
41 2. This character is the second of a two-character comment-start sequence.
42 3. This character is the first of a two-character comment-end sequence.
43 4. This character is the second of a two-character comment-end sequence.
44 5. This character is a prefix, for backward-prefix-chars.
45 6. The char is part of a delimiter for comments of style "b".
46 7. This character is part of a nestable comment sequence.
47 8. The char is part of a delimiter for comments of style "c".
48 Note that any two-character sequence whose first character has flag 1
49 and whose second character has flag 2 will be interpreted as a comment start.
50
51 bit 6 and 8 are used to discriminate between different comment styles.
52 Languages such as C++ allow two orthogonal syntax start/end pairs
53 and bit 6 is used to determine whether a comment-end or Scommentend
54 ends style a or b. Comment markers can start style a, b, c, or bc.
55 Style a is always the default.
56 For 2-char comment markers, the style b flag is only looked up on the second
57 char of the comment marker and on the first char of the comment ender.
58 For style c (like to for the nested flag), the flag can be placed on any
59 one of the chars.
60 */
61
62/* These macros extract specific flags from an integer
63 that holds the syntax code and the flags. */
64
65#define SYNTAX_FLAGS_COMSTART_FIRST(flags) (((flags) >> 16) & 1)
66
67#define SYNTAX_FLAGS_COMSTART_SECOND(flags) (((flags) >> 17) & 1)
68
69#define SYNTAX_FLAGS_COMEND_FIRST(flags) (((flags) >> 18) & 1)
70
71#define SYNTAX_FLAGS_COMEND_SECOND(flags) (((flags) >> 19) & 1)
72
73#define SYNTAX_FLAGS_PREFIX(flags) (((flags) >> 20) & 1)
74
75#define SYNTAX_FLAGS_COMMENT_STYLEB(flags) (((flags) >> 21) & 1)
76#define SYNTAX_FLAGS_COMMENT_STYLEC(flags) (((flags) >> 22) & 2)
77/* FLAGS should be the flags of the main char of the comment marker, e.g.
78 the second for comstart and the first for comend. */
79#define SYNTAX_FLAGS_COMMENT_STYLE(flags, other_flags) \
80 (SYNTAX_FLAGS_COMMENT_STYLEB (flags) \
81 | SYNTAX_FLAGS_COMMENT_STYLEC (flags) \
82 | SYNTAX_FLAGS_COMMENT_STYLEC (other_flags))
83
84#define SYNTAX_FLAGS_COMMENT_NESTED(flags) (((flags) >> 22) & 1)
85
86/* These macros extract a particular flag for a given character. */
87
88#define SYNTAX_COMEND_FIRST(c) \
89 (SYNTAX_FLAGS_COMEND_FIRST (SYNTAX_WITH_FLAGS (c)))
90#define SYNTAX_PREFIX(c) (SYNTAX_FLAGS_PREFIX (SYNTAX_WITH_FLAGS (c)))
37 91
38/* We use these constants in place for comment-style and 92/* We use these constants in place for comment-style and
39 string-ender-char to distinguish comments/strings started by 93 string-ender-char to distinguish comments/strings started by
@@ -41,7 +95,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
41 95
42#define ST_COMMENT_STYLE (256 + 1) 96#define ST_COMMENT_STYLE (256 + 1)
43#define ST_STRING_STYLE (256 + 2) 97#define ST_STRING_STYLE (256 + 2)
44#include "category.h"
45 98
46Lisp_Object Qsyntax_table_p, Qsyntax_table, Qscan_error; 99Lisp_Object Qsyntax_table_p, Qsyntax_table, Qscan_error;
47 100
@@ -98,18 +151,23 @@ static EMACS_INT find_start_begv;
98static int find_start_modiff; 151static int find_start_modiff;
99 152
100 153
101static Lisp_Object skip_chars P_ ((int, Lisp_Object, Lisp_Object, int)); 154static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int);
102static Lisp_Object skip_syntaxes P_ ((int, Lisp_Object, Lisp_Object)); 155static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object);
103static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int)); 156static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int);
104static void scan_sexps_forward P_ ((struct lisp_parse_state *, 157static void scan_sexps_forward (struct lisp_parse_state *,
105 EMACS_INT, EMACS_INT, EMACS_INT, int, 158 EMACS_INT, EMACS_INT, EMACS_INT, int,
106 int, Lisp_Object, int)); 159 int, Lisp_Object, int);
107static int in_classes P_ ((int, Lisp_Object)); 160static int in_classes (int, Lisp_Object);
108 161
162/* Whether the syntax of the character C has the prefix flag set. */
163int syntax_prefix_flag_p (int c)
164{
165 return SYNTAX_PREFIX (c);
166}
109 167
110struct gl_state_s gl_state; /* Global state of syntax parser. */ 168struct gl_state_s gl_state; /* Global state of syntax parser. */
111 169
112INTERVAL interval_of (); 170INTERVAL interval_of (int, Lisp_Object);
113#define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals 171#define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
114 to scan to property-change. */ 172 to scan to property-change. */
115 173
@@ -127,9 +185,7 @@ INTERVAL interval_of ();
127 start/end of OBJECT. */ 185 start/end of OBJECT. */
128 186
129void 187void
130update_syntax_table (charpos, count, init, object) 188update_syntax_table (int charpos, int count, int init, Lisp_Object object)
131 int charpos, count, init;
132 Lisp_Object object;
133{ 189{
134 Lisp_Object tmp_table; 190 Lisp_Object tmp_table;
135 int cnt = 0, invalidate = 1; 191 int cnt = 0, invalidate = 1;
@@ -318,8 +374,7 @@ char_quoted (EMACS_INT charpos, EMACS_INT bytepos)
318 We assume that BYTEPOS is not at the end of the buffer. */ 374 We assume that BYTEPOS is not at the end of the buffer. */
319 375
320INLINE EMACS_INT 376INLINE EMACS_INT
321inc_bytepos (bytepos) 377inc_bytepos (EMACS_INT bytepos)
322 EMACS_INT bytepos;
323{ 378{
324 if (NILP (current_buffer->enable_multibyte_characters)) 379 if (NILP (current_buffer->enable_multibyte_characters))
325 return bytepos + 1; 380 return bytepos + 1;
@@ -332,8 +387,7 @@ inc_bytepos (bytepos)
332 We assume that BYTEPOS is not at the start of the buffer. */ 387 We assume that BYTEPOS is not at the start of the buffer. */
333 388
334INLINE EMACS_INT 389INLINE EMACS_INT
335dec_bytepos (bytepos) 390dec_bytepos (EMACS_INT bytepos)
336 EMACS_INT bytepos;
337{ 391{
338 if (NILP (current_buffer->enable_multibyte_characters)) 392 if (NILP (current_buffer->enable_multibyte_characters))
339 return bytepos - 1; 393 return bytepos - 1;
@@ -357,8 +411,7 @@ dec_bytepos (bytepos)
357 update the global data. */ 411 update the global data. */
358 412
359static EMACS_INT 413static EMACS_INT
360find_defun_start (pos, pos_byte) 414find_defun_start (EMACS_INT pos, EMACS_INT pos_byte)
361 EMACS_INT pos, pos_byte;
362{ 415{
363 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; 416 EMACS_INT opoint = PT, opoint_byte = PT_BYTE;
364 417
@@ -422,8 +475,7 @@ find_defun_start (pos, pos_byte)
422/* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */ 475/* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
423 476
424static int 477static int
425prev_char_comend_first (pos, pos_byte) 478prev_char_comend_first (int pos, int pos_byte)
426 int pos, pos_byte;
427{ 479{
428 int c, val; 480 int c, val;
429 481
@@ -465,10 +517,7 @@ prev_char_comend_first (pos, pos_byte)
465 the returned value (or at FROM, if the search was not successful). */ 517 the returned value (or at FROM, if the search was not successful). */
466 518
467static int 519static int
468back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_ptr) 520back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested, int comstyle, EMACS_INT *charpos_ptr, EMACS_INT *bytepos_ptr)
469 EMACS_INT from, from_byte, stop;
470 int comnested, comstyle;
471 EMACS_INT *charpos_ptr, *bytepos_ptr;
472{ 521{
473 /* Look back, counting the parity of string-quotes, 522 /* Look back, counting the parity of string-quotes,
474 and recording the comment-starters seen. 523 and recording the comment-starters seen.
@@ -523,7 +572,8 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
523 /* Check for 2-char comment markers. */ 572 /* Check for 2-char comment markers. */
524 com2start = (SYNTAX_FLAGS_COMSTART_FIRST (syntax) 573 com2start = (SYNTAX_FLAGS_COMSTART_FIRST (syntax)
525 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax) 574 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax)
526 && comstyle == SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax) 575 && (comstyle
576 == SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax, syntax))
527 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax) 577 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax)
528 || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested); 578 || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested);
529 com2end = (SYNTAX_FLAGS_COMEND_FIRST (syntax) 579 com2end = (SYNTAX_FLAGS_COMEND_FIRST (syntax)
@@ -552,7 +602,8 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
552 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax)) 602 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax))
553 || ((com2end || comnested) 603 || ((com2end || comnested)
554 && SYNTAX_FLAGS_COMSTART_SECOND (syntax) 604 && SYNTAX_FLAGS_COMSTART_SECOND (syntax)
555 && comstyle == SYNTAX_FLAGS_COMMENT_STYLE (syntax) 605 && (comstyle
606 == SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_syntax))
556 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax))) 607 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax)))
557 goto lossage; 608 goto lossage;
558 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */ 609 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
@@ -572,7 +623,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
572 code = Scomment; 623 code = Scomment;
573 /* Ignore comment starters of a different style. */ 624 /* Ignore comment starters of a different style. */
574 else if (code == Scomment 625 else if (code == Scomment
575 && (comstyle != SYNTAX_FLAGS_COMMENT_STYLE (syntax) 626 && (comstyle != SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0)
576 || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested)) 627 || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested))
577 continue; 628 continue;
578 629
@@ -622,7 +673,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
622 break; 673 break;
623 674
624 case Sendcomment: 675 case Sendcomment:
625 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax) == comstyle 676 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == comstyle
626 && ((com2end && SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax)) 677 && ((com2end && SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax))
627 || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested) 678 || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested)
628 /* This is the same style of comment ender as ours. */ 679 /* This is the same style of comment ender as ours. */
@@ -730,8 +781,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
730DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, 781DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0,
731 doc: /* Return t if OBJECT is a syntax table. 782 doc: /* Return t if OBJECT is a syntax table.
732Currently, any char-table counts as a syntax table. */) 783Currently, any char-table counts as a syntax table. */)
733 (object) 784 (Lisp_Object object)
734 Lisp_Object object;
735{ 785{
736 if (CHAR_TABLE_P (object) 786 if (CHAR_TABLE_P (object)
737 && EQ (XCHAR_TABLE (object)->purpose, Qsyntax_table)) 787 && EQ (XCHAR_TABLE (object)->purpose, Qsyntax_table))
@@ -740,8 +790,7 @@ Currently, any char-table counts as a syntax table. */)
740} 790}
741 791
742static void 792static void
743check_syntax_table (obj) 793check_syntax_table (Lisp_Object obj)
744 Lisp_Object obj;
745{ 794{
746 CHECK_TYPE (CHAR_TABLE_P (obj) && EQ (XCHAR_TABLE (obj)->purpose, Qsyntax_table), 795 CHECK_TYPE (CHAR_TABLE_P (obj) && EQ (XCHAR_TABLE (obj)->purpose, Qsyntax_table),
747 Qsyntax_table_p, obj); 796 Qsyntax_table_p, obj);
@@ -750,7 +799,7 @@ check_syntax_table (obj)
750DEFUN ("syntax-table", Fsyntax_table, Ssyntax_table, 0, 0, 0, 799DEFUN ("syntax-table", Fsyntax_table, Ssyntax_table, 0, 0, 0,
751 doc: /* Return the current syntax table. 800 doc: /* Return the current syntax table.
752This is the one specified by the current buffer. */) 801This is the one specified by the current buffer. */)
753 () 802 (void)
754{ 803{
755 return current_buffer->syntax_table; 804 return current_buffer->syntax_table;
756} 805}
@@ -759,7 +808,7 @@ DEFUN ("standard-syntax-table", Fstandard_syntax_table,
759 Sstandard_syntax_table, 0, 0, 0, 808 Sstandard_syntax_table, 0, 0, 0,
760 doc: /* Return the standard syntax table. 809 doc: /* Return the standard syntax table.
761This is the one used for new buffers. */) 810This is the one used for new buffers. */)
762 () 811 (void)
763{ 812{
764 return Vstandard_syntax_table; 813 return Vstandard_syntax_table;
765} 814}
@@ -767,8 +816,7 @@ This is the one used for new buffers. */)
767DEFUN ("copy-syntax-table", Fcopy_syntax_table, Scopy_syntax_table, 0, 1, 0, 816DEFUN ("copy-syntax-table", Fcopy_syntax_table, Scopy_syntax_table, 0, 1, 0,
768 doc: /* Construct a new syntax table and return it. 817 doc: /* Construct a new syntax table and return it.
769It is a copy of the TABLE, which defaults to the standard syntax table. */) 818It is a copy of the TABLE, which defaults to the standard syntax table. */)
770 (table) 819 (Lisp_Object table)
771 Lisp_Object table;
772{ 820{
773 Lisp_Object copy; 821 Lisp_Object copy;
774 822
@@ -794,8 +842,7 @@ It is a copy of the TABLE, which defaults to the standard syntax table. */)
794DEFUN ("set-syntax-table", Fset_syntax_table, Sset_syntax_table, 1, 1, 0, 842DEFUN ("set-syntax-table", Fset_syntax_table, Sset_syntax_table, 1, 1, 0,
795 doc: /* Select a new syntax table for the current buffer. 843 doc: /* Select a new syntax table for the current buffer.
796One argument, a syntax table. */) 844One argument, a syntax table. */)
797 (table) 845 (Lisp_Object table)
798 Lisp_Object table;
799{ 846{
800 int idx; 847 int idx;
801 check_syntax_table (table); 848 check_syntax_table (table);
@@ -854,8 +901,7 @@ For example, if CHARACTER is a word constituent, the
854character `w' (119) is returned. 901character `w' (119) is returned.
855The characters that correspond to various syntax codes 902The characters that correspond to various syntax codes
856are listed in the documentation of `modify-syntax-entry'. */) 903are listed in the documentation of `modify-syntax-entry'. */)
857 (character) 904 (Lisp_Object character)
858 Lisp_Object character;
859{ 905{
860 int char_int; 906 int char_int;
861 CHECK_CHARACTER (character); 907 CHECK_CHARACTER (character);
@@ -866,8 +912,7 @@ are listed in the documentation of `modify-syntax-entry'. */)
866 912
867DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, 913DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0,
868 doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */) 914 doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
869 (character) 915 (Lisp_Object character)
870 Lisp_Object character;
871{ 916{
872 int char_int, code; 917 int char_int, code;
873 CHECK_NUMBER (character); 918 CHECK_NUMBER (character);
@@ -885,8 +930,7 @@ STRING should be a string as it is allowed as argument of
885`modify-syntax-entry'. Value is the equivalent cons cell 930`modify-syntax-entry'. Value is the equivalent cons cell
886\(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table' 931\(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
887text property. */) 932text property. */)
888 (string) 933 (Lisp_Object string)
889 Lisp_Object string;
890{ 934{
891 register const unsigned char *p; 935 register const unsigned char *p;
892 register enum syntaxcode code; 936 register enum syntaxcode code;
@@ -946,6 +990,10 @@ text property. */)
946 case 'n': 990 case 'n':
947 val |= 1 << 22; 991 val |= 1 << 22;
948 break; 992 break;
993
994 case 'c':
995 val |= 1 << 23;
996 break;
949 } 997 }
950 998
951 if (val < XVECTOR (Vsyntax_code_object)->size && NILP (match)) 999 if (val < XVECTOR (Vsyntax_code_object)->size && NILP (match))
@@ -985,20 +1033,20 @@ Defined flags are the characters 1, 2, 3, 4, b, p, and n.
985 3 means CHAR is the start of a two-char comment end sequence. 1033 3 means CHAR is the start of a two-char comment end sequence.
986 4 means CHAR is the second character of such a sequence. 1034 4 means CHAR is the second character of such a sequence.
987 1035
988There can be up to two orthogonal comment sequences. This is to support 1036There can be several orthogonal comment sequences. This is to support
989language modes such as C++. By default, all comment sequences are of style 1037language modes such as C++. By default, all comment sequences are of style
990a, but you can set the comment sequence style to b (on the second character 1038a, but you can set the comment sequence style to b (on the second character
991of a comment-start, or the first character of a comment-end sequence) using 1039of a comment-start, and the first character of a comment-end sequence) and/or
992this flag: 1040c (on any of its chars) using this flag:
993 b means CHAR is part of comment sequence b. 1041 b means CHAR is part of comment sequence b.
1042 c means CHAR is part of comment sequence c.
994 n means CHAR is part of a nestable comment sequence. 1043 n means CHAR is part of a nestable comment sequence.
995 1044
996 p means CHAR is a prefix character for `backward-prefix-chars'; 1045 p means CHAR is a prefix character for `backward-prefix-chars';
997 such characters are treated as whitespace when they occur 1046 such characters are treated as whitespace when they occur
998 between expressions. 1047 between expressions.
999usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */) 1048usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1000 (c, newentry, syntax_table) 1049 (Lisp_Object c, Lisp_Object newentry, Lisp_Object syntax_table)
1001 Lisp_Object c, newentry, syntax_table;
1002{ 1050{
1003 if (CONSP (c)) 1051 if (CONSP (c))
1004 { 1052 {
@@ -1031,11 +1079,12 @@ usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1031DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, 1079DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
1032 Sinternal_describe_syntax_value, 1, 1, 0, 1080 Sinternal_describe_syntax_value, 1, 1, 0,
1033 doc: /* Insert a description of the internal syntax description SYNTAX at point. */) 1081 doc: /* Insert a description of the internal syntax description SYNTAX at point. */)
1034 (syntax) 1082 (Lisp_Object syntax)
1035 Lisp_Object syntax;
1036{ 1083{
1037 register enum syntaxcode code; 1084 register enum syntaxcode code;
1038 char desc, start1, start2, end1, end2, prefix, comstyle, comnested; 1085 int syntax_code;
1086 char desc, start1, start2, end1, end2, prefix,
1087 comstyleb, comstylec, comnested;
1039 char str[2]; 1088 char str[2];
1040 Lisp_Object first, match_lisp, value = syntax; 1089 Lisp_Object first, match_lisp, value = syntax;
1041 1090
@@ -1066,14 +1115,16 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
1066 return syntax; 1115 return syntax;
1067 } 1116 }
1068 1117
1069 code = (enum syntaxcode) (XINT (first) & 0377); 1118 syntax_code = XINT (first);
1070 start1 = (XINT (first) >> 16) & 1; 1119 code = (enum syntaxcode) (syntax_code & 0377);
1071 start2 = (XINT (first) >> 17) & 1; 1120 start1 = SYNTAX_FLAGS_COMSTART_FIRST (syntax_code);
1072 end1 = (XINT (first) >> 18) & 1; 1121 start2 = SYNTAX_FLAGS_COMSTART_SECOND (syntax_code);;
1073 end2 = (XINT (first) >> 19) & 1; 1122 end1 = SYNTAX_FLAGS_COMEND_FIRST (syntax_code);
1074 prefix = (XINT (first) >> 20) & 1; 1123 end2 = SYNTAX_FLAGS_COMEND_SECOND (syntax_code);
1075 comstyle = (XINT (first) >> 21) & 1; 1124 prefix = SYNTAX_FLAGS_PREFIX (syntax_code);
1076 comnested = (XINT (first) >> 22) & 1; 1125 comstyleb = SYNTAX_FLAGS_COMMENT_STYLEB (syntax_code);
1126 comstylec = SYNTAX_FLAGS_COMMENT_STYLEC (syntax_code);
1127 comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax_code);
1077 1128
1078 if ((int) code < 0 || (int) code >= (int) Smax) 1129 if ((int) code < 0 || (int) code >= (int) Smax)
1079 { 1130 {
@@ -1102,8 +1153,10 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
1102 1153
1103 if (prefix) 1154 if (prefix)
1104 insert ("p", 1); 1155 insert ("p", 1);
1105 if (comstyle) 1156 if (comstyleb)
1106 insert ("b", 1); 1157 insert ("b", 1);
1158 if (comstylec)
1159 insert ("c", 1);
1107 if (comnested) 1160 if (comnested)
1108 insert ("n", 1); 1161 insert ("n", 1);
1109 1162
@@ -1163,8 +1216,10 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
1163 insert_string (",\n\t is the first character of a comment-end sequence"); 1216 insert_string (",\n\t is the first character of a comment-end sequence");
1164 if (end2) 1217 if (end2)
1165 insert_string (",\n\t is the second character of a comment-end sequence"); 1218 insert_string (",\n\t is the second character of a comment-end sequence");
1166 if (comstyle) 1219 if (comstyleb)
1167 insert_string (" (comment style b)"); 1220 insert_string (" (comment style b)");
1221 if (comstylec)
1222 insert_string (" (comment style c)");
1168 if (comnested) 1223 if (comnested)
1169 insert_string (" (nestable)"); 1224 insert_string (" (nestable)");
1170 1225
@@ -1185,8 +1240,7 @@ Lisp_Object Vfind_word_boundary_function_table;
1185 COUNT negative means scan backward and stop at word beginning. */ 1240 COUNT negative means scan backward and stop at word beginning. */
1186 1241
1187int 1242int
1188scan_words (from, count) 1243scan_words (register int from, register int count)
1189 register int from, count;
1190{ 1244{
1191 register int beg = BEGV; 1245 register int beg = BEGV;
1192 register int end = ZV; 1246 register int end = ZV;
@@ -1318,8 +1372,7 @@ Normally returns t.
1318If an edge of the buffer or a field boundary is reached, point is left there 1372If an edge of the buffer or a field boundary is reached, point is left there
1319and the function returns nil. Field boundaries are not noticed if 1373and the function returns nil. Field boundaries are not noticed if
1320`inhibit-field-text-motion' is non-nil. */) 1374`inhibit-field-text-motion' is non-nil. */)
1321 (arg) 1375 (Lisp_Object arg)
1322 Lisp_Object arg;
1323{ 1376{
1324 Lisp_Object tmp; 1377 Lisp_Object tmp;
1325 int orig_val, val; 1378 int orig_val, val;
@@ -1342,7 +1395,7 @@ and the function returns nil. Field boundaries are not noticed if
1342 return val == orig_val ? Qt : Qnil; 1395 return val == orig_val ? Qt : Qnil;
1343} 1396}
1344 1397
1345Lisp_Object skip_chars (); 1398Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int);
1346 1399
1347DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0, 1400DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0,
1348 doc: /* Move point forward, stopping before a char not in STRING, or at pos LIM. 1401 doc: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
@@ -1354,8 +1407,7 @@ With arg "^a-zA-Z", skips nonletters stopping before first letter.
1354Char classes, e.g. `[:alpha:]', are supported. 1407Char classes, e.g. `[:alpha:]', are supported.
1355 1408
1356Returns the distance traveled, either zero or positive. */) 1409Returns the distance traveled, either zero or positive. */)
1357 (string, lim) 1410 (Lisp_Object string, Lisp_Object lim)
1358 Lisp_Object string, lim;
1359{ 1411{
1360 return skip_chars (1, string, lim, 1); 1412 return skip_chars (1, string, lim, 1);
1361} 1413}
@@ -1364,8 +1416,7 @@ DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2,
1364 doc: /* Move point backward, stopping after a char not in STRING, or at pos LIM. 1416 doc: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1365See `skip-chars-forward' for details. 1417See `skip-chars-forward' for details.
1366Returns the distance traveled, either zero or negative. */) 1418Returns the distance traveled, either zero or negative. */)
1367 (string, lim) 1419 (Lisp_Object string, Lisp_Object lim)
1368 Lisp_Object string, lim;
1369{ 1420{
1370 return skip_chars (0, string, lim, 1); 1421 return skip_chars (0, string, lim, 1);
1371} 1422}
@@ -1376,8 +1427,7 @@ SYNTAX is a string of syntax code characters.
1376Stop before a char whose syntax is not in SYNTAX, or at position LIM. 1427Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1377If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. 1428If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1378This function returns the distance traveled, either zero or positive. */) 1429This function returns the distance traveled, either zero or positive. */)
1379 (syntax, lim) 1430 (Lisp_Object syntax, Lisp_Object lim)
1380 Lisp_Object syntax, lim;
1381{ 1431{
1382 return skip_syntaxes (1, syntax, lim); 1432 return skip_syntaxes (1, syntax, lim);
1383} 1433}
@@ -1388,17 +1438,13 @@ SYNTAX is a string of syntax code characters.
1388Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM. 1438Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1389If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. 1439If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1390This function returns the distance traveled, either zero or negative. */) 1440This function returns the distance traveled, either zero or negative. */)
1391 (syntax, lim) 1441 (Lisp_Object syntax, Lisp_Object lim)
1392 Lisp_Object syntax, lim;
1393{ 1442{
1394 return skip_syntaxes (0, syntax, lim); 1443 return skip_syntaxes (0, syntax, lim);
1395} 1444}
1396 1445
1397static Lisp_Object 1446static Lisp_Object
1398skip_chars (forwardp, string, lim, handle_iso_classes) 1447skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_classes)
1399 int forwardp;
1400 Lisp_Object string, lim;
1401 int handle_iso_classes;
1402{ 1448{
1403 register unsigned int c; 1449 register unsigned int c;
1404 unsigned char fastmap[0400]; 1450 unsigned char fastmap[0400];
@@ -1436,7 +1482,7 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
1436 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); 1482 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE));
1437 string_multibyte = SBYTES (string) > SCHARS (string); 1483 string_multibyte = SBYTES (string) > SCHARS (string);
1438 1484
1439 bzero (fastmap, sizeof fastmap); 1485 memset (fastmap, 0, sizeof fastmap);
1440 1486
1441 str = SDATA (string); 1487 str = SDATA (string);
1442 size_byte = SBYTES (string); 1488 size_byte = SBYTES (string);
@@ -1485,7 +1531,7 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
1485 || *class_end != ':' || class_end[1] != ']') 1531 || *class_end != ':' || class_end[1] != ']')
1486 goto not_a_class_name; 1532 goto not_a_class_name;
1487 1533
1488 bcopy (class_beg, class_name, class_end - class_beg); 1534 memcpy (class_name, class_beg, class_end - class_beg);
1489 class_name[class_end - class_beg] = 0; 1535 class_name[class_end - class_beg] = 0;
1490 1536
1491 cc = re_wctype (class_name); 1537 cc = re_wctype (class_name);
@@ -1546,8 +1592,8 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
1546 unsigned char fastmap2[0400]; 1592 unsigned char fastmap2[0400];
1547 int range_start_byte, range_start_char; 1593 int range_start_byte, range_start_char;
1548 1594
1549 bcopy (fastmap2 + 0200, fastmap + 0200, 0200); 1595 memcpy (fastmap + 0200, fastmap2 + 0200, 0200);
1550 bzero (fastmap + 0200, 0200); 1596 memset (fastmap + 0200, 0, 0200);
1551 /* We are sure that this loop stops. */ 1597 /* We are sure that this loop stops. */
1552 for (i = 0200; ! fastmap2[i]; i++); 1598 for (i = 0200; ! fastmap2[i]; i++);
1553 c = BYTE8_TO_CHAR (i); 1599 c = BYTE8_TO_CHAR (i);
@@ -1607,7 +1653,7 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
1607 || *class_end != ':' || class_end[1] != ']') 1653 || *class_end != ':' || class_end[1] != ']')
1608 goto not_a_class_name_multibyte; 1654 goto not_a_class_name_multibyte;
1609 1655
1610 bcopy (class_beg, class_name, class_end - class_beg); 1656 memcpy (class_name, class_beg, class_end - class_beg);
1611 class_name[class_end - class_beg] = 0; 1657 class_name[class_end - class_beg] = 0;
1612 1658
1613 cc = re_wctype (class_name); 1659 cc = re_wctype (class_name);
@@ -1692,7 +1738,7 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
1692 1738
1693 if (! multibyte && n_char_ranges > 0) 1739 if (! multibyte && n_char_ranges > 0)
1694 { 1740 {
1695 bzero (fastmap + 0200, 0200); 1741 memset (fastmap + 0200, 0, 0200);
1696 for (i = 0; i < n_char_ranges; i += 2) 1742 for (i = 0; i < n_char_ranges; i += 2)
1697 { 1743 {
1698 int c1 = char_ranges[i]; 1744 int c1 = char_ranges[i];
@@ -1892,9 +1938,7 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
1892 1938
1893 1939
1894static Lisp_Object 1940static Lisp_Object
1895skip_syntaxes (forwardp, string, lim) 1941skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim)
1896 int forwardp;
1897 Lisp_Object string, lim;
1898{ 1942{
1899 register unsigned int c; 1943 register unsigned int c;
1900 unsigned char fastmap[0400]; 1944 unsigned char fastmap[0400];
@@ -1923,7 +1967,7 @@ skip_syntaxes (forwardp, string, lim)
1923 multibyte = (!NILP (current_buffer->enable_multibyte_characters) 1967 multibyte = (!NILP (current_buffer->enable_multibyte_characters)
1924 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); 1968 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE));
1925 1969
1926 bzero (fastmap, sizeof fastmap); 1970 memset (fastmap, 0, sizeof fastmap);
1927 1971
1928 if (SBYTES (string) > SCHARS (string)) 1972 if (SBYTES (string) > SCHARS (string))
1929 /* As this is very rare case (syntax spec is ASCII only), don't 1973 /* As this is very rare case (syntax spec is ASCII only), don't
@@ -2067,9 +2111,7 @@ skip_syntaxes (forwardp, string, lim)
2067 integer which is its type according to re_wctype. */ 2111 integer which is its type according to re_wctype. */
2068 2112
2069static int 2113static int
2070in_classes (c, iso_classes) 2114in_classes (int c, Lisp_Object iso_classes)
2071 int c;
2072 Lisp_Object iso_classes;
2073{ 2115{
2074 int fits_class = 0; 2116 int fits_class = 0;
2075 2117
@@ -2091,7 +2133,7 @@ in_classes (c, iso_classes)
2091 FROM_BYTE is the bytepos corresponding to FROM. 2133 FROM_BYTE is the bytepos corresponding to FROM.
2092 Do not move past STOP (a charpos). 2134 Do not move past STOP (a charpos).
2093 The comment over which we have to jump is of style STYLE 2135 The comment over which we have to jump is of style STYLE
2094 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE). 2136 (either SYNTAX_FLAGS_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2095 NESTING should be positive to indicate the nesting at the beginning 2137 NESTING should be positive to indicate the nesting at the beginning
2096 for nested comments and should be zero or negative else. 2138 for nested comments and should be zero or negative else.
2097 ST_COMMENT_STYLE cannot be nested. 2139 ST_COMMENT_STYLE cannot be nested.
@@ -2111,16 +2153,14 @@ in_classes (c, iso_classes)
2111 remains valid for forward search starting at the returned position. */ 2153 remains valid for forward search starting at the returned position. */
2112 2154
2113static int 2155static int
2114forw_comment (from, from_byte, stop, nesting, style, prev_syntax, 2156forw_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop,
2115 charpos_ptr, bytepos_ptr, incomment_ptr) 2157 int nesting, int style, int prev_syntax,
2116 EMACS_INT from, from_byte, stop; 2158 EMACS_INT *charpos_ptr, EMACS_INT *bytepos_ptr,
2117 int nesting, style, prev_syntax; 2159 int *incomment_ptr)
2118 EMACS_INT *charpos_ptr, *bytepos_ptr;
2119 int *incomment_ptr;
2120{ 2160{
2121 register int c, c1; 2161 register int c, c1;
2122 register enum syntaxcode code; 2162 register enum syntaxcode code;
2123 register int syntax; 2163 register int syntax, other_syntax;
2124 2164
2125 if (nesting <= 0) nesting = -1; 2165 if (nesting <= 0) nesting = -1;
2126 2166
@@ -2142,7 +2182,7 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
2142 syntax = SYNTAX_WITH_FLAGS (c); 2182 syntax = SYNTAX_WITH_FLAGS (c);
2143 code = syntax & 0xff; 2183 code = syntax & 0xff;
2144 if (code == Sendcomment 2184 if (code == Sendcomment
2145 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style 2185 && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style
2146 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? 2186 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
2147 (nesting > 0 && --nesting == 0) : nesting < 0)) 2187 (nesting > 0 && --nesting == 0) : nesting < 0))
2148 /* we have encountered a comment end of the same style 2188 /* we have encountered a comment end of the same style
@@ -2158,7 +2198,7 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
2158 if (nesting > 0 2198 if (nesting > 0
2159 && code == Scomment 2199 && code == Scomment
2160 && SYNTAX_FLAGS_COMMENT_NESTED (syntax) 2200 && SYNTAX_FLAGS_COMMENT_NESTED (syntax)
2161 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style) 2201 && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style)
2162 /* we have encountered a nested comment of the same style 2202 /* we have encountered a nested comment of the same style
2163 as the comment sequence which began this comment section */ 2203 as the comment sequence which began this comment section */
2164 nesting++; 2204 nesting++;
@@ -2167,11 +2207,13 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
2167 2207
2168 forw_incomment: 2208 forw_incomment:
2169 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) 2209 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax)
2170 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
2171 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), 2210 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte),
2172 SYNTAX_COMEND_SECOND (c1)) 2211 other_syntax = SYNTAX_WITH_FLAGS (c1),
2212 SYNTAX_FLAGS_COMEND_SECOND (other_syntax))
2213 && SYNTAX_FLAGS_COMMENT_STYLE (syntax, other_syntax) == style
2173 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) || 2214 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
2174 SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0)) 2215 SYNTAX_FLAGS_COMMENT_NESTED (other_syntax))
2216 ? nesting > 0 : nesting < 0))
2175 { 2217 {
2176 if (--nesting <= 0) 2218 if (--nesting <= 0)
2177 /* we have encountered a comment end of the same style 2219 /* we have encountered a comment end of the same style
@@ -2188,10 +2230,11 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
2188 && from < stop 2230 && from < stop
2189 && SYNTAX_FLAGS_COMSTART_FIRST (syntax) 2231 && SYNTAX_FLAGS_COMSTART_FIRST (syntax)
2190 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), 2232 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte),
2191 SYNTAX_COMMENT_STYLE (c1) == style 2233 other_syntax = SYNTAX_WITH_FLAGS (c1),
2192 && SYNTAX_COMSTART_SECOND (c1)) 2234 SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax) == style
2235 && SYNTAX_FLAGS_COMSTART_SECOND (other_syntax))
2193 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) || 2236 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
2194 SYNTAX_COMMENT_NESTED (c1))) 2237 SYNTAX_FLAGS_COMMENT_NESTED (other_syntax)))
2195 /* we have encountered a nested comment of the same style 2238 /* we have encountered a nested comment of the same style
2196 as the comment sequence which began this comment 2239 as the comment sequence which began this comment
2197 section */ 2240 section */
@@ -2213,8 +2256,7 @@ Stop scanning if we find something other than a comment or whitespace.
2213Set point to where scanning stops. 2256Set point to where scanning stops.
2214If COUNT comments are found as expected, with nothing except whitespace 2257If COUNT comments are found as expected, with nothing except whitespace
2215between them, return t; otherwise return nil. */) 2258between them, return t; otherwise return nil. */)
2216 (count) 2259 (Lisp_Object count)
2217 Lisp_Object count;
2218{ 2260{
2219 register EMACS_INT from; 2261 register EMACS_INT from;
2220 EMACS_INT from_byte; 2262 EMACS_INT from_byte;
@@ -2243,7 +2285,7 @@ between them, return t; otherwise return nil. */)
2243 { 2285 {
2244 do 2286 do
2245 { 2287 {
2246 int comstart_first; 2288 int comstart_first, syntax, other_syntax;
2247 2289
2248 if (from == stop) 2290 if (from == stop)
2249 { 2291 {
@@ -2252,15 +2294,17 @@ between them, return t; otherwise return nil. */)
2252 return Qnil; 2294 return Qnil;
2253 } 2295 }
2254 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2296 c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2297 syntax = SYNTAX_WITH_FLAGS (c);
2255 code = SYNTAX (c); 2298 code = SYNTAX (c);
2256 comstart_first = SYNTAX_COMSTART_FIRST (c); 2299 comstart_first = SYNTAX_FLAGS_COMSTART_FIRST (syntax);
2257 comnested = SYNTAX_COMMENT_NESTED (c); 2300 comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax);
2258 comstyle = SYNTAX_COMMENT_STYLE (c); 2301 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0);
2259 INC_BOTH (from, from_byte); 2302 INC_BOTH (from, from_byte);
2260 UPDATE_SYNTAX_TABLE_FORWARD (from); 2303 UPDATE_SYNTAX_TABLE_FORWARD (from);
2261 if (from < stop && comstart_first 2304 if (from < stop && comstart_first
2262 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), 2305 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte),
2263 SYNTAX_COMSTART_SECOND (c1))) 2306 other_syntax = SYNTAX_WITH_FLAGS (c1),
2307 SYNTAX_FLAGS_COMSTART_SECOND (other_syntax)))
2264 { 2308 {
2265 /* We have encountered a comment start sequence and we 2309 /* We have encountered a comment start sequence and we
2266 are ignoring all text inside comments. We must record 2310 are ignoring all text inside comments. We must record
@@ -2268,8 +2312,9 @@ between them, return t; otherwise return nil. */)
2268 only a comment end of the same style actually ends 2312 only a comment end of the same style actually ends
2269 the comment section. */ 2313 the comment section. */
2270 code = Scomment; 2314 code = Scomment;
2271 comstyle = SYNTAX_COMMENT_STYLE (c1); 2315 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
2272 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); 2316 comnested
2317 = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
2273 INC_BOTH (from, from_byte); 2318 INC_BOTH (from, from_byte);
2274 UPDATE_SYNTAX_TABLE_FORWARD (from); 2319 UPDATE_SYNTAX_TABLE_FORWARD (from);
2275 } 2320 }
@@ -2305,7 +2350,7 @@ between them, return t; otherwise return nil. */)
2305 { 2350 {
2306 while (1) 2351 while (1)
2307 { 2352 {
2308 int quoted; 2353 int quoted, syntax;
2309 2354
2310 if (from <= stop) 2355 if (from <= stop)
2311 { 2356 {
@@ -2318,15 +2363,17 @@ between them, return t; otherwise return nil. */)
2318 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */ 2363 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2319 quoted = char_quoted (from, from_byte); 2364 quoted = char_quoted (from, from_byte);
2320 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2365 c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2366 syntax = SYNTAX_WITH_FLAGS (c);
2321 code = SYNTAX (c); 2367 code = SYNTAX (c);
2322 comstyle = 0; 2368 comstyle = 0;
2323 comnested = SYNTAX_COMMENT_NESTED (c); 2369 comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax);
2324 if (code == Sendcomment) 2370 if (code == Sendcomment)
2325 comstyle = SYNTAX_COMMENT_STYLE (c); 2371 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0);
2326 if (from > stop && SYNTAX_COMEND_SECOND (c) 2372 if (from > stop && SYNTAX_FLAGS_COMEND_SECOND (syntax)
2327 && prev_char_comend_first (from, from_byte) 2373 && prev_char_comend_first (from, from_byte)
2328 && !char_quoted (from - 1, dec_bytepos (from_byte))) 2374 && !char_quoted (from - 1, dec_bytepos (from_byte)))
2329 { 2375 {
2376 int other_syntax;
2330 /* We must record the comment style encountered so that 2377 /* We must record the comment style encountered so that
2331 later, we can match only the proper comment begin 2378 later, we can match only the proper comment begin
2332 sequence of the same style. */ 2379 sequence of the same style. */
@@ -2335,8 +2382,10 @@ between them, return t; otherwise return nil. */)
2335 /* Calling char_quoted, above, set up global syntax position 2382 /* Calling char_quoted, above, set up global syntax position
2336 at the new value of FROM. */ 2383 at the new value of FROM. */
2337 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2384 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2338 comstyle = SYNTAX_COMMENT_STYLE (c1); 2385 other_syntax = SYNTAX_WITH_FLAGS (c1);
2339 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); 2386 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
2387 comnested
2388 = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
2340 } 2389 }
2341 2390
2342 if (code == Scomment_fence) 2391 if (code == Scomment_fence)
@@ -2383,7 +2432,7 @@ between them, return t; otherwise return nil. */)
2383 { 2432 {
2384 /* Failure: we should go back to the end of this 2433 /* Failure: we should go back to the end of this
2385 not-quite-endcomment. */ 2434 not-quite-endcomment. */
2386 if (SYNTAX(c) != code) 2435 if (SYNTAX (c) != code)
2387 /* It was a two-char Sendcomment. */ 2436 /* It was a two-char Sendcomment. */
2388 INC_BOTH (from, from_byte); 2437 INC_BOTH (from, from_byte);
2389 goto leave; 2438 goto leave;
@@ -2422,10 +2471,7 @@ between them, return t; otherwise return nil. */)
2422 ? SYNTAX (c) : Ssymbol) 2471 ? SYNTAX (c) : Ssymbol)
2423 2472
2424static Lisp_Object 2473static Lisp_Object
2425scan_lists (from, count, depth, sexpflag) 2474scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpflag)
2426 register EMACS_INT from;
2427 EMACS_INT count, depth;
2428 int sexpflag;
2429{ 2475{
2430 Lisp_Object val; 2476 Lisp_Object val;
2431 register EMACS_INT stop = count > 0 ? ZV : BEGV; 2477 register EMACS_INT stop = count > 0 ? ZV : BEGV;
@@ -2460,21 +2506,23 @@ scan_lists (from, count, depth, sexpflag)
2460 { 2506 {
2461 while (from < stop) 2507 while (from < stop)
2462 { 2508 {
2463 int comstart_first, prefix; 2509 int comstart_first, prefix, syntax, other_syntax;
2464 UPDATE_SYNTAX_TABLE_FORWARD (from); 2510 UPDATE_SYNTAX_TABLE_FORWARD (from);
2465 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2511 c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2512 syntax = SYNTAX_WITH_FLAGS (c);
2466 code = SYNTAX_WITH_MULTIBYTE_CHECK (c); 2513 code = SYNTAX_WITH_MULTIBYTE_CHECK (c);
2467 comstart_first = SYNTAX_COMSTART_FIRST (c); 2514 comstart_first = SYNTAX_FLAGS_COMSTART_FIRST (syntax);
2468 comnested = SYNTAX_COMMENT_NESTED (c); 2515 comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax);
2469 comstyle = SYNTAX_COMMENT_STYLE (c); 2516 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0);
2470 prefix = SYNTAX_PREFIX (c); 2517 prefix = SYNTAX_FLAGS_PREFIX (syntax);
2471 if (depth == min_depth) 2518 if (depth == min_depth)
2472 last_good = from; 2519 last_good = from;
2473 INC_BOTH (from, from_byte); 2520 INC_BOTH (from, from_byte);
2474 UPDATE_SYNTAX_TABLE_FORWARD (from); 2521 UPDATE_SYNTAX_TABLE_FORWARD (from);
2475 if (from < stop && comstart_first 2522 if (from < stop && comstart_first
2476 && (c = FETCH_CHAR_AS_MULTIBYTE (from_byte), 2523 && (c = FETCH_CHAR_AS_MULTIBYTE (from_byte),
2477 SYNTAX_COMSTART_SECOND (c)) 2524 other_syntax = SYNTAX_WITH_FLAGS (c),
2525 SYNTAX_FLAGS_COMSTART_SECOND (other_syntax))
2478 && parse_sexp_ignore_comments) 2526 && parse_sexp_ignore_comments)
2479 { 2527 {
2480 /* we have encountered a comment start sequence and we 2528 /* we have encountered a comment start sequence and we
@@ -2483,9 +2531,9 @@ scan_lists (from, count, depth, sexpflag)
2483 only a comment end of the same style actually ends 2531 only a comment end of the same style actually ends
2484 the comment section */ 2532 the comment section */
2485 code = Scomment; 2533 code = Scomment;
2486 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2534 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
2487 comstyle = SYNTAX_COMMENT_STYLE (c1); 2535 comnested
2488 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); 2536 = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
2489 INC_BOTH (from, from_byte); 2537 INC_BOTH (from, from_byte);
2490 UPDATE_SYNTAX_TABLE_FORWARD (from); 2538 UPDATE_SYNTAX_TABLE_FORWARD (from);
2491 } 2539 }
@@ -2629,29 +2677,34 @@ scan_lists (from, count, depth, sexpflag)
2629 { 2677 {
2630 while (from > stop) 2678 while (from > stop)
2631 { 2679 {
2680 int syntax;
2632 DEC_BOTH (from, from_byte); 2681 DEC_BOTH (from, from_byte);
2633 UPDATE_SYNTAX_TABLE_BACKWARD (from); 2682 UPDATE_SYNTAX_TABLE_BACKWARD (from);
2634 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2683 c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2684 syntax= SYNTAX_WITH_FLAGS (c);
2635 code = SYNTAX_WITH_MULTIBYTE_CHECK (c); 2685 code = SYNTAX_WITH_MULTIBYTE_CHECK (c);
2636 if (depth == min_depth) 2686 if (depth == min_depth)
2637 last_good = from; 2687 last_good = from;
2638 comstyle = 0; 2688 comstyle = 0;
2639 comnested = SYNTAX_COMMENT_NESTED (c); 2689 comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax);
2640 if (code == Sendcomment) 2690 if (code == Sendcomment)
2641 comstyle = SYNTAX_COMMENT_STYLE (c); 2691 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0);
2642 if (from > stop && SYNTAX_COMEND_SECOND (c) 2692 if (from > stop && SYNTAX_FLAGS_COMEND_SECOND (syntax)
2643 && prev_char_comend_first (from, from_byte) 2693 && prev_char_comend_first (from, from_byte)
2644 && parse_sexp_ignore_comments) 2694 && parse_sexp_ignore_comments)
2645 { 2695 {
2646 /* We must record the comment style encountered so that 2696 /* We must record the comment style encountered so that
2647 later, we can match only the proper comment begin 2697 later, we can match only the proper comment begin
2648 sequence of the same style. */ 2698 sequence of the same style. */
2699 int c1, other_syntax;
2649 DEC_BOTH (from, from_byte); 2700 DEC_BOTH (from, from_byte);
2650 UPDATE_SYNTAX_TABLE_BACKWARD (from); 2701 UPDATE_SYNTAX_TABLE_BACKWARD (from);
2651 code = Sendcomment; 2702 code = Sendcomment;
2652 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2703 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2653 comstyle = SYNTAX_COMMENT_STYLE (c1); 2704 other_syntax = SYNTAX_WITH_FLAGS (c1);
2654 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); 2705 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
2706 comnested
2707 = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
2655 } 2708 }
2656 2709
2657 /* Quoting turns anything except a comment-ender 2710 /* Quoting turns anything except a comment-ender
@@ -2662,7 +2715,7 @@ scan_lists (from, count, depth, sexpflag)
2662 DEC_BOTH (from, from_byte); 2715 DEC_BOTH (from, from_byte);
2663 code = Sword; 2716 code = Sword;
2664 } 2717 }
2665 else if (SYNTAX_PREFIX (c)) 2718 else if (SYNTAX_FLAGS_PREFIX (syntax))
2666 continue; 2719 continue;
2667 2720
2668 switch (SWITCH_ENUM_CAST (code)) 2721 switch (SWITCH_ENUM_CAST (code))
@@ -2820,8 +2873,7 @@ Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2820If the beginning or end of (the accessible part of) the buffer is reached 2873If the beginning or end of (the accessible part of) the buffer is reached
2821and the depth is wrong, an error is signaled. 2874and the depth is wrong, an error is signaled.
2822If the depth is right but the count is not used up, nil is returned. */) 2875If the depth is right but the count is not used up, nil is returned. */)
2823 (from, count, depth) 2876 (Lisp_Object from, Lisp_Object count, Lisp_Object depth)
2824 Lisp_Object from, count, depth;
2825{ 2877{
2826 CHECK_NUMBER (from); 2878 CHECK_NUMBER (from);
2827 CHECK_NUMBER (count); 2879 CHECK_NUMBER (count);
@@ -2841,8 +2893,7 @@ If the beginning or end of (the accessible part of) the buffer is reached
2841in the middle of a parenthetical grouping, an error is signaled. 2893in the middle of a parenthetical grouping, an error is signaled.
2842If the beginning or end is reached between groupings 2894If the beginning or end is reached between groupings
2843but before count is used up, nil is returned. */) 2895but before count is used up, nil is returned. */)
2844 (from, count) 2896 (Lisp_Object from, Lisp_Object count)
2845 Lisp_Object from, count;
2846{ 2897{
2847 CHECK_NUMBER (from); 2898 CHECK_NUMBER (from);
2848 CHECK_NUMBER (count); 2899 CHECK_NUMBER (count);
@@ -2854,7 +2905,7 @@ DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, Sbackward_prefix_chars,
2854 0, 0, 0, 2905 0, 0, 0,
2855 doc: /* Move point backward over any number of chars with prefix syntax. 2906 doc: /* Move point backward over any number of chars with prefix syntax.
2856This includes chars with "quote" or "prefix" syntax (' or p). */) 2907This includes chars with "quote" or "prefix" syntax (' or p). */)
2857 () 2908 (void)
2858{ 2909{
2859 int beg = BEGV; 2910 int beg = BEGV;
2860 int opoint = PT; 2911 int opoint = PT;
@@ -2900,14 +2951,10 @@ This includes chars with "quote" or "prefix" syntax (' or p). */)
2900 after the beginning of a string, or after the end of a string. */ 2951 after the beginning of a string, or after the end of a string. */
2901 2952
2902static void 2953static void
2903scan_sexps_forward (stateptr, from, from_byte, end, targetdepth, 2954scan_sexps_forward (struct lisp_parse_state *stateptr,
2904 stopbefore, oldstate, commentstop) 2955 EMACS_INT from, EMACS_INT from_byte, EMACS_INT end,
2905 struct lisp_parse_state *stateptr; 2956 int targetdepth, int stopbefore,
2906 register EMACS_INT from; 2957 Lisp_Object oldstate, int commentstop)
2907 EMACS_INT from_byte, end;
2908 int targetdepth, stopbefore;
2909 Lisp_Object oldstate;
2910 int commentstop;
2911{ 2958{
2912 struct lisp_parse_state state; 2959 struct lisp_parse_state state;
2913 2960
@@ -2992,8 +3039,11 @@ do { prev_from = from; \
2992 oldstate = Fcdr (oldstate); 3039 oldstate = Fcdr (oldstate);
2993 oldstate = Fcdr (oldstate); 3040 oldstate = Fcdr (oldstate);
2994 tem = Fcar (oldstate); 3041 tem = Fcar (oldstate);
2995 state.comstyle = NILP (tem) ? 0 : (EQ (tem, Qsyntax_table) 3042 state.comstyle = (NILP (tem)
2996 ? ST_COMMENT_STYLE : 1); 3043 ? 0
3044 : (EQ (tem, Qsyntax_table)
3045 ? ST_COMMENT_STYLE
3046 : INTEGERP (tem) ? XINT (tem) : 1));
2997 3047
2998 oldstate = Fcdr (oldstate); 3048 oldstate = Fcdr (oldstate);
2999 tem = Fcar (oldstate); 3049 tem = Fcar (oldstate);
@@ -3038,22 +3088,25 @@ do { prev_from = from; \
3038 3088
3039 while (from < end) 3089 while (from < end)
3040 { 3090 {
3091 int syntax;
3041 INC_FROM; 3092 INC_FROM;
3042 code = prev_from_syntax & 0xff; 3093 code = prev_from_syntax & 0xff;
3043 3094
3044 if (from < end 3095 if (from < end
3045 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax) 3096 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)
3046 && (c1 = FETCH_CHAR (from_byte), 3097 && (c1 = FETCH_CHAR (from_byte),
3047 SYNTAX_COMSTART_SECOND (c1))) 3098 syntax = SYNTAX_WITH_FLAGS (c1),
3099 SYNTAX_FLAGS_COMSTART_SECOND (syntax)))
3048 /* Duplicate code to avoid a complex if-expression 3100 /* Duplicate code to avoid a complex if-expression
3049 which causes trouble for the SGI compiler. */ 3101 which causes trouble for the SGI compiler. */
3050 { 3102 {
3051 /* Record the comment style we have entered so that only 3103 /* Record the comment style we have entered so that only
3052 the comment-end sequence of the same style actually 3104 the comment-end sequence of the same style actually
3053 terminates the comment section. */ 3105 terminates the comment section. */
3054 state.comstyle = SYNTAX_COMMENT_STYLE (c1); 3106 state.comstyle
3107 = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax);
3055 comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax); 3108 comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax);
3056 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); 3109 comnested = comnested || SYNTAX_FLAGS_COMMENT_NESTED (syntax);
3057 state.incomment = comnested ? 1 : -1; 3110 state.incomment = comnested ? 1 : -1;
3058 state.comstr_start = prev_from; 3111 state.comstr_start = prev_from;
3059 INC_FROM; 3112 INC_FROM;
@@ -3071,7 +3124,7 @@ do { prev_from = from; \
3071 } 3124 }
3072 else if (code == Scomment) 3125 else if (code == Scomment)
3073 { 3126 {
3074 state.comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax); 3127 state.comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax, 0);
3075 state.incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ? 3128 state.incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ?
3076 1 : -1); 3129 1 : -1);
3077 state.comstr_start = prev_from; 3130 state.comstr_start = prev_from;
@@ -3264,8 +3317,7 @@ Value is a list of elements describing final state of parsing:
3264 else an integer (the current comment nesting). 3317 else an integer (the current comment nesting).
3265 5. t if following a quote character. 3318 5. t if following a quote character.
3266 6. the minimum paren-depth encountered during this scan. 3319 6. the minimum paren-depth encountered during this scan.
3267 7. t if in a comment of style b; symbol `syntax-table' if the comment 3320 7. style of comment, if any.
3268 should be terminated by a generic comment delimiter.
3269 8. character address of start of comment or string; nil if not in one. 3321 8. character address of start of comment or string; nil if not in one.
3270 9. Intermediate data for continuation of parsing (subject to change). 3322 9. Intermediate data for continuation of parsing (subject to change).
3271If third arg TARGETDEPTH is non-nil, parsing stops if the depth 3323If third arg TARGETDEPTH is non-nil, parsing stops if the depth
@@ -3278,8 +3330,7 @@ Fifth arg OLDSTATE is a list like what this function returns.
3278Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. 3330Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3279 If it is symbol `syntax-table', stop after the start of a comment or a 3331 If it is symbol `syntax-table', stop after the start of a comment or a
3280 string, or after end of a comment or a string. */) 3332 string, or after end of a comment or a string. */)
3281 (from, to, targetdepth, stopbefore, oldstate, commentstop) 3333 (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth, Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop)
3282 Lisp_Object from, to, targetdepth, stopbefore, oldstate, commentstop;
3283{ 3334{
3284 struct lisp_parse_state state; 3335 struct lisp_parse_state state;
3285 int target; 3336 int target;
@@ -3302,8 +3353,10 @@ Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3302 SET_PT (state.location); 3353 SET_PT (state.location);
3303 3354
3304 return Fcons (make_number (state.depth), 3355 return Fcons (make_number (state.depth),
3305 Fcons (state.prevlevelstart < 0 ? Qnil : make_number (state.prevlevelstart), 3356 Fcons (state.prevlevelstart < 0
3306 Fcons (state.thislevelstart < 0 ? Qnil : make_number (state.thislevelstart), 3357 ? Qnil : make_number (state.prevlevelstart),
3358 Fcons (state.thislevelstart < 0
3359 ? Qnil : make_number (state.thislevelstart),
3307 Fcons (state.instring >= 0 3360 Fcons (state.instring >= 0
3308 ? (state.instring == ST_STRING_STYLE 3361 ? (state.instring == ST_STRING_STYLE
3309 ? Qt : make_number (state.instring)) : Qnil, 3362 ? Qt : make_number (state.instring)) : Qnil,
@@ -3314,8 +3367,9 @@ Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3314 Fcons (make_number (state.mindepth), 3367 Fcons (make_number (state.mindepth),
3315 Fcons ((state.comstyle 3368 Fcons ((state.comstyle
3316 ? (state.comstyle == ST_COMMENT_STYLE 3369 ? (state.comstyle == ST_COMMENT_STYLE
3317 ? Qsyntax_table : Qt) : 3370 ? Qsyntax_table
3318 Qnil), 3371 : make_number (state.comstyle))
3372 : Qnil),
3319 Fcons (((state.incomment 3373 Fcons (((state.incomment
3320 || (state.instring >= 0)) 3374 || (state.instring >= 0))
3321 ? make_number (state.comstr_start) 3375 ? make_number (state.comstr_start)
@@ -3324,7 +3378,7 @@ Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3324} 3378}
3325 3379
3326void 3380void
3327init_syntax_once () 3381init_syntax_once (void)
3328{ 3382{
3329 register int i, c; 3383 register int i, c;
3330 Lisp_Object temp; 3384 Lisp_Object temp;
@@ -3414,7 +3468,7 @@ init_syntax_once ()
3414} 3468}
3415 3469
3416void 3470void
3417syms_of_syntax () 3471syms_of_syntax (void)
3418{ 3472{
3419 Qsyntax_table_p = intern_c_string ("syntax-table-p"); 3473 Qsyntax_table_p = intern_c_string ("syntax-table-p");
3420 staticpro (&Qsyntax_table_p); 3474 staticpro (&Qsyntax_table_p);