Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / emacs-lisp / syntax.el
index 619fa18..b1a4664 100644 (file)
@@ -1,17 +1,17 @@
 ;;; syntax.el --- helper functions to find syntactic context
 
 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: internal
 
 ;; 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
@@ -19,9 +19,7 @@
 ;; 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/>.
 
 ;;; Commentary:
 
 
 (defun syntax-ppss-toplevel-pos (ppss)
   "Get the latest syntactically outermost position found in a syntactic scan.
-PPSS is a scan state, as returned by `partial-parse-sexp' or `syntax-ppss'.
+PPSS is a scan state, as returned by `parse-partial-sexp' or `syntax-ppss'.
 An \"outermost position\" means one that it is outside of any syntactic entity:
 outside of any parentheses, comments, or strings encountered in the scan.
 If no such position is recorded in PPSS (because the end of the scan was
 itself at the outermost level), return nil."
+  ;; BEWARE! We rely on the undocumented 9th field.  The 9th field currently
+  ;; contains the list of positions of the enclosing open-parens.
+  ;; I.e. those positions are outside of any string/comment and the first of
+  ;; those is outside of any paren (i.e. corresponds to a nil ppss).
+  ;; If this list is empty but we are in a string or comment, then the 8th
+  ;; field contains a similar "toplevel" position.
   (or (car (nth 9 ppss))
-      (nth 8 ppss)))      
+      (nth 8 ppss)))
 
 (defsubst syntax-ppss-context (ppss)
   (cond
@@ -97,8 +101,7 @@ point (where the PPSS is equivalent to nil).")
     ;; depend on the text after BEG (which is presumably changed).  So if
     ;; BEG=(car (nth 10 syntax-ppss-last)) don't reuse that data because the
     ;; assumed nil state at BEG may not be valid any more.
-    (if (<= beg (or (car (nth 10 syntax-ppss-last))
-                    (nth 9 syntax-ppss-last)
+    (if (<= beg (or (syntax-ppss-toplevel-pos (cdr syntax-ppss-last))
                     (nth 3 syntax-ppss-last)
                     0))
        (setq syntax-ppss-last nil)
@@ -119,7 +122,7 @@ point (where the PPSS is equivalent to nil).")
          syntax-ppss-stats))
 
 (defun syntax-ppss (&optional pos)
-  "Parse-Partial-Sexp State at POS.
+  "Parse-Partial-Sexp State at POS, defaulting to point.
 The returned value is the same as `parse-partial-sexp' except that
 the 2nd and 6th values of the returned state cannot be relied upon.
 Point is at POS when this function returns."
@@ -146,22 +149,14 @@ Point is at POS when this function returns."
          (cond
           ;; Use OLD-PPSS if possible and close enough.
           ((and (not old-pos) old-ppss
-                ;; BEWARE! We rely on the undocumented 9th field.  The 9th
-                ;; field currently contains the list of positions of
-                ;; open-parens of the enclosing parens.  I.e. those
-                ;; positions are outside of any string/comment
-                ;; and the first of those is outside of any paren
-                ;; (i.e. corresponds to a nil ppss).  If this list is empty
-                ;; but we are in a string or comment, then the 8th field
-                ;; contains a similar "toplevel" position.  If `pt-min' is
-                ;; too far from `pos', we could try to use other positions
-                ;; in (nth 9 old-ppss), but that doesn't seem to happen in
-                ;; practice and it would complicate this code (and the
-                ;; before-change-function code even more).  But maybe it
-                ;; would be useful in "degenerate" cases such as when the
-                ;; whole file is wrapped in a set of parenthesis.
-                (setq pt-min (or (car (nth 9 old-ppss))
-                                 (nth 8 old-ppss)
+                 ;; If `pt-min' is too far from `pos', we could try to use
+                ;; other positions in (nth 9 old-ppss), but that doesn't
+                ;; seem to happen in practice and it would complicate this
+                ;; code (and the before-change-function code even more).
+                ;; But maybe it would be useful in "degenerate" cases such
+                ;; as when the whole file is wrapped in a set
+                ;; of parentheses.
+                (setq pt-min (or (syntax-ppss-toplevel-pos old-ppss)
                                  (nth 2 old-ppss)))
                 (<= pt-min pos) (< (- pos pt-min) syntax-ppss-max-span))
            (incf (car (aref syntax-ppss-stats 1)))