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