]> code.delx.au - gnu-emacs/blobdiff - src/syntax.c
Merge from emacs--rel--22
[gnu-emacs] / src / syntax.c
index e3e1f27b9d82f33ae8be18454b9d082dcdf39011..8c5ebb96f285e7e94e9f76fa3b496edc76c86a32 100644 (file)
@@ -1,13 +1,14 @@
 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
-   Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2002,
-                 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2001,
+                 2002, 2003, 2004, 2005, 2006, 2007, 2008
+                 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,9 +16,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
@@ -97,11 +96,12 @@ static int find_start_modiff;
 
 
 static int find_defun_start P_ ((int, int));
-static int back_comment P_ ((int, int, int, int, int, int *, int *));
+static int back_comment P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int, int,
+                            EMACS_INT *, EMACS_INT *));
 static int char_quoted P_ ((int, int));
 static Lisp_Object skip_chars P_ ((int, Lisp_Object, Lisp_Object, int));
 static Lisp_Object skip_syntaxes P_ ((int, Lisp_Object, Lisp_Object));
-static Lisp_Object scan_lists P_ ((int, int, int, int));
+static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int));
 static void scan_sexps_forward P_ ((struct lisp_parse_state *,
                                    int, int, int, int,
                                    int, Lisp_Object, int));
@@ -472,9 +472,9 @@ prev_char_comend_first (pos, pos_byte)
 
 static int
 back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_ptr)
-     int from, from_byte, stop;
+     EMACS_INT from, from_byte, stop;
      int comnested, comstyle;
-     int *charpos_ptr, *bytepos_ptr;
+     EMACS_INT *charpos_ptr, *bytepos_ptr;
 {
   /* Look back, counting the parity of string-quotes,
      and recording the comment-starters seen.
@@ -749,9 +749,8 @@ static void
 check_syntax_table (obj)
      Lisp_Object obj;
 {
-  if (!(CHAR_TABLE_P (obj)
-       && EQ (XCHAR_TABLE (obj)->purpose, Qsyntax_table)))
-    wrong_type_argument (Qsyntax_table_p, obj);
+  CHECK_TYPE (CHAR_TABLE_P (obj) && EQ (XCHAR_TABLE (obj)->purpose, Qsyntax_table),
+             Qsyntax_table_p, obj);
 }
 
 DEFUN ("syntax-table", Fsyntax_table, Ssyntax_table, 0, 0, 0,
@@ -893,7 +892,7 @@ 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'
+\(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
 text property.  */)
      (string)
      Lisp_Object string;
@@ -1029,6 +1028,11 @@ usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
     SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table, c, newentry);
   else
     SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), newentry);
+
+  /* We clear the regexp cache, since character classes can now have
+     different values from those in the compiled regexps.*/
+  clear_regexp_cache ();
+
   return Qnil;
 }
 \f
@@ -1293,20 +1297,20 @@ scan_words (from, count)
          script = CHAR_TABLE_REF (Vchar_script_table, ch1);
          while (1)
            {
-             int temp_byte;
-
              if (from == beg)
                break;
-             temp_byte = dec_bytepos (from_byte);
+             DEC_BOTH (from, from_byte);
              UPDATE_SYNTAX_TABLE_BACKWARD (from);
-             ch0 = FETCH_CHAR_AS_MULTIBYTE (temp_byte);
+             ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
              code = SYNTAX (ch0);
              if ((code != Sword
                   && (! words_include_escapes
                       || (code != Sescape && code != Scharquote)))
                  || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch0), script))
-               break;
-             DEC_BOTH (from, from_byte);
+               {
+                 INC_BOTH (from, from_byte);
+                 break;
+               }
              ch1 = ch0;
            }
        }
@@ -1318,7 +1322,7 @@ scan_words (from, count)
   return from;
 }
 
-DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "p",
+DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "^p",
        doc: /* Move point forward ARG words (backward if ARG is negative).
 Normally returns t.
 If an edge of the buffer or a field boundary is reached, point is left there
@@ -1476,7 +1480,7 @@ skip_chars (forwardp, string, lim, handle_iso_classes)
              const unsigned char *class_beg = str + i_byte + 1;
              const unsigned char *class_end = class_beg;
              const unsigned char *class_limit = str + size_byte - 2;
-             /* Leave room for the null.        */
+             /* Leave room for the null.  */
              unsigned char class_name[CHAR_CLASS_MAX_LENGTH + 1];
              re_wctype_t cc;
 
@@ -2025,13 +2029,13 @@ skip_syntaxes (forwardp, string, lim)
                    p = GPT_ADDR;
                    stop = endp;
                  }
+               UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
                prev_p = p;
                while (--p >= stop && ! CHAR_HEAD_P (*p));
                c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
                if (! fastmap[(int) SYNTAX (c)])
                  break;
                pos--, pos_byte -= prev_p - p;
