45078
|
1 ;;; syntax.el --- helper functions to find syntactic context
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2
|
64751
|
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
|
|
4 ;; 2005 Free Software Foundation, Inc.
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5
|
45078
|
6 ;; Maintainer: FSF
|
|
7 ;; Keywords: internal
|
|
8
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 ;; any later version.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
64085
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
24 ;; Boston, MA 02110-1301, USA.
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 ;;; Commentary:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 ;; The main exported function is `syntax-ppss'. You might also need
|
51941
9bf93e387b5e
(syntax-ppss-flush-cache): Rename from syntax-ppss-after-change-function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
29 ;; to call `syntax-ppss-flush-cache' or to add it to
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;; after-change-functions'(although this is automatically done by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 ;; syntax-ppss when needed, but that might fail if syntax-ppss is
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;; called in a context where after-change-functions is temporarily
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 ;; let-bound to nil).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 ;;; Todo:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 ;; - do something about the case where the syntax-table is changed.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 ;; This typically happens with tex-mode and its `$' operator.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 ;; - move font-lock-syntactic-keywords in here. Then again, maybe not.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 ;; - new functions `syntax-state', ... to replace uses of parse-partial-state
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 ;; with something higher-level (similar to syntax-ppss-context).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 ;; - interaction with mmm-mode.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 ;;; Code:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 ;; Note: PPSS stands for `parse-partial-sexp state'
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (eval-when-compile (require 'cl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49
|
65194
|
50 (defvar font-lock-beginning-of-syntax-function)
|
|
51
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (defsubst syntax-ppss-depth (ppss)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (nth 0 ppss))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (defsubst syntax-ppss-context (ppss)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 ((nth 3 ppss) 'string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 ((nth 4 ppss) 'comment)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (t nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (defvar syntax-ppss-max-span 20000
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 "Threshold below which cache info is deemed unnecessary.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 We try to make sure that cache entries are at least this far apart
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 from each other, to avoid keeping too much useless info.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (defvar syntax-begin-function nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 "Function to move back outside of any comment/string/paren.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 This function should move the cursor back to some syntactically safe
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 point (where the PPSS is equivalent to nil).")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 (defvar syntax-ppss-cache nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 "List of (POS . PPSS) pairs, in decreasing POS order.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 (make-variable-buffer-local 'syntax-ppss-cache)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 (defvar syntax-ppss-last nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 "Cache of (LAST-POS . LAST-PPSS).")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (make-variable-buffer-local 'syntax-ppss-last)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77
|
51941
9bf93e387b5e
(syntax-ppss-flush-cache): Rename from syntax-ppss-after-change-function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
78 (defalias 'syntax-ppss-after-change-function 'syntax-ppss-flush-cache)
|
9bf93e387b5e
(syntax-ppss-flush-cache): Rename from syntax-ppss-after-change-function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
79 (defun syntax-ppss-flush-cache (beg &rest ignored)
|
9bf93e387b5e
(syntax-ppss-flush-cache): Rename from syntax-ppss-after-change-function.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
80 "Flush the cache of `syntax-ppss' starting at position BEG."
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 ;; Flush invalid cache entries.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 (while (and syntax-ppss-cache (> (caar syntax-ppss-cache) beg))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 (setq syntax-ppss-cache (cdr syntax-ppss-cache)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 ;; Throw away `last' value if made invalid.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 (when (< beg (or (car syntax-ppss-last) 0))
|
66266
|
86 ;; If syntax-begin-function jumped to BEG, then the old state at BEG can
|
|
87 ;; depend on the text after BEG (which is presumably changed). So if
|
|
88 ;; BEG=(car (nth 10 syntax-ppss-last)) don't reuse that data because the
|
|
89 ;; assumed nil state at BEG may not be valid any more.
|
|
90 (if (<= beg (or (car (nth 10 syntax-ppss-last))
|
|
91 (nth 9 syntax-ppss-last)
|
66267
|
92 (nth 3 syntax-ppss-last)
|
66266
|
93 0))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (setq syntax-ppss-last nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (setcar syntax-ppss-last nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 ;; Unregister if there's no cache left. Sadly this doesn't work
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 ;; because `after-change-functions' is temporarily bound to nil here.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 ;; (unless syntax-ppss-cache
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 ;; (remove-hook 'after-change-functions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 ;; 'syntax-ppss-after-change-function t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (defvar syntax-ppss-stats
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 [(0 . 0.0) (0 . 0.0) (0 . 0.0) (0 . 0.0) (0 . 0.0) (1 . 2500.0)])
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 (defun syntax-ppss-stats ()
|
40396
894b9bc4ca7a
(syntax-ppss-stats): Be more robust when dividing by 0.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
106 (mapcar (lambda (x)
|
894b9bc4ca7a
(syntax-ppss-stats): Be more robust when dividing by 0.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
107 (condition-case nil
|
894b9bc4ca7a
(syntax-ppss-stats): Be more robust when dividing by 0.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
108 (cons (car x) (truncate (/ (cdr x) (car x))))
|
894b9bc4ca7a
(syntax-ppss-stats): Be more robust when dividing by 0.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
109 (error nil)))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 syntax-ppss-stats))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (defun syntax-ppss (&optional pos)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 "Parse-Partial-Sexp State at POS.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 The returned value is the same as `parse-partial-sexp' except that
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 the 2nd and 6th values of the returned state cannot be relied upon.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 Point is at POS when this function returns."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 ;; Default values.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 (unless pos (setq pos (point)))
|
49598
|
119 ;;
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120 (let ((old-ppss (cdr syntax-ppss-last))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 (old-pos (car syntax-ppss-last))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 (ppss nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 (pt-min (point-min)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 (if (and old-pos (> old-pos pos)) (setq old-pos nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 ;; Use the OLD-POS if usable and close. Don't update the `last' cache.
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
126 (condition-case nil
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
127 (if (and old-pos (< (- pos old-pos)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
128 ;; The time to use syntax-begin-function and
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
129 ;; find PPSS is assumed to be about 2 * distance.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
130 (* 2 (/ (cdr (aref syntax-ppss-stats 5))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
131 (1+ (car (aref syntax-ppss-stats 5)))))))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
132 (progn
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
133 (incf (car (aref syntax-ppss-stats 0)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
134 (incf (cdr (aref syntax-ppss-stats 0)) (- pos old-pos))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
135 (parse-partial-sexp old-pos pos nil nil old-ppss))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 (cond
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
138 ;; Use OLD-PPSS if possible and close enough.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
139 ((and (not old-pos) old-ppss
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
140 ;; BEWARE! We rely on the undocumented 9th field. The 9th
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
141 ;; field currently contains the list of positions of
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
142 ;; open-parens of the enclosing parens. I.e. those
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
143 ;; positions are outside of any string/comment
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
144 ;; and the first of those is outside of any paren
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
145 ;; (i.e. corresponds to a nil ppss). If this list is empty
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
146 ;; but we are in a string or comment, then the 8th field
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
147 ;; contains a similar "toplevel" position. If `pt-min' is
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
148 ;; too far from `pos', we could try to use other positions
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
149 ;; in (nth 9 old-ppss), but that doesn't seem to happen in
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
150 ;; practice and it would complicate this code (and the
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
151 ;; after-change-function code even more). But maybe it
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
152 ;; would be useful in "degenerate" cases such as when the
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
153 ;; whole file is wrapped in a set of parenthesis.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
154 (setq pt-min (or (car (nth 9 old-ppss))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
155 (nth 8 old-ppss)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
156 (nth 2 old-ppss)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
157 (<= pt-min pos) (< (- pos pt-min) syntax-ppss-max-span))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
158 (incf (car (aref syntax-ppss-stats 1)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
159 (incf (cdr (aref syntax-ppss-stats 1)) (- pos pt-min))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
160 (setq ppss (parse-partial-sexp pt-min pos)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
161 ;; The OLD-* data can't be used. Consult the cache.
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 (t
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
163 (let ((cache-pred nil)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
164 (cache syntax-ppss-cache)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
165 (pt-min (point-min))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
166 ;; I differentiate between PT-MIN and PT-BEST because
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
167 ;; I feel like it might be important to ensure that the
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
168 ;; cache is only filled with 100% sure data (whereas
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
169 ;; syntax-begin-function might return incorrect data).
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
170 ;; Maybe that's just stupid.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
171 (pt-best (point-min))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
172 (ppss-best nil))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
173 ;; look for a usable cache entry.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
174 (while (and cache (< pos (caar cache)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
175 (setq cache-pred cache)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
176 (setq cache (cdr cache)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
177 (if cache (setq pt-min (caar cache) ppss (cdar cache)))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
179 ;; Setup the after-change function if necessary.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
180 (unless (or syntax-ppss-cache syntax-ppss-last)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
181 (add-hook 'after-change-functions
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
182 'syntax-ppss-flush-cache nil t))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
184 ;; Use the best of OLD-POS and CACHE.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
185 (if (or (not old-pos) (< old-pos pt-min))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
186 (setq pt-best pt-min ppss-best ppss)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
187 (incf (car (aref syntax-ppss-stats 4)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
188 (incf (cdr (aref syntax-ppss-stats 4)) (- pos old-pos))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
189 (setq pt-best old-pos ppss-best old-ppss))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
191 ;; Use the `syntax-begin-function' if available.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
192 ;; We could try using that function earlier, but:
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
193 ;; - The result might not be 100% reliable, so it's better to use
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
194 ;; the cache if available.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
195 ;; - The function might be slow.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
196 ;; - If this function almost always finds a safe nearby spot,
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
197 ;; the cache won't be populated, so consulting it is cheap.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
198 (when (and (not syntax-begin-function)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
199 (boundp 'font-lock-beginning-of-syntax-function)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
200 font-lock-beginning-of-syntax-function)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
201 (set (make-local-variable 'syntax-begin-function)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
202 font-lock-beginning-of-syntax-function))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
203 (when (and syntax-begin-function
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
204 (progn (goto-char pos)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
205 (funcall syntax-begin-function)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
206 ;; Make sure it's better.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
207 (> (point) pt-best))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
208 ;; Simple sanity check.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
209 (not (memq (get-text-property (point) 'face)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
210 '(font-lock-string-face font-lock-doc-face
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
211 font-lock-comment-face))))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
212 (incf (car (aref syntax-ppss-stats 5)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
213 (incf (cdr (aref syntax-ppss-stats 5)) (- pos (point)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
214 (setq pt-best (point) ppss-best nil))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
215
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
216 (cond
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
217 ;; Quick case when we found a nearby pos.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
218 ((< (- pos pt-best) syntax-ppss-max-span)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
219 (incf (car (aref syntax-ppss-stats 2)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
220 (incf (cdr (aref syntax-ppss-stats 2)) (- pos pt-best))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
221 (setq ppss (parse-partial-sexp pt-best pos nil nil ppss-best)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
222 ;; Slow case: compute the state from some known position and
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
223 ;; populate the cache so we won't need to do it again soon.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
224 (t
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
225 (incf (car (aref syntax-ppss-stats 3)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
226 (incf (cdr (aref syntax-ppss-stats 3)) (- pos pt-min))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
227
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
228 ;; If `pt-min' is too far, add a few intermediate entries.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
229 (while (> (- pos pt-min) (* 2 syntax-ppss-max-span))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
230 (setq ppss (parse-partial-sexp
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
231 pt-min (setq pt-min (/ (+ pt-min pos) 2))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
232 nil nil ppss))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
233 (let ((pair (cons pt-min ppss)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
234 (if cache-pred
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
235 (push pair (cdr cache-pred))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
236 (push pair syntax-ppss-cache))))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
237
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
238 ;; Compute the actual return value.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
239 (setq ppss (parse-partial-sexp pt-min pos nil nil ppss))
|
49598
|
240
|
51942
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
241 ;; Debugging check.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
242 ;; (let ((real-ppss (parse-partial-sexp (point-min) pos)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
243 ;; (setcar (last ppss 4) 0)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
244 ;; (setcar (last real-ppss 4) 0)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
245 ;; (setcar (last ppss 8) nil)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
246 ;; (setcar (last real-ppss 8) nil)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
247 ;; (unless (equal ppss real-ppss)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
248 ;; (message "!!Syntax: %s != %s" ppss real-ppss)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
249 ;; (setq ppss real-ppss)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
250
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
251 ;; Store it in the cache.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
252 (let ((pair (cons pos ppss)))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
253 (if cache-pred
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
254 (if (> (- (caar cache-pred) pos) syntax-ppss-max-span)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
255 (push pair (cdr cache-pred))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
256 (setcar cache-pred pair))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
257 (if (or (null syntax-ppss-cache)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
258 (> (- (caar syntax-ppss-cache) pos)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
259 syntax-ppss-max-span))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
260 (push pair syntax-ppss-cache)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
261 (setcar syntax-ppss-cache pair)))))))))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
262
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
263 (setq syntax-ppss-last (cons pos ppss))
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
264 ppss)
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
265 (args-out-of-range
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
266 ;; If the buffer is more narrowed than when we built the cache,
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
267 ;; we may end up calling parse-partial-sexp with a position before
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
268 ;; point-min. In that case, just parse from point-min assuming
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
269 ;; a nil state.
|
5fdfe35f3ac4
(syntax-ppss): Catch the case where the buffer is narrowed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
270 (parse-partial-sexp (point-min) pos)))))
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
271
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
272 ;; Debugging functions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
273
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
274 (defun syntax-ppss-debug ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
275 (let ((pt nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
276 (min-diffs nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
277 (dolist (x (append syntax-ppss-cache (list (cons (point-min) nil))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
278 (when pt (push (- pt (car x)) min-diffs))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
279 (setq pt (car x)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
280 min-diffs))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
281
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
282 ;; XEmacs compatibility functions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
283
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
284 ;; (defun buffer-syntactic-context (&optional buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
285 ;; "Syntactic context at point in BUFFER.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
286 ;; Either of `string', `comment' or `nil'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
287 ;; This is an XEmacs compatibility function."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
288 ;; (with-current-buffer (or buffer (current-buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
289 ;; (syntax-ppss-context (syntax-ppss))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
290
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
291 ;; (defun buffer-syntactic-context-depth (&optional buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
292 ;; "Syntactic parenthesis depth at point in BUFFER.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
293 ;; This is an XEmacs compatibility function."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
294 ;; (with-current-buffer (or buffer (current-buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
295 ;; (syntax-ppss-depth (syntax-ppss))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
297 (provide 'syntax)
|
52401
|
298
|
66266
|
299 ;; arch-tag: 302f1eeb-e77c-4680-a8c5-c543e01161a5
|
39756
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
300 ;;; syntax.el ends here
|