* callproc.c (strerror): Remove decl.
[bpt/emacs.git] / src / syntax.c
index 82fabc2..d08c29b 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
-   Copyright (C) 1985, 87, 93, 94, 95, 97, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1985, 87, 93, 94, 95, 97, 1998, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -25,7 +25,6 @@ Boston, MA 02111-1307, USA.  */
 #include "commands.h"
 #include "buffer.h"
 #include "charset.h"
-#include <assert.h>
 
 /* Make syntax table lookup grant data in gl_state.  */
 #define SYNTAX_ENTRY_VIA_PROPERTY
@@ -120,7 +119,7 @@ update_syntax_table (charpos, count, init, object)
      Lisp_Object object;
 {
   Lisp_Object tmp_table;
-  int cnt = 0, doing_extra = 0, invalidate = 1;
+  int cnt = 0, invalidate = 1;
   INTERVAL i, oldi;
 
   if (init)
@@ -345,8 +344,6 @@ static int
 find_defun_start (pos, pos_byte)
      int pos, pos_byte;
 {
-  int tem;
-  int shortage;
   int opoint = PT, opoint_byte = PT_BYTE;
 
   /* Use previous finding, if it's valid and applies to this inquiry.  */
@@ -480,7 +477,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
      that determines quote parity to the comment-end.  */
   while (from != stop)
     {
-      int temp_byte, prev_comend_second;
+      int temp_byte;
 
       /* Move back and examine a character.  */
       DEC_BOTH (from, from_byte);
@@ -565,10 +562,12 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
         (because they go with the earlier comment-ender).  */
       if (code == Sendcomment
          && SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)) == comstyle)
-       if (comnested)
-         nesting++;
-       else
-         break;
+       {
+         if (comnested)
+           nesting++;
+         else
+           break;
+       }
 
       /* Assume a defun-start point is outside of strings.  */
       if (code == Sopen
@@ -955,7 +954,7 @@ describe_syntax (value)
     Lisp_Object value;
 {
   register enum syntaxcode code;
-  char desc, match, start1, start2, end1, end2, prefix, comstyle;
+  char desc, start1, start2, end1, end2, prefix, comstyle;
   char str[2];
   Lisp_Object first, match_lisp;
 
@@ -979,8 +978,8 @@ describe_syntax (value)
       return;
     }
 
-  first = XCONS (value)->car;
-  match_lisp = XCONS (value)->cdr;
+  first = XCAR (value);
+  match_lisp = XCDR (value);
 
   if (!INTEGERP (first) || !(NILP (match_lisp) || INTEGERP (match_lisp)))
     {
@@ -1222,32 +1221,24 @@ scan_words (from, count)
 DEFUN ("forward-word", Fforward_word, Sforward_word, 1, 1, "p",
   "Move point forward ARG words (backward if ARG is negative).\n\
 Normally returns t.\n\
-If an edge of the buffer is reached, point is left there\n\
-and nil is returned.")
+If an edge of the buffer or a field boundary is reached, point is left there\n\
+and the function returns nil.")
   (count)
      Lisp_Object count;
 {
-  int val;
+  int orig_val, val;
   CHECK_NUMBER (count, 0);
 
-  if (!(val = scan_words (PT, XINT (count))))
-    {
-      SET_PT (XINT (count) > 0 ? ZV : BEGV);
-      return Qnil;
-    }
+  val = orig_val = scan_words (PT, XINT (count));
+  if (! orig_val)
+    val = XINT (count) > 0 ? ZV : BEGV;
+
+  /* Avoid jumping out of an input field.  */
+  val = XFASTINT (Fconstrain_to_field (make_number (val), make_number (PT),
+                                      Qt, Qnil));
 
-  /* If in a mini-buffer and moving backwards, stop in front of the
-     prompt if we are currently in front of it.  This prevents
-     accidentially moving into the read-only prompt.  */
-  if (INTEGERP (current_buffer->minibuffer_prompt_length))
-    {
-      int prompt_end = XFASTINT (current_buffer->minibuffer_prompt_length);
-      if (PT > prompt_end && val < prompt_end)
-       val = prompt_end;
-    }
-  
   SET_PT (val);
-  return Qt;
+  return (val == orig_val ? Qt : Qnil);
 }
 \f
 Lisp_Object skip_chars ();
@@ -1305,7 +1296,6 @@ skip_chars (forwardp, syntaxp, string, lim)
      int forwardp, syntaxp;
      Lisp_Object string, lim;
 {
-  register unsigned char *p, *pend;
   register unsigned int c;
   register int ch;
   unsigned char fastmap[0400];
@@ -1706,16 +1696,18 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
          && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
          && (c1 = FETCH_CHAR (from_byte),
              SYNTAX_COMEND_SECOND (c1)))
-       if (--nesting <= 0)
-         /* we have encountered a comment end of the same style
-            as the comment sequence which began this comment
-            section */
-         break;
-       else
-         {
-           INC_BOTH (from, from_byte);
-           UPDATE_SYNTAX_TABLE_FORWARD (from);
-         }
+       {
+         if (--nesting <= 0)
+           /* we have encountered a comment end of the same style
+              as the comment sequence which began this comment
+              section */
+           break;
+         else
+           {
+             INC_BOTH (from, from_byte);
+             UPDATE_SYNTAX_TABLE_FORWARD (from);
+           }
+       }
       if (nesting > 0
          && from < stop
          && SYNTAX_FLAGS_COMSTART_FIRST (syntax)
@@ -2463,14 +2455,14 @@ do { prev_from = from;                          \
       oldstate = Fcdr (oldstate);
       tem = Fcar (oldstate);
       /* Check whether we are inside string_fence-style string: */
-      state.instring = ( !NILP (tem) 
-                        ? ( INTEGERP (tem) ? XINT (tem) : ST_STRING_STYLE) 
-                        : -1);
+      state.instring = (!NILP (tem) 
+                       ? (INTEGERP (tem) ? XINT (tem) : ST_STRING_STYLE) 
+                       : -1);
 
       oldstate = Fcdr (oldstate);
       tem = Fcar (oldstate);
-      state.incomment = ( !NILP (tem)
-                        ? ( INTEGERP (tem) ? XINT (tem) : -1)
+      state.incomment = (!NILP (tem)
+                        ? (INTEGERP (tem) ? XINT (tem) : -1)
                         : 0);
 
       oldstate = Fcdr (oldstate);
@@ -2482,8 +2474,8 @@ do { prev_from = from;                            \
       oldstate = Fcdr (oldstate);
       oldstate = Fcdr (oldstate);
       tem = Fcar (oldstate);
-      state.comstyle = NILP (tem) ? 0 : ( EQ (tem, Qsyntax_table) 
-                                         ? ST_COMMENT_STYLE : 1 );
+      state.comstyle = NILP (tem) ? 0 : (EQ (tem, Qsyntax_table) 
+                                        ? ST_COMMENT_STYLE : 1);
 
       oldstate = Fcdr (oldstate);
       tem = Fcar (oldstate);
@@ -2619,7 +2611,8 @@ do { prev_from = from;                            \
          goto commentloop;
 
        case Scomment:
-         assert (state.incomment != 0); /* state.incomment = -1; */
+         if (! state.incomment)
+           abort ();
          if (commentstop || boundary_stop) goto done;
        commentloop:
          /* The (from == BEGV) test is to enter the loop in the middle so