-               UPDATE_SYNTAX_TABLE_BACKWARD (pos);
              }
          }
        else
@@ -2045,10 +2049,10 @@ skip_syntaxes (forwardp, string, lim)
                    p = GPT_ADDR;
                    stop = endp;
                  }
+               UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
                if (! fastmap[(int) SYNTAX (p[-1])])
                  break;
                p--, pos--, pos_byte--;
-               UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
              }
          }
       }
@@ -2111,9 +2115,10 @@ in_classes (c, iso_classes)
 static int
 forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
              charpos_ptr, bytepos_ptr, incomment_ptr)
-     int from, from_byte, stop;
+     EMACS_INT from, from_byte, stop;
      int nesting, style, prev_syntax;
-     int *charpos_ptr, *bytepos_ptr, *incomment_ptr;
+     EMACS_INT *charpos_ptr, *bytepos_ptr;
+     int *incomment_ptr;
 {
   register int c, c1;
   register enum syntaxcode code;
@@ -2213,16 +2218,16 @@ between them, return t; otherwise return nil.  */)
      (count)
      Lisp_Object count;
 {
-  register int from;
-  int from_byte;
-  register int stop;
+  register EMACS_INT from;
+  EMACS_INT from_byte;
+  register EMACS_INT stop;
   register int c, c1;
   register enum syntaxcode code;
   int comstyle = 0;        /* style of comment encountered */
   int comnested = 0;       /* whether the comment is nestable or not */
   int found;
-  int count1;
-  int out_charpos, out_bytepos;
+  EMACS_INT count1;
+  EMACS_INT out_charpos, out_bytepos;
   int dummy;
 
   CHECK_NUMBER (count);
@@ -2344,8 +2349,6 @@ between them, return t; otherwise return nil.  */)
              while (1)
                {
                  DEC_BOTH (from, from_byte);
-                 if (from == stop)
-                   break;
                  UPDATE_SYNTAX_TABLE_BACKWARD (from);
                  c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
                  if (SYNTAX (c) == Scomment_fence
@@ -2354,6 +2357,8 @@ between them, return t; otherwise return nil.  */)
                      found = 1;
                      break;
                    }
+                 else if (from == stop)
+                   break;
                }
              if (found == 0)
                {
@@ -2361,6 +2366,9 @@ between them, return t; otherwise return nil.  */)
                  from_byte = ini_byte;
                  goto leave;
                }
+             else
+               /* We have skipped one comment.  */
+               break;
            }
          else if (code == Sendcomment)
            {
@@ -2417,11 +2425,12 @@ between them, return t; otherwise return nil.  */)
 
 static Lisp_Object
 scan_lists (from, count, depth, sexpflag)
-     register int from;
-     int count, depth, sexpflag;
+     register EMACS_INT from;
+     EMACS_INT count, depth;
+     int sexpflag;
 {
   Lisp_Object val;
-  register int stop = count > 0 ? ZV : BEGV;
+  register EMACS_INT stop = count > 0 ? ZV : BEGV;
   register int c, c1;
   int stringterm;
   int quoted;
@@ -2430,11 +2439,11 @@ scan_lists (from, count, depth, sexpflag)
   int min_depth = depth;    /* Err out if depth gets less than this.  */
   int comstyle = 0;        /* style of comment encountered */
   int comnested = 0;       /* whether the comment is nestable or not */
-  int temp_pos;
-  int last_good = from;
+  EMACS_INT temp_pos;
+  EMACS_INT last_good = from;
   int found;
-  int from_byte;
-  int out_bytepos, out_charpos;
+  EMACS_INT from_byte;
+  EMACS_INT out_bytepos, out_charpos;
   int temp, dummy;
   int multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol;
 
@@ -2490,7 +2499,8 @@ scan_lists (from, count, depth, sexpflag)
            {
            case Sescape:
            case Scharquote:
-             if (from == stop) goto lose;
+             if (from == stop)
+               goto lose;
              INC_BOTH (from, from_byte);
              /* treat following character as a word constituent */
            case Sword:
@@ -2509,7 +2519,8 @@ scan_lists (from, count, depth, sexpflag)
                    case Scharquote:
                    case Sescape:
                      INC_BOTH (from, from_byte);
-                     if (from == stop) goto lose;
+                     if (from == stop)
+                       goto lose;
                      break;
                    case Sword:
                    case Ssymbol:
@@ -2564,10 +2575,9 @@ scan_lists (from, count, depth, sexpflag)
            close1:
              if (!--depth) goto done;
              if (depth < min_depth)
-               Fsignal (Qscan_error,
-                        Fcons (build_string ("Containing expression ends prematurely"),
-                               Fcons (make_number (last_good),
-                                      Fcons (make_number (from), Qnil))));
+               xsignal3 (Qscan_error,
+                         build_string ("Containing expression ends prematurely"),
+                         make_number (last_good), make_number (from));
              break;
 
            case Sstring:
@@ -2576,7 +2586,8 @@ scan_lists (from, count, depth, sexpflag)
              stringterm = FETCH_CHAR_AS_MULTIBYTE (temp_pos);
              while (1)
                {
-                 if (from >= stop) goto lose;
+                 if (from >= stop)
+                   goto lose;
                  UPDATE_SYNTAX_TABLE_FORWARD (from);
                  c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
                  if (code == Sstring
@@ -2605,7 +2616,8 @@ scan_lists (from, count, depth, sexpflag)
        }
 
       /* Reached end of buffer.  Error if within object, return nil if between */
-      if (depth) goto lose;
+      if (depth)
+       goto lose;
 
       immediate_quit = 0;
       return Qnil;
@@ -2716,10 +2728,9 @@ scan_lists (from, count, depth, sexpflag)
            open2:
              if (!--depth) goto done2;
              if (depth < min_depth)
-               Fsignal (Qscan_error,
-                        Fcons (build_string ("Containing expression ends prematurely"),
-                               Fcons (make_number (last_good),
-                                      Fcons (make_number (from), Qnil))));
+               xsignal3 (Qscan_error,
+                         build_string ("Containing expression ends prematurely"),
+                         make_number (last_good), make_number (from));
              break;
 
            case Sendcomment:
@@ -2741,7 +2752,8 @@ scan_lists (from, count, depth, sexpflag)
            case Sstring_fence:
              while (1)
                {
-                 if (from == stop) goto lose;
+                 if (from == stop)
+                   goto lose;
                  DEC_BOTH (from, from_byte);
                  UPDATE_SYNTAX_TABLE_BACKWARD (from);
                  if (!char_quoted (from, from_byte)
@@ -2756,7 +2768,8 @@ scan_lists (from, count, depth, sexpflag)
              stringterm = FETCH_CHAR_AS_MULTIBYTE (from_byte);
              while (1)
                {
-                 if (from == stop) goto lose;
+                 if (from == stop)
+                   goto lose;
                  DEC_BOTH (from, from_byte);
                  UPDATE_SYNTAX_TABLE_BACKWARD (from);
                  if (!char_quoted (from, from_byte)
@@ -2774,7 +2787,8 @@ scan_lists (from, count, depth, sexpflag)
        }
 
       /* Reached start of buffer.  Error if within object, return nil if between */
-      if (depth) goto lose;
+      if (depth)
+       goto lose;
 
       immediate_quit = 0;
       return Qnil;
@@ -2789,12 +2803,9 @@ scan_lists (from, count, depth, sexpflag)
   return val;
 
  lose:
-  Fsignal (Qscan_error,
-          Fcons (build_string ("Unbalanced parentheses"),
-                 Fcons (make_number (last_good),
-                        Fcons (make_number (from), Qnil))));
-  abort ();
-  /* NOTREACHED */
+  xsignal3 (Qscan_error,
+           build_string ("Unbalanced parentheses"),
+           make_number (last_good), make_number (from));
 }
 
 DEFUN ("scan-lists", Fscan_lists, Sscan_lists, 3, 3, 0,
@@ -2921,7 +2932,7 @@ scan_sexps_forward (stateptr, from, from_byte, end, targetdepth,
   int boundary_stop = commentstop == -1;
   int nofence;
   int found;
-  int out_bytepos, out_charpos;
+  EMACS_INT out_bytepos, out_charpos;
   int temp;
 
   prev_from = from;
@@ -3244,7 +3255,7 @@ Parsing stops at TO or when certain criteria are met;
  point is set to where parsing stops.
 If fifth arg OLDSTATE is omitted or nil,
  parsing assumes that FROM is the beginning of a function.
-Value is a list of ten elements describing final state of parsing:
+Value is a list of elements describing final state of parsing:
  0. depth in parens.
  1. character address of start of innermost containing list; nil if none.
  2. character address of start of last complete sexp terminated.
@@ -3263,9 +3274,9 @@ If third arg TARGETDEPTH is non-nil, parsing stops if the depth
 in parentheses becomes equal to TARGETDEPTH.
 Fourth arg STOPBEFORE non-nil means stop when come to
  any character that starts a sexp.
-Fifth arg OLDSTATE is a nine-element list like what this function returns.
+Fifth arg OLDSTATE is a list like what this function returns.
  It is used to initialize the state of the parse.  Elements number 1, 2, 6
- and 8 are ignored; you can leave off element 8 (the last) entirely.
+ and 8 are ignored.
 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
  If it is symbol `syntax-table', stop after the start of a comment or a
  string, or after end of a comment or a string.  */)
@@ -3343,6 +3354,20 @@ init_syntax_once ()
 
   Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp);
 
+  /* Control characters should not be whitespace.  */
+  temp = XVECTOR (Vsyntax_code_object)->contents[(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];
+  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];
   for (i = 'a'; i <= 'z'; i++)
     SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);