Fix -Wimplicit warnings.
[bpt/emacs.git] / src / syntax.c
index 68ef328..c39e2c2 100644 (file)
@@ -130,8 +130,23 @@ update_syntax_table (charpos, count, init, object)
       invalidate = 0;
       if (NULL_INTERVAL_P (i))
        return;
-      gl_state.b_property = i->position - 1;
-      gl_state.e_property = INTERVAL_LAST_POS (i);
+      /* interval_of () updates only ->position of the return value,
+        update the parents manually to speed up update_interval.  */
+      while (!NULL_PARENT (i)) 
+       {
+         if (AM_RIGHT_CHILD (i))
+           i->parent->position = i->position
+             - LEFT_TOTAL_LENGTH (i) + TOTAL_LENGTH (i) /* right end */
+             - TOTAL_LENGTH (i->parent)
+             + LEFT_TOTAL_LENGTH (i->parent);
+         else
+           i->parent->position = i->position - LEFT_TOTAL_LENGTH (i)
+             + TOTAL_LENGTH (i);
+         i = i->parent;
+       }
+      i = gl_state.forward_i;
+      gl_state.b_property = i->position - 1 - gl_state.offset;
+      gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
       goto update;
     }
   oldi = i = count > 0 ? gl_state.forward_i : gl_state.backward_i;
@@ -151,7 +166,7 @@ update_syntax_table (charpos, count, init, object)
          invalidate = 0;
          gl_state.right_ok = 1;        /* Invalidate the other end.  */
          gl_state.forward_i = i;
-         gl_state.e_property = INTERVAL_LAST_POS (i);
+         gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
        }
     } 
   else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right.  */
@@ -165,7 +180,7 @@ update_syntax_table (charpos, count, init, object)
          invalidate = 0;
          gl_state.left_ok = 1;         /* Invalidate the other end.  */
          gl_state.backward_i = i;
-         gl_state.b_property = i->position - 1;
+         gl_state.b_property = i->position - 1 - gl_state.offset;
        }
     }
   else if (count > 0 ? gl_state.right_ok : gl_state.left_ok)
@@ -187,13 +202,13 @@ update_syntax_table (charpos, count, init, object)
        {
          gl_state.backward_i = i;
          gl_state.left_ok = 1;         /* Invalidate the other end.  */
-         gl_state.b_property = i->position - 1;
+         gl_state.b_property = i->position - 1 - gl_state.offset;
        } 
       else 
        {
          gl_state.forward_i = i;       
          gl_state.right_ok = 1;        /* Invalidate the other end.  */
-         gl_state.e_property = INTERVAL_LAST_POS (i);
+         gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
        }
     }
 
@@ -246,12 +261,12 @@ update_syntax_table (charpos, count, init, object)
     {
       if (count > 0) 
        {
-         gl_state.e_property = i->position;
+         gl_state.e_property = i->position - gl_state.offset;
          gl_state.forward_i = i;
        }
       else 
        {
-         gl_state.b_property = i->position + LENGTH (i) - 1;
+         gl_state.b_property = i->position + LENGTH (i) - 1 - gl_state.offset;
          gl_state.backward_i = i;
        }
     }    
@@ -1050,6 +1065,7 @@ int parse_sexp_ignore_comments;
    If that many words cannot be found before the end of the buffer, return 0.
    COUNT negative means scan backward and stop at word beginning.  */
 
+int
 scan_words (from, count)
      register int from, count;
 {
@@ -1370,15 +1386,17 @@ skip_chars (forwardp, syntaxp, string, lim)
          {
            if (multibyte)
              {
-               while (pos < XINT (lim)
-                      && fastmap[(int) SYNTAX (FETCH_CHAR (pos_byte))])
-                 {
-                   /* Since we already checked for multibyteness,
-                      avoid using INC_BOTH which checks again.  */
-                   INC_POS (pos_byte);
-                   pos++;
-                   UPDATE_SYNTAX_TABLE_FORWARD (pos);
-                 }
+               if (pos < XINT (lim))
+                 while (fastmap[(int) SYNTAX (FETCH_CHAR (pos_byte))])
+                   {
+                     /* Since we already checked for multibyteness,
+                        avoid using INC_BOTH which checks again.  */
+                     INC_POS (pos_byte);
+                     pos++;
+                     if (pos >= XINT (lim))
+                       break;
+                     UPDATE_SYNTAX_TABLE_FORWARD (pos);
+                   }
              }
            else
              {
@@ -1412,16 +1430,14 @@ skip_chars (forwardp, syntaxp, string, lim)
              }
            else
              {
-               while (pos > XINT (lim))
-                 {
-                   pos--;
-                   UPDATE_SYNTAX_TABLE_BACKWARD (pos);
-                   if (!fastmap[(int) SYNTAX (FETCH_BYTE (pos))])
-                     {
-                       pos++;
+               if (pos > XINT (lim))
+                 while (fastmap[(int) SYNTAX (FETCH_BYTE (pos - 1))])
+                   {
+                     pos--;
+                     if (pos <= XINT (lim))
                        break;
-                     }
-                 }
+                     UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
+                   }
              }
          }
       }
@@ -2159,12 +2175,16 @@ This includes chars with \"quote\" or \"prefix\" syntax (' or p).")
 
   DEC_BOTH (pos, pos_byte);
 
-  while (pos + 1 > beg && !char_quoted (pos, pos_byte)
+  while (!char_quoted (pos, pos_byte)
         /* Previous statement updates syntax table.  */
         && ((c = FETCH_CHAR (pos_byte), SYNTAX (c) == Squote)
             || SYNTAX_PREFIX (c)))
     {
-      DEC_BOTH (pos, pos_byte);
+      opoint = pos;
+      opoint_byte = pos_byte;
+
+      if (pos + 1 > beg)
+       DEC_BOTH (pos, pos_byte);
     }
 
   SET_PT_BOTH (opoint, opoint_byte);
@@ -2205,6 +2225,7 @@ scan_sexps_forward (stateptr, from, from_byte, end, targetdepth,
   Lisp_Object tem;
   int prev_from;               /* Keep one character before FROM.  */
   int prev_from_byte;
+  int prev_from_syntax;
   int boundary_stop = commentstop == -1;
   int nofence;
 
@@ -2217,14 +2238,15 @@ scan_sexps_forward (stateptr, from, from_byte, end, targetdepth,
 #define INC_FROM                               \
 do { prev_from = from;                         \
      prev_from_byte = from_byte;               \
+     prev_from_syntax                          \
+       = SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte)); \
      INC_BOTH (from, from_byte);               \
+     UPDATE_SYNTAX_TABLE_FORWARD (from);       \
   } while (0)
 
   immediate_quit = 1;
   QUIT;
 
-  SETUP_SYNTAX_TABLE (from, 1);
-
   if (NILP (oldstate))
     {
       depth = 0;
@@ -2287,11 +2309,15 @@ do { prev_from = from;                          \
     }
   if (start_quoted) goto startquoted;
 
+
+  SETUP_SYNTAX_TABLE (prev_from, 1);
+  prev_from_syntax = SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte));
+  UPDATE_SYNTAX_TABLE_FORWARD (from);
+
   while (from < end)
     {
-      UPDATE_SYNTAX_TABLE_FORWARD (from);
-      code = SYNTAX (FETCH_CHAR (from_byte));
       INC_FROM;
+      code = prev_from_syntax & 0xff;
 
       if (code == Scomment)
        state.comstr_start = prev_from;
@@ -2304,13 +2330,14 @@ do { prev_from = from;                          \
                             ? ST_COMMENT_STYLE 
                             : SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)));
          state.comstr_start = prev_from;
-         if (code != Scomment_fence) INC_FROM;
+         if (code != Scomment_fence)
+           INC_FROM;
          code = Scomment;
        }
      else if (from < end)
-       if (SYNTAX_COMSTART_FIRST (FETCH_CHAR (prev_from_byte)))
+       if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax))
          if (SYNTAX_COMSTART_SECOND (FETCH_CHAR (from_byte)))
-           /* Duplicate code to avoid a very complex if-expression
+           /* Duplicate code to avoid a complex if-expression
               which causes trouble for the SGI compiler.  */
            {
              /* Record the comment style we have entered so that only
@@ -2320,11 +2347,12 @@ do { prev_from = from;                          \
                                 ? ST_COMMENT_STYLE 
                                 : SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)));
              state.comstr_start = prev_from;
-             if (code != Scomment_fence) INC_FROM;
+             if (code != Scomment_fence)
+               INC_FROM;
              code = Scomment;
            }
 
-      if (SYNTAX_PREFIX (FETCH_CHAR (prev_from_byte)))
+      if (SYNTAX_FLAGS_PREFIX (prev_from_syntax))
        continue;
       switch (SWITCH_ENUM_CAST (code))
        {
@@ -2344,7 +2372,6 @@ do { prev_from = from;                            \
        symstarted:
          while (from < end)
            {
-             UPDATE_SYNTAX_TABLE_FORWARD (from);
              switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte))))
                {
                case Scharquote:
@@ -2372,7 +2399,6 @@ do { prev_from = from;                            \
            {
              /* Enter the loop in the middle so that we find
                 a 2-char comment ender if we start in the middle of it.  */
-             prev = FETCH_CHAR (prev_from_byte);
              goto startincomment_1;
            }
          /* At beginning of buffer, enter the loop the ordinary way.  */
@@ -2386,7 +2412,6 @@ do { prev_from = from;                            \
          while (1)
            {
              if (from == end) goto done;
-             UPDATE_SYNTAX_TABLE_FORWARD (from);
              prev = FETCH_CHAR (from_byte);
              if (SYNTAX (prev) == Sendcomment
                  && SYNTAX_COMMENT_STYLE (prev) == state.comstyle)
@@ -2399,9 +2424,10 @@ do { prev_from = from;                           \
                break;
              INC_FROM;
            startincomment_1:
-             if (from < end && SYNTAX_COMEND_FIRST (prev)
+             if (from < end && SYNTAX_FLAGS_COMEND_FIRST (prev_from_syntax)
                  && SYNTAX_COMEND_SECOND (FETCH_CHAR (from_byte))
-                 && SYNTAX_COMMENT_STYLE (prev) == state.comstyle)
+                 && (SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax)
+                     == state.comstyle))
                /* Only terminate the comment section if the end-comment
                   sequence of the same style as the start sequence has
                   been encountered.  */
@@ -2455,7 +2481,6 @@ do { prev_from = from;                            \
                if (from >= end) goto done;
                c = FETCH_CHAR (from_byte);
                if (nofence && c == state.instring) break;
-               UPDATE_SYNTAX_TABLE_FORWARD (from);
                switch (SWITCH_ENUM_CAST (SYNTAX (c)))
                  {
                  case Sstring_fence:
@@ -2581,6 +2606,7 @@ DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 6, 0,
                                     Qnil)))))))));
 }
 \f
+void
 init_syntax_once ()
 {
   register int i, c;
@@ -2652,6 +2678,7 @@ init_syntax_once ()
     }
 }
 
+void
 syms_of_syntax ()
 {
   Qsyntax_table_p = intern ("syntax-table-p");