comparison lisp/emacs-lisp/syntax.el @ 74725:7bf99b0f8330

(syntax-ppss-flush-cache, syntax-ppss): Use syntax-ppss-toplevel-pos.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 18 Dec 2006 14:34:01 +0000
parents 80f7458bbb20
children 7a3f13e2dd57 bc10a33dd40b
comparison
equal deleted inserted replaced
74724:80f7458bbb20 74725:7bf99b0f8330
57 PPSS is a scan state, as returned by `partial-parse-sexp' or `syntax-ppss'. 57 PPSS is a scan state, as returned by `partial-parse-sexp' or `syntax-ppss'.
58 An \"outermost position\" means one that it is outside of any syntactic entity: 58 An \"outermost position\" means one that it is outside of any syntactic entity:
59 outside of any parentheses, comments, or strings encountered in the scan. 59 outside of any parentheses, comments, or strings encountered in the scan.
60 If no such position is recorded in PPSS (because the end of the scan was 60 If no such position is recorded in PPSS (because the end of the scan was
61 itself at the outermost level), return nil." 61 itself at the outermost level), return nil."
62 ;; BEWARE! We rely on the undocumented 9th field. The 9th field currently
63 ;; contains the list of positions of the enclosing open-parens.
64 ;; I.e. those positions are outside of any string/comment and the first of
65 ;; those is outside of any paren (i.e. corresponds to a nil ppss).
66 ;; If this list is empty but we are in a string or comment, then the 8th
67 ;; field contains a similar "toplevel" position.
62 (or (car (nth 9 ppss)) 68 (or (car (nth 9 ppss))
63 (nth 8 ppss))) 69 (nth 8 ppss)))
64 70
65 (defsubst syntax-ppss-context (ppss) 71 (defsubst syntax-ppss-context (ppss)
66 (cond 72 (cond
67 ((nth 3 ppss) 'string) 73 ((nth 3 ppss) 'string)
68 ((nth 4 ppss) 'comment) 74 ((nth 4 ppss) 'comment)
95 (when (< beg (or (car syntax-ppss-last) 0)) 101 (when (< beg (or (car syntax-ppss-last) 0))
96 ;; If syntax-begin-function jumped to BEG, then the old state at BEG can 102 ;; If syntax-begin-function jumped to BEG, then the old state at BEG can
97 ;; depend on the text after BEG (which is presumably changed). So if 103 ;; depend on the text after BEG (which is presumably changed). So if
98 ;; BEG=(car (nth 10 syntax-ppss-last)) don't reuse that data because the 104 ;; BEG=(car (nth 10 syntax-ppss-last)) don't reuse that data because the
99 ;; assumed nil state at BEG may not be valid any more. 105 ;; assumed nil state at BEG may not be valid any more.
100 (if (<= beg (or (car (nth 10 syntax-ppss-last)) 106 (if (<= beg (or (syntax-ppss-toplevel-pos (cdr syntax-ppss-last))
101 (nth 9 syntax-ppss-last)
102 (nth 3 syntax-ppss-last) 107 (nth 3 syntax-ppss-last)
103 0)) 108 0))
104 (setq syntax-ppss-last nil) 109 (setq syntax-ppss-last nil)
105 (setcar syntax-ppss-last nil))) 110 (setcar syntax-ppss-last nil)))
106 ;; Unregister if there's no cache left. Sadly this doesn't work 111 ;; Unregister if there's no cache left. Sadly this doesn't work
144 (parse-partial-sexp old-pos pos nil nil old-ppss)) 149 (parse-partial-sexp old-pos pos nil nil old-ppss))
145 150
146 (cond 151 (cond
147 ;; Use OLD-PPSS if possible and close enough. 152 ;; Use OLD-PPSS if possible and close enough.
148 ((and (not old-pos) old-ppss 153 ((and (not old-pos) old-ppss
149 ;; BEWARE! We rely on the undocumented 9th field. The 9th 154 ;; If `pt-min' is too far from `pos', we could try to use
150 ;; field currently contains the list of positions of 155 ;; other positions in (nth 9 old-ppss), but that doesn't
151 ;; open-parens of the enclosing parens. I.e. those 156 ;; seem to happen in practice and it would complicate this
152 ;; positions are outside of any string/comment 157 ;; code (and the before-change-function code even more).
153 ;; and the first of those is outside of any paren 158 ;; But maybe it would be useful in "degenerate" cases such
154 ;; (i.e. corresponds to a nil ppss). If this list is empty 159 ;; as when the whole file is wrapped in a set
155 ;; but we are in a string or comment, then the 8th field 160 ;; of parentheses.
156 ;; contains a similar "toplevel" position. If `pt-min' is 161 (setq pt-min (or (syntax-ppss-toplevel-pos old-ppss)
157 ;; too far from `pos', we could try to use other positions
158 ;; in (nth 9 old-ppss), but that doesn't seem to happen in
159 ;; practice and it would complicate this code (and the
160 ;; before-change-function code even more). But maybe it
161 ;; would be useful in "degenerate" cases such as when the
162 ;; whole file is wrapped in a set of parenthesis.
163 (setq pt-min (or (car (nth 9 old-ppss))
164 (nth 8 old-ppss)
165 (nth 2 old-ppss))) 162 (nth 2 old-ppss)))
166 (<= pt-min pos) (< (- pos pt-min) syntax-ppss-max-span)) 163 (<= pt-min pos) (< (- pos pt-min) syntax-ppss-max-span))
167 (incf (car (aref syntax-ppss-stats 1))) 164 (incf (car (aref syntax-ppss-stats 1)))
168 (incf (cdr (aref syntax-ppss-stats 1)) (- pos pt-min)) 165 (incf (cdr (aref syntax-ppss-stats 1)) (- pos pt-min))
169 (setq ppss (parse-partial-sexp pt-min pos))) 166 (setq ppss (parse-partial-sexp pt-min pos)))