]> code.delx.au - gnu-emacs/blobdiff - src/syntax.c
Minor alignas cleanup
[gnu-emacs] / src / syntax.c
index de45c50ca3f8a85e85da43ae1ea05772ef051bb9..8b5cc1df4075e767f2961d5eae4b0afb2c4fd831 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
-   Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2015 Free
+   Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2016 Free
    Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -23,12 +23,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/types.h>
 
 #include "lisp.h"
-#include "commands.h"
 #include "character.h"
 #include "buffer.h"
-#include "keymap.h"
 #include "regex.h"
-
 #include "syntax.h"
 #include "intervals.h"
 #include "category.h"
@@ -499,6 +496,14 @@ parse_sexp_propertize (ptrdiff_t charpos)
       gl_state.e_property = syntax_propertize__done;
       gl_state.e_property_truncated = true;
     }
+  else if (gl_state.e_property_truncated
+          && gl_state.e_property < syntax_propertize__done)
+    { /* When moving backward, e_property might be set without resetting
+        e_property_truncated, so the e_property_truncated flag may
+        occasionally be left raised spuriously.  This should be rare.  */
+      gl_state.e_property_truncated = false;
+      update_syntax_table_forward (charpos, false, Qnil);
+    }
 }
 
 void
@@ -509,14 +514,12 @@ update_syntax_table_forward (ptrdiff_t charpos, bool init,
     {
       eassert (NILP (object));
       eassert (charpos >= gl_state.e_property);
-      eassert (charpos >= syntax_propertize__done);
       parse_sexp_propertize (charpos);
     }
   else
     {
       update_syntax_table (charpos, 1, init, object);
-      if (gl_state.e_property > syntax_propertize__done
-         && NILP (object))
+      if (NILP (object) && gl_state.e_property > syntax_propertize__done)
        parse_sexp_propertize (charpos);
     }
 }
@@ -787,8 +790,10 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
                   || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested))
        continue;
 
-      /* Ignore escaped characters, except comment-enders.  */
-      if (code != Sendcomment && char_quoted (from, from_byte))
+      /* Ignore escaped characters, except comment-enders which cannot
+         be escaped.  */
+      if ((Vcomment_end_can_be_escaped || code != Sendcomment)
+          && char_quoted (from, from_byte))
        continue;
 
       switch (code)
@@ -1098,7 +1103,7 @@ DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0,
        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
+cons cell (CODE . MATCHING-CHAR) which can be used, for example, as
 the value of a `syntax-table' text property.  */)
   (Lisp_Object string)
 {
@@ -2343,7 +2348,8 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
       if (code == Sendcomment
          && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style
          && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
-             (nesting > 0 && --nesting == 0) : nesting < 0))
+             (nesting > 0 && --nesting == 0) : nesting < 0)
+          && !(Vcomment_end_can_be_escaped && char_quoted (from, from_byte)))
        /* We have encountered a comment end of the same style
           as the comment sequence which began this comment
           section.  */
@@ -2799,12 +2805,8 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
                      : c_code == Sstring_fence)
                    break;
 
-                 switch (c_code)
-                   {
-                   case Scharquote:
-                   case Sescape:
-                     INC_BOTH (from, from_byte);
-                   }
+                 if (c_code == Scharquote || c_code == Sescape)
+                   INC_BOTH (from, from_byte);
                  INC_BOTH (from, from_byte);
                }
              INC_BOTH (from, from_byte);
@@ -3419,11 +3421,16 @@ do { prev_from = from;                          \
                  case Sstring_fence:
                    if (!nofence) goto string_end;
                    break;
+
                  case Scharquote:
                  case Sescape:
                    INC_FROM;
                  startquotedinstring:
                    if (from >= end) goto endquoted;
+                   break;
+
+                 default:
+                   break;
                  }
                INC_FROM;
              }
@@ -3664,6 +3671,7 @@ See the info node `(elisp)Syntax Properties' for a description of the
              doc: /* Position up to which syntax-table properties have been set.  */);
   syntax_propertize__done = -1;
   DEFSYM (Qinternal__syntax_propertize, "internal--syntax-propertize");
+  Fmake_variable_buffer_local (intern ("syntax-propertize--done"));
 
   words_include_escapes = 0;
   DEFVAR_BOOL ("words-include-escapes", words_include_escapes,
@@ -3687,16 +3695,22 @@ Each function is called with two arguments; POS and LIMIT.
 POS and LIMIT are character positions in the current buffer.
 
 If POS is less than LIMIT, POS is at the first character of a word,
-and the return value of a function is a position after the last
-character of that word.
+and the return value of a function should be a position after the
+last character of that word.
 
 If POS is not less than LIMIT, POS is at the last character of a word,
-and the return value of a function is a position at the first
+and the return value of a function should be a position at the first
 character of that word.
 
 In both cases, LIMIT bounds the search. */);
   Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil);
 
+  DEFVAR_BOOL ("comment-end-can-be-escaped", Vcomment_end_can_be_escaped,
+               doc: /* Non-nil means an escaped ender inside a comment doesn'tend the comment.  */);
+  Vcomment_end_can_be_escaped = 0;
+  DEFSYM (Qcomment_end_can_be_escaped, "comment-end-can-be-escaped");
+  Fmake_variable_buffer_local (Qcomment_end_can_be_escaped);
+
   defsubr (&Ssyntax_table_p);
   defsubr (&Ssyntax_table);
   defsubr (&Sstandard_syntax_table);