/* GNU Emacs routines to deal with syntax tables; also word and list parsing.
Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
#include <ctype.h>
+#include <setjmp.h>
#include "lisp.h"
#include "commands.h"
#include "buffer.h"
return bytepos;
}
\f
-/* Return a defun-start position before before POS and not too far before.
+/* Return a defun-start position before POS and not too far before.
It should be the last one before POS, or nearly the last.
When open_paren_in_column_0_is_defun_start is nonzero,
/* We optimize syntax-table lookup for rare updates. Thus we accept
only those `^\s(' which are good in global _and_ text-property
syntax-tables. */
- gl_state.current_syntax_table = current_buffer->syntax_table;
- gl_state.use_global = 0;
+ SETUP_BUFFER_SYNTAX_TABLE ();
while (PT > BEGV)
{
int c;
if (SYNTAX (c) == Sopen)
break;
/* Now fallback to the default value. */
- gl_state.current_syntax_table = current_buffer->syntax_table;
- gl_state.use_global = 0;
+ SETUP_BUFFER_SYNTAX_TABLE ();
}
/* Move to beg of previous line. */
scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -2, 1);
\f
DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0,
doc: /* Return the syntax code of CHARACTER, described by a character.
-For example, if CHARACTER is a word constituent,
-the character `w' is returned.
+For example, if CHARACTER is a word constituent, the
+character `w' (119) is returned.
The characters that correspond to various syntax codes
are listed in the documentation of `modify-syntax-entry'. */)
(character)
Lisp_Object character;
{
int char_int;
- gl_state.current_syntax_table = current_buffer->syntax_table;
-
- gl_state.use_global = 0;
- CHECK_NUMBER (character);
+ CHECK_CHARACTER (character);
char_int = XINT (character);
+ SETUP_BUFFER_SYNTAX_TABLE ();
return make_number (syntax_code_spec[(int) SYNTAX (char_int)]);
}
Lisp_Object character;
{
int char_int, code;
- gl_state.current_syntax_table = current_buffer->syntax_table;
- gl_state.use_global = 0;
CHECK_NUMBER (character);
char_int = XINT (character);
+ SETUP_BUFFER_SYNTAX_TABLE ();
code = SYNTAX (char_int);
if (code == Sopen || code == Sclose)
return SYNTAX_MATCH (char_int);
if (*p)
{
int len;
- int character = (STRING_CHAR_AND_LENGTH
- (p, SBYTES (string) - 1, len));
+ int character = STRING_CHAR_AND_LENGTH (p, len);
XSETINT (match, character);
if (XFASTINT (match) == ' ')
match = Qnil;
The syntax is changed only for table SYNTAX-TABLE, which defaults to
the current buffer's syntax table.
CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
-in the range MIN and MAX are changed.
+in the range MIN to MAX are changed.
The first character of NEWENTRY should be one of the following:
Space or - whitespace syntax. w word constituent.
_ symbol constituent. . punctuation.
p means CHAR is a prefix character for `backward-prefix-chars';
such characters are treated as whitespace when they occur
between expressions.
-usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
+usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
(c, newentry, syntax_table)
Lisp_Object c, newentry, syntax_table;
{
if ((code != Sword
&& (! words_include_escapes
|| (code != Sescape && code != Scharquote)))
- || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch1), script))
+ || word_boundary_p (ch0, ch1))
break;
INC_BOTH (from, from_byte);
ch0 = ch1;
if ((code != Sword
&& (! words_include_escapes
|| (code != Sescape && code != Scharquote)))
- || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch0), script))
+ || word_boundary_p (ch0, ch1))
{
INC_BOTH (from, from_byte);
break;
doc: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
STRING is like the inside of a `[...]' in a regular expression
except that `]' is never special and `\\' quotes `^', `-' or `\\'
- (but not as the end of a range; quoting is never needed there).
+ (but not at the end of a range; quoting is never needed there).
Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
With arg "^a-zA-Z", skips nonletters stopping before first letter.
Char classes, e.g. `[:alpha:]', are supported.
bzero (fastmap + 0200, 0200);
/* We are sure that this loop stops. */
for (i = 0200; ! fastmap2[i]; i++);
- c = unibyte_char_to_multibyte (i);
+ c = BYTE8_TO_CHAR (i);
fastmap[CHAR_LEADING_CODE (c)] = 1;
range_start_byte = i;
range_start_char = c;
char_ranges = (int *) alloca (sizeof (int) * 128 * 2);
for (i = 129; i < 0400; i++)
{
- c = unibyte_char_to_multibyte (i);
+ c = BYTE8_TO_CHAR (i);
fastmap[CHAR_LEADING_CODE (c)] = 1;
if (i - range_start_byte != c - range_start_char)
{
unsigned char leading_code;
leading_code = str[i_byte];
- c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len);
+ c = STRING_CHAR_AND_LENGTH (str + i_byte, len);
i_byte += len;
if (handle_iso_classes && c == '['
&& i_byte < size_byte
- && STRING_CHAR (str + i_byte, size_byte - i_byte) == ':')
+ && STRING_CHAR (str + i_byte) == ':')
{
const unsigned char *class_beg = str + i_byte + 1;
const unsigned char *class_end = class_beg;
break;
leading_code = str[i_byte];
- c = STRING_CHAR_AND_LENGTH (str + i_byte,
- size_byte - i_byte, len);
+ c = STRING_CHAR_AND_LENGTH (str + i_byte, len);
i_byte += len;
}
/* Treat `-' as range character only if another character
/* Get the end of the range. */
leading_code2 = str[i_byte];
- c2 = STRING_CHAR_AND_LENGTH (str + i_byte,
- size_byte - i_byte, len);
+ c2 = STRING_CHAR_AND_LENGTH (str + i_byte, len);
i_byte += len;
if (c2 == '\\'
&& i_byte < size_byte)
{
leading_code2 = str[i_byte];
- c2 =STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len);
+ c2 =STRING_CHAR_AND_LENGTH (str + i_byte, len);
i_byte += len;
}
}
immediate_quit = 1;
+ /* This code may look up syntax tables using macros that rely on the
+ gl_state object. To make sure this object is not out of date,
+ let's initialize it manually.
+ We ignore syntax-table text-properties for now, since that's
+ what we've done in the past. */
+ SETUP_BUFFER_SYNTAX_TABLE ();
if (forwardp)
{
if (multibyte)
p = GAP_END_ADDR;
stop = endp;
}
- c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes);
+ c = STRING_CHAR_AND_LENGTH (p, nbytes);
if (! NILP (iso_classes) && in_classes (c, iso_classes))
{
if (negate)
}
prev_p = p;
while (--p >= stop && ! CHAR_HEAD_P (*p));
- c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
+ c = STRING_CHAR (p);
if (! NILP (iso_classes) && in_classes (c, iso_classes))
{
p = GAP_END_ADDR;
stop = endp;
}
- c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes);
+ c = STRING_CHAR_AND_LENGTH (p, nbytes);
if (! fastmap[(int) SYNTAX (c)])
break;
p += nbytes, pos++, pos_byte += nbytes;
UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
prev_p = p;
while (--p >= stop && ! CHAR_HEAD_P (*p));
- c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
+ c = STRING_CHAR (p);
if (! fastmap[(int) SYNTAX (c)])
break;
pos--, pos_byte -= prev_p - p;
{
int fits_class = 0;
- while (! NILP (iso_classes))
+ while (CONSP (iso_classes))
{
Lisp_Object elt;
elt = XCAR (iso_classes);
Lisp_Object temp;
/* This has to be done here, before we call Fmake_char_table. */
- Qsyntax_table = intern ("syntax-table");
+ Qsyntax_table = intern_c_string ("syntax-table");
staticpro (&Qsyntax_table);
- /* Intern this now in case it isn't already done.
+ /* Intern_C_String this now in case it isn't already done.
Setting this variable twice is harmless.
But don't staticpro it here--that is done in alloc.c. */
- Qchar_table_extra_slots = intern ("char-table-extra-slots");
+ Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots");
/* Create objects which can be shared among syntax tables. */
Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil);
void
syms_of_syntax ()
{
- Qsyntax_table_p = intern ("syntax-table-p");
+ Qsyntax_table_p = intern_c_string ("syntax-table-p");
staticpro (&Qsyntax_table_p);
staticpro (&Vsyntax_code_object);
/* Defined in regex.c */
staticpro (&re_match_object);
- Qscan_error = intern ("scan-error");
+ Qscan_error = intern_c_string ("scan-error");
staticpro (&Qscan_error);
Fput (Qscan_error, Qerror_conditions,
- Fcons (Qscan_error, Fcons (Qerror, Qnil)));
+ pure_cons (Qscan_error, pure_cons (Qerror, Qnil)));
Fput (Qscan_error, Qerror_message,
- build_string ("Scan error"));
+ make_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. */);