annotate src/font-lock.c @ 826:6728e641994e

[xemacs-hg @ 2002-05-05 11:30:15 by ben] syntax cache, 8-bit-format, lots of code cleanup README.packages: Update info about --package-path. i.c: Create an inheritable event and pass it on to XEmacs, so that ^C can be handled properly. Intercept ^C and signal the event. "Stop Build" in VC++ now works. bytecomp-runtime.el: Doc string changes. compat.el: Some attempts to redo this to make it truly useful and fix the "multiple versions interacting with each other" problem. Not yet done. Currently doesn't work. files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code. xemacs.mak: Split up CFLAGS into a version without flags specifying the C library. The problem seems to be that minitar depends on zlib, which depends specifically on libc.lib, not on any of the other C libraries. Unless you compile with libc.lib, you get errors -- specifically, no _errno in the other libraries, which must make it something other than an int. (#### But this doesn't seem to obtain in XEmacs, which also uses zlib, and can be linked with any of the C libraries. Maybe zlib is used differently and doesn't need errno, or maybe XEmacs provides an int errno; ... I don't understand. Makefile.in.in: Fix so that packages are around when testing. abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch. -- FUNCTIONALITY CHANGES: add partial support for 8-bit-fixed, 16-bit-fixed, and 32-bit-fixed formats. not quite done yet. (in particular, needs functions to actually convert the buffer.) NOTE: lots of changes to regex.c here. also, many new *_fmt() inline funs that take an Internal_Format argument. redo syntax cache code. make the cache per-buffer; keep the cache valid across calls to functions that use it. also keep it valid across insertions/deletions and extent changes, as much as is possible. eliminate the junky regex-reentrancy code by passing in the relevant lisp info to the regex routines as local vars. add general mechanism in extents code for signalling extent changes. fix numerous problems with the case-table implementation; yoshiki never properly transferred many algorithms from old-style to new-style case tables. redo char tables to support a default argument, so that mapping only occurs over changed args. change many chartab functions to accept Lisp_Object instead of Lisp_Char_Table *. comment out the code in font-lock.c by default, because font-lock.el no longer uses it. we should consider eliminating it entirely. Don't output bell as ^G in console-stream when not a TTY. add -mswindows-termination-handle to interface with i.c, so we can properly kill a build. add more error-checking to buffer/string macros. add some additional buffer_or_string_() funs. -- INTERFACE CHANGES AFFECTING MORE CODE: switch the arguments of write_c_string and friends to be consistent with write_fmt_string, which must have printcharfun first. change BI_* macros to BYTE_* for increased clarity; similarly for bi_* local vars. change VOID_TO_LISP to be a one-argument function. eliminate no-longer-needed CVOID_TO_LISP. -- char/string macro changes: rename MAKE_CHAR() to make_emchar() for slightly less confusion with make_char(). (The former generates an Emchar, the latter a Lisp object. Conceivably we should rename make_char() -> wrap_char() and similarly for make_int(), make_float().) Similar changes for other *CHAR* macros -- we now consistently use names with `emchar' whenever we are working with Emchars. Any remaining name with just `char' always refers to a Lisp object. rename macros with XSTRING_* to string_* except for those that reference actual fields in the Lisp_String object, following conventions used elsewhere. rename set_string_{data,length} macros (the only ones to work with a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_* to make the difference clear. try to be consistent about caps vs. lowercase in macro/inline-fun names for chars and such, which wasn't the case before. we now reserve caps either for XFOO_ macros that reference object fields (e.g. XSTRING_DATA) or for things that have non-function semantics, e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an arg (any arg) more than once. otherwise, use lowercase. here is a summary of most of the macros/inline funs changed by all of the above changes: BYTE_*_P -> byte_*_p XSTRING_BYTE -> string_byte set_string_data/length -> set_lispstringp_data/length XSTRING_CHAR_LENGTH -> string_char_length XSTRING_CHAR -> string_emchar INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p charptr_copy_char -> charptr_copy_emchar LEADING_BYTE_* -> leading_byte_* CHAR_* -> EMCHAR_* *_CHAR_* -> *_EMCHAR_* *_CHAR -> *_EMCHAR CHARSET_BY_ -> charset_by_* BYTE_SHIFT_JIS* -> byte_shift_jis* BYTE_BIG5* -> byte_big5* REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte char_to_unicode -> emchar_to_unicode valid_char_p -> valid_emchar_p Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality). -- INTERFACE CHANGES AFFECTING LESS CODE: use DECLARE_INLINE_HEADER in various places. remove '#ifdef emacs' from XEmacs-only files. eliminate CHAR_TABLE_VALUE(), which duplicated the functionality of get_char_table(). add BUFFER_TEXT_LOOP to simplify iterations over buffer text. define typedefs for signed and unsigned types of fixed sizes (INT_32_BIT, UINT_32_BIT, etc.). create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE; fix code to use it. add charptr_emchar_len to return the text length of the character pointed to by a ptr; use it in place of charcount_to_bytecount(..., 1). add emchar_len to return the text length of a given character. add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount and Charbpos/Charcount, in code (particularly, the extents code and redisplay code) that works with either kind of index. rename redisplay struct params with names such as `charbpos' to e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos. eliminate xxDEFUN in place of DEFUN; no longer necessary with changes awhile back to doc.c. split up big ugly combined list of EXFUNs in lisp.h on a file-by-file basis, since other prototypes are similarly split. rewrite some "*_UNSAFE" macros as inline funs and eliminate the _UNSAFE suffix. move most string code from lisp.h to text.h; the string code and text.h code is now intertwined in such a fashion that they need to be in the same place and partially interleaved. (you can't create forward references for inline funs) automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in batch mode. Fix up some problems in lisp-tests/symbol-tests that were causing spurious failures.
author ben
date Sun, 05 May 2002 11:33:57 +0000
parents fdefd0186b75
children bf645ed7cfe3
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.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
4 Copyright (C) 2002 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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
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 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* This code computes the syntactic context of the current point, that is,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 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
27 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
28 and moving forward, examining the syntax of each character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 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
31 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
32 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
33 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
34 within a line relatively cheap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 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
37 current top-level form) we simply continue computing forward. If we move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 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
39 switch buffers, then we call `beginning-of-defun' and start over from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #### We should really rewrite this to keep extents over the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 that hold the current syntactic information. This would be a big win.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 This way there would be no guessing or incorrect results.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
47 #if 0 /* no longer used */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
48
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Lisp_Object Qcomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 Lisp_Object Qblock_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Lisp_Object Qbeginning_of_defun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 enum syntactic_context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 context_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 context_string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 context_comment,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
65 context_block_comment,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
66 context_generic_comment,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
67 context_generic_string
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 enum block_comment_context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ccontext_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ccontext_start1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ccontext_start2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ccontext_end1
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 enum comment_style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 comment_style_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 comment_style_a,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 comment_style_b
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 struct context_cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
87 Charbpos start_point; /* beginning of defun */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
88 Charbpos cur_point; /* cache location */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
89 Charbpos end_point; /* end of defun */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 struct buffer *buffer; /* does this need to be staticpro'd? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 enum syntactic_context context; /* single-char-syntax state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 enum block_comment_context ccontext; /* block-comment state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 enum comment_style style; /* which comment group */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Emchar scontext; /* active string delimiter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 int depth; /* depth in parens */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 int backslash_p; /* just read a backslash */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 int needs_its_head_reexamined; /* we're apparently outside of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 a top level form, and far away
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 from it. This is a bad situation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 because it will lead to constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 slowness as we keep going way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 back to that form and moving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 forward again. In this case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 we try to compute a "pseudo-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 top-level-form" where the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 depth is 0 and the context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 is none at both ends. */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 /* We have two caches; one for the current point and one for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 the beginning of line. We used to rely on the caller to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 tell us when to invalidate them, but now we do it ourselves;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 it lets us be smarter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 static struct context_cache context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static struct context_cache bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 int font_lock_debug;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 #define reset_context_cache(cc) memset (cc, 0, sizeof (struct context_cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 /* This function is called from signal_after_change() to tell us when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 textual changes are made so we can flush our caches when necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 We make the following somewhat heuristic assumptions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (remember that current_point is always >= start_point, but may be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 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
130 top-level form)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 1) Textual changes before the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 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
134 appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 2) Textual changes right at the beginning of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 top-level form messes things up and requires that we flush
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 the caches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 3) Textual changes after the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 and before one or both or the caches invalidates the corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 cache(s).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 4) Textual changes after the caches and before the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 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
143 offset the caches appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 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
145 necessitate recomputing that end value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 6) Textual changes after the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 are ignored. */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
151 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
152 Charbpos orig_end, Charbpos new_end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 /* Note: either both context_cache and bol_context_cache are valid and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 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
156 invalidate just context_cache, we recopy it from bol_context_cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 if (context_cache.buffer != buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 /* caches don't apply */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /* NOTE: The order of the if statements below is important. If you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 change them around unthinkingly, you will probably break something. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 if (orig_end <= context_cache.start_point - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 /* case 1: before the beginning of the current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 Charcount diff = new_end - orig_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 stderr_out ("font-lock; Case 1\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 context_cache.start_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 context_cache.cur_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 bol_context_cache.start_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 bol_context_cache.cur_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 bol_context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 else if (start <= context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 stderr_out ("font-lock; Case 2\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 /* case 2: right at the current top-level form (paren that starts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 top level form got deleted or moved away from the newline it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 was touching) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 /* 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
187 current top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 else if (start < bol_context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 stderr_out ("font-lock; Case 3 (1)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 /* case 3: after the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 and before both of the caches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 else if (start < context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 stderr_out ("font-lock; Case 3 (2)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 /* case 3: but only need to invalidate one cache */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 context_cache = bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 /* OK, now we know that the start is after the caches. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 else if (start >= context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 stderr_out ("font-lock; Case 6\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* case 6: after the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 and after the caches. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 else if (orig_end <= context_cache.end_point - 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 /* case 4: after the caches and before the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 Charcount diff = new_end - orig_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 stderr_out ("font-lock; Case 4\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 bol_context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 stderr_out ("font-lock; Case 5\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 /* case 5: right at the end of the current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 context_cache.end_point = context_cache.start_point - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 bol_context_cache.end_point = context_cache.start_point - 1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 /* This function is called from Fkill_buffer(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 font_lock_buffer_was_killed (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 if (context_cache.buffer == buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 reset_context_cache (&bol_context_cache);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
244 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
245 beginning_of_defun (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
248 Charbpos opt = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 if (pt == BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 return pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 BUF_SET_PT (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 /* There used to be some kludginess to call c++-beginning-of-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 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
254 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
255 mode working, fix it rather than the C code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 call0_in_buffer (buf, Qbeginning_of_defun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 pt = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 BUF_SET_PT (buf, opt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 return pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
262 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
263 end_of_defun (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 Lisp_Object retval = scan_lists (buf, pt, 1, 0, 0, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 if (NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 return BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 return XINT (retval);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 /* Set up context_cache for attempting to determine the syntactic context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 in buffer BUF at point PT. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
276 setup_context_cache (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 int recomputed_start_point = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 if (context_cache.buffer != buf || pt < context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 start_over:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 stderr_out ("reset context cache\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 /* OK, completely invalid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 if (!context_cache.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 /* Need to recompute the start point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 stderr_out ("recompute start\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 context_cache.start_point = beginning_of_defun (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 recomputed_start_point = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 bol_context_cache.start_point = context_cache.start_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 bol_context_cache.buffer = context_cache.buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 if (context_cache.end_point < context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 /* Need to recompute the end point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 stderr_out ("recompute end\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 context_cache.end_point = end_of_defun (buf, context_cache.start_point);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 bol_context_cache.end_point = context_cache.end_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 if (bol_context_cache.cur_point == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 pt < bol_context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 stderr_out ("reset to start\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if (pt > context_cache.end_point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 /* 3000 is some arbitrary delta but seems reasonable;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 about the size of a reasonable function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 && pt - context_cache.end_point > 3000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 /* If we're far past the end of the top level form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 don't trust it; recompute it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 /* But don't get in an infinite loop doing this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 If we're really far past the end of the top level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 form, try to compute a pseudo-top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 if (recomputed_start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 context_cache.needs_its_head_reexamined = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 /* force recomputation */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 goto start_over;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 /* 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
329 us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 if (pt > context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 pt = context_cache.end_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 pt = context_cache.start_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 /* Reset current point to start of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 context_cache.cur_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 context_cache.scontext = '\000';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 context_cache.depth = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
341 /* #### shouldn't this be checking the character's syntax instead of
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
342 explicitly testing for backslash characters? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 context_cache.backslash_p = ((pt > 1) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (BUF_FETCH_CHAR (buf, pt - 1) == '\\'));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 /* Note that the BOL context cache may not be at the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 of the line, but that should be OK, nobody's checking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 else if (pt < context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 stderr_out ("reset to bol\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 /* bol cache is OK but current_cache is not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 context_cache = bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 else if (pt <= context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 stderr_out ("everything is OK\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 /* in same top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 return;
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 /* 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
367 Charbpos maxpt = max (context_cache.end_point, context_cache.cur_point);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 int shortage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 stderr_out ("past end\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 if (pt <= maxpt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 /* OK, fine. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 #if 0
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
378 /* This appears to cause huge slowdowns in files which have no
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
379 top-level forms.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 In any case, it's not really necessary that we know for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 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
383 but the form we have recorded is the previous one,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 it will be OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 scan_buffer (buf, '\n', maxpt, pt, 1, &shortage, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 if (!shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 /* If there was a newline in the region past the known universe,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 we might be inside another top-level form, so start over.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 Otherwise, we're outside of any top-level forms and we know
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 the one directly before us, so it's OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 goto start_over;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 #endif
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
397 /* 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
398 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
399 differently */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
400 #define SYNTAX_START_STYLE(c1, c2) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
401 ((enum comment_style) \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
402 (SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 comment_style_a : \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
404 SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
406 comment_style_none))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
408 #define SYNTAX_END_STYLE(c1, c2) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
409 ((enum comment_style) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
410 (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
411 comment_style_a : \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
412 SYNTAX_CODES_MATCH_END_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
413 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
414 comment_style_none))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
415
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
416 #define SINGLE_SYNTAX_STYLE(c) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
417 ((enum comment_style) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
418 (SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_A) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 comment_style_a : \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
420 SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_B) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
422 comment_style_none))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 /* Set up context_cache for position PT in BUF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
427 find_context (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 Emchar prev_c, c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
431 int prev_syncode, syncode;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
432 Charbpos target = pt;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
433 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
434
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 setup_context_cache (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 pt = context_cache.cur_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
438 scache = setup_buffer_syntax_cache (buf, pt - 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 if (pt > BUF_BEGV (buf))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
440 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
441 c = BUF_FETCH_CHAR (buf, pt - 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
442 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
443 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 else
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
445 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
446 c = '\n'; /* to get bol_context_cache at point-min */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
447 syncode = Swhitespace;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
448 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 for (; pt < target; pt++, context_cache.cur_point = pt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 if (context_cache.needs_its_head_reexamined)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 if (context_cache.depth == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 && context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 /* We've found an anchor spot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 Try to put the start of defun within 6000 chars of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 the target, and the end of defun as close as possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 6000 is also arbitrary but tries to strike a balance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 between two conflicting pulls when dealing with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 file that has lots of stuff sitting outside of a top-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 level form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 a) If you move past the start of defun, you will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 have to recompute defun, which in this case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 means that start of defun goes all the way back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 to the beginning of the file; so you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 to set start of defun a ways back from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 current point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 b) If you move a line backwards but within start of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 defun, you have to move back to start of defun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 so you don't want start of defun too far from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 the current point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 if (target - context_cache.start_point > 6000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 context_cache.start_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 context_cache.end_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
483 UPDATE_SYNTAX_CACHE_FORWARD (scache, pt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 prev_c = c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
485 prev_syncode = syncode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 c = BUF_FETCH_CHAR (buf, pt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
487 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 if (prev_c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 bol_context_cache = context_cache;
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 if (context_cache.backslash_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 context_cache.backslash_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
498 switch (SYNTAX_FROM_CODE (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 context_cache.backslash_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 break;
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 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 context_cache.depth++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 context_cache.depth--;
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 Scomment:
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 context_cache.context = context_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 context_cache.ccontext = ccontext_none;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
519 context_cache.style = SINGLE_SYNTAX_STYLE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 }
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 Sendcomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
525 if (context_cache.style != SINGLE_SYNTAX_STYLE (syncode))
428
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 else if (context_cache.context == context_comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 context_cache.style = comment_style_none;
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 else if (context_cache.context == context_block_comment &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (context_cache.ccontext == ccontext_start2 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 context_cache.ccontext == ccontext_end1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 break;
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 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 if (context_cache.context == context_string &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 context_cache.scontext == c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 context_cache.scontext = '\000';
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 else if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
552 Lisp_Object stringtermobj =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
553 syntax_match (scache->current_syntax_table, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 Emchar stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 if (CHARP (stringtermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 stringterm = XCHAR (stringtermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 stringterm = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 context_cache.context = context_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 context_cache.scontext = stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
566
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
567 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
568 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
569 if (context_cache.context == context_generic_comment)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
570 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
571 context_cache.context = context_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
572 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
573 else if (context_cache.context == context_none)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
574 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
575 context_cache.context = context_generic_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
576 context_cache.ccontext = ccontext_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
577 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
578 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
579 }
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 case Sstring_fence:
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 if (context_cache.context == context_generic_string)
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_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
586 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
587 else if (context_cache.context == context_none)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
588 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
589 context_cache.context = context_generic_string;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
590 context_cache.ccontext = ccontext_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
591 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
592 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
593 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
594
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 /* That takes care of the characters with manifest syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 Now we've got to hack multi-char sequences that start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 and end block comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
603 if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 SYNTAX_SECOND_CHAR_START) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 context_cache.context == context_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 context_cache.ccontext == ccontext_start1 &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
607 SYNTAX_CODES_START_P (prev_syncode, syncode) /* the two chars match */
428
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 context_cache.ccontext = ccontext_start2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
611 context_cache.style = SYNTAX_START_STYLE (prev_syncode, syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
614 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 SYNTAX_FIRST_CHAR_START) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 context_cache.context == context_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (context_cache.ccontext == ccontext_none ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 context_cache.ccontext == ccontext_start1))
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_start1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 context_cache.style = comment_style_none; /* should be this already*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
623 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 SYNTAX_SECOND_CHAR_END) &&
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
625 context_cache.context ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
626 (enum syntactic_context) context_block_comment &&
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
627 context_cache.ccontext ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
628 (enum block_comment_context) ccontext_end1 &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
629 SYNTAX_CODES_END_P (prev_syncode, syncode) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 /* the two chars match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 context_cache.style ==
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
632 SYNTAX_END_STYLE (prev_syncode, syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
639 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 SYNTAX_FIRST_CHAR_END) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 context_cache.context == context_block_comment &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
642 context_cache.style == SINGLE_SYNTAX_STYLE (syncode) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (context_cache.ccontext == ccontext_start2 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 context_cache.ccontext == ccontext_end1))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
645 /* #### is it right to check for end1 here??
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
646 yes, because this might be a repetition of the first char
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
647 of a comment-end sequence. ie, '/xxx foo xxx/' or
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
648 '/xxx foo x/', where 'x' = '*' -- mct */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 context_cache.ccontext = ccontext_end1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 else if (context_cache.ccontext == ccontext_start1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 if (context_cache.context != context_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 else if (context_cache.ccontext == ccontext_end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 if (context_cache.context != context_block_comment) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 context_cache.ccontext = ccontext_start2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 if (context_cache.ccontext == ccontext_start2 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 context_cache.context == context_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 context_cache.context = context_block_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 else if (context_cache.ccontext == ccontext_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 context_cache.context == context_block_comment)
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 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 }
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.needs_its_head_reexamined = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 }
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 context_to_symbol (enum syntactic_context context)
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 switch (context)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
687 case context_none: return Qnil;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
688 case context_string: return Qstring;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
689 case context_comment: return Qcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
690 case context_block_comment: return Qblock_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
691 case context_generic_comment: return Qblock_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
692 case context_generic_string: return Qstring;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 default: abort (); return Qnil; /* suppress compiler warning */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 DEFUN ("buffer-syntactic-context", Fbuffer_syntactic_context, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 Return the syntactic context of BUFFER at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 If BUFFER is nil or omitted, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 The returned value is one of the following symbols:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 nil ; meaning no special interpretation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 string ; meaning point is within a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 comment ; meaning point is within a line comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 block-comment ; meaning point is within a block comment
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 See also the function `buffer-syntactic-context-depth', which returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 the current nesting-depth within all parenthesis-syntax delimiters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 and the function `syntactically-sectionize', which will map a function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 over each syntactic context in a region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 find_context (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 return context_to_symbol (context_cache.context);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 DEFUN ("buffer-syntactic-context-depth", Fbuffer_syntactic_context_depth,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 Return the depth within all parenthesis-syntax delimiters at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 If BUFFER is nil or omitted, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 find_context (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 return make_int (context_cache.depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 DEFUN ("syntactically-sectionize", Fsyntactically_sectionize, 3, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 Call FUNCTION for each contiguous syntactic context in the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 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
740 region, a symbol representing the syntactic context, and the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 depth (as returned by the functions `buffer-syntactic-context' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 `buffer-syntactic-context-depth'). When this function is called, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 current buffer will be set to BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 WARNING: this may alter match-data.
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 (function, start, end, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
750 Charbpos s, pt, e;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 int edepth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 enum syntactic_context this_context;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 Lisp_Object extent = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 get_buffer_range_char (buf, start, end, &s, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 pt = s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 find_context (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 GCPRO1 (extent);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 while (pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
765 Charbpos estart, eend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* skip over "blank" areas, and bug out at end-of-buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 while (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 pt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 if (pt >= e) goto DONE_LABEL;
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 /* 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
774 this_context = context_cache.context;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 estart = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 /* Minor kludge: consider the comment-start character(s) a part of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 the comment.
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 if (this_context == context_block_comment &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 context_cache.ccontext == ccontext_start2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 estart -= 2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
783 else if (this_context == context_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
784 || this_context == context_generic_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
785 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 estart -= 1;
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 edepth = context_cache.depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 while (context_cache.context == this_context && pt < e)
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 pt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 find_context (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 eend = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 /* Minor kludge: consider the character which terminated the comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 a part of the comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 if ((this_context == context_block_comment ||
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
801 this_context == context_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
802 || this_context == context_generic_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
803 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 && pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 eend++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 if (estart == eend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 /* Make sure not to pass in values that are outside the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 actual bounds of this function. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 call4_in_buffer (buf, function, make_int (max (s, estart)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 make_int (eend == e ? e : eend - 1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 context_to_symbol (this_context),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 make_int (edepth));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 DONE_LABEL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 syms_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
824 DEFSYMBOL (Qcomment);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
825 DEFSYMBOL (Qblock_comment);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
826 DEFSYMBOL (Qbeginning_of_defun);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 DEFSUBR (Fbuffer_syntactic_context);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 DEFSUBR (Fbuffer_syntactic_context_depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 DEFSUBR (Fsyntactically_sectionize);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 reinit_vars_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 xzero (context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 xzero (bol_context_cache);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 vars_of_font_lock (void)
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 reinit_vars_of_font_lock ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
845 #endif /* 0 */