diff options
| author | Eli Zaretskii | 2013-09-05 11:01:04 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2013-09-05 11:01:04 +0300 |
| commit | 41306318777a942420bc4feadbfacf662ea179dc (patch) | |
| tree | 669e5cca02f95d6064ce73c0d3fbbf91b8c8b563 /src/syntax.c | |
| parent | 141f1ff7a40cda10f0558e891dd196a943a5082e (diff) | |
| parent | 257b3b03cb1cff917e0b3b7832ad3eab5b59f257 (diff) | |
| download | emacs-41306318777a942420bc4feadbfacf662ea179dc.tar.gz emacs-41306318777a942420bc4feadbfacf662ea179dc.zip | |
Merge from trunk after a lot of time.
Diffstat (limited to 'src/syntax.c')
| -rw-r--r-- | src/syntax.c | 735 |
1 files changed, 421 insertions, 314 deletions
diff --git a/src/syntax.c b/src/syntax.c index 71da13e7a66..31eb86faed8 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* GNU Emacs routines to deal with syntax tables; also word and list parsing. | 1 | /* GNU Emacs routines to deal with syntax tables; also word and list parsing. |
| 2 | Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2012 | 2 | Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2013 Free |
| 3 | Free Software Foundation, Inc. | 3 | Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -20,13 +20,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | 20 | ||
| 21 | #include <config.h> | 21 | #include <config.h> |
| 22 | 22 | ||
| 23 | #include <ctype.h> | 23 | #define SYNTAX_INLINE EXTERN_INLINE |
| 24 | |||
| 24 | #include <sys/types.h> | 25 | #include <sys/types.h> |
| 25 | #include <setjmp.h> | 26 | |
| 26 | #include "lisp.h" | 27 | #include "lisp.h" |
| 27 | #include "commands.h" | 28 | #include "commands.h" |
| 28 | #include "buffer.h" | ||
| 29 | #include "character.h" | 29 | #include "character.h" |
| 30 | #include "buffer.h" | ||
| 30 | #include "keymap.h" | 31 | #include "keymap.h" |
| 31 | #include "regex.h" | 32 | #include "regex.h" |
| 32 | 33 | ||
| @@ -37,7 +38,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 37 | #include "intervals.h" | 38 | #include "intervals.h" |
| 38 | #include "category.h" | 39 | #include "category.h" |
| 39 | 40 | ||
| 40 | /* Then there are seven single-bit flags that have the following meanings: | 41 | /* Eight single-bit flags have the following meanings: |
| 41 | 1. This character is the first of a two-character comment-start sequence. | 42 | 1. This character is the first of a two-character comment-start sequence. |
| 42 | 2. This character is the second of a two-character comment-start sequence. | 43 | 2. This character is the second of a two-character comment-start sequence. |
| 43 | 3. This character is the first of a two-character comment-end sequence. | 44 | 3. This character is the first of a two-character comment-end sequence. |
| @@ -49,64 +50,96 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 49 | Note that any two-character sequence whose first character has flag 1 | 50 | Note that any two-character sequence whose first character has flag 1 |
| 50 | and whose second character has flag 2 will be interpreted as a comment start. | 51 | and whose second character has flag 2 will be interpreted as a comment start. |
| 51 | 52 | ||
| 52 | bit 6 and 8 are used to discriminate between different comment styles. | 53 | Bits 6 and 8 discriminate among different comment styles. |
| 53 | Languages such as C++ allow two orthogonal syntax start/end pairs | 54 | Languages such as C++ allow two orthogonal syntax start/end pairs |
| 54 | and bit 6 is used to determine whether a comment-end or Scommentend | 55 | and bit 6 determines whether a comment-end or Scommentend |
| 55 | ends style a or b. Comment markers can start style a, b, c, or bc. | 56 | ends style a or b. Comment markers can start style a, b, c, or bc. |
| 56 | Style a is always the default. | 57 | Style a is always the default. |
| 57 | For 2-char comment markers, the style b flag is only looked up on the second | 58 | For 2-char comment markers, the style b flag is looked up only on the second |
| 58 | char of the comment marker and on the first char of the comment ender. | 59 | char of the comment marker and on the first char of the comment ender. |
| 59 | For style c (like to for the nested flag), the flag can be placed on any | 60 | For style c (like the nested flag), the flag can be placed on any of |
| 60 | one of the chars. | 61 | the chars. */ |
| 61 | */ | ||
| 62 | 62 | ||
| 63 | /* These macros extract specific flags from an integer | 63 | /* These functions extract specific flags from an integer |
| 64 | that holds the syntax code and the flags. */ | 64 | that holds the syntax code and the flags. */ |
| 65 | 65 | ||
| 66 | #define SYNTAX_FLAGS_COMSTART_FIRST(flags) (((flags) >> 16) & 1) | 66 | static bool |
| 67 | 67 | SYNTAX_FLAGS_COMSTART_FIRST (int flags) | |
| 68 | #define SYNTAX_FLAGS_COMSTART_SECOND(flags) (((flags) >> 17) & 1) | 68 | { |
| 69 | 69 | return (flags >> 16) & 1; | |
| 70 | #define SYNTAX_FLAGS_COMEND_FIRST(flags) (((flags) >> 18) & 1) | 70 | } |
| 71 | 71 | static bool | |
| 72 | #define SYNTAX_FLAGS_COMEND_SECOND(flags) (((flags) >> 19) & 1) | 72 | SYNTAX_FLAGS_COMSTART_SECOND (int flags) |
| 73 | 73 | { | |
| 74 | #define SYNTAX_FLAGS_PREFIX(flags) (((flags) >> 20) & 1) | 74 | return (flags >> 17) & 1; |
| 75 | } | ||
| 76 | static bool | ||
| 77 | SYNTAX_FLAGS_COMEND_FIRST (int flags) | ||
| 78 | { | ||
| 79 | return (flags >> 18) & 1; | ||
| 80 | } | ||
| 81 | static bool | ||
| 82 | SYNTAX_FLAGS_COMEND_SECOND (int flags) | ||
| 83 | { | ||
| 84 | return (flags >> 19) & 1; | ||
| 85 | } | ||
| 86 | static bool | ||
| 87 | SYNTAX_FLAGS_PREFIX (int flags) | ||
| 88 | { | ||
| 89 | return (flags >> 20) & 1; | ||
| 90 | } | ||
| 91 | static bool | ||
| 92 | SYNTAX_FLAGS_COMMENT_STYLEB (int flags) | ||
| 93 | { | ||
| 94 | return (flags >> 21) & 1; | ||
| 95 | } | ||
| 96 | static bool | ||
| 97 | SYNTAX_FLAGS_COMMENT_STYLEC (int flags) | ||
| 98 | { | ||
| 99 | return (flags >> 23) & 1; | ||
| 100 | } | ||
| 101 | static int | ||
| 102 | SYNTAX_FLAGS_COMMENT_STYLEC2 (int flags) | ||
| 103 | { | ||
| 104 | return (flags >> 22) & 2; /* SYNTAX_FLAGS_COMMENT_STYLEC (flags) * 2 */ | ||
| 105 | } | ||
| 106 | static bool | ||
| 107 | SYNTAX_FLAGS_COMMENT_NESTED (int flags) | ||
| 108 | { | ||
| 109 | return (flags >> 22) & 1; | ||
| 110 | } | ||
| 75 | 111 | ||
| 76 | #define SYNTAX_FLAGS_COMMENT_STYLEB(flags) (((flags) >> 21) & 1) | ||
| 77 | #define SYNTAX_FLAGS_COMMENT_STYLEC(flags) (((flags) >> 22) & 2) | ||
| 78 | /* FLAGS should be the flags of the main char of the comment marker, e.g. | 112 | /* FLAGS should be the flags of the main char of the comment marker, e.g. |
| 79 | the second for comstart and the first for comend. */ | 113 | the second for comstart and the first for comend. */ |
| 80 | #define SYNTAX_FLAGS_COMMENT_STYLE(flags, other_flags) \ | 114 | static int |
| 81 | (SYNTAX_FLAGS_COMMENT_STYLEB (flags) \ | 115 | SYNTAX_FLAGS_COMMENT_STYLE (int flags, int other_flags) |
| 82 | | SYNTAX_FLAGS_COMMENT_STYLEC (flags) \ | 116 | { |
| 83 | | SYNTAX_FLAGS_COMMENT_STYLEC (other_flags)) | 117 | return (SYNTAX_FLAGS_COMMENT_STYLEB (flags) |
| 84 | 118 | | SYNTAX_FLAGS_COMMENT_STYLEC2 (flags) | |
| 85 | #define SYNTAX_FLAGS_COMMENT_NESTED(flags) (((flags) >> 22) & 1) | 119 | | SYNTAX_FLAGS_COMMENT_STYLEC2 (other_flags)); |
| 120 | } | ||
| 86 | 121 | ||
| 87 | /* These macros extract a particular flag for a given character. */ | 122 | /* Extract a particular flag for a given character. */ |
| 88 | 123 | ||
| 89 | #define SYNTAX_COMEND_FIRST(c) \ | 124 | static bool |
| 90 | (SYNTAX_FLAGS_COMEND_FIRST (SYNTAX_WITH_FLAGS (c))) | 125 | SYNTAX_COMEND_FIRST (int c) |
| 91 | #define SYNTAX_PREFIX(c) (SYNTAX_FLAGS_PREFIX (SYNTAX_WITH_FLAGS (c))) | 126 | { |
| 127 | return SYNTAX_FLAGS_COMEND_FIRST (SYNTAX_WITH_FLAGS (c)); | ||
| 128 | } | ||
| 92 | 129 | ||
| 93 | /* We use these constants in place for comment-style and | 130 | /* We use these constants in place for comment-style and |
| 94 | string-ender-char to distinguish comments/strings started by | 131 | string-ender-char to distinguish comments/strings started by |
| 95 | comment_fence and string_fence codes. */ | 132 | comment_fence and string_fence codes. */ |
| 96 | 133 | ||
| 97 | #define ST_COMMENT_STYLE (256 + 1) | 134 | enum |
| 98 | #define ST_STRING_STYLE (256 + 2) | 135 | { |
| 136 | ST_COMMENT_STYLE = 256 + 1, | ||
| 137 | ST_STRING_STYLE = 256 + 2 | ||
| 138 | }; | ||
| 99 | 139 | ||
| 100 | static Lisp_Object Qsyntax_table_p; | 140 | static Lisp_Object Qsyntax_table_p; |
| 101 | static Lisp_Object Qsyntax_table, Qscan_error; | 141 | static Lisp_Object Qsyntax_table, Qscan_error; |
| 102 | 142 | ||
| 103 | #ifndef __GNUC__ | ||
| 104 | /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h, | ||
| 105 | if not compiled with GCC. No need to mark it, since it is used | ||
| 106 | only very temporarily. */ | ||
| 107 | Lisp_Object syntax_temp; | ||
| 108 | #endif | ||
| 109 | |||
| 110 | /* This is the internal form of the parse state used in parse-partial-sexp. */ | 143 | /* This is the internal form of the parse state used in parse-partial-sexp. */ |
| 111 | 144 | ||
| 112 | struct lisp_parse_state | 145 | struct lisp_parse_state |
| @@ -115,13 +148,14 @@ struct lisp_parse_state | |||
| 115 | int instring; /* -1 if not within string, else desired terminator. */ | 148 | int instring; /* -1 if not within string, else desired terminator. */ |
| 116 | EMACS_INT incomment; /* -1 if in unnestable comment else comment nesting */ | 149 | EMACS_INT incomment; /* -1 if in unnestable comment else comment nesting */ |
| 117 | int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */ | 150 | int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */ |
| 118 | int quoted; /* Nonzero if just after an escape char at end of parsing */ | 151 | bool quoted; /* True if just after an escape char at end of parsing. */ |
| 119 | EMACS_INT mindepth; /* Minimum depth seen while scanning. */ | 152 | EMACS_INT mindepth; /* Minimum depth seen while scanning. */ |
| 120 | /* Char number of most recent start-of-expression at current level */ | 153 | /* Char number of most recent start-of-expression at current level */ |
| 121 | ptrdiff_t thislevelstart; | 154 | ptrdiff_t thislevelstart; |
| 122 | /* Char number of start of containing expression */ | 155 | /* Char number of start of containing expression */ |
| 123 | ptrdiff_t prevlevelstart; | 156 | ptrdiff_t prevlevelstart; |
| 124 | ptrdiff_t location; /* Char number at which parsing stopped. */ | 157 | ptrdiff_t location; /* Char number at which parsing stopped. */ |
| 158 | ptrdiff_t location_byte; /* Corresponding byte position. */ | ||
| 125 | ptrdiff_t comstr_start; /* Position of last comment/string starter. */ | 159 | ptrdiff_t comstr_start; /* Position of last comment/string starter. */ |
| 126 | Lisp_Object levelstarts; /* Char numbers of starts-of-expression | 160 | Lisp_Object levelstarts; /* Char numbers of starts-of-expression |
| 127 | of levels (starting from outermost). */ | 161 | of levels (starting from outermost). */ |
| @@ -143,26 +177,126 @@ static ptrdiff_t find_start_begv; | |||
| 143 | static EMACS_INT find_start_modiff; | 177 | static EMACS_INT find_start_modiff; |
| 144 | 178 | ||
| 145 | 179 | ||
| 146 | static Lisp_Object Fsyntax_table_p (Lisp_Object); | 180 | static Lisp_Object skip_chars (bool, Lisp_Object, Lisp_Object, bool); |
| 147 | static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int); | 181 | static Lisp_Object skip_syntaxes (bool, Lisp_Object, Lisp_Object); |
| 148 | static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object); | 182 | static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, bool); |
| 149 | static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int); | ||
| 150 | static void scan_sexps_forward (struct lisp_parse_state *, | 183 | static void scan_sexps_forward (struct lisp_parse_state *, |
| 151 | ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, | 184 | ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, |
| 152 | int, Lisp_Object, int); | 185 | bool, Lisp_Object, int); |
| 153 | static int in_classes (int, Lisp_Object); | 186 | static bool in_classes (int, Lisp_Object); |
| 187 | |||
| 188 | /* This setter is used only in this file, so it can be private. */ | ||
| 189 | static void | ||
| 190 | bset_syntax_table (struct buffer *b, Lisp_Object val) | ||
| 191 | { | ||
| 192 | b->INTERNAL_FIELD (syntax_table) = val; | ||
| 193 | } | ||
| 154 | 194 | ||
| 155 | /* Whether the syntax of the character C has the prefix flag set. */ | 195 | /* Whether the syntax of the character C has the prefix flag set. */ |
| 156 | int syntax_prefix_flag_p (int c) | 196 | bool |
| 197 | syntax_prefix_flag_p (int c) | ||
| 157 | { | 198 | { |
| 158 | return SYNTAX_PREFIX (c); | 199 | return SYNTAX_FLAGS_PREFIX (SYNTAX_WITH_FLAGS (c)); |
| 159 | } | 200 | } |
| 160 | 201 | ||
| 161 | struct gl_state_s gl_state; /* Global state of syntax parser. */ | 202 | struct gl_state_s gl_state; /* Global state of syntax parser. */ |
| 162 | 203 | ||
| 163 | #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals | 204 | enum { INTERVALS_AT_ONCE = 10 }; /* 1 + max-number of intervals |
| 164 | to scan to property-change. */ | 205 | to scan to property-change. */ |
| 165 | 206 | ||
| 207 | /* Set the syntax entry VAL for char C in table TABLE. */ | ||
| 208 | |||
| 209 | static void | ||
| 210 | SET_RAW_SYNTAX_ENTRY (Lisp_Object table, int c, Lisp_Object val) | ||
| 211 | { | ||
| 212 | CHAR_TABLE_SET (table, c, val); | ||
| 213 | } | ||
| 214 | |||
| 215 | /* Set the syntax entry VAL for char-range RANGE in table TABLE. | ||
| 216 | RANGE is a cons (FROM . TO) specifying the range of characters. */ | ||
| 217 | |||
| 218 | static void | ||
| 219 | SET_RAW_SYNTAX_ENTRY_RANGE (Lisp_Object table, Lisp_Object range, | ||
| 220 | Lisp_Object val) | ||
| 221 | { | ||
| 222 | Fset_char_table_range (table, range, val); | ||
| 223 | } | ||
| 224 | |||
| 225 | /* Extract the information from the entry for character C | ||
| 226 | in the current syntax table. */ | ||
| 227 | |||
| 228 | static Lisp_Object | ||
| 229 | SYNTAX_MATCH (int c) | ||
| 230 | { | ||
| 231 | Lisp_Object ent = SYNTAX_ENTRY (c); | ||
| 232 | return CONSP (ent) ? XCDR (ent) : Qnil; | ||
| 233 | } | ||
| 234 | |||
| 235 | /* This should be called with FROM at the start of forward | ||
| 236 | search, or after the last position of the backward search. It | ||
| 237 | makes sure that the first char is picked up with correct table, so | ||
| 238 | one does not need to call UPDATE_SYNTAX_TABLE immediately after the | ||
| 239 | call. | ||
| 240 | Sign of COUNT gives the direction of the search. | ||
| 241 | */ | ||
| 242 | |||
| 243 | static void | ||
| 244 | SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count) | ||
| 245 | { | ||
| 246 | SETUP_BUFFER_SYNTAX_TABLE (); | ||
| 247 | gl_state.b_property = BEGV; | ||
| 248 | gl_state.e_property = ZV + 1; | ||
| 249 | gl_state.object = Qnil; | ||
| 250 | gl_state.offset = 0; | ||
| 251 | if (parse_sexp_lookup_properties) | ||
| 252 | if (count > 0 || from > BEGV) | ||
| 253 | update_syntax_table (count > 0 ? from : from - 1, count, 1, Qnil); | ||
| 254 | } | ||
| 255 | |||
| 256 | /* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. | ||
| 257 | If it is t (which is only used in fast_c_string_match_ignore_case), | ||
| 258 | ignore properties altogether. | ||
| 259 | |||
| 260 | This is meant for regex.c to use. For buffers, regex.c passes arguments | ||
| 261 | to the UPDATE_SYNTAX_TABLE functions which are relative to BEGV. | ||
| 262 | So if it is a buffer, we set the offset field to BEGV. */ | ||
| 263 | |||
| 264 | void | ||
| 265 | SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, | ||
| 266 | ptrdiff_t from, ptrdiff_t count) | ||
| 267 | { | ||
| 268 | SETUP_BUFFER_SYNTAX_TABLE (); | ||
| 269 | gl_state.object = object; | ||
| 270 | if (BUFFERP (gl_state.object)) | ||
| 271 | { | ||
| 272 | struct buffer *buf = XBUFFER (gl_state.object); | ||
| 273 | gl_state.b_property = 1; | ||
| 274 | gl_state.e_property = BUF_ZV (buf) - BUF_BEGV (buf) + 1; | ||
| 275 | gl_state.offset = BUF_BEGV (buf) - 1; | ||
| 276 | } | ||
| 277 | else if (NILP (gl_state.object)) | ||
| 278 | { | ||
| 279 | gl_state.b_property = 1; | ||
| 280 | gl_state.e_property = ZV - BEGV + 1; | ||
| 281 | gl_state.offset = BEGV - 1; | ||
| 282 | } | ||
| 283 | else if (EQ (gl_state.object, Qt)) | ||
| 284 | { | ||
| 285 | gl_state.b_property = 0; | ||
| 286 | gl_state.e_property = PTRDIFF_MAX; | ||
| 287 | gl_state.offset = 0; | ||
| 288 | } | ||
| 289 | else | ||
| 290 | { | ||
| 291 | gl_state.b_property = 0; | ||
| 292 | gl_state.e_property = 1 + SCHARS (gl_state.object); | ||
| 293 | gl_state.offset = 0; | ||
| 294 | } | ||
| 295 | if (parse_sexp_lookup_properties) | ||
| 296 | update_syntax_table (from + gl_state.offset - (count <= 0), | ||
| 297 | count, 1, gl_state.object); | ||
| 298 | } | ||
| 299 | |||
| 166 | /* Update gl_state to an appropriate interval which contains CHARPOS. The | 300 | /* Update gl_state to an appropriate interval which contains CHARPOS. The |
| 167 | sign of COUNT give the relative position of CHARPOS wrt the previously | 301 | sign of COUNT give the relative position of CHARPOS wrt the previously |
| 168 | valid interval. If INIT, only [be]_property fields of gl_state are | 302 | valid interval. If INIT, only [be]_property fields of gl_state are |
| @@ -172,17 +306,17 @@ struct gl_state_s gl_state; /* Global state of syntax parser. */ | |||
| 172 | direction than the intervals - or in an interval. We update the | 306 | direction than the intervals - or in an interval. We update the |
| 173 | current syntax-table basing on the property of this interval, and | 307 | current syntax-table basing on the property of this interval, and |
| 174 | update the interval to start further than CHARPOS - or be | 308 | update the interval to start further than CHARPOS - or be |
| 175 | NULL_INTERVAL. We also update lim_property to be the next value of | 309 | NULL. We also update lim_property to be the next value of |
| 176 | charpos to call this subroutine again - or be before/after the | 310 | charpos to call this subroutine again - or be before/after the |
| 177 | start/end of OBJECT. */ | 311 | start/end of OBJECT. */ |
| 178 | 312 | ||
| 179 | void | 313 | void |
| 180 | update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, | 314 | update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, |
| 181 | Lisp_Object object) | 315 | Lisp_Object object) |
| 182 | { | 316 | { |
| 183 | Lisp_Object tmp_table; | 317 | Lisp_Object tmp_table; |
| 184 | unsigned cnt = 0; | 318 | int cnt = 0; |
| 185 | int invalidate = 1; | 319 | bool invalidate = 1; |
| 186 | INTERVAL i; | 320 | INTERVAL i; |
| 187 | 321 | ||
| 188 | if (init) | 322 | if (init) |
| @@ -193,7 +327,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, | |||
| 193 | i = interval_of (charpos, object); | 327 | i = interval_of (charpos, object); |
| 194 | gl_state.backward_i = gl_state.forward_i = i; | 328 | gl_state.backward_i = gl_state.forward_i = i; |
| 195 | invalidate = 0; | 329 | invalidate = 0; |
| 196 | if (NULL_INTERVAL_P (i)) | 330 | if (!i) |
| 197 | return; | 331 | return; |
| 198 | /* interval_of updates only ->position of the return value, so | 332 | /* interval_of updates only ->position of the return value, so |
| 199 | update the parents manually to speed up update_interval. */ | 333 | update the parents manually to speed up update_interval. */ |
| @@ -218,7 +352,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, | |||
| 218 | 352 | ||
| 219 | /* We are guaranteed to be called with CHARPOS either in i, | 353 | /* We are guaranteed to be called with CHARPOS either in i, |
| 220 | or further off. */ | 354 | or further off. */ |
| 221 | if (NULL_INTERVAL_P (i)) | 355 | if (!i) |
| 222 | error ("Error in syntax_table logic for to-the-end intervals"); | 356 | error ("Error in syntax_table logic for to-the-end intervals"); |
| 223 | else if (charpos < i->position) /* Move left. */ | 357 | else if (charpos < i->position) /* Move left. */ |
| 224 | { | 358 | { |
| @@ -288,7 +422,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, | |||
| 288 | } | 422 | } |
| 289 | } | 423 | } |
| 290 | 424 | ||
| 291 | while (!NULL_INTERVAL_P (i)) | 425 | while (i) |
| 292 | { | 426 | { |
| 293 | if (cnt && !EQ (tmp_table, textget (i->plist, Qsyntax_table))) | 427 | if (cnt && !EQ (tmp_table, textget (i->plist, Qsyntax_table))) |
| 294 | { | 428 | { |
| @@ -314,7 +448,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, | |||
| 314 | /* e_property at EOB is not set to ZV but to ZV+1, so that | 448 | /* e_property at EOB is not set to ZV but to ZV+1, so that |
| 315 | we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without | 449 | we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without |
| 316 | having to check eob between the two. */ | 450 | having to check eob between the two. */ |
| 317 | + (NULL_INTERVAL_P (next_interval (i)) ? 1 : 0); | 451 | + (next_interval (i) ? 0 : 1); |
| 318 | gl_state.forward_i = i; | 452 | gl_state.forward_i = i; |
| 319 | } | 453 | } |
| 320 | else | 454 | else |
| @@ -327,23 +461,23 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, | |||
| 327 | cnt++; | 461 | cnt++; |
| 328 | i = count > 0 ? next_interval (i) : previous_interval (i); | 462 | i = count > 0 ? next_interval (i) : previous_interval (i); |
| 329 | } | 463 | } |
| 330 | eassert (NULL_INTERVAL_P (i)); /* This property goes to the end. */ | 464 | eassert (i == NULL); /* This property goes to the end. */ |
| 331 | if (count > 0) | 465 | if (count > 0) |
| 332 | gl_state.e_property = gl_state.stop; | 466 | gl_state.e_property = gl_state.stop; |
| 333 | else | 467 | else |
| 334 | gl_state.b_property = gl_state.start; | 468 | gl_state.b_property = gl_state.start; |
| 335 | } | 469 | } |
| 336 | 470 | ||
| 337 | /* Returns TRUE if char at CHARPOS is quoted. | 471 | /* Returns true if char at CHARPOS is quoted. |
| 338 | Global syntax-table data should be set up already to be good at CHARPOS | 472 | Global syntax-table data should be set up already to be good at CHARPOS |
| 339 | or after. On return global syntax data is good for lookup at CHARPOS. */ | 473 | or after. On return global syntax data is good for lookup at CHARPOS. */ |
| 340 | 474 | ||
| 341 | static int | 475 | static bool |
| 342 | char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos) | 476 | char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos) |
| 343 | { | 477 | { |
| 344 | register enum syntaxcode code; | 478 | enum syntaxcode code; |
| 345 | register ptrdiff_t beg = BEGV; | 479 | ptrdiff_t beg = BEGV; |
| 346 | register int quoted = 0; | 480 | bool quoted = 0; |
| 347 | ptrdiff_t orig = charpos; | 481 | ptrdiff_t orig = charpos; |
| 348 | 482 | ||
| 349 | while (charpos > beg) | 483 | while (charpos > beg) |
| @@ -367,7 +501,7 @@ char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos) | |||
| 367 | /* Return the bytepos one character before BYTEPOS. | 501 | /* Return the bytepos one character before BYTEPOS. |
| 368 | We assume that BYTEPOS is not at the start of the buffer. */ | 502 | We assume that BYTEPOS is not at the start of the buffer. */ |
| 369 | 503 | ||
| 370 | static inline ptrdiff_t | 504 | static ptrdiff_t |
| 371 | dec_bytepos (ptrdiff_t bytepos) | 505 | dec_bytepos (ptrdiff_t bytepos) |
| 372 | { | 506 | { |
| 373 | if (NILP (BVAR (current_buffer, enable_multibyte_characters))) | 507 | if (NILP (BVAR (current_buffer, enable_multibyte_characters))) |
| @@ -460,10 +594,11 @@ find_defun_start (ptrdiff_t pos, ptrdiff_t pos_byte) | |||
| 460 | 594 | ||
| 461 | /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */ | 595 | /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */ |
| 462 | 596 | ||
| 463 | static int | 597 | static bool |
| 464 | prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) | 598 | prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) |
| 465 | { | 599 | { |
| 466 | int c, val; | 600 | int c; |
| 601 | bool val; | ||
| 467 | 602 | ||
| 468 | DEC_BOTH (pos, pos_byte); | 603 | DEC_BOTH (pos, pos_byte); |
| 469 | UPDATE_SYNTAX_TABLE_BACKWARD (pos); | 604 | UPDATE_SYNTAX_TABLE_BACKWARD (pos); |
| @@ -473,28 +608,11 @@ prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) | |||
| 473 | return val; | 608 | return val; |
| 474 | } | 609 | } |
| 475 | 610 | ||
| 476 | /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */ | 611 | /* Check whether charpos FROM is at the end of a comment. |
| 477 | |||
| 478 | /* static int | ||
| 479 | * prev_char_comstart_first (pos, pos_byte) | ||
| 480 | * int pos, pos_byte; | ||
| 481 | * { | ||
| 482 | * int c, val; | ||
| 483 | * | ||
| 484 | * DEC_BOTH (pos, pos_byte); | ||
| 485 | * UPDATE_SYNTAX_TABLE_BACKWARD (pos); | ||
| 486 | * c = FETCH_CHAR (pos_byte); | ||
| 487 | * val = SYNTAX_COMSTART_FIRST (c); | ||
| 488 | * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1); | ||
| 489 | * return val; | ||
| 490 | * } */ | ||
| 491 | |||
| 492 | /* Checks whether charpos FROM is at the end of a comment. | ||
| 493 | FROM_BYTE is the bytepos corresponding to FROM. | 612 | FROM_BYTE is the bytepos corresponding to FROM. |
| 494 | Do not move back before STOP. | 613 | Do not move back before STOP. |
| 495 | 614 | ||
| 496 | Return a positive value if we find a comment ending at FROM/FROM_BYTE; | 615 | Return true if we find a comment ending at FROM/FROM_BYTE. |
| 497 | return -1 otherwise. | ||
| 498 | 616 | ||
| 499 | If successful, store the charpos of the comment's beginning | 617 | If successful, store the charpos of the comment's beginning |
| 500 | into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR. | 618 | into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR. |
| @@ -502,8 +620,10 @@ prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) | |||
| 502 | Global syntax data remains valid for backward search starting at | 620 | Global syntax data remains valid for backward search starting at |
| 503 | the returned value (or at FROM, if the search was not successful). */ | 621 | the returned value (or at FROM, if the search was not successful). */ |
| 504 | 622 | ||
| 505 | static int | 623 | static bool |
| 506 | back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested, int comstyle, ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr) | 624 | back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, |
| 625 | bool comnested, int comstyle, ptrdiff_t *charpos_ptr, | ||
| 626 | ptrdiff_t *bytepos_ptr) | ||
| 507 | { | 627 | { |
| 508 | /* Look back, counting the parity of string-quotes, | 628 | /* Look back, counting the parity of string-quotes, |
| 509 | and recording the comment-starters seen. | 629 | and recording the comment-starters seen. |
| @@ -515,13 +635,13 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested | |||
| 515 | which is I+2X quotes from the comment-end. | 635 | which is I+2X quotes from the comment-end. |
| 516 | PARITY is current parity of quotes from the comment end. */ | 636 | PARITY is current parity of quotes from the comment end. */ |
| 517 | int string_style = -1; /* Presumed outside of any string. */ | 637 | int string_style = -1; /* Presumed outside of any string. */ |
| 518 | int string_lossage = 0; | 638 | bool string_lossage = 0; |
| 519 | /* Not a real lossage: indicates that we have passed a matching comment | 639 | /* Not a real lossage: indicates that we have passed a matching comment |
| 520 | starter plus a non-matching comment-ender, meaning that any matching | 640 | starter plus a non-matching comment-ender, meaning that any matching |
| 521 | comment-starter we might see later could be a false positive (hidden | 641 | comment-starter we might see later could be a false positive (hidden |
| 522 | inside another comment). | 642 | inside another comment). |
| 523 | Test case: { a (* b } c (* d *) */ | 643 | Test case: { a (* b } c (* d *) */ |
| 524 | int comment_lossage = 0; | 644 | bool comment_lossage = 0; |
| 525 | ptrdiff_t comment_end = from; | 645 | ptrdiff_t comment_end = from; |
| 526 | ptrdiff_t comment_end_byte = from_byte; | 646 | ptrdiff_t comment_end_byte = from_byte; |
| 527 | ptrdiff_t comstart_pos = 0; | 647 | ptrdiff_t comstart_pos = 0; |
| @@ -530,8 +650,8 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested | |||
| 530 | or 0 if we didn't come across it yet. */ | 650 | or 0 if we didn't come across it yet. */ |
| 531 | ptrdiff_t defun_start = 0; | 651 | ptrdiff_t defun_start = 0; |
| 532 | ptrdiff_t defun_start_byte = 0; | 652 | ptrdiff_t defun_start_byte = 0; |
| 533 | register enum syntaxcode code; | 653 | enum syntaxcode code; |
| 534 | int nesting = 1; /* current comment nesting */ | 654 | ptrdiff_t nesting = 1; /* current comment nesting */ |
| 535 | int c; | 655 | int c; |
| 536 | int syntax = 0; | 656 | int syntax = 0; |
| 537 | 657 | ||
| @@ -544,8 +664,8 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested | |||
| 544 | while (from != stop) | 664 | while (from != stop) |
| 545 | { | 665 | { |
| 546 | ptrdiff_t temp_byte; | 666 | ptrdiff_t temp_byte; |
| 547 | int prev_syntax, com2start, com2end; | 667 | int prev_syntax; |
| 548 | int comstart; | 668 | bool com2start, com2end, comstart; |
| 549 | 669 | ||
| 550 | /* Move back and examine a character. */ | 670 | /* Move back and examine a character. */ |
| 551 | DEC_BOTH (from, from_byte); | 671 | DEC_BOTH (from, from_byte); |
| @@ -766,7 +886,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested | |||
| 766 | *charpos_ptr = from; | 886 | *charpos_ptr = from; |
| 767 | *bytepos_ptr = from_byte; | 887 | *bytepos_ptr = from_byte; |
| 768 | 888 | ||
| 769 | return (from == comment_end) ? -1 : from; | 889 | return from != comment_end; |
| 770 | } | 890 | } |
| 771 | 891 | ||
| 772 | DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, | 892 | DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, |
| @@ -820,7 +940,7 @@ It is a copy of the TABLE, which defaults to the standard syntax table. */) | |||
| 820 | 940 | ||
| 821 | /* Only the standard syntax table should have a default element. | 941 | /* Only the standard syntax table should have a default element. |
| 822 | Other syntax tables should inherit from parents instead. */ | 942 | Other syntax tables should inherit from parents instead. */ |
| 823 | XCHAR_TABLE (copy)->defalt = Qnil; | 943 | set_char_table_defalt (copy, Qnil); |
| 824 | 944 | ||
| 825 | /* Copied syntax tables should all have parents. | 945 | /* Copied syntax tables should all have parents. |
| 826 | If we copied one with no parent, such as the standard syntax table, | 946 | If we copied one with no parent, such as the standard syntax table, |
| @@ -837,7 +957,7 @@ One argument, a syntax table. */) | |||
| 837 | { | 957 | { |
| 838 | int idx; | 958 | int idx; |
| 839 | check_syntax_table (table); | 959 | check_syntax_table (table); |
| 840 | BVAR (current_buffer, syntax_table) = table; | 960 | bset_syntax_table (current_buffer, table); |
| 841 | /* Indicate that this buffer now has a specified syntax table. */ | 961 | /* Indicate that this buffer now has a specified syntax table. */ |
| 842 | idx = PER_BUFFER_VAR_IDX (syntax_table); | 962 | idx = PER_BUFFER_VAR_IDX (syntax_table); |
| 843 | SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1); | 963 | SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1); |
| @@ -848,31 +968,28 @@ One argument, a syntax table. */) | |||
| 848 | into the code it signifies. | 968 | into the code it signifies. |
| 849 | This is used by modify-syntax-entry, and other things. */ | 969 | This is used by modify-syntax-entry, and other things. */ |
| 850 | 970 | ||
| 851 | unsigned char syntax_spec_code[0400] = | 971 | unsigned char const syntax_spec_code[0400] = |
| 852 | { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 972 | { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 853 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 973 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 854 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 974 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 855 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 975 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 856 | (char) Swhitespace, (char) Scomment_fence, (char) Sstring, 0377, | 976 | Swhitespace, Scomment_fence, Sstring, 0377, Smath, 0377, 0377, Squote, |
| 857 | (char) Smath, 0377, 0377, (char) Squote, | 977 | Sopen, Sclose, 0377, 0377, 0377, Swhitespace, Spunct, Scharquote, |
| 858 | (char) Sopen, (char) Sclose, 0377, 0377, | ||
| 859 | 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote, | ||
| 860 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 978 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 861 | 0377, 0377, 0377, 0377, | 979 | 0377, 0377, 0377, 0377, Scomment, 0377, Sendcomment, 0377, |
| 862 | (char) Scomment, 0377, (char) Sendcomment, 0377, | 980 | Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */ |
| 863 | (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */ | ||
| 864 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 981 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 865 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword, | 982 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, Sword, |
| 866 | 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol, | 983 | 0377, 0377, 0377, 0377, Sescape, 0377, 0377, Ssymbol, |
| 867 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */ | 984 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */ |
| 868 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | 985 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
| 869 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword, | 986 | 0377, 0377, 0377, 0377, 0377, 0377, 0377, Sword, |
| 870 | 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377 | 987 | 0377, 0377, 0377, 0377, Sstring_fence, 0377, 0377, 0377 |
| 871 | }; | 988 | }; |
| 872 | 989 | ||
| 873 | /* Indexed by syntax code, give the letter that describes it. */ | 990 | /* Indexed by syntax code, give the letter that describes it. */ |
| 874 | 991 | ||
| 875 | char syntax_code_spec[16] = | 992 | char const syntax_code_spec[16] = |
| 876 | { | 993 | { |
| 877 | ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@', | 994 | ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@', |
| 878 | '!', '|' | 995 | '!', '|' |
| @@ -898,15 +1015,16 @@ are listed in the documentation of `modify-syntax-entry'. */) | |||
| 898 | CHECK_CHARACTER (character); | 1015 | CHECK_CHARACTER (character); |
| 899 | char_int = XINT (character); | 1016 | char_int = XINT (character); |
| 900 | SETUP_BUFFER_SYNTAX_TABLE (); | 1017 | SETUP_BUFFER_SYNTAX_TABLE (); |
| 901 | return make_number (syntax_code_spec[(int) SYNTAX (char_int)]); | 1018 | return make_number (syntax_code_spec[SYNTAX (char_int)]); |
| 902 | } | 1019 | } |
| 903 | 1020 | ||
| 904 | DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, | 1021 | DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, |
| 905 | doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */) | 1022 | doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */) |
| 906 | (Lisp_Object character) | 1023 | (Lisp_Object character) |
| 907 | { | 1024 | { |
| 908 | int char_int, code; | 1025 | int char_int; |
| 909 | CHECK_NUMBER (character); | 1026 | enum syntaxcode code; |
| 1027 | CHECK_CHARACTER (character); | ||
| 910 | char_int = XINT (character); | 1028 | char_int = XINT (character); |
| 911 | SETUP_BUFFER_SYNTAX_TABLE (); | 1029 | SETUP_BUFFER_SYNTAX_TABLE (); |
| 912 | code = SYNTAX (char_int); | 1030 | code = SYNTAX (char_int); |
| @@ -916,26 +1034,25 @@ DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, | |||
| 916 | } | 1034 | } |
| 917 | 1035 | ||
| 918 | DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0, | 1036 | DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0, |
| 919 | doc: /* Convert a syntax specification STRING into syntax cell form. | 1037 | doc: /* Convert a syntax descriptor STRING into a raw syntax descriptor. |
| 920 | STRING should be a string as it is allowed as argument of | 1038 | STRING should be a string of the form allowed as argument of |
| 921 | `modify-syntax-entry'. Value is the equivalent cons cell | 1039 | `modify-syntax-entry'. The return value is a raw syntax descriptor: a |
| 922 | \(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table' | 1040 | cons cell \(CODE . MATCHING-CHAR) which can be used, for example, as |
| 923 | text property. */) | 1041 | the value of a `syntax-table' text property. */) |
| 924 | (Lisp_Object string) | 1042 | (Lisp_Object string) |
| 925 | { | 1043 | { |
| 926 | register const unsigned char *p; | 1044 | const unsigned char *p; |
| 927 | register enum syntaxcode code; | ||
| 928 | int val; | 1045 | int val; |
| 929 | Lisp_Object match; | 1046 | Lisp_Object match; |
| 930 | 1047 | ||
| 931 | CHECK_STRING (string); | 1048 | CHECK_STRING (string); |
| 932 | 1049 | ||
| 933 | p = SDATA (string); | 1050 | p = SDATA (string); |
| 934 | code = (enum syntaxcode) syntax_spec_code[*p++]; | 1051 | val = syntax_spec_code[*p++]; |
| 935 | if (((int) code & 0377) == 0377) | 1052 | if (val == 0377) |
| 936 | error ("Invalid syntax description letter: %c", p[-1]); | 1053 | error ("Invalid syntax description letter: %c", p[-1]); |
| 937 | 1054 | ||
| 938 | if (code == Sinherit) | 1055 | if (val == Sinherit) |
| 939 | return Qnil; | 1056 | return Qnil; |
| 940 | 1057 | ||
| 941 | if (*p) | 1058 | if (*p) |
| @@ -950,7 +1067,6 @@ text property. */) | |||
| 950 | else | 1067 | else |
| 951 | match = Qnil; | 1068 | match = Qnil; |
| 952 | 1069 | ||
| 953 | val = (int) code; | ||
| 954 | while (*p) | 1070 | while (*p) |
| 955 | switch (*p++) | 1071 | switch (*p++) |
| 956 | { | 1072 | { |
| @@ -988,7 +1104,7 @@ text property. */) | |||
| 988 | } | 1104 | } |
| 989 | 1105 | ||
| 990 | if (val < ASIZE (Vsyntax_code_object) && NILP (match)) | 1106 | if (val < ASIZE (Vsyntax_code_object) && NILP (match)) |
| 991 | return XVECTOR (Vsyntax_code_object)->contents[val]; | 1107 | return AREF (Vsyntax_code_object, val); |
| 992 | else | 1108 | else |
| 993 | /* Since we can't use a shared object, let's make a new one. */ | 1109 | /* Since we can't use a shared object, let's make a new one. */ |
| 994 | return Fcons (make_number (val), match); | 1110 | return Fcons (make_number (val), match); |
| @@ -1010,7 +1126,7 @@ The first character of NEWENTRY should be one of the following: | |||
| 1010 | " string quote. \\ escape. | 1126 | " string quote. \\ escape. |
| 1011 | $ paired delimiter. ' expression quote or prefix operator. | 1127 | $ paired delimiter. ' expression quote or prefix operator. |
| 1012 | < comment starter. > comment ender. | 1128 | < comment starter. > comment ender. |
| 1013 | / character-quote. @ inherit from `standard-syntax-table'. | 1129 | / character-quote. @ inherit from parent table. |
| 1014 | | generic string fence. ! generic comment fence. | 1130 | | generic string fence. ! generic comment fence. |
| 1015 | 1131 | ||
| 1016 | Only single-character comment start and end sequences are represented thus. | 1132 | Only single-character comment start and end sequences are represented thus. |
| @@ -1072,10 +1188,8 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, | |||
| 1072 | doc: /* Insert a description of the internal syntax description SYNTAX at point. */) | 1188 | doc: /* Insert a description of the internal syntax description SYNTAX at point. */) |
| 1073 | (Lisp_Object syntax) | 1189 | (Lisp_Object syntax) |
| 1074 | { | 1190 | { |
| 1075 | register enum syntaxcode code; | 1191 | int code, syntax_code; |
| 1076 | int syntax_code; | 1192 | bool start1, start2, end1, end2, prefix, comstyleb, comstylec, comnested; |
| 1077 | char desc, start1, start2, end1, end2, prefix, | ||
| 1078 | comstyleb, comstylec, comnested; | ||
| 1079 | char str[2]; | 1193 | char str[2]; |
| 1080 | Lisp_Object first, match_lisp, value = syntax; | 1194 | Lisp_Object first, match_lisp, value = syntax; |
| 1081 | 1195 | ||
| @@ -1107,7 +1221,7 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, | |||
| 1107 | } | 1221 | } |
| 1108 | 1222 | ||
| 1109 | syntax_code = XINT (first) & INT_MAX; | 1223 | syntax_code = XINT (first) & INT_MAX; |
| 1110 | code = (enum syntaxcode) (syntax_code & 0377); | 1224 | code = syntax_code & 0377; |
| 1111 | start1 = SYNTAX_FLAGS_COMSTART_FIRST (syntax_code); | 1225 | start1 = SYNTAX_FLAGS_COMSTART_FIRST (syntax_code); |
| 1112 | start2 = SYNTAX_FLAGS_COMSTART_SECOND (syntax_code);; | 1226 | start2 = SYNTAX_FLAGS_COMSTART_SECOND (syntax_code);; |
| 1113 | end1 = SYNTAX_FLAGS_COMEND_FIRST (syntax_code); | 1227 | end1 = SYNTAX_FLAGS_COMEND_FIRST (syntax_code); |
| @@ -1117,14 +1231,13 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, | |||
| 1117 | comstylec = SYNTAX_FLAGS_COMMENT_STYLEC (syntax_code); | 1231 | comstylec = SYNTAX_FLAGS_COMMENT_STYLEC (syntax_code); |
| 1118 | comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax_code); | 1232 | comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax_code); |
| 1119 | 1233 | ||
| 1120 | if ((int) code < 0 || (int) code >= (int) Smax) | 1234 | if (Smax <= code) |
| 1121 | { | 1235 | { |
| 1122 | insert_string ("invalid"); | 1236 | insert_string ("invalid"); |
| 1123 | return syntax; | 1237 | return syntax; |
| 1124 | } | 1238 | } |
| 1125 | desc = syntax_code_spec[(int) code]; | ||
| 1126 | 1239 | ||
| 1127 | str[0] = desc, str[1] = 0; | 1240 | str[0] = syntax_code_spec[code], str[1] = 0; |
| 1128 | insert (str, 1); | 1241 | insert (str, 1); |
| 1129 | 1242 | ||
| 1130 | if (NILP (match_lisp)) | 1243 | if (NILP (match_lisp)) |
| @@ -1153,7 +1266,7 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, | |||
| 1153 | 1266 | ||
| 1154 | insert_string ("\twhich means: "); | 1267 | insert_string ("\twhich means: "); |
| 1155 | 1268 | ||
| 1156 | switch (SWITCH_ENUM_CAST (code)) | 1269 | switch (code) |
| 1157 | { | 1270 | { |
| 1158 | case Swhitespace: | 1271 | case Swhitespace: |
| 1159 | insert_string ("whitespace"); break; | 1272 | insert_string ("whitespace"); break; |
| @@ -1351,6 +1464,7 @@ scan_words (register ptrdiff_t from, register EMACS_INT count) | |||
| 1351 | 1464 | ||
| 1352 | DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "^p", | 1465 | DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "^p", |
| 1353 | doc: /* Move point forward ARG words (backward if ARG is negative). | 1466 | doc: /* Move point forward ARG words (backward if ARG is negative). |
| 1467 | If ARG is omitted or nil, move point forward one word. | ||
| 1354 | Normally returns t. | 1468 | Normally returns t. |
| 1355 | If an edge of the buffer or a field boundary is reached, point is left there | 1469 | If an edge of the buffer or a field boundary is reached, point is left there |
| 1356 | and the function returns nil. Field boundaries are not noticed if | 1470 | and the function returns nil. Field boundaries are not noticed if |
| @@ -1425,21 +1539,21 @@ This function returns the distance traveled, either zero or negative. */) | |||
| 1425 | } | 1539 | } |
| 1426 | 1540 | ||
| 1427 | static Lisp_Object | 1541 | static Lisp_Object |
| 1428 | skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_classes) | 1542 | skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, |
| 1543 | bool handle_iso_classes) | ||
| 1429 | { | 1544 | { |
| 1430 | register unsigned int c; | 1545 | int c; |
| 1431 | unsigned char fastmap[0400]; | 1546 | char fastmap[0400]; |
| 1432 | /* Store the ranges of non-ASCII characters. */ | 1547 | /* Store the ranges of non-ASCII characters. */ |
| 1433 | int *char_ranges IF_LINT (= NULL); | 1548 | int *char_ranges IF_LINT (= NULL); |
| 1434 | int n_char_ranges = 0; | 1549 | int n_char_ranges = 0; |
| 1435 | int negate = 0; | 1550 | bool negate = 0; |
| 1436 | register ptrdiff_t i, i_byte; | 1551 | ptrdiff_t i, i_byte; |
| 1437 | /* Set to 1 if the current buffer is multibyte and the region | 1552 | /* True if the current buffer is multibyte and the region contains |
| 1438 | contains non-ASCII chars. */ | 1553 | non-ASCII chars. */ |
| 1439 | int multibyte; | 1554 | bool multibyte; |
| 1440 | /* Set to 1 if STRING is multibyte and it contains non-ASCII | 1555 | /* True if STRING is multibyte and it contains non-ASCII chars. */ |
| 1441 | chars. */ | 1556 | bool string_multibyte; |
| 1442 | int string_multibyte; | ||
| 1443 | ptrdiff_t size_byte; | 1557 | ptrdiff_t size_byte; |
| 1444 | const unsigned char *str; | 1558 | const unsigned char *str; |
| 1445 | int len; | 1559 | int len; |
| @@ -1483,7 +1597,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1483 | 1597 | ||
| 1484 | if (! string_multibyte) | 1598 | if (! string_multibyte) |
| 1485 | { | 1599 | { |
| 1486 | int string_has_eight_bit = 0; | 1600 | bool string_has_eight_bit = 0; |
| 1487 | 1601 | ||
| 1488 | /* At first setup fastmap. */ | 1602 | /* At first setup fastmap. */ |
| 1489 | while (i_byte < size_byte) | 1603 | while (i_byte < size_byte) |
| @@ -1538,7 +1652,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1538 | if (i_byte + 1 < size_byte | 1652 | if (i_byte + 1 < size_byte |
| 1539 | && str[i_byte] == '-') | 1653 | && str[i_byte] == '-') |
| 1540 | { | 1654 | { |
| 1541 | unsigned int c2; | 1655 | int c2; |
| 1542 | 1656 | ||
| 1543 | /* Skip over the dash. */ | 1657 | /* Skip over the dash. */ |
| 1544 | i_byte++; | 1658 | i_byte++; |
| @@ -1551,7 +1665,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1551 | 1665 | ||
| 1552 | if (c <= c2) | 1666 | if (c <= c2) |
| 1553 | { | 1667 | { |
| 1554 | unsigned lim2 = c2 + 1; | 1668 | int lim2 = c2 + 1; |
| 1555 | while (c < lim2) | 1669 | while (c < lim2) |
| 1556 | fastmap[c++] = 1; | 1670 | fastmap[c++] = 1; |
| 1557 | if (! ASCII_CHAR_P (c2)) | 1671 | if (! ASCII_CHAR_P (c2)) |
| @@ -1571,45 +1685,40 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1571 | the corresponding multibyte chars. */ | 1685 | the corresponding multibyte chars. */ |
| 1572 | if (multibyte && string_has_eight_bit) | 1686 | if (multibyte && string_has_eight_bit) |
| 1573 | { | 1687 | { |
| 1574 | unsigned char fastmap2[0400]; | 1688 | char *p1; |
| 1575 | int range_start_byte, range_start_char; | 1689 | char himap[0200 + 1]; |
| 1576 | 1690 | memcpy (himap, fastmap + 0200, 0200); | |
| 1577 | memcpy (fastmap + 0200, fastmap2 + 0200, 0200); | 1691 | himap[0200] = 0; |
| 1578 | memset (fastmap + 0200, 0, 0200); | 1692 | memset (fastmap + 0200, 0, 0200); |
| 1579 | /* We are sure that this loop stops. */ | 1693 | char_ranges = alloca (sizeof *char_ranges * 128 * 2); |
| 1580 | for (i = 0200; ! fastmap2[i]; i++); | 1694 | i = 0; |
| 1581 | c = BYTE8_TO_CHAR (i); | 1695 | |
| 1582 | fastmap[CHAR_LEADING_CODE (c)] = 1; | 1696 | while ((p1 = memchr (himap + i, 1, 0200 - i))) |
| 1583 | range_start_byte = i; | ||
| 1584 | range_start_char = c; | ||
| 1585 | char_ranges = (int *) alloca (sizeof (int) * 128 * 2); | ||
| 1586 | for (i = 129; i < 0400; i++) | ||
| 1587 | { | 1697 | { |
| 1588 | c = BYTE8_TO_CHAR (i); | 1698 | /* Deduce the next range C..C2 from the next clump of 1s |
| 1589 | fastmap[CHAR_LEADING_CODE (c)] = 1; | 1699 | in HIMAP starting with &HIMAP[I]. HIMAP is the high |
| 1590 | if (i - range_start_byte != c - range_start_char) | 1700 | order half of the old FASTMAP. */ |
| 1591 | { | 1701 | int c2, leading_code; |
| 1592 | char_ranges[n_char_ranges++] = range_start_char; | 1702 | i = p1 - himap; |
| 1593 | char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) | 1703 | c = BYTE8_TO_CHAR (i + 0200); |
| 1594 | + range_start_char); | 1704 | i += strlen (p1); |
| 1595 | range_start_byte = i; | 1705 | c2 = BYTE8_TO_CHAR (i + 0200 - 1); |
| 1596 | range_start_char = c; | 1706 | |
| 1597 | } | 1707 | char_ranges[n_char_ranges++] = c; |
| 1708 | char_ranges[n_char_ranges++] = c2; | ||
| 1709 | leading_code = CHAR_LEADING_CODE (c); | ||
| 1710 | memset (fastmap + leading_code, 1, | ||
| 1711 | CHAR_LEADING_CODE (c2) - leading_code + 1); | ||
| 1598 | } | 1712 | } |
| 1599 | char_ranges[n_char_ranges++] = range_start_char; | ||
| 1600 | char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) | ||
| 1601 | + range_start_char); | ||
| 1602 | } | 1713 | } |
| 1603 | } | 1714 | } |
| 1604 | else /* STRING is multibyte */ | 1715 | else /* STRING is multibyte */ |
| 1605 | { | 1716 | { |
| 1606 | char_ranges = (int *) alloca (sizeof (int) * SCHARS (string) * 2); | 1717 | char_ranges = alloca (sizeof *char_ranges * SCHARS (string) * 2); |
| 1607 | 1718 | ||
| 1608 | while (i_byte < size_byte) | 1719 | while (i_byte < size_byte) |
| 1609 | { | 1720 | { |
| 1610 | unsigned char leading_code; | 1721 | int leading_code = str[i_byte]; |
| 1611 | |||
| 1612 | leading_code = str[i_byte]; | ||
| 1613 | c = STRING_CHAR_AND_LENGTH (str + i_byte, len); | 1722 | c = STRING_CHAR_AND_LENGTH (str + i_byte, len); |
| 1614 | i_byte += len; | 1723 | i_byte += len; |
| 1615 | 1724 | ||
| @@ -1663,8 +1772,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1663 | if (i_byte + 1 < size_byte | 1772 | if (i_byte + 1 < size_byte |
| 1664 | && str[i_byte] == '-') | 1773 | && str[i_byte] == '-') |
| 1665 | { | 1774 | { |
| 1666 | unsigned int c2; | 1775 | int c2, leading_code2; |
| 1667 | unsigned char leading_code2; | ||
| 1668 | 1776 | ||
| 1669 | /* Skip over the dash. */ | 1777 | /* Skip over the dash. */ |
| 1670 | i_byte++; | 1778 | i_byte++; |
| @@ -1678,7 +1786,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1678 | && i_byte < size_byte) | 1786 | && i_byte < size_byte) |
| 1679 | { | 1787 | { |
| 1680 | leading_code2 = str[i_byte]; | 1788 | leading_code2 = str[i_byte]; |
| 1681 | c2 =STRING_CHAR_AND_LENGTH (str + i_byte, len); | 1789 | c2 = STRING_CHAR_AND_LENGTH (str + i_byte, len); |
| 1682 | i_byte += len; | 1790 | i_byte += len; |
| 1683 | } | 1791 | } |
| 1684 | 1792 | ||
| @@ -1692,7 +1800,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1692 | } | 1800 | } |
| 1693 | if (! ASCII_CHAR_P (c)) | 1801 | if (! ASCII_CHAR_P (c)) |
| 1694 | { | 1802 | { |
| 1695 | unsigned lim2 = leading_code2 + 1; | 1803 | int lim2 = leading_code2 + 1; |
| 1696 | while (leading_code < lim2) | 1804 | while (leading_code < lim2) |
| 1697 | fastmap[leading_code++] = 1; | 1805 | fastmap[leading_code++] = 1; |
| 1698 | if (c <= c2) | 1806 | if (c <= c2) |
| @@ -1725,7 +1833,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1725 | for (i = 0; i < n_char_ranges; i += 2) | 1833 | for (i = 0; i < n_char_ranges; i += 2) |
| 1726 | { | 1834 | { |
| 1727 | int c1 = char_ranges[i]; | 1835 | int c1 = char_ranges[i]; |
| 1728 | unsigned lim2 = char_ranges[i + 1] + 1; | 1836 | int lim2 = char_ranges[i + 1] + 1; |
| 1729 | 1837 | ||
| 1730 | for (; c1 < lim2; c1++) | 1838 | for (; c1 < lim2; c1++) |
| 1731 | { | 1839 | { |
| @@ -1771,7 +1879,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1771 | } | 1879 | } |
| 1772 | 1880 | ||
| 1773 | immediate_quit = 1; | 1881 | immediate_quit = 1; |
| 1774 | /* This code may look up syntax tables using macros that rely on the | 1882 | /* This code may look up syntax tables using functions that rely on the |
| 1775 | gl_state object. To make sure this object is not out of date, | 1883 | gl_state object. To make sure this object is not out of date, |
| 1776 | let's initialize it manually. | 1884 | let's initialize it manually. |
| 1777 | We ignore syntax-table text-properties for now, since that's | 1885 | We ignore syntax-table text-properties for now, since that's |
| @@ -1921,13 +2029,13 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl | |||
| 1921 | 2029 | ||
| 1922 | 2030 | ||
| 1923 | static Lisp_Object | 2031 | static Lisp_Object |
| 1924 | skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) | 2032 | skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim) |
| 1925 | { | 2033 | { |
| 1926 | register unsigned int c; | 2034 | int c; |
| 1927 | unsigned char fastmap[0400]; | 2035 | unsigned char fastmap[0400]; |
| 1928 | int negate = 0; | 2036 | bool negate = 0; |
| 1929 | register ptrdiff_t i, i_byte; | 2037 | ptrdiff_t i, i_byte; |
| 1930 | int multibyte; | 2038 | bool multibyte; |
| 1931 | ptrdiff_t size_byte; | 2039 | ptrdiff_t size_byte; |
| 1932 | unsigned char *str; | 2040 | unsigned char *str; |
| 1933 | 2041 | ||
| @@ -2015,7 +2123,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) | |||
| 2015 | stop = endp; | 2123 | stop = endp; |
| 2016 | } | 2124 | } |
| 2017 | c = STRING_CHAR_AND_LENGTH (p, nbytes); | 2125 | c = STRING_CHAR_AND_LENGTH (p, nbytes); |
| 2018 | if (! fastmap[(int) SYNTAX (c)]) | 2126 | if (! fastmap[SYNTAX (c)]) |
| 2019 | break; | 2127 | break; |
| 2020 | p += nbytes, pos++, pos_byte += nbytes; | 2128 | p += nbytes, pos++, pos_byte += nbytes; |
| 2021 | UPDATE_SYNTAX_TABLE_FORWARD (pos); | 2129 | UPDATE_SYNTAX_TABLE_FORWARD (pos); |
| @@ -2032,7 +2140,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) | |||
| 2032 | p = GAP_END_ADDR; | 2140 | p = GAP_END_ADDR; |
| 2033 | stop = endp; | 2141 | stop = endp; |
| 2034 | } | 2142 | } |
| 2035 | if (! fastmap[(int) SYNTAX (*p)]) | 2143 | if (! fastmap[SYNTAX (*p)]) |
| 2036 | break; | 2144 | break; |
| 2037 | p++, pos++, pos_byte++; | 2145 | p++, pos++, pos_byte++; |
| 2038 | UPDATE_SYNTAX_TABLE_FORWARD (pos); | 2146 | UPDATE_SYNTAX_TABLE_FORWARD (pos); |
| @@ -2058,7 +2166,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) | |||
| 2058 | prev_p = p; | 2166 | prev_p = p; |
| 2059 | while (--p >= stop && ! CHAR_HEAD_P (*p)); | 2167 | while (--p >= stop && ! CHAR_HEAD_P (*p)); |
| 2060 | c = STRING_CHAR (p); | 2168 | c = STRING_CHAR (p); |
| 2061 | if (! fastmap[(int) SYNTAX (c)]) | 2169 | if (! fastmap[SYNTAX (c)]) |
| 2062 | break; | 2170 | break; |
| 2063 | pos--, pos_byte -= prev_p - p; | 2171 | pos--, pos_byte -= prev_p - p; |
| 2064 | } | 2172 | } |
| @@ -2075,7 +2183,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) | |||
| 2075 | stop = endp; | 2183 | stop = endp; |
| 2076 | } | 2184 | } |
| 2077 | UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); | 2185 | UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); |
| 2078 | if (! fastmap[(int) SYNTAX (p[-1])]) | 2186 | if (! fastmap[SYNTAX (p[-1])]) |
| 2079 | break; | 2187 | break; |
| 2080 | p--, pos--, pos_byte--; | 2188 | p--, pos--, pos_byte--; |
| 2081 | } | 2189 | } |
| @@ -2089,14 +2197,14 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) | |||
| 2089 | } | 2197 | } |
| 2090 | } | 2198 | } |
| 2091 | 2199 | ||
| 2092 | /* Return 1 if character C belongs to one of the ISO classes | 2200 | /* Return true if character C belongs to one of the ISO classes |
| 2093 | in the list ISO_CLASSES. Each class is represented by an | 2201 | in the list ISO_CLASSES. Each class is represented by an |
| 2094 | integer which is its type according to re_wctype. */ | 2202 | integer which is its type according to re_wctype. */ |
| 2095 | 2203 | ||
| 2096 | static int | 2204 | static bool |
| 2097 | in_classes (int c, Lisp_Object iso_classes) | 2205 | in_classes (int c, Lisp_Object iso_classes) |
| 2098 | { | 2206 | { |
| 2099 | int fits_class = 0; | 2207 | bool fits_class = 0; |
| 2100 | 2208 | ||
| 2101 | while (CONSP (iso_classes)) | 2209 | while (CONSP (iso_classes)) |
| 2102 | { | 2210 | { |
| @@ -2116,26 +2224,26 @@ in_classes (int c, Lisp_Object iso_classes) | |||
| 2116 | FROM_BYTE is the bytepos corresponding to FROM. | 2224 | FROM_BYTE is the bytepos corresponding to FROM. |
| 2117 | Do not move past STOP (a charpos). | 2225 | Do not move past STOP (a charpos). |
| 2118 | The comment over which we have to jump is of style STYLE | 2226 | The comment over which we have to jump is of style STYLE |
| 2119 | (either SYNTAX_FLAGS_COMMENT_STYLE(foo) or ST_COMMENT_STYLE). | 2227 | (either SYNTAX_FLAGS_COMMENT_STYLE (foo) or ST_COMMENT_STYLE). |
| 2120 | NESTING should be positive to indicate the nesting at the beginning | 2228 | NESTING should be positive to indicate the nesting at the beginning |
| 2121 | for nested comments and should be zero or negative else. | 2229 | for nested comments and should be zero or negative else. |
| 2122 | ST_COMMENT_STYLE cannot be nested. | 2230 | ST_COMMENT_STYLE cannot be nested. |
| 2123 | PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character | 2231 | PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character |
| 2124 | (or 0 If the search cannot start in the middle of a two-character). | 2232 | (or 0 If the search cannot start in the middle of a two-character). |
| 2125 | 2233 | ||
| 2126 | If successful, return 1 and store the charpos of the comment's end | 2234 | If successful, return true and store the charpos of the comment's end |
| 2127 | into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR. | 2235 | into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR. |
| 2128 | Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the | 2236 | Else, return false and store the charpos STOP into *CHARPOS_PTR, the |
| 2129 | corresponding bytepos into *BYTEPOS_PTR and the current nesting | 2237 | corresponding bytepos into *BYTEPOS_PTR and the current nesting |
| 2130 | (as defined for state.incomment) in *INCOMMENT_PTR. | 2238 | (as defined for state.incomment) in *INCOMMENT_PTR. |
| 2131 | 2239 | ||
| 2132 | The comment end is the last character of the comment rather than the | 2240 | The comment end is the last character of the comment rather than the |
| 2133 | character just after the comment. | 2241 | character just after the comment. |
| 2134 | 2242 | ||
| 2135 | Global syntax data is assumed to initially be valid for FROM and | 2243 | Global syntax data is assumed to initially be valid for FROM and |
| 2136 | remains valid for forward search starting at the returned position. */ | 2244 | remains valid for forward search starting at the returned position. */ |
| 2137 | 2245 | ||
| 2138 | static int | 2246 | static bool |
| 2139 | forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, | 2247 | forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, |
| 2140 | EMACS_INT nesting, int style, int prev_syntax, | 2248 | EMACS_INT nesting, int style, int prev_syntax, |
| 2141 | ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr, | 2249 | ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr, |
| @@ -2241,14 +2349,12 @@ If COUNT comments are found as expected, with nothing except whitespace | |||
| 2241 | between them, return t; otherwise return nil. */) | 2349 | between them, return t; otherwise return nil. */) |
| 2242 | (Lisp_Object count) | 2350 | (Lisp_Object count) |
| 2243 | { | 2351 | { |
| 2244 | register ptrdiff_t from; | 2352 | ptrdiff_t from, from_byte, stop; |
| 2245 | ptrdiff_t from_byte; | 2353 | int c, c1; |
| 2246 | register ptrdiff_t stop; | 2354 | enum syntaxcode code; |
| 2247 | register int c, c1; | ||
| 2248 | register enum syntaxcode code; | ||
| 2249 | int comstyle = 0; /* style of comment encountered */ | 2355 | int comstyle = 0; /* style of comment encountered */ |
| 2250 | int comnested = 0; /* whether the comment is nestable or not */ | 2356 | bool comnested = 0; /* whether the comment is nestable or not */ |
| 2251 | int found; | 2357 | bool found; |
| 2252 | EMACS_INT count1; | 2358 | EMACS_INT count1; |
| 2253 | ptrdiff_t out_charpos, out_bytepos; | 2359 | ptrdiff_t out_charpos, out_bytepos; |
| 2254 | EMACS_INT dummy; | 2360 | EMACS_INT dummy; |
| @@ -2268,7 +2374,8 @@ between them, return t; otherwise return nil. */) | |||
| 2268 | { | 2374 | { |
| 2269 | do | 2375 | do |
| 2270 | { | 2376 | { |
| 2271 | int comstart_first, syntax, other_syntax; | 2377 | bool comstart_first; |
| 2378 | int syntax, other_syntax; | ||
| 2272 | 2379 | ||
| 2273 | if (from == stop) | 2380 | if (from == stop) |
| 2274 | { | 2381 | { |
| @@ -2296,8 +2403,7 @@ between them, return t; otherwise return nil. */) | |||
| 2296 | the comment section. */ | 2403 | the comment section. */ |
| 2297 | code = Scomment; | 2404 | code = Scomment; |
| 2298 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); | 2405 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); |
| 2299 | comnested | 2406 | comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); |
| 2300 | = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); | ||
| 2301 | INC_BOTH (from, from_byte); | 2407 | INC_BOTH (from, from_byte); |
| 2302 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2408 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2303 | } | 2409 | } |
| @@ -2333,7 +2439,8 @@ between them, return t; otherwise return nil. */) | |||
| 2333 | { | 2439 | { |
| 2334 | while (1) | 2440 | while (1) |
| 2335 | { | 2441 | { |
| 2336 | int quoted, syntax; | 2442 | bool quoted; |
| 2443 | int syntax; | ||
| 2337 | 2444 | ||
| 2338 | if (from <= stop) | 2445 | if (from <= stop) |
| 2339 | { | 2446 | { |
| @@ -2367,14 +2474,13 @@ between them, return t; otherwise return nil. */) | |||
| 2367 | c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 2474 | c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2368 | other_syntax = SYNTAX_WITH_FLAGS (c1); | 2475 | other_syntax = SYNTAX_WITH_FLAGS (c1); |
| 2369 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); | 2476 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); |
| 2370 | comnested | 2477 | comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); |
| 2371 | = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); | ||
| 2372 | } | 2478 | } |
| 2373 | 2479 | ||
| 2374 | if (code == Scomment_fence) | 2480 | if (code == Scomment_fence) |
| 2375 | { | 2481 | { |
| 2376 | /* Skip until first preceding unquoted comment_fence. */ | 2482 | /* Skip until first preceding unquoted comment_fence. */ |
| 2377 | int fence_found = 0; | 2483 | bool fence_found = 0; |
| 2378 | ptrdiff_t ini = from, ini_byte = from_byte; | 2484 | ptrdiff_t ini = from, ini_byte = from_byte; |
| 2379 | 2485 | ||
| 2380 | while (1) | 2486 | while (1) |
| @@ -2405,7 +2511,7 @@ between them, return t; otherwise return nil. */) | |||
| 2405 | { | 2511 | { |
| 2406 | found = back_comment (from, from_byte, stop, comnested, comstyle, | 2512 | found = back_comment (from, from_byte, stop, comnested, comstyle, |
| 2407 | &out_charpos, &out_bytepos); | 2513 | &out_charpos, &out_bytepos); |
| 2408 | if (found == -1) | 2514 | if (!found) |
| 2409 | { | 2515 | { |
| 2410 | if (c == '\n') | 2516 | if (c == '\n') |
| 2411 | /* This end-of-line is not an end-of-comment. | 2517 | /* This end-of-line is not an end-of-comment. |
| @@ -2448,33 +2554,34 @@ between them, return t; otherwise return nil. */) | |||
| 2448 | } | 2554 | } |
| 2449 | 2555 | ||
| 2450 | /* Return syntax code of character C if C is an ASCII character | 2556 | /* Return syntax code of character C if C is an ASCII character |
| 2451 | or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */ | 2557 | or if MULTIBYTE_SYMBOL_P is false. Otherwise, return Ssymbol. */ |
| 2452 | 2558 | ||
| 2453 | #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \ | 2559 | static enum syntaxcode |
| 2454 | ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \ | 2560 | syntax_multibyte (int c, bool multibyte_symbol_p) |
| 2455 | ? SYNTAX (c) : Ssymbol) | 2561 | { |
| 2562 | return ASCII_CHAR_P (c) || !multibyte_symbol_p ? SYNTAX (c) : Ssymbol; | ||
| 2563 | } | ||
| 2456 | 2564 | ||
| 2457 | static Lisp_Object | 2565 | static Lisp_Object |
| 2458 | scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpflag) | 2566 | scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag) |
| 2459 | { | 2567 | { |
| 2460 | Lisp_Object val; | 2568 | Lisp_Object val; |
| 2461 | register ptrdiff_t stop = count > 0 ? ZV : BEGV; | 2569 | ptrdiff_t stop = count > 0 ? ZV : BEGV; |
| 2462 | register int c, c1; | 2570 | int c, c1; |
| 2463 | int stringterm; | 2571 | int stringterm; |
| 2464 | int quoted; | 2572 | bool quoted; |
| 2465 | int mathexit = 0; | 2573 | bool mathexit = 0; |
| 2466 | register enum syntaxcode code, temp_code; | 2574 | enum syntaxcode code; |
| 2467 | EMACS_INT min_depth = depth; /* Err out if depth gets less than this. */ | 2575 | EMACS_INT min_depth = depth; /* Err out if depth gets less than this. */ |
| 2468 | int comstyle = 0; /* style of comment encountered */ | 2576 | int comstyle = 0; /* style of comment encountered */ |
| 2469 | int comnested = 0; /* whether the comment is nestable or not */ | 2577 | bool comnested = 0; /* whether the comment is nestable or not */ |
| 2470 | ptrdiff_t temp_pos; | 2578 | ptrdiff_t temp_pos; |
| 2471 | EMACS_INT last_good = from; | 2579 | EMACS_INT last_good = from; |
| 2472 | int found; | 2580 | bool found; |
| 2473 | ptrdiff_t from_byte; | 2581 | ptrdiff_t from_byte; |
| 2474 | ptrdiff_t out_bytepos, out_charpos; | 2582 | ptrdiff_t out_bytepos, out_charpos; |
| 2475 | int temp; | ||
| 2476 | EMACS_INT dummy; | 2583 | EMACS_INT dummy; |
| 2477 | int multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol; | 2584 | bool multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol; |
| 2478 | 2585 | ||
| 2479 | if (depth > 0) min_depth = 0; | 2586 | if (depth > 0) min_depth = 0; |
| 2480 | 2587 | ||
| @@ -2491,11 +2598,12 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2491 | { | 2598 | { |
| 2492 | while (from < stop) | 2599 | while (from < stop) |
| 2493 | { | 2600 | { |
| 2494 | int comstart_first, prefix, syntax, other_syntax; | 2601 | bool comstart_first, prefix; |
| 2602 | int syntax, other_syntax; | ||
| 2495 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2603 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2496 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 2604 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2497 | syntax = SYNTAX_WITH_FLAGS (c); | 2605 | syntax = SYNTAX_WITH_FLAGS (c); |
| 2498 | code = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2606 | code = syntax_multibyte (c, multibyte_symbol_p); |
| 2499 | comstart_first = SYNTAX_FLAGS_COMSTART_FIRST (syntax); | 2607 | comstart_first = SYNTAX_FLAGS_COMSTART_FIRST (syntax); |
| 2500 | comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax); | 2608 | comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax); |
| 2501 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0); | 2609 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0); |
| @@ -2517,8 +2625,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2517 | the comment section */ | 2625 | the comment section */ |
| 2518 | code = Scomment; | 2626 | code = Scomment; |
| 2519 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); | 2627 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); |
| 2520 | comnested | 2628 | comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); |
| 2521 | = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); | ||
| 2522 | INC_BOTH (from, from_byte); | 2629 | INC_BOTH (from, from_byte); |
| 2523 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2630 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2524 | } | 2631 | } |
| @@ -2526,7 +2633,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2526 | if (prefix) | 2633 | if (prefix) |
| 2527 | continue; | 2634 | continue; |
| 2528 | 2635 | ||
| 2529 | switch (SWITCH_ENUM_CAST (code)) | 2636 | switch (code) |
| 2530 | { | 2637 | { |
| 2531 | case Sescape: | 2638 | case Sescape: |
| 2532 | case Scharquote: | 2639 | case Scharquote: |
| @@ -2542,10 +2649,8 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2542 | { | 2649 | { |
| 2543 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2650 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2544 | 2651 | ||
| 2545 | /* Some compilers can't handle this inside the switch. */ | ||
| 2546 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 2652 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2547 | temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2653 | switch (syntax_multibyte (c, multibyte_symbol_p)) |
| 2548 | switch (temp) | ||
| 2549 | { | 2654 | { |
| 2550 | case Scharquote: | 2655 | case Scharquote: |
| 2551 | case Sescape: | 2656 | case Sescape: |
| @@ -2617,19 +2722,18 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2617 | stringterm = FETCH_CHAR_AS_MULTIBYTE (temp_pos); | 2722 | stringterm = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2618 | while (1) | 2723 | while (1) |
| 2619 | { | 2724 | { |
| 2725 | enum syntaxcode c_code; | ||
| 2620 | if (from >= stop) | 2726 | if (from >= stop) |
| 2621 | goto lose; | 2727 | goto lose; |
| 2622 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2728 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2623 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 2729 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2730 | c_code = syntax_multibyte (c, multibyte_symbol_p); | ||
| 2624 | if (code == Sstring | 2731 | if (code == Sstring |
| 2625 | ? (c == stringterm | 2732 | ? c == stringterm && c_code == Sstring |
| 2626 | && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) | 2733 | : c_code == Sstring_fence) |
| 2627 | : SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring_fence) | ||
| 2628 | break; | 2734 | break; |
| 2629 | 2735 | ||
| 2630 | /* Some compilers can't handle this inside the switch. */ | 2736 | switch (c_code) |
| 2631 | temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); | ||
| 2632 | switch (temp) | ||
| 2633 | { | 2737 | { |
| 2634 | case Scharquote: | 2738 | case Scharquote: |
| 2635 | case Sescape: | 2739 | case Sescape: |
| @@ -2667,7 +2771,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2667 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2771 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2668 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 2772 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2669 | syntax= SYNTAX_WITH_FLAGS (c); | 2773 | syntax= SYNTAX_WITH_FLAGS (c); |
| 2670 | code = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2774 | code = syntax_multibyte (c, multibyte_symbol_p); |
| 2671 | if (depth == min_depth) | 2775 | if (depth == min_depth) |
| 2672 | last_good = from; | 2776 | last_good = from; |
| 2673 | comstyle = 0; | 2777 | comstyle = 0; |
| @@ -2688,8 +2792,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2688 | c2 = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 2792 | c2 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2689 | other_syntax = SYNTAX_WITH_FLAGS (c2); | 2793 | other_syntax = SYNTAX_WITH_FLAGS (c2); |
| 2690 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); | 2794 | comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); |
| 2691 | comnested | 2795 | comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); |
| 2692 | = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); | ||
| 2693 | } | 2796 | } |
| 2694 | 2797 | ||
| 2695 | /* Quoting turns anything except a comment-ender | 2798 | /* Quoting turns anything except a comment-ender |
| @@ -2703,7 +2806,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2703 | else if (SYNTAX_FLAGS_PREFIX (syntax)) | 2806 | else if (SYNTAX_FLAGS_PREFIX (syntax)) |
| 2704 | continue; | 2807 | continue; |
| 2705 | 2808 | ||
| 2706 | switch (SWITCH_ENUM_CAST (code)) | 2809 | switch (code) |
| 2707 | { | 2810 | { |
| 2708 | case Sword: | 2811 | case Sword: |
| 2709 | case Ssymbol: | 2812 | case Ssymbol: |
| @@ -2721,9 +2824,8 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2721 | temp_pos--; | 2824 | temp_pos--; |
| 2722 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2825 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2723 | c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); | 2826 | c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2724 | temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); | ||
| 2725 | /* Don't allow comment-end to be quoted. */ | 2827 | /* Don't allow comment-end to be quoted. */ |
| 2726 | if (temp_code == Sendcomment) | 2828 | if (syntax_multibyte (c1, multibyte_symbol_p) == Sendcomment) |
| 2727 | goto done2; | 2829 | goto done2; |
| 2728 | quoted = char_quoted (from - 1, temp_pos); | 2830 | quoted = char_quoted (from - 1, temp_pos); |
| 2729 | if (quoted) | 2831 | if (quoted) |
| @@ -2733,11 +2835,12 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2733 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2835 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2734 | } | 2836 | } |
| 2735 | c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); | 2837 | c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2736 | temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); | 2838 | if (! quoted) |
| 2737 | if (! (quoted || temp_code == Sword | 2839 | switch (syntax_multibyte (c1, multibyte_symbol_p)) |
| 2738 | || temp_code == Ssymbol | 2840 | { |
| 2739 | || temp_code == Squote)) | 2841 | case Sword: case Ssymbol: case Squote: break; |
| 2740 | goto done2; | 2842 | default: goto done2; |
| 2843 | } | ||
| 2741 | DEC_BOTH (from, from_byte); | 2844 | DEC_BOTH (from, from_byte); |
| 2742 | } | 2845 | } |
| 2743 | goto done2; | 2846 | goto done2; |
| @@ -2774,13 +2877,13 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2774 | break; | 2877 | break; |
| 2775 | found = back_comment (from, from_byte, stop, comnested, comstyle, | 2878 | found = back_comment (from, from_byte, stop, comnested, comstyle, |
| 2776 | &out_charpos, &out_bytepos); | 2879 | &out_charpos, &out_bytepos); |
| 2777 | /* FIXME: if found == -1, then it really wasn't a comment-end. | 2880 | /* FIXME: if !found, it really wasn't a comment-end. |
| 2778 | For single-char Sendcomment, we can't do much about it apart | 2881 | For single-char Sendcomment, we can't do much about it apart |
| 2779 | from skipping the char. | 2882 | from skipping the char. |
| 2780 | For 2-char endcomments, we could try again, taking both | 2883 | For 2-char endcomments, we could try again, taking both |
| 2781 | chars as separate entities, but it's a lot of trouble | 2884 | chars as separate entities, but it's a lot of trouble |
| 2782 | for very little gain, so we don't bother either. -sm */ | 2885 | for very little gain, so we don't bother either. -sm */ |
| 2783 | if (found != -1) | 2886 | if (found) |
| 2784 | from = out_charpos, from_byte = out_bytepos; | 2887 | from = out_charpos, from_byte = out_bytepos; |
| 2785 | break; | 2888 | break; |
| 2786 | 2889 | ||
| @@ -2792,10 +2895,12 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2792 | goto lose; | 2895 | goto lose; |
| 2793 | DEC_BOTH (from, from_byte); | 2896 | DEC_BOTH (from, from_byte); |
| 2794 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2897 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2795 | if (!char_quoted (from, from_byte) | 2898 | if (!char_quoted (from, from_byte)) |
| 2796 | && (c = FETCH_CHAR_AS_MULTIBYTE (from_byte), | 2899 | { |
| 2797 | SYNTAX_WITH_MULTIBYTE_CHECK (c) == code)) | 2900 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2798 | break; | 2901 | if (syntax_multibyte (c, multibyte_symbol_p) == code) |
| 2902 | break; | ||
| 2903 | } | ||
| 2799 | } | 2904 | } |
| 2800 | if (code == Sstring_fence && !depth && sexpflag) goto done2; | 2905 | if (code == Sstring_fence && !depth && sexpflag) goto done2; |
| 2801 | break; | 2906 | break; |
| @@ -2808,11 +2913,14 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf | |||
| 2808 | goto lose; | 2913 | goto lose; |
| 2809 | DEC_BOTH (from, from_byte); | 2914 | DEC_BOTH (from, from_byte); |
| 2810 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2915 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2811 | if (!char_quoted (from, from_byte) | 2916 | if (!char_quoted (from, from_byte)) |
| 2812 | && (stringterm | 2917 | { |
| 2813 | == (c = FETCH_CHAR_AS_MULTIBYTE (from_byte))) | 2918 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2814 | && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) | 2919 | if (c == stringterm |
| 2815 | break; | 2920 | && (syntax_multibyte (c, multibyte_symbol_p) |
| 2921 | == Sstring)) | ||
| 2922 | break; | ||
| 2923 | } | ||
| 2816 | } | 2924 | } |
| 2817 | if (!depth && sexpflag) goto done2; | 2925 | if (!depth && sexpflag) goto done2; |
| 2818 | break; | 2926 | break; |
| @@ -2918,7 +3026,7 @@ This includes chars with "quote" or "prefix" syntax (' or p). */) | |||
| 2918 | while (!char_quoted (pos, pos_byte) | 3026 | while (!char_quoted (pos, pos_byte) |
| 2919 | /* Previous statement updates syntax table. */ | 3027 | /* Previous statement updates syntax table. */ |
| 2920 | && ((c = FETCH_CHAR_AS_MULTIBYTE (pos_byte), SYNTAX (c) == Squote) | 3028 | && ((c = FETCH_CHAR_AS_MULTIBYTE (pos_byte), SYNTAX (c) == Squote) |
| 2921 | || SYNTAX_PREFIX (c))) | 3029 | || syntax_prefix_flag_p (c))) |
| 2922 | { | 3030 | { |
| 2923 | opoint = pos; | 3031 | opoint = pos; |
| 2924 | opoint_byte = pos_byte; | 3032 | opoint_byte = pos_byte; |
| @@ -2935,7 +3043,7 @@ This includes chars with "quote" or "prefix" syntax (' or p). */) | |||
| 2935 | /* Parse forward from FROM / FROM_BYTE to END, | 3043 | /* Parse forward from FROM / FROM_BYTE to END, |
| 2936 | assuming that FROM has state OLDSTATE (nil means FROM is start of function), | 3044 | assuming that FROM has state OLDSTATE (nil means FROM is start of function), |
| 2937 | and return a description of the state of the parse at END. | 3045 | and return a description of the state of the parse at END. |
| 2938 | If STOPBEFORE is nonzero, stop at the start of an atom. | 3046 | If STOPBEFORE, stop at the start of an atom. |
| 2939 | If COMMENTSTOP is 1, stop at the start of a comment. | 3047 | If COMMENTSTOP is 1, stop at the start of a comment. |
| 2940 | If COMMENTSTOP is -1, stop at the start or end of a comment, | 3048 | If COMMENTSTOP is -1, stop at the start or end of a comment, |
| 2941 | after the beginning of a string, or after the end of a string. */ | 3049 | after the beginning of a string, or after the end of a string. */ |
| @@ -2943,30 +3051,29 @@ This includes chars with "quote" or "prefix" syntax (' or p). */) | |||
| 2943 | static void | 3051 | static void |
| 2944 | scan_sexps_forward (struct lisp_parse_state *stateptr, | 3052 | scan_sexps_forward (struct lisp_parse_state *stateptr, |
| 2945 | ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t end, | 3053 | ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t end, |
| 2946 | EMACS_INT targetdepth, int stopbefore, | 3054 | EMACS_INT targetdepth, bool stopbefore, |
| 2947 | Lisp_Object oldstate, int commentstop) | 3055 | Lisp_Object oldstate, int commentstop) |
| 2948 | { | 3056 | { |
| 2949 | struct lisp_parse_state state; | 3057 | struct lisp_parse_state state; |
| 2950 | 3058 | enum syntaxcode code; | |
| 2951 | register enum syntaxcode code; | ||
| 2952 | int c1; | 3059 | int c1; |
| 2953 | int comnested; | 3060 | bool comnested; |
| 2954 | struct level { ptrdiff_t last, prev; }; | 3061 | struct level { ptrdiff_t last, prev; }; |
| 2955 | struct level levelstart[100]; | 3062 | struct level levelstart[100]; |
| 2956 | register struct level *curlevel = levelstart; | 3063 | struct level *curlevel = levelstart; |
| 2957 | struct level *endlevel = levelstart + 100; | 3064 | struct level *endlevel = levelstart + 100; |
| 2958 | register EMACS_INT depth; /* Paren depth of current scanning location. | 3065 | EMACS_INT depth; /* Paren depth of current scanning location. |
| 2959 | level - levelstart equals this except | 3066 | level - levelstart equals this except |
| 2960 | when the depth becomes negative. */ | 3067 | when the depth becomes negative. */ |
| 2961 | EMACS_INT mindepth; /* Lowest DEPTH value seen. */ | 3068 | EMACS_INT mindepth; /* Lowest DEPTH value seen. */ |
| 2962 | int start_quoted = 0; /* Nonzero means starting after a char quote */ | 3069 | bool start_quoted = 0; /* True means starting after a char quote. */ |
| 2963 | Lisp_Object tem; | 3070 | Lisp_Object tem; |
| 2964 | ptrdiff_t prev_from; /* Keep one character before FROM. */ | 3071 | ptrdiff_t prev_from; /* Keep one character before FROM. */ |
| 2965 | ptrdiff_t prev_from_byte; | 3072 | ptrdiff_t prev_from_byte; |
| 2966 | int prev_from_syntax; | 3073 | int prev_from_syntax; |
| 2967 | int boundary_stop = commentstop == -1; | 3074 | bool boundary_stop = commentstop == -1; |
| 2968 | int nofence; | 3075 | bool nofence; |
| 2969 | int found; | 3076 | bool found; |
| 2970 | ptrdiff_t out_bytepos, out_charpos; | 3077 | ptrdiff_t out_bytepos, out_charpos; |
| 2971 | int temp; | 3078 | int temp; |
| 2972 | 3079 | ||
| @@ -3097,8 +3204,8 @@ do { prev_from = from; \ | |||
| 3097 | terminates the comment section. */ | 3204 | terminates the comment section. */ |
| 3098 | state.comstyle | 3205 | state.comstyle |
| 3099 | = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax); | 3206 | = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax); |
| 3100 | comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax); | 3207 | comnested = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) |
| 3101 | comnested = comnested || SYNTAX_FLAGS_COMMENT_NESTED (syntax); | 3208 | | SYNTAX_FLAGS_COMMENT_NESTED (syntax)); |
| 3102 | state.incomment = comnested ? 1 : -1; | 3209 | state.incomment = comnested ? 1 : -1; |
| 3103 | state.comstr_start = prev_from; | 3210 | state.comstr_start = prev_from; |
| 3104 | INC_FROM; | 3211 | INC_FROM; |
| @@ -3124,7 +3231,7 @@ do { prev_from = from; \ | |||
| 3124 | 3231 | ||
| 3125 | if (SYNTAX_FLAGS_PREFIX (prev_from_syntax)) | 3232 | if (SYNTAX_FLAGS_PREFIX (prev_from_syntax)) |
| 3126 | continue; | 3233 | continue; |
| 3127 | switch (SWITCH_ENUM_CAST (code)) | 3234 | switch (code) |
| 3128 | { | 3235 | { |
| 3129 | case Sescape: | 3236 | case Sescape: |
| 3130 | case Scharquote: | 3237 | case Scharquote: |
| @@ -3142,10 +3249,8 @@ do { prev_from = from; \ | |||
| 3142 | symstarted: | 3249 | symstarted: |
| 3143 | while (from < end) | 3250 | while (from < end) |
| 3144 | { | 3251 | { |
| 3145 | /* Some compilers can't handle this inside the switch. */ | 3252 | int symchar = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 3146 | temp = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 3253 | switch (SYNTAX (symchar)) |
| 3147 | temp = SYNTAX (temp); | ||
| 3148 | switch (temp) | ||
| 3149 | { | 3254 | { |
| 3150 | case Scharquote: | 3255 | case Scharquote: |
| 3151 | case Sescape: | 3256 | case Sescape: |
| @@ -3227,19 +3332,19 @@ do { prev_from = from; \ | |||
| 3227 | while (1) | 3332 | while (1) |
| 3228 | { | 3333 | { |
| 3229 | int c; | 3334 | int c; |
| 3335 | enum syntaxcode c_code; | ||
| 3230 | 3336 | ||
| 3231 | if (from >= end) goto done; | 3337 | if (from >= end) goto done; |
| 3232 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | 3338 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 3233 | /* Some compilers can't handle this inside the switch. */ | 3339 | c_code = SYNTAX (c); |
| 3234 | temp = SYNTAX (c); | ||
| 3235 | 3340 | ||
| 3236 | /* Check TEMP here so that if the char has | 3341 | /* Check C_CODE here so that if the char has |
| 3237 | a syntax-table property which says it is NOT | 3342 | a syntax-table property which says it is NOT |
| 3238 | a string character, it does not end the string. */ | 3343 | a string character, it does not end the string. */ |
| 3239 | if (nofence && c == state.instring && temp == Sstring) | 3344 | if (nofence && c == state.instring && c_code == Sstring) |
| 3240 | break; | 3345 | break; |
| 3241 | 3346 | ||
| 3242 | switch (temp) | 3347 | switch (c_code) |
| 3243 | { | 3348 | { |
| 3244 | case Sstring_fence: | 3349 | case Sstring_fence: |
| 3245 | if (!nofence) goto string_end; | 3350 | if (!nofence) goto string_end; |
| @@ -3272,6 +3377,7 @@ do { prev_from = from; \ | |||
| 3272 | 3377 | ||
| 3273 | stop: /* Here if stopping before start of sexp. */ | 3378 | stop: /* Here if stopping before start of sexp. */ |
| 3274 | from = prev_from; /* We have just fetched the char that starts it; */ | 3379 | from = prev_from; /* We have just fetched the char that starts it; */ |
| 3380 | from_byte = prev_from_byte; | ||
| 3275 | goto done; /* but return the position before it. */ | 3381 | goto done; /* but return the position before it. */ |
| 3276 | 3382 | ||
| 3277 | endquoted: | 3383 | endquoted: |
| @@ -3283,6 +3389,7 @@ do { prev_from = from; \ | |||
| 3283 | state.prevlevelstart | 3389 | state.prevlevelstart |
| 3284 | = (curlevel == levelstart) ? -1 : (curlevel - 1)->last; | 3390 | = (curlevel == levelstart) ? -1 : (curlevel - 1)->last; |
| 3285 | state.location = from; | 3391 | state.location = from; |
| 3392 | state.location_byte = from_byte; | ||
| 3286 | state.levelstarts = Qnil; | 3393 | state.levelstarts = Qnil; |
| 3287 | while (curlevel > levelstart) | 3394 | while (curlevel > levelstart) |
| 3288 | state.levelstarts = Fcons (make_number ((--curlevel)->last), | 3395 | state.levelstarts = Fcons (make_number ((--curlevel)->last), |
| @@ -3322,7 +3429,8 @@ Fifth arg OLDSTATE is a list like what this function returns. | |||
| 3322 | Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. | 3429 | Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. |
| 3323 | If it is symbol `syntax-table', stop after the start of a comment or a | 3430 | If it is symbol `syntax-table', stop after the start of a comment or a |
| 3324 | string, or after end of a comment or a string. */) | 3431 | string, or after end of a comment or a string. */) |
| 3325 | (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth, Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop) | 3432 | (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth, |
| 3433 | Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop) | ||
| 3326 | { | 3434 | { |
| 3327 | struct lisp_parse_state state; | 3435 | struct lisp_parse_state state; |
| 3328 | EMACS_INT target; | 3436 | EMACS_INT target; |
| @@ -3342,7 +3450,7 @@ Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. | |||
| 3342 | (NILP (commentstop) | 3450 | (NILP (commentstop) |
| 3343 | ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1))); | 3451 | ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1))); |
| 3344 | 3452 | ||
| 3345 | SET_PT (state.location); | 3453 | SET_PT_BOTH (state.location, state.location_byte); |
| 3346 | 3454 | ||
| 3347 | return Fcons (make_number (state.depth), | 3455 | return Fcons (make_number (state.depth), |
| 3348 | Fcons (state.prevlevelstart < 0 | 3456 | Fcons (state.prevlevelstart < 0 |
| @@ -3378,40 +3486,39 @@ init_syntax_once (void) | |||
| 3378 | /* This has to be done here, before we call Fmake_char_table. */ | 3486 | /* This has to be done here, before we call Fmake_char_table. */ |
| 3379 | DEFSYM (Qsyntax_table, "syntax-table"); | 3487 | DEFSYM (Qsyntax_table, "syntax-table"); |
| 3380 | 3488 | ||
| 3381 | /* Intern_C_String this now in case it isn't already done. | 3489 | /* This variable is DEFSYMed in alloc.c and not initialized yet, so |
| 3382 | Setting this variable twice is harmless. | 3490 | intern it here. NOTE: you must guarantee that init_syntax_once |
| 3383 | But don't staticpro it here--that is done in alloc.c. */ | 3491 | is called before all other users of this variable. */ |
| 3384 | Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots"); | 3492 | Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots"); |
| 3385 | 3493 | ||
| 3386 | /* Create objects which can be shared among syntax tables. */ | 3494 | /* Create objects which can be shared among syntax tables. */ |
| 3387 | Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil); | 3495 | Vsyntax_code_object = make_uninit_vector (Smax); |
| 3388 | for (i = 0; i < ASIZE (Vsyntax_code_object); i++) | 3496 | for (i = 0; i < Smax; i++) |
| 3389 | XVECTOR (Vsyntax_code_object)->contents[i] | 3497 | ASET (Vsyntax_code_object, i, Fcons (make_number (i), Qnil)); |
| 3390 | = Fcons (make_number (i), Qnil); | ||
| 3391 | 3498 | ||
| 3392 | /* Now we are ready to set up this property, so we can | 3499 | /* Now we are ready to set up this property, so we can |
| 3393 | create syntax tables. */ | 3500 | create syntax tables. */ |
| 3394 | Fput (Qsyntax_table, Qchar_table_extra_slots, make_number (0)); | 3501 | Fput (Qsyntax_table, Qchar_table_extra_slots, make_number (0)); |
| 3395 | 3502 | ||
| 3396 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace]; | 3503 | temp = AREF (Vsyntax_code_object, Swhitespace); |
| 3397 | 3504 | ||
| 3398 | Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp); | 3505 | Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp); |
| 3399 | 3506 | ||
| 3400 | /* Control characters should not be whitespace. */ | 3507 | /* Control characters should not be whitespace. */ |
| 3401 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct]; | 3508 | temp = AREF (Vsyntax_code_object, Spunct); |
| 3402 | for (i = 0; i <= ' ' - 1; i++) | 3509 | for (i = 0; i <= ' ' - 1; i++) |
| 3403 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); | 3510 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); |
| 3404 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 0177, temp); | 3511 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 0177, temp); |
| 3405 | 3512 | ||
| 3406 | /* Except that a few really are whitespace. */ | 3513 | /* Except that a few really are whitespace. */ |
| 3407 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace]; | 3514 | temp = AREF (Vsyntax_code_object, Swhitespace); |
| 3408 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ' ', temp); | 3515 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ' ', temp); |
| 3409 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\t', temp); | 3516 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\t', temp); |
| 3410 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\n', temp); | 3517 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\n', temp); |
| 3411 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 015, temp); | 3518 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 015, temp); |
| 3412 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 014, temp); | 3519 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 014, temp); |
| 3413 | 3520 | ||
| 3414 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; | 3521 | temp = AREF (Vsyntax_code_object, Sword); |
| 3415 | for (i = 'a'; i <= 'z'; i++) | 3522 | for (i = 'a'; i <= 'z'; i++) |
| 3416 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); | 3523 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); |
| 3417 | for (i = 'A'; i <= 'Z'; i++) | 3524 | for (i = 'A'; i <= 'Z'; i++) |
| @@ -3435,18 +3542,18 @@ init_syntax_once (void) | |||
| 3435 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '}', | 3542 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '}', |
| 3436 | Fcons (make_number (Sclose), make_number ('{'))); | 3543 | Fcons (make_number (Sclose), make_number ('{'))); |
| 3437 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '"', | 3544 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '"', |
| 3438 | Fcons (make_number ((int) Sstring), Qnil)); | 3545 | Fcons (make_number (Sstring), Qnil)); |
| 3439 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\\', | 3546 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\\', |
| 3440 | Fcons (make_number ((int) Sescape), Qnil)); | 3547 | Fcons (make_number (Sescape), Qnil)); |
| 3441 | 3548 | ||
| 3442 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Ssymbol]; | 3549 | temp = AREF (Vsyntax_code_object, Ssymbol); |
| 3443 | for (i = 0; i < 10; i++) | 3550 | for (i = 0; i < 10; i++) |
| 3444 | { | 3551 | { |
| 3445 | c = "_-+*/&|<>="[i]; | 3552 | c = "_-+*/&|<>="[i]; |
| 3446 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); | 3553 | SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); |
| 3447 | } | 3554 | } |
| 3448 | 3555 | ||
| 3449 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct]; | 3556 | temp = AREF (Vsyntax_code_object, Spunct); |
| 3450 | for (i = 0; i < 12; i++) | 3557 | for (i = 0; i < 12; i++) |
| 3451 | { | 3558 | { |
| 3452 | c = ".,;:?!#@~^'`"[i]; | 3559 | c = ".,;:?!#@~^'`"[i]; |
| @@ -3454,7 +3561,7 @@ init_syntax_once (void) | |||
| 3454 | } | 3561 | } |
| 3455 | 3562 | ||
| 3456 | /* All multibyte characters have syntax `word' by default. */ | 3563 | /* All multibyte characters have syntax `word' by default. */ |
| 3457 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; | 3564 | temp = AREF (Vsyntax_code_object, Sword); |
| 3458 | char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); | 3565 | char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); |
| 3459 | } | 3566 | } |
| 3460 | 3567 | ||
| @@ -3475,9 +3582,9 @@ syms_of_syntax (void) | |||
| 3475 | 3582 | ||
| 3476 | DEFSYM (Qscan_error, "scan-error"); | 3583 | DEFSYM (Qscan_error, "scan-error"); |
| 3477 | Fput (Qscan_error, Qerror_conditions, | 3584 | Fput (Qscan_error, Qerror_conditions, |
| 3478 | pure_cons (Qscan_error, pure_cons (Qerror, Qnil))); | 3585 | listn (CONSTYPE_PURE, 2, Qscan_error, Qerror)); |
| 3479 | Fput (Qscan_error, Qerror_message, | 3586 | Fput (Qscan_error, Qerror_message, |
| 3480 | make_pure_c_string ("Scan error")); | 3587 | build_pure_c_string ("Scan error")); |
| 3481 | 3588 | ||
| 3482 | DEFVAR_BOOL ("parse-sexp-ignore-comments", parse_sexp_ignore_comments, | 3589 | DEFVAR_BOOL ("parse-sexp-ignore-comments", parse_sexp_ignore_comments, |
| 3483 | doc: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */); | 3590 | doc: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */); |