X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/a89654f8f34114db543cb91363e8fded6d73e986..463d631919baa394ee73a46843b2006aac9fdd4e:/src/syntax.c diff --git a/src/syntax.c b/src/syntax.c index 70e66ba187..72d904914e 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1,6 +1,6 @@ /* GNU Emacs routines to deal with syntax tables; also word and list parsing. - Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2012 - Free Software Foundation, Inc. + Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2013 Free + Software Foundation, Inc. This file is part of GNU Emacs. @@ -20,13 +20,12 @@ along with GNU Emacs. If not, see . */ #include -#include #include -#include + #include "lisp.h" #include "commands.h" -#include "buffer.h" #include "character.h" +#include "buffer.h" #include "keymap.h" #include "regex.h" @@ -143,7 +142,6 @@ static ptrdiff_t find_start_begv; static EMACS_INT find_start_modiff; -static Lisp_Object Fsyntax_table_p (Lisp_Object); static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int); static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object); static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int); @@ -151,6 +149,13 @@ static void scan_sexps_forward (struct lisp_parse_state *, ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, int, Lisp_Object, int); static int in_classes (int, Lisp_Object); + +/* This setter is used only in this file, so it can be private. */ +static void +bset_syntax_table (struct buffer *b, Lisp_Object val) +{ + b->INTERNAL_FIELD (syntax_table) = val; +} /* Whether the syntax of the character C has the prefix flag set. */ int syntax_prefix_flag_p (int c) @@ -172,7 +177,7 @@ struct gl_state_s gl_state; /* Global state of syntax parser. */ direction than the intervals - or in an interval. We update the current syntax-table basing on the property of this interval, and update the interval to start further than CHARPOS - or be - NULL_INTERVAL. We also update lim_property to be the next value of + NULL. We also update lim_property to be the next value of charpos to call this subroutine again - or be before/after the start/end of OBJECT. */ @@ -193,7 +198,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, i = interval_of (charpos, object); gl_state.backward_i = gl_state.forward_i = i; invalidate = 0; - if (NULL_INTERVAL_P (i)) + if (!i) return; /* interval_of updates only ->position of the return value, so update the parents manually to speed up update_interval. */ @@ -218,7 +223,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, /* We are guaranteed to be called with CHARPOS either in i, or further off. */ - if (NULL_INTERVAL_P (i)) + if (!i) error ("Error in syntax_table logic for to-the-end intervals"); else if (charpos < i->position) /* Move left. */ { @@ -288,7 +293,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, } } - while (!NULL_INTERVAL_P (i)) + while (i) { if (cnt && !EQ (tmp_table, textget (i->plist, Qsyntax_table))) { @@ -314,7 +319,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, /* e_property at EOB is not set to ZV but to ZV+1, so that we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without having to check eob between the two. */ - + (NULL_INTERVAL_P (next_interval (i)) ? 1 : 0); + + (next_interval (i) ? 0 : 1); gl_state.forward_i = i; } else @@ -327,7 +332,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, cnt++; i = count > 0 ? next_interval (i) : previous_interval (i); } - eassert (NULL_INTERVAL_P (i)); /* This property goes to the end. */ + eassert (i == NULL); /* This property goes to the end. */ if (count > 0) gl_state.e_property = gl_state.stop; else @@ -367,7 +372,7 @@ char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos) /* Return the bytepos one character before BYTEPOS. We assume that BYTEPOS is not at the start of the buffer. */ -static inline ptrdiff_t +static ptrdiff_t dec_bytepos (ptrdiff_t bytepos) { if (NILP (BVAR (current_buffer, enable_multibyte_characters))) @@ -820,7 +825,7 @@ It is a copy of the TABLE, which defaults to the standard syntax table. */) /* Only the standard syntax table should have a default element. Other syntax tables should inherit from parents instead. */ - XCHAR_TABLE (copy)->defalt = Qnil; + set_char_table_defalt (copy, Qnil); /* Copied syntax tables should all have parents. If we copied one with no parent, such as the standard syntax table, @@ -837,7 +842,7 @@ One argument, a syntax table. */) { int idx; check_syntax_table (table); - BVAR (current_buffer, syntax_table) = table; + bset_syntax_table (current_buffer, table); /* Indicate that this buffer now has a specified syntax table. */ idx = PER_BUFFER_VAR_IDX (syntax_table); SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1); @@ -916,11 +921,11 @@ DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, } DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0, - doc: /* Convert a syntax specification STRING into syntax cell form. -STRING should be a string as it is allowed as argument of -`modify-syntax-entry'. Value is the equivalent cons cell -\(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table' -text property. */) + doc: /* Convert a syntax descriptor STRING into a raw syntax descriptor. +STRING should be a string of the form allowed as argument of +`modify-syntax-entry'. The return value is a raw syntax descriptor: a +cons cell \(CODE . MATCHING-CHAR) which can be used, for example, as +the value of a `syntax-table' text property. */) (Lisp_Object string) { register const unsigned char *p; @@ -988,7 +993,7 @@ text property. */) } if (val < ASIZE (Vsyntax_code_object) && NILP (match)) - return XVECTOR (Vsyntax_code_object)->contents[val]; + return AREF (Vsyntax_code_object, val); else /* Since we can't use a shared object, let's make a new one. */ return Fcons (make_number (val), match); @@ -1010,7 +1015,7 @@ The first character of NEWENTRY should be one of the following: " string quote. \\ escape. $ paired delimiter. ' expression quote or prefix operator. < comment starter. > comment ender. - / character-quote. @ inherit from `standard-syntax-table'. + / character-quote. @ inherit from parent table. | generic string fence. ! generic comment fence. Only single-character comment start and end sequences are represented thus. @@ -1153,7 +1158,7 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, insert_string ("\twhich means: "); - switch (SWITCH_ENUM_CAST (code)) + switch (code) { case Swhitespace: insert_string ("whitespace"); break; @@ -1582,7 +1587,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl fastmap[CHAR_LEADING_CODE (c)] = 1; range_start_byte = i; range_start_char = c; - char_ranges = (int *) alloca (sizeof (int) * 128 * 2); + char_ranges = alloca (sizeof *char_ranges * 128 * 2); for (i = 129; i < 0400; i++) { c = BYTE8_TO_CHAR (i); @@ -1603,7 +1608,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl } else /* STRING is multibyte */ { - char_ranges = (int *) alloca (sizeof (int) * SCHARS (string) * 2); + char_ranges = alloca (sizeof *char_ranges * SCHARS (string) * 2); while (i_byte < size_byte) { @@ -2526,7 +2531,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf if (prefix) continue; - switch (SWITCH_ENUM_CAST (code)) + switch (code) { case Sescape: case Scharquote: @@ -2703,7 +2708,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf else if (SYNTAX_FLAGS_PREFIX (syntax)) continue; - switch (SWITCH_ENUM_CAST (code)) + switch (code) { case Sword: case Ssymbol: @@ -3124,7 +3129,7 @@ do { prev_from = from; \ if (SYNTAX_FLAGS_PREFIX (prev_from_syntax)) continue; - switch (SWITCH_ENUM_CAST (code)) + switch (code) { case Sescape: case Scharquote: @@ -3386,32 +3391,31 @@ init_syntax_once (void) /* Create objects which can be shared among syntax tables. */ Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil); for (i = 0; i < ASIZE (Vsyntax_code_object); i++) - XVECTOR (Vsyntax_code_object)->contents[i] - = Fcons (make_number (i), Qnil); + ASET (Vsyntax_code_object, i, Fcons (make_number (i), Qnil)); /* Now we are ready to set up this property, so we can create syntax tables. */ Fput (Qsyntax_table, Qchar_table_extra_slots, make_number (0)); - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace]; + temp = AREF (Vsyntax_code_object, (int) Swhitespace); Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp); /* Control characters should not be whitespace. */ - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct]; + temp = AREF (Vsyntax_code_object, (int) Spunct); for (i = 0; i <= ' ' - 1; i++) SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 0177, temp); /* Except that a few really are whitespace. */ - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace]; + temp = AREF (Vsyntax_code_object, (int) Swhitespace); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ' ', temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\t', temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\n', temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 015, temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 014, temp); - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; + temp = AREF (Vsyntax_code_object, (int) Sword); for (i = 'a'; i <= 'z'; i++) SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); for (i = 'A'; i <= 'Z'; i++) @@ -3439,14 +3443,14 @@ init_syntax_once (void) SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\\', Fcons (make_number ((int) Sescape), Qnil)); - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Ssymbol]; + temp = AREF (Vsyntax_code_object, (int) Ssymbol); for (i = 0; i < 10; i++) { c = "_-+*/&|<>="[i]; SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); } - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct]; + temp = AREF (Vsyntax_code_object, (int) Spunct); for (i = 0; i < 12; i++) { c = ".,;:?!#@~^'`"[i]; @@ -3454,7 +3458,7 @@ init_syntax_once (void) } /* All multibyte characters have syntax `word' by default. */ - temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; + temp = AREF (Vsyntax_code_object, (int) Sword); char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); } @@ -3475,9 +3479,9 @@ syms_of_syntax (void) DEFSYM (Qscan_error, "scan-error"); Fput (Qscan_error, Qerror_conditions, - pure_cons (Qscan_error, pure_cons (Qerror, Qnil))); + listn (CONSTYPE_PURE, 2, Qscan_error, Qerror)); Fput (Qscan_error, Qerror_message, - make_pure_c_string ("Scan error")); + build_pure_c_string ("Scan error")); DEFVAR_BOOL ("parse-sexp-ignore-comments", parse_sexp_ignore_comments, doc: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */); @@ -3498,7 +3502,7 @@ See the info node `(elisp)Syntax Properties' for a description of the DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start", open_paren_in_column_0_is_defun_start, - doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */); + doc: /* Non-nil means an open paren in column 0 denotes the start of a defun. */); open_paren_in_column_0_is_defun_start = 1;