annotate src/font-lock.c @ 5915:1af53d35dd53

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