annotate src/font-lock.c @ 304:c6de09ad3017 r21-0b50

Import from CVS: tag r21-0b50
author cvs
date Mon, 13 Aug 2007 10:41:12 +0200
parents 7df0dd720c89
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Routines to compute the current syntactic context, for font-lock mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* This code computes the syntactic context of the current point, that is,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 whether point is within a comment, a string, what have you. It does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 this by picking a point "known" to be outside of any syntactic constructs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 and moving forward, examining the syntax of each character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 Two caches are used: one caches the last point computed, and the other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 caches the last point at the beginning of a line. This makes there
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
31 be little penalty for moving left-to-right on a line a character at a
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 time; makes starting over on a line be cheap; and makes random-accessing
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
33 within a line relatively cheap.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 When we move to a different line farther down in the file (but within the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 current top-level form) we simply continue computing forward. If we move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 backward more than a line, or move beyond the end of the current tlf, or
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
38 switch buffers, then we call `beginning-of-defun' and start over from
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #### We should really rewrite this to keep extents over the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 that hold the current syntactic information. This would be a big win.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 This way there would be no guessing or incorrect results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include "syntax.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 Lisp_Object Qcomment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Lisp_Object Qblock_comment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Lisp_Object Qbeginning_of_defun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 enum syntactic_context
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 context_none,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 context_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 context_comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 context_block_comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 enum block_comment_context
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ccontext_none,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ccontext_start1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ccontext_start2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ccontext_end1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 enum comment_style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 comment_style_none,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 comment_style_a,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 comment_style_b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 struct context_cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 Bufpos start_point; /* beginning of defun */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Bufpos cur_point; /* cache location */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 Bufpos end_point; /* end of defun */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 struct buffer *buffer; /* does this need to be staticpro'd? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 enum syntactic_context context; /* single-char-syntax state */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 enum block_comment_context ccontext; /* block-comment state */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 enum comment_style style; /* which comment group */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 Emchar scontext; /* active string delimiter */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 int depth; /* depth in parens */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 int backslash_p; /* just read a backslash */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 int needs_its_head_reexamined; /* we're apparently outside of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 a top level form, and far away
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 from it. This is a bad situation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 because it will lead to constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 slowness as we keep going way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 back to that form and moving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 forward again. In this case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 we try to compute a "pseudo-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 top-level-form" where the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 depth is 0 and the context
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 is none at both ends. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 /* We have two caches; one for the current point and one for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 the beginning of line. We used to rely on the caller to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 tell us when to invalidate them, but now we do it ourselves;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 it lets us be smarter. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 static struct context_cache context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 static struct context_cache bol_context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 int font_lock_debug;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #define reset_context_cache(cc) memset (cc, 0, sizeof (struct context_cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 /* This function is called from signal_after_change() to tell us when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 textual changes are made so we can flush our caches when necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 We make the following somewhat heuristic assumptions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (remember that current_point is always >= start_point, but may be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 less than or greater than end_point (we might not be inside any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 top-level form)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 1) Textual changes before the beginning of the current top-level form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 don't affect anything; all we need to do is offset the caches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 appropriately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 2) Textual changes right at the beginning of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 top-level form messes things up and requires that we flush
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 the caches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 3) Textual changes after the beginning of the current top-level form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 and before one or both or the caches invalidates the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 cache(s).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 4) Textual changes after the caches and before the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 current top-level form don't affect anything; all we need to do is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 offset the caches appropriately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 5) Textual changes right at the end of the current top-level form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 necessitate recomputing that end value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 6) Textual changes after the end of the current top-level form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 are ignored. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 font_lock_maybe_update_syntactic_caches (struct buffer *buf, Bufpos start,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Bufpos orig_end, Bufpos new_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 /* Note: either both context_cache and bol_context_cache are valid and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 point to the same buffer, or both are invalid. If we have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 invalidate just context_cache, we recopy it from bol_context_cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 if (context_cache.buffer != buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 /* caches don't apply */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 /* NOTE: The order of the if statements below is important. If you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 change them around unthinkingly, you will probably break something. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 if (orig_end <= context_cache.start_point - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 /* case 1: before the beginning of the current top-level form */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 Charcount diff = new_end - orig_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 stderr_out ("font-lock; Case 1\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 context_cache.start_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 context_cache.cur_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 context_cache.end_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 bol_context_cache.start_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 bol_context_cache.cur_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 bol_context_cache.end_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 else if (start <= context_cache.start_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 stderr_out ("font-lock; Case 2\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 /* case 2: right at the current top-level form (paren that starts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 top level form got deleted or moved away from the newline it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 was touching) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 reset_context_cache (&context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 reset_context_cache (&bol_context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 /* OK, now we know that the start is after the beginning of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 current top-level form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 else if (start < bol_context_cache.cur_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 stderr_out ("font-lock; Case 3 (1)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 /* case 3: after the beginning of the current top-level form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 and before both of the caches */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 reset_context_cache (&context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 reset_context_cache (&bol_context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 else if (start < context_cache.cur_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 stderr_out ("font-lock; Case 3 (2)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 /* case 3: but only need to invalidate one cache */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 context_cache = bol_context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 /* OK, now we know that the start is after the caches. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 else if (start >= context_cache.end_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 stderr_out ("font-lock; Case 6\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* case 6: after the end of the current top-level form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 and after the caches. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 else if (orig_end <= context_cache.end_point - 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 /* case 4: after the caches and before the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 current top-level form */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 Charcount diff = new_end - orig_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 stderr_out ("font-lock; Case 4\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 context_cache.end_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 bol_context_cache.end_point += diff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 stderr_out ("font-lock; Case 5\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 /* case 5: right at the end of the current top-level form */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 context_cache.end_point = context_cache.start_point - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 bol_context_cache.end_point = context_cache.start_point - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 /* This function is called from Fkill_buffer(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 font_lock_buffer_was_killed (struct buffer *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 if (context_cache.buffer == buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 reset_context_cache (&context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 reset_context_cache (&bol_context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 static Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 beginning_of_defun (struct buffer *buf, Bufpos pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 Bufpos opt = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 if (pt == BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 return pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 BUF_SET_PT (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 /* There used to be some kludginess to call c++-beginning-of-defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 if we're in C++ mode. There's no point in this any more;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 we're using cc-mode. If you really want to get the old c++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 mode working, fix it rather than the C code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 call0_in_buffer (buf, Qbeginning_of_defun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 pt = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 BUF_SET_PT (buf, opt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 return pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 static Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 end_of_defun (struct buffer *buf, Bufpos pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 Lisp_Object retval = scan_lists (buf, pt, 1, 0, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 if (NILP (retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 return BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 return XINT (retval);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 /* Set up context_cache for attempting to determine the syntactic context
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 in buffer BUF at point PT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 setup_context_cache (struct buffer *buf, Bufpos pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 int recomputed_start_point = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 if (context_cache.buffer != buf || pt < context_cache.start_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 start_over:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 stderr_out ("reset context cache\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 /* OK, completely invalid. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 reset_context_cache (&context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 reset_context_cache (&bol_context_cache);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 if (!context_cache.buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 /* Need to recompute the start point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 stderr_out ("recompute start\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 context_cache.start_point = beginning_of_defun (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 recomputed_start_point = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 bol_context_cache.start_point = context_cache.start_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 bol_context_cache.buffer = context_cache.buffer = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 if (context_cache.end_point < context_cache.start_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 /* Need to recompute the end point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 stderr_out ("recompute end\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 context_cache.end_point = end_of_defun (buf, context_cache.start_point);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 bol_context_cache.end_point = context_cache.end_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 if (bol_context_cache.cur_point == 0 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 pt < bol_context_cache.cur_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 stderr_out ("reset to start\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 if (pt > context_cache.end_point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 /* 3000 is some arbitrary delta but seems reasonable;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 about the size of a reasonable function */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 && pt - context_cache.end_point > 3000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 /* If we're far past the end of the top level form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 don't trust it; recompute it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 /* But don't get in an infinite loop doing this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 If we're really far past the end of the top level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 form, try to compute a pseudo-top-level form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 if (recomputed_start_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 context_cache.needs_its_head_reexamined = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 /* force recomputation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 goto start_over;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 /* Go to the nearest end of the top-level form that's before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 if (pt > context_cache.end_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 pt = context_cache.end_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 pt = context_cache.start_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 /* Reset current point to start of buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 context_cache.cur_point = pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 context_cache.ccontext = ccontext_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 context_cache.style = comment_style_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 context_cache.scontext = '\000';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 context_cache.depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 context_cache.backslash_p = ((pt > 1) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (BUF_FETCH_CHAR (buf, pt - 1) == '\\'));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 /* Note that the BOL context cache may not be at the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 of the line, but that should be OK, nobody's checking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 bol_context_cache = context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 else if (pt < context_cache.cur_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 stderr_out ("reset to bol\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 /* bol cache is OK but current_cache is not. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 context_cache = bol_context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 else if (pt <= context_cache.end_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 stderr_out ("everything is OK\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 /* in same top-level form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 /* OK, we're past the end of the top-level form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 Bufpos maxpt = max (context_cache.end_point, context_cache.cur_point);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 int shortage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (font_lock_debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 stderr_out ("past end\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 if (pt <= maxpt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 /* OK, fine. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 /* This appears to cause huge slowdowns in files like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 emacsfns.h, which have no top-level forms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 In any case, it's not really necessary that we know for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 sure the top-level form we're in; if we're in a form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 but the form we have recorded is the previous one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 it will be OK. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 scan_buffer (buf, '\n', maxpt, pt, 1, &shortage, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 if (!shortage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 /* If there was a newline in the region past the known universe,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 we might be inside another top-level form, so start over.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 Otherwise, we're outside of any top-level forms and we know
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 the one directly before us, so it's OK. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 goto start_over;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 #define SYNTAX_START_STYLE(table, c1, c2) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (SYNTAX_STYLES_MATCH_START_P (table, c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 comment_style_a : \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 SYNTAX_STYLES_MATCH_START_P (table, c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 comment_style_b : \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 comment_style_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 #define SYNTAX_END_STYLE(table, c1, c2) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (SYNTAX_STYLES_MATCH_END_P (table, c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 comment_style_a : \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 SYNTAX_STYLES_MATCH_END_P (table, c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 comment_style_b : \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 comment_style_none)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
403
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 #define SINGLE_SYNTAX_STYLE(table, c) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (SYNTAX_STYLES_MATCH_1CHAR_P (table, c, SYNTAX_COMMENT_STYLE_A) ? \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 comment_style_a : \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 SYNTAX_STYLES_MATCH_1CHAR_P (table, c, SYNTAX_COMMENT_STYLE_B) ? \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 comment_style_b : \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 comment_style_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 /* Set up context_cache for position PT in BUF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 find_context (struct buffer *buf, Bufpos pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 /* This function can GC */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
417 struct Lisp_Char_Table *mirrortab =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
418 XCHAR_TABLE (buf->mirror_syntax_table);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
419 Lisp_Object syntaxtab = buf->syntax_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 Emchar prev_c, c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 Bufpos target = pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 setup_context_cache (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 pt = context_cache.cur_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 if (pt > BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 c = BUF_FETCH_CHAR (buf, pt - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 c = '\n'; /* to get bol_context_cache at point-min */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 for (; pt < target; pt++, context_cache.cur_point = pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (context_cache.needs_its_head_reexamined)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 if (context_cache.depth == 0
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
435 && context_cache.context == context_none)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 /* We've found an anchor spot.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 Try to put the start of defun within 6000 chars of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 the target, and the end of defun as close as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 6000 is also arbitrary but tries to strike a balance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 between two conflicting pulls when dealing with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 file that has lots of stuff sitting outside of a top-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 level form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 a) If you move past the start of defun, you will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 have to recompute defun, which in this case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 means that start of defun goes all the way back
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
448 to the beginning of the file; so you want
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 to set start of defun a ways back from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 current point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 b) If you move a line backwards but within start of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 defun, you have to move back to start of defun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 so you don't want start of defun too far from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 the current point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 if (target - context_cache.start_point > 6000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 context_cache.start_point = pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 context_cache.end_point = pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 bol_context_cache = context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 prev_c = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 c = BUF_FETCH_CHAR (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 if (prev_c == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 bol_context_cache = context_cache;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 if (context_cache.backslash_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 context_cache.backslash_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
475 switch (SYNTAX (mirrortab, c))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 context_cache.backslash_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 case Sopen:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 if (context_cache.context == context_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 context_cache.depth++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 case Sclose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 if (context_cache.context == context_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 context_cache.depth--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 case Scomment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 if (context_cache.context == context_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 context_cache.context = context_comment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 context_cache.ccontext = ccontext_none;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
496 context_cache.style = SINGLE_SYNTAX_STYLE (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 if (context_cache.style == comment_style_none) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 case Sendcomment:
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
502 if (context_cache.style != SINGLE_SYNTAX_STYLE (mirrortab, c))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 else if (context_cache.context == context_comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 context_cache.style = comment_style_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 else if (context_cache.context == context_block_comment &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (context_cache.ccontext == ccontext_start2 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 context_cache.ccontext == ccontext_end1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 context_cache.ccontext = ccontext_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 context_cache.style = comment_style_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 case Sstring:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if (context_cache.context == context_string &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 context_cache.scontext == c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 context_cache.scontext = '\000';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 else if (context_cache.context == context_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
529 Lisp_Object stringtermobj = syntax_match (syntaxtab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 Emchar stringterm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 if (CHARP (stringtermobj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 stringterm = XCHAR (stringtermobj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 stringterm = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 context_cache.context = context_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 context_cache.scontext = stringterm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 context_cache.ccontext = ccontext_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 /* That takes care of the characters with manifest syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 Now we've got to hack multi-char sequences that start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 and end block comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
550 if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 SYNTAX_SECOND_CHAR_START) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 context_cache.context == context_none &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 context_cache.ccontext == ccontext_start1 &&
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
554 SYNTAX_START_P (mirrortab, prev_c, c) /* the two chars match */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 context_cache.ccontext = ccontext_start2;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
558 context_cache.style = SYNTAX_START_STYLE (mirrortab, prev_c, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 if (context_cache.style == comment_style_none) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
561 else if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 SYNTAX_FIRST_CHAR_START) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 context_cache.context == context_none &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (context_cache.ccontext == ccontext_none ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 context_cache.ccontext == ccontext_start1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 context_cache.ccontext = ccontext_start1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 context_cache.style = comment_style_none; /* should be this already*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
570 else if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 SYNTAX_SECOND_CHAR_END) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 context_cache.context == context_block_comment &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 context_cache.ccontext == ccontext_end1 &&
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
574 SYNTAX_END_P (mirrortab, prev_c, c) &&
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 /* the two chars match */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 context_cache.style ==
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
577 SYNTAX_END_STYLE (mirrortab, prev_c, c)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 context_cache.ccontext = ccontext_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 context_cache.style = comment_style_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
584 else if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 SYNTAX_FIRST_CHAR_END) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 context_cache.context == context_block_comment &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (context_cache.style ==
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
588 SYNTAX_END_STYLE (mirrortab, c,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 BUF_FETCH_CHAR (buf, pt+1))) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (context_cache.ccontext == ccontext_start2 ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 context_cache.ccontext == ccontext_end1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 /* #### is it right to check for end1 here?? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 if (context_cache.style == comment_style_none) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 context_cache.ccontext = ccontext_end1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 else if (context_cache.ccontext == ccontext_start1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 if (context_cache.context != context_none) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 context_cache.ccontext = ccontext_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 else if (context_cache.ccontext == ccontext_end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 if (context_cache.context != context_block_comment) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 context_cache.ccontext = ccontext_start2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 if (context_cache.ccontext == ccontext_start2 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 context_cache.context == context_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 context_cache.context = context_block_comment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 if (context_cache.style == comment_style_none) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 else if (context_cache.ccontext == ccontext_none &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 context_cache.context == context_block_comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 context_cache.context = context_none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 context_cache.needs_its_head_reexamined = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 context_to_symbol (enum syntactic_context context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 switch (context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
631 case context_none: return Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
632 case context_string: return Qstring;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
633 case context_comment: return Qcomment;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
634 case context_block_comment: return Qblock_comment;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
635 default: abort (); return Qnil; /* suppress compiler warning */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
639 DEFUN ("buffer-syntactic-context", Fbuffer_syntactic_context, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 Return the syntactic context of BUFFER at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 If BUFFER is nil or omitted, the current buffer is assumed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 The returned value is one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 nil ; meaning no special interpretation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 string ; meaning point is within a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 comment ; meaning point is within a line comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 block-comment ; meaning point is within a block comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 See also the function `buffer-syntactic-context-depth', which returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 the current nesting-depth within all parenthesis-syntax delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 and the function `syntactically-sectionize', which will map a function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 over each syntactic context in a region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 WARNING: this may alter match-data.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
655 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
656 (buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 find_context (buf, BUF_PT (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 return context_to_symbol (context_cache.context);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
664 DEFUN ("buffer-syntactic-context-depth", Fbuffer_syntactic_context_depth,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
665 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 Return the depth within all parenthesis-syntax delimiters at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 If BUFFER is nil or omitted, the current buffer is assumed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 WARNING: this may alter match-data.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
669 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
670 (buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 find_context (buf, BUF_PT (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 return make_int (context_cache.depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
679 DEFUN ("syntactically-sectionize", Fsyntactically_sectionize, 3, 4, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
680 Call FUNCTION for each contiguous syntactic context in the region.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
681 Call the given function with four arguments: the start and end of the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 region, a symbol representing the syntactic context, and the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 depth (as returned by the functions `buffer-syntactic-context' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 `buffer-syntactic-context-depth'). When this function is called, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 current buffer will be set to BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 WARNING: this may alter match-data.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
688 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
689 (function, start, end, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 Bufpos s, pt, e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 int edepth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 enum syntactic_context this_context;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 Lisp_Object extent = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 get_buffer_range_char (buf, start, end, &s, &e, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 pt = s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 find_context (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 GCPRO1 (extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 while (pt < e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 Bufpos estart, eend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 /* skip over "blank" areas, and bug out at end-of-buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 while (context_cache.context == context_none)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 pt++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 if (pt >= e) goto DONE_LABEL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 find_context (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 /* We've found a non-blank area; keep going until we reach its end */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 this_context = context_cache.context;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 estart = pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 /* Minor kludge: consider the comment-start character(s) a part of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 the comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 if (this_context == context_block_comment &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 context_cache.ccontext == ccontext_start2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 estart -= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 else if (this_context == context_comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 estart -= 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 edepth = context_cache.depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 while (context_cache.context == this_context && pt < e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 pt++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 find_context (buf, pt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 eend = pt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 /* Minor kludge: consider the character which terminated the comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 a part of the comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 if ((this_context == context_block_comment ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 this_context == context_comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 && pt < e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 eend++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 if (estart == eend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 /* Make sure not to pass in values that are outside the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 actual bounds of this function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 call4_in_buffer (buf, function, make_int (max (s, estart)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 make_int (eend == e ? e : eend - 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 context_to_symbol (this_context),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 make_int (edepth));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 DONE_LABEL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 syms_of_font_lock (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 defsymbol (&Qcomment, "comment");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 defsymbol (&Qblock_comment, "block-comment");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 defsymbol (&Qbeginning_of_defun, "beginning-of-defun");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
766 DEFSUBR (Fbuffer_syntactic_context);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
767 DEFSUBR (Fbuffer_syntactic_context_depth);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
768 DEFSUBR (Fsyntactically_sectionize);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 vars_of_font_lock (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
774 xzero (context_cache);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 185
diff changeset
775 xzero (bol_context_cache);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 }