annotate src/font-lock.c @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents b39c14581166
children 6728e641994e
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.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 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
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* This code computes the syntactic context of the current point, that is,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 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
26 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
27 and moving forward, examining the syntax of each character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 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
30 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
31 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
32 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
33 within a line relatively cheap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 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
36 current top-level form) we simply continue computing forward. If we move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 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
38 switch buffers, then we call `beginning-of-defun' and start over from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #### We should really rewrite this to keep extents over the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 that hold the current syntactic information. This would be a big win.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 This way there would be no guessing or incorrect results.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 */
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 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 Lisp_Object Qcomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 Lisp_Object Qblock_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 Lisp_Object Qbeginning_of_defun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 enum syntactic_context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 context_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 context_string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 context_comment,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
62 context_block_comment,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
63 context_generic_comment,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
64 context_generic_string
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 enum block_comment_context
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 ccontext_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ccontext_start1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ccontext_start2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ccontext_end1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 enum comment_style
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 comment_style_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 comment_style_a,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 comment_style_b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 struct context_cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
84 Charbpos start_point; /* beginning of defun */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
85 Charbpos cur_point; /* cache location */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
86 Charbpos end_point; /* end of defun */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 struct buffer *buffer; /* does this need to be staticpro'd? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 enum syntactic_context context; /* single-char-syntax state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 enum block_comment_context ccontext; /* block-comment state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 enum comment_style style; /* which comment group */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 Emchar scontext; /* active string delimiter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 int depth; /* depth in parens */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 int backslash_p; /* just read a backslash */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 int needs_its_head_reexamined; /* we're apparently outside of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 a top level form, and far away
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 from it. This is a bad situation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 because it will lead to constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 slowness as we keep going way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 back to that form and moving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 forward again. In this case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 we try to compute a "pseudo-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 top-level-form" where the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 depth is 0 and the context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 is none at both ends. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 /* We have two caches; one for the current point and one for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 the beginning of line. We used to rely on the caller to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 tell us when to invalidate them, but now we do it ourselves;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 it lets us be smarter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 static struct context_cache context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 static struct context_cache bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 int font_lock_debug;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #define reset_context_cache(cc) memset (cc, 0, sizeof (struct context_cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 /* This function is called from signal_after_change() to tell us when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 textual changes are made so we can flush our caches when necessary.
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 We make the following somewhat heuristic assumptions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (remember that current_point is always >= start_point, but may be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 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
127 top-level form)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 1) Textual changes before the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 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
131 appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 2) Textual changes right at the beginning of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 top-level form messes things up and requires that we flush
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 the caches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 3) Textual changes after the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 and before one or both or the caches invalidates the corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 cache(s).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 4) Textual changes after the caches and before the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 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
140 offset the caches appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 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
142 necessitate recomputing that end value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 6) Textual changes after the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 are ignored. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
148 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
149 Charbpos orig_end, Charbpos new_end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 /* Note: either both context_cache and bol_context_cache are valid and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 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
153 invalidate just context_cache, we recopy it from bol_context_cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 if (context_cache.buffer != buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 /* caches don't apply */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 /* NOTE: The order of the if statements below is important. If you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 change them around unthinkingly, you will probably break something. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 if (orig_end <= context_cache.start_point - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 /* case 1: before the beginning of the current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 Charcount diff = new_end - orig_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 stderr_out ("font-lock; Case 1\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 context_cache.start_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 context_cache.cur_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 bol_context_cache.start_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 bol_context_cache.cur_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 bol_context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 else if (start <= context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 stderr_out ("font-lock; Case 2\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* case 2: right at the current top-level form (paren that starts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 top level form got deleted or moved away from the newline it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 was touching) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 /* 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
184 current top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 else if (start < bol_context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 stderr_out ("font-lock; Case 3 (1)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 /* case 3: after the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 and before both of the caches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 else if (start < context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 stderr_out ("font-lock; Case 3 (2)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 /* case 3: but only need to invalidate one cache */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 context_cache = bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 /* OK, now we know that the start is after the caches. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 else if (start >= context_cache.end_point)
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 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 stderr_out ("font-lock; Case 6\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 /* case 6: after the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 and after the caches. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 else if (orig_end <= context_cache.end_point - 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 /* case 4: after the caches and before the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 Charcount diff = new_end - orig_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 stderr_out ("font-lock; Case 4\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 bol_context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 stderr_out ("font-lock; Case 5\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /* case 5: right at the end of the current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 context_cache.end_point = context_cache.start_point - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 bol_context_cache.end_point = context_cache.start_point - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 /* This function is called from Fkill_buffer(). */
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 font_lock_buffer_was_killed (struct buffer *buf)
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 if (context_cache.buffer == buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 reset_context_cache (&bol_context_cache);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
241 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
242 beginning_of_defun (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
245 Charbpos opt = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 if (pt == BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 return pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 BUF_SET_PT (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 /* There used to be some kludginess to call c++-beginning-of-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 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
251 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
252 mode working, fix it rather than the C code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 call0_in_buffer (buf, Qbeginning_of_defun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 pt = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 BUF_SET_PT (buf, opt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 return pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
259 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
260 end_of_defun (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 Lisp_Object retval = scan_lists (buf, pt, 1, 0, 0, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 if (NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 return BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 return XINT (retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 /* Set up context_cache for attempting to determine the syntactic context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 in buffer BUF at point PT. */
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 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
273 setup_context_cache (struct buffer *buf, Charbpos pt)
428
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 int recomputed_start_point = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 if (context_cache.buffer != buf || pt < context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 start_over:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 stderr_out ("reset context cache\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 /* OK, completely invalid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 if (!context_cache.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 /* Need to recompute the start point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 stderr_out ("recompute start\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 context_cache.start_point = beginning_of_defun (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 recomputed_start_point = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 bol_context_cache.start_point = context_cache.start_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 bol_context_cache.buffer = context_cache.buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 if (context_cache.end_point < context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 /* Need to recompute the end point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 stderr_out ("recompute end\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 context_cache.end_point = end_of_defun (buf, context_cache.start_point);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 bol_context_cache.end_point = context_cache.end_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 if (bol_context_cache.cur_point == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 pt < bol_context_cache.cur_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 (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 stderr_out ("reset to start\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 if (pt > context_cache.end_point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 /* 3000 is some arbitrary delta but seems reasonable;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 about the size of a reasonable function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 && pt - context_cache.end_point > 3000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 /* If we're far past the end of the top level form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 don't trust it; recompute it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 /* But don't get in an infinite loop doing this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 If we're really far past the end of the top level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 form, try to compute a pseudo-top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 if (recomputed_start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 context_cache.needs_its_head_reexamined = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 /* force recomputation */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 goto start_over;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 /* 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
326 us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 if (pt > context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 pt = context_cache.end_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 pt = context_cache.start_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 /* Reset current point to start of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 context_cache.cur_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 context_cache.scontext = '\000';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 context_cache.depth = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
338 /* #### shouldn't this be checking the character's syntax instead of
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
339 explicitly testing for backslash characters? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 context_cache.backslash_p = ((pt > 1) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (BUF_FETCH_CHAR (buf, pt - 1) == '\\'));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 /* Note that the BOL context cache may not be at the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 of the line, but that should be OK, nobody's checking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 else if (pt < context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 stderr_out ("reset to bol\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 /* bol cache is OK but current_cache is not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 context_cache = bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 else if (pt <= context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 stderr_out ("everything is OK\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 /* in same top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 /* 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
364 Charbpos maxpt = max (context_cache.end_point, context_cache.cur_point);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 int shortage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 stderr_out ("past end\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 if (pt <= maxpt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 /* OK, fine. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 #if 0
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
375 /* This appears to cause huge slowdowns in files which have no
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
376 top-level forms.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 In any case, it's not really necessary that we know for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 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
380 but the form we have recorded is the previous one,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 it will be OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 scan_buffer (buf, '\n', maxpt, pt, 1, &shortage, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 if (!shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 /* If there was a newline in the region past the known universe,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 we might be inside another top-level form, so start over.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 Otherwise, we're outside of any top-level forms and we know
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 the one directly before us, so it's OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 goto start_over;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
394 /* 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
395 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
396 differently */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
397 #define SYNTAX_START_STYLE(c1, c2) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
398 ((enum comment_style) \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
399 (SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 comment_style_a : \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
401 SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
403 comment_style_none))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
405 #define SYNTAX_END_STYLE(c1, c2) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
406 ((enum comment_style) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
407 (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
408 comment_style_a : \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
409 SYNTAX_CODES_MATCH_END_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
410 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
411 comment_style_none))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
412
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
413 #define SINGLE_SYNTAX_STYLE(c) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
414 ((enum comment_style) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
415 (SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_A) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 comment_style_a : \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
417 SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_B) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
419 comment_style_none))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 /* Set up context_cache for position PT in BUF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
424 find_context (struct buffer *buf, Charbpos pt)
428
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 /* This function can GC */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
427 #ifndef emacs
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
428 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 Lisp_Object syntaxtab = buf->syntax_table;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
430 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 Emchar prev_c, c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
432 int prev_syncode, syncode;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
433 Charbpos target = pt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 setup_context_cache (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 pt = context_cache.cur_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
437 SETUP_SYNTAX_CACHE (pt - 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 if (pt > BUF_BEGV (buf))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
439 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
440 c = BUF_FETCH_CHAR (buf, pt - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
441 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
442 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 else
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
444 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
445 c = '\n'; /* to get bol_context_cache at point-min */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
446 syncode = Swhitespace;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
447 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 for (; pt < target; pt++, context_cache.cur_point = pt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 if (context_cache.needs_its_head_reexamined)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 if (context_cache.depth == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 && context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 /* We've found an anchor spot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 Try to put the start of defun within 6000 chars of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 the target, and the end of defun as close as possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 6000 is also arbitrary but tries to strike a balance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 between two conflicting pulls when dealing with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 file that has lots of stuff sitting outside of a top-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 level form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 a) If you move past the start of defun, you will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 have to recompute defun, which in this case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 means that start of defun goes all the way back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 to the beginning of the file; so you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 to set start of defun a ways back from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 current point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 b) If you move a line backwards but within start of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 defun, you have to move back to start of defun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 so you don't want start of defun too far from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 the current point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 if (target - context_cache.start_point > 6000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 context_cache.start_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 context_cache.end_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 }
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
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
482 UPDATE_SYNTAX_CACHE_FORWARD (pt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 prev_c = c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
484 prev_syncode = syncode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 c = BUF_FETCH_CHAR (buf, pt);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
486 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 if (prev_c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 if (context_cache.backslash_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 context_cache.backslash_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
497 switch (SYNTAX_FROM_CACHE (mirrortab, c))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 context_cache.backslash_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 context_cache.depth++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 context_cache.depth--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 context_cache.context = context_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 context_cache.ccontext = ccontext_none;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
518 context_cache.style = SINGLE_SYNTAX_STYLE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 case Sendcomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
524 if (context_cache.style != SINGLE_SYNTAX_STYLE (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 else if (context_cache.context == context_comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 else if (context_cache.context == context_block_comment &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (context_cache.ccontext == ccontext_start2 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 context_cache.ccontext == ccontext_end1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 if (context_cache.context == context_string &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 context_cache.scontext == c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 context_cache.scontext = '\000';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 else if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
551 Lisp_Object stringtermobj =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
552 syntax_match (syntax_cache.current_syntax_table, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 Emchar stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 if (CHARP (stringtermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 stringterm = XCHAR (stringtermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 stringterm = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 context_cache.context = context_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 context_cache.scontext = stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
565
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
566 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
567 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
568 if (context_cache.context == context_generic_comment)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
569 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
570 context_cache.context = context_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
571 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
572 else if (context_cache.context == context_none)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
573 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
574 context_cache.context = context_generic_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
575 context_cache.ccontext = ccontext_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
576 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
577 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
578 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
579
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
580 case Sstring_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
581 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
582 if (context_cache.context == context_generic_string)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
583 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
584 context_cache.context = context_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
585 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
586 else if (context_cache.context == context_none)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
587 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
588 context_cache.context = context_generic_string;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
589 context_cache.ccontext = ccontext_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
590 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
591 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
592 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
593
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 ;
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 /* That takes care of the characters with manifest syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 Now we've got to hack multi-char sequences that start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 and end block comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
602 if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 SYNTAX_SECOND_CHAR_START) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 context_cache.context == context_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 context_cache.ccontext == ccontext_start1 &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
606 SYNTAX_CODES_START_P (prev_syncode, syncode) /* the two chars match */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 context_cache.ccontext = ccontext_start2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
610 context_cache.style = SYNTAX_START_STYLE (prev_syncode, syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
613 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 SYNTAX_FIRST_CHAR_START) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 context_cache.context == context_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (context_cache.ccontext == ccontext_none ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 context_cache.ccontext == ccontext_start1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 context_cache.ccontext = ccontext_start1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 context_cache.style = comment_style_none; /* should be this already*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
622 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 SYNTAX_SECOND_CHAR_END) &&
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
624 context_cache.context ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
625 (enum syntactic_context) context_block_comment &&
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
626 context_cache.ccontext ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
627 (enum block_comment_context) ccontext_end1 &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
628 SYNTAX_CODES_END_P (prev_syncode, syncode) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 /* the two chars match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 context_cache.style ==
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
631 SYNTAX_END_STYLE (prev_syncode, syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 )
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 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
638 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 SYNTAX_FIRST_CHAR_END) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 context_cache.context == context_block_comment &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
641 context_cache.style == SINGLE_SYNTAX_STYLE (syncode) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (context_cache.ccontext == ccontext_start2 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 context_cache.ccontext == ccontext_end1))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
644 /* #### is it right to check for end1 here??
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
645 yes, because this might be a repetition of the first char
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
646 of a comment-end sequence. ie, '/xxx foo xxx/' or
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
647 '/xxx foo x/', where 'x' = '*' -- mct */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 context_cache.ccontext = ccontext_end1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 }
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 else if (context_cache.ccontext == ccontext_start1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 if (context_cache.context != context_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 else if (context_cache.ccontext == ccontext_end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 if (context_cache.context != context_block_comment) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 context_cache.ccontext = ccontext_start2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 if (context_cache.ccontext == ccontext_start2 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 context_cache.context = context_block_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 else if (context_cache.ccontext == ccontext_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 context_cache.context == context_block_comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 }
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 context_cache.needs_its_head_reexamined = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 }
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 context_to_symbol (enum syntactic_context context)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 switch (context)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
686 case context_none: return Qnil;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
687 case context_string: return Qstring;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
688 case context_comment: return Qcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
689 case context_block_comment: return Qblock_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
690 case context_generic_comment: return Qblock_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
691 case context_generic_string: return Qstring;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 default: abort (); return Qnil; /* suppress compiler warning */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 }
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 DEFUN ("buffer-syntactic-context", Fbuffer_syntactic_context, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 Return the syntactic context of BUFFER at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 If BUFFER is nil or omitted, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 The returned value is one of the following symbols:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 nil ; meaning no special interpretation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 string ; meaning point is within a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 comment ; meaning point is within a line comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 block-comment ; meaning point is within a block comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 See also the function `buffer-syntactic-context-depth', which returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 the current nesting-depth within all parenthesis-syntax delimiters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 and the function `syntactically-sectionize', which will map a function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 over each syntactic context in a region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 find_context (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 return context_to_symbol (context_cache.context);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 }
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 DEFUN ("buffer-syntactic-context-depth", Fbuffer_syntactic_context_depth,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 Return the depth within all parenthesis-syntax delimiters at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 If BUFFER is nil or omitted, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 find_context (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 return make_int (context_cache.depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 }
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 DEFUN ("syntactically-sectionize", Fsyntactically_sectionize, 3, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 Call FUNCTION for each contiguous syntactic context in the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 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
739 region, a symbol representing the syntactic context, and the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 depth (as returned by the functions `buffer-syntactic-context' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 `buffer-syntactic-context-depth'). When this function is called, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 current buffer will be set to BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 (function, start, end, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
749 Charbpos s, pt, e;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 int edepth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 enum syntactic_context this_context;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 Lisp_Object extent = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 get_buffer_range_char (buf, start, end, &s, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 pt = s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 find_context (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 GCPRO1 (extent);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 while (pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
764 Charbpos estart, eend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 /* skip over "blank" areas, and bug out at end-of-buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 while (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 pt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 if (pt >= e) goto DONE_LABEL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 find_context (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 /* 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
773 this_context = context_cache.context;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 estart = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 /* Minor kludge: consider the comment-start character(s) a part of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 the comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 if (this_context == context_block_comment &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 context_cache.ccontext == ccontext_start2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 estart -= 2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
782 else if (this_context == context_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
783 || this_context == context_generic_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
784 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 estart -= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 edepth = context_cache.depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 while (context_cache.context == this_context && pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 pt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 find_context (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 }
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 eend = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 /* Minor kludge: consider the character which terminated the comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 a part of the comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 if ((this_context == context_block_comment ||
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
800 this_context == context_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
801 || this_context == context_generic_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
802 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 && pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 eend++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 if (estart == eend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 /* Make sure not to pass in values that are outside the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 actual bounds of this function. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 call4_in_buffer (buf, function, make_int (max (s, estart)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 make_int (eend == e ? e : eend - 1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 context_to_symbol (this_context),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 make_int (edepth));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 DONE_LABEL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 }
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 syms_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
823 DEFSYMBOL (Qcomment);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
824 DEFSYMBOL (Qblock_comment);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
825 DEFSYMBOL (Qbeginning_of_defun);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 DEFSUBR (Fbuffer_syntactic_context);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 DEFSUBR (Fbuffer_syntactic_context_depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 DEFSUBR (Fsyntactically_sectionize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 reinit_vars_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 xzero (context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 xzero (bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 }
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 vars_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 reinit_vars_of_font_lock ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 }