annotate src/syntax.c @ 867:804517e16990

[xemacs-hg @ 2002-06-05 09:54:39 by ben] Textual renaming: text/char names abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, charset.h, chartab.c, chartab.h, cmds.c, console-gtk.h, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console-x.h, console.h, data.c, device-msw.c, device-x.c, dialog-msw.c, dired-msw.c, dired.c, doc.c, doprnt.c, editfns.c, eldap.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-unixoid.c, events.c, events.h, file-coding.c, file-coding.h, fileio.c, filelock.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, glyphs-eimage.c, glyphs-msw.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-x.c, gui-x.h, gui.c, gui.h, hpplay.c, indent.c, insdel.c, insdel.h, intl-win32.c, keymap.c, line-number.c, line-number.h, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, md5.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, ndir.h, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-tty.c, objects-x.c, objects.c, objects.h, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, procimpl.h, realpath.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, search.c, select-common.h, select-gtk.c, select-x.c, sound.h, symbols.c, syntax.c, syntax.h, sysdep.c, sysdep.h, sysdir.h, sysfile.h, sysproc.h, syspwd.h, systime.h, syswindows.h, termcap.c, tests.c, text.c, text.h, toolbar-common.c, tooltalk.c, ui-gtk.c, unexnt.c, unicode.c, win32.c: Text/char naming rationalization. [a] distinguish between "charptr" when it refers to operations on the pointer itself and when it refers to operations on text; and [b] use consistent naming for everything referring to internal format, i.e. Itext == text in internal format Ibyte == a byte in such text Ichar == a char as represented in internal character format thus e.g. set_charptr_emchar -> set_itext_ichar The pre and post tags on either side of this change are: pre-internal-format-textual-renaming post-internal-format-textual-renaming See the Internals Manual for details of exactly how this was done, how to handle the change in your workspace, etc.
author ben
date Wed, 05 Jun 2002 09:58:45 +0000
parents 6728e641994e
children 79c6ff3eef26
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 /* XEmacs routines to deal with syntax tables; also word and list parsing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985-1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
4 Copyright (C) 2001, 2002 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: FSF 19.28. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* This file has been Mule-ized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "syntax.h"
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
32 #include "extents.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 /* Here is a comment from Ken'ichi HANDA <handa@etl.go.jp>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 explaining the purpose of the Sextword syntax category:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 Japanese words are not separated by spaces, which makes finding word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 boundaries very difficult. Theoretically it's impossible without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 using natural language processing techniques. But, by defining
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 pseudo-words as below (much simplified for letting you understand it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 easily) for Japanese, we can have a convenient forward-word function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 for Japanese.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 A Japanese word is a sequence of characters that consists of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 zero or more Kanji characters followed by zero or more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Hiragana characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Then, the problem is that now we can't say that a sequence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 word-constituents makes up a WORD. For instance, both Hiragana "A"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 and Kanji "KAN" are word-constituents but the sequence of these two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 letters can't be a single word.
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 So, we introduced Sextword for Japanese letters. A character of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 Sextword is a word-constituent but a word boundary may exist between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 two such characters. */
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 /* Mule 2.4 doesn't seem to have Sextword - I'm removing it -- mrb */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 /* Recovered by tomo */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
60 #define ST_COMMENT_STYLE 0x101
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
61 #define ST_STRING_STYLE 0x102
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
62
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
63 Lisp_Object Qsyntax_table;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
64 int lookup_syntax_properties;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
65
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 Lisp_Object Qsyntax_table_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 int words_include_escapes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 int parse_sexp_ignore_comments;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 /* The following two variables are provided to tell additional information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 to the regex routines. We do it this way rather than change the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 arguments to re_search_2() in an attempt to maintain some call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 compatibility with other versions of the regex code. */
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 /* Tell the regex routines not to QUIT. Normally there is a QUIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 each iteration in re_search_2(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 int no_quit_in_re_search;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
81 /* The standard syntax table is stored where it will automatically
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
82 be used in all new buffers. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 Lisp_Object Vstandard_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 Lisp_Object Vsyntax_designator_chars_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
87 Lisp_Object Vtemp_table_for_use_updating_syntax_tables;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
88
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
89 static void syntax_cache_table_was_changed (struct buffer *buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
90
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 /* This is the internal form of the parse state used in parse-partial-sexp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 struct lisp_parse_state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 int depth; /* Depth at end of parsing */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
96 Ichar instring; /* -1 if not within string, else desired terminator */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 int incomment; /* Nonzero if within a comment at end of parsing */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
98 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 int quoted; /* Nonzero if just after an escape char at end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 parsing */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
101 Charbpos thislevelstart;/* Char number of most recent start-of-expression
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 at current level */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
103 Charbpos prevlevelstart;/* Char number of start of containing expression */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
104 Charbpos location; /* Char number at which parsing stopped */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 int mindepth; /* Minimum depth seen while scanning */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
106 Charbpos comstr_start;/* Position just after last comment/string starter */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
107 Lisp_Object levelstarts;/* Char numbers of starts-of-expression
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
108 of levels (starting from outermost). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 /* These variables are a cache for finding the start of a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 find_start_pos is the place for which the defun start was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 find_start_value is the defun start position found for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 find_start_buffer is the buffer it was found in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 find_start_begv is the BEGV value when it was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 find_start_modiff is the value of MODIFF when it was found. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
118 static Charbpos find_start_pos;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
119 static Charbpos find_start_value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 static struct buffer *find_start_buffer;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
121 static Charbpos find_start_begv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 static int find_start_modiff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 /* Find a defun-start that is the last one before POS (or nearly the last).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 We record what we find, so that another call in the same area
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 can return the same value right away. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
128 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
129 find_defun_start (struct buffer *buf, Charbpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
131 Charbpos tem;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
132 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
133
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 /* Use previous finding, if it's valid and applies to this inquiry. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 if (buf == find_start_buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 /* Reuse the defun-start even if POS is a little farther on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 POS might be in the next defun, but that's ok.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 Our value may not be the best possible, but will still be usable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 && pos <= find_start_pos + 1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 && pos >= find_start_value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 && BUF_BEGV (buf) == find_start_begv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 && BUF_MODIFF (buf) == find_start_modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 return find_start_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 /* Back up to start of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 tem = find_next_newline (buf, pos, -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
148 scache = setup_buffer_syntax_cache (buf, tem, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 while (tem > BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
151 UPDATE_SYNTAX_CACHE_BACKWARD (scache, tem);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
152
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 /* Open-paren at start of line means we found our defun-start. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
154 if (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, tem)) == Sopen)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 /* Move to beg of previous line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 tem = find_next_newline (buf, tem, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 /* Record what we found, for the next try. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 find_start_value = tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 find_start_buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 find_start_modiff = BUF_MODIFF (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 find_start_begv = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 find_start_pos = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 return find_start_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
171 Return t if OBJECT is a syntax table.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 Any vector of 256 elements will do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
174 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
176 return (CHAR_TABLEP (object)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
177 && XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_SYNTAX)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 check_syntax_table (Lisp_Object obj, Lisp_Object default_)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 if (NILP (obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 obj = default_;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 while (NILP (Fsyntax_table_p (obj)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 obj = wrong_type_argument (Qsyntax_table_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 return obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 Return the current syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 This is the one specified by the current buffer, or by BUFFER if it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 is non-nil.
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 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 return decode_buffer (buffer, 0)->syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
201 #ifdef DEBUG_XEMACS
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
202
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
203 DEFUN ("mirror-syntax-table", Fmirror_syntax_table, 0, 1, 0, /*
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
204 Return the current mirror syntax table, for debugging purposes.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
205 This is the one specified by the current buffer, or by BUFFER if it
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
206 is non-nil.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
207 */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
208 (buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
209 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
210 return decode_buffer (buffer, 0)->mirror_syntax_table;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
211 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
212
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
213 DEFUN ("syntax-cache-info", Fsyntax_cache_info, 0, 1, 0, /*
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
214 Return info about the syntax cache in BUFFER.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
215 BUFFER defaults to the current buffer if nil.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
216 */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
217 (buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
218 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
219 struct buffer *buf = decode_buffer (buffer, 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
220 struct syntax_cache *cache = buf->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
221 return list4 (cache->start, cache->end, make_int (cache->prev_change),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
222 make_int (cache->next_change));
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
223 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
224
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
225 #endif /* DEBUG_XEMACS */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
226
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 Return the standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 This is the one used for new buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 return Vstandard_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 }
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 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
237 Return a new syntax table which is a copy of SYNTAX-TABLE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
238 SYNTAX-TABLE defaults to the standard syntax table.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
240 (syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 if (NILP (Vstandard_syntax_table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 return Fmake_char_table (Qsyntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
245 syntax_table = check_syntax_table (syntax_table, Vstandard_syntax_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
246 return Fcopy_char_table (syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
250 Select SYNTAX-TABLE as the new syntax table for BUFFER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 BUFFER defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
253 (syntax_table, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 struct buffer *buf = decode_buffer (buffer, 0);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
256 syntax_table = check_syntax_table (syntax_table, Qnil);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
257 buf->syntax_table = syntax_table;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
258 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
259 syntax_cache_table_was_changed (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 /* Indicate that this buffer now has a specified syntax table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
262 return syntax_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
265
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
266 static void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
267 init_syntax_cache (struct syntax_cache *cache, Lisp_Object object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
268 struct buffer *buffer, int infinite)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
269 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
270 xzero (*cache);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
271 cache->object = object;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
272 cache->buffer = buffer;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
273 cache->no_syntax_table_prop = 1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
274 cache->current_syntax_table =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
275 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
276 cache->start = Qnil;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
277 cache->end = Qnil;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
278 if (infinite)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
279 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
280 cache->prev_change = EMACS_INT_MIN;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
281 cache->next_change = EMACS_INT_MAX;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
282 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
283 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
284 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
285 cache->prev_change = -1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
286 cache->next_change = -1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
287 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
288 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
289
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
290 struct syntax_cache *
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
291 setup_syntax_cache (struct syntax_cache *cache, Lisp_Object object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
292 struct buffer *buffer, Charxpos from, int count)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
293 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
294 if (BUFFERP (object))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
295 cache = XBUFFER (object)->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
296 if (!lookup_syntax_properties)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
297 init_syntax_cache (cache, object, buffer, 1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
298 else if (!BUFFERP (object))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
299 init_syntax_cache (cache, object, buffer, 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
300 if (lookup_syntax_properties)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
301 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
302 if (count <= 0)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
303 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
304 from--;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
305 from = buffer_or_string_clip_to_accessible_byte (cache->object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
306 from);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
307 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
308 if (!(from >= cache->prev_change && from < cache->next_change))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
309 update_syntax_cache (cache, from, count);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
310 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
311 return cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
312 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
313
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
314 struct syntax_cache *
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
315 setup_buffer_syntax_cache (struct buffer *buffer, Charxpos from, int count)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
316 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
317 return setup_syntax_cache (NULL, wrap_buffer (buffer), buffer, from, count);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
318 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
319
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
320 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
321 mark_buffer_syntax_cache (struct buffer *buf)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
322 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
323 struct syntax_cache *cache = buf->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
324 if (!cache) /* Vbuffer_defaults and such don't have caches */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
325 return;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
326 mark_object (cache->object);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
327 if (cache->buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
328 mark_object (wrap_buffer (cache->buffer));
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
329 mark_object (cache->current_syntax_table);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
330 mark_object (cache->start);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
331 mark_object (cache->end);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
332 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
333
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
334 static void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
335 reset_buffer_cache_range (struct syntax_cache *cache, Lisp_Object buffer)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
336 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
337 Fset_marker (cache->start, make_int (1), buffer);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
338 Fset_marker (cache->end, make_int (1), buffer);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
339 Fset_marker_insertion_type (cache->start, Qt);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
340 Fset_marker_insertion_type (cache->end, Qnil);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
341 cache->prev_change = -1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
342 cache->next_change = -1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
343 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
344
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
345 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
346 init_buffer_syntax_cache (struct buffer *buf)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
347 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
348 struct syntax_cache *cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
349 buf->syntax_cache = xnew_and_zero (struct syntax_cache);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
350 cache = buf->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
351 cache->object = wrap_buffer (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
352 cache->buffer = buf;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
353 cache->no_syntax_table_prop = 1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
354 cache->current_syntax_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
355 cache->start = Fmake_marker ();
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
356 cache->end = Fmake_marker ();
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
357 reset_buffer_cache_range (cache, cache->object);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
358 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
359
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
360 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
361 uninit_buffer_syntax_cache (struct buffer *buf)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
362 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
363 xfree (buf->syntax_cache);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
364 buf->syntax_cache = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
365 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
366
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
367
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
368 static void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
369 syntax_cache_table_was_changed (struct buffer *buf)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
370 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
371 struct syntax_cache *cache = buf->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
372 if (cache->no_syntax_table_prop)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
373 cache->current_syntax_table =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
374 BUFFER_MIRROR_SYNTAX_TABLE (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
375 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
376
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
377 /* The syntax-table property on the range covered by EXTENT may be changing,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
378 either because EXTENT has a syntax-table property and is being attached
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
379 or detached (this includes having its endpoints changed), or because
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
380 the value of EXTENT's syntax-table property is changing. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
381
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
382 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
383 signal_syntax_table_extent_changed (EXTENT extent)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
384 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
385 Lisp_Object buffer = extent_object (extent);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
386 if (BUFFERP (buffer))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
387 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
388 struct syntax_cache *cache = XBUFFER (buffer)->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
389 Bytexpos start = extent_endpoint_byte (extent, 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
390 Bytexpos end = extent_endpoint_byte (extent, 1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
391 Bytexpos start2 = byte_marker_position (cache->start);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
392 Bytexpos end2 = byte_marker_position (cache->end);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
393 /* If the extent is entirely before or entirely after the cache range,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
394 it doesn't overlap. Otherwise, invalidate the range. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
395 if (!(end < start2 || start > end2))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
396 reset_buffer_cache_range (cache, buffer);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
397 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
398 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
399
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
400 /* Extents have been adjusted for insertion or deletion, so we need to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
401 refetch the start and end position of the extent */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
402 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
403 signal_syntax_table_extent_adjust (struct buffer *buf)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
404 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
405 struct syntax_cache *cache = buf->syntax_cache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
406 /* If the cache was invalid before, leave it that way. We only want
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
407 to update the limits of validity when they were actually valid. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
408 if (cache->prev_change < 0)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
409 return;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
410 cache->prev_change = marker_position (cache->start);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
411 cache->next_change = marker_position (cache->end);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
412 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
413
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
414 /*
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
415 Update syntax_cache to an appropriate setting for position POS
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
416
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
417 The sign of COUNT gives the relative position of POS wrt the
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
418 previously valid interval. (not currently used)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
419
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
420 `syntax_cache.*_change' are the next and previous positions at
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
421 which syntax_code and c_s_t will need to be recalculated.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
422
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
423 #### Currently this code uses 'get-char-property', which will
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
424 return the "last smallest" extent at a given position. In cases
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
425 where overlapping extents are defined, this code will simply use
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
426 whatever is returned by get-char-property.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
427
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
428 It might be worth it at some point to merge provided syntax tables
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
429 outward to the current buffer (#### rewrite in English please?!). */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
430
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
431 void
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
432 update_syntax_cache (struct syntax_cache *cache, Charxpos cpos, int count)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
433 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
434 Lisp_Object tmp_table;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
435 Bytexpos pos;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
436 Bytexpos lim;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
437 Bytexpos next, prev;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
438 int at_begin = 0, at_end = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
439
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
440 if (NILP (cache->object))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
441 return;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
442
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
443 pos = buffer_or_string_charxpos_to_bytexpos (cache->object, cpos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
444
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
445 tmp_table = get_char_property (pos, Qsyntax_table, cache->object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
446 EXTENT_AT_AFTER, 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
447 lim = next_single_property_change (pos, Qsyntax_table, cache->object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
448 -1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
449 if (lim < 0)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
450 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
451 next = buffer_or_string_absolute_end_byte (cache->object);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
452 at_begin = 1;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
453 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
454 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
455 next = lim;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
456
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
457 if (pos < buffer_or_string_absolute_end_byte (cache->object))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
458 pos = next_bytexpos (cache->object, pos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
459 lim = previous_single_property_change (pos, Qsyntax_table, cache->object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
460 -1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
461 if (lim < 0)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
462 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
463 prev = buffer_or_string_absolute_begin_byte (cache->object);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
464 at_end = 1;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
465 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
466 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
467 prev = lim;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
468
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
469 cache->prev_change =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
470 buffer_or_string_bytexpos_to_charxpos (cache->object, prev);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
471 cache->next_change =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
472 buffer_or_string_bytexpos_to_charxpos (cache->object, next);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
473
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
474 if (BUFFERP (cache->object))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
475 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
476 /* If we are at the beginning or end of buffer, check to see if there's
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
477 a zero-length `syntax-table' extent there (highly unlikely); if not,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
478 then we can safely make the end closed, so it will take in newly
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
479 inserted text. (If such an extent is inserted, we will be informed
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
480 through signal_syntax_table_extent_changed().) */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
481 Fset_marker (cache->start, make_int (cache->prev_change), cache->object);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
482 Fset_marker_insertion_type
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
483 (cache->start,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
484 at_begin && NILP (extent_at (prev, cache->object, Qsyntax_table,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
485 NULL, EXTENT_AT_AT, 0))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
486 ? Qnil : Qt);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
487 Fset_marker (cache->end, make_int (cache->next_change), cache->object);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
488 Fset_marker_insertion_type
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
489 (cache->end,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
490 at_end && NILP (extent_at (next, cache->object, Qsyntax_table,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
491 NULL, EXTENT_AT_AT, 0))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
492 ? Qt : Qnil);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
493 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
494
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
495 if (!NILP (Fsyntax_table_p (tmp_table)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
496 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
497 cache->use_code = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
498 cache->current_syntax_table =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
499 XCHAR_TABLE (tmp_table)->mirror_table;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
500 cache->no_syntax_table_prop = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
501 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
502 else if (CONSP (tmp_table) && INTP (XCAR (tmp_table)))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
503 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
504 cache->use_code = 1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
505 cache->syntax_code = XINT (XCAR (tmp_table));
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
506 cache->no_syntax_table_prop = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
507 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
508 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
509 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
510 cache->use_code = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
511 cache->no_syntax_table_prop = 1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
512 cache->current_syntax_table =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
513 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
514 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
515 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
516
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 /* Convert a letter which signifies a syntax code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 into the code it signifies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 This is used by modify-syntax-entry, and other things. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
521 const unsigned char syntax_spec_code[0400] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 (char) Swhitespace, 0377, (char) Sstring, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (char) Smath, 0377, 0377, (char) Squote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (char) Sopen, (char) Sclose, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (char) Scomment, 0377, (char) Sendcomment, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
540 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
543 const unsigned char syntax_code_spec[] = " .w_()'\"$\\/<>@!|";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 Return a string of the recognized syntax designator chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 The chars are ordered by their internal syntax codes, which are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 numbered starting at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 return Vsyntax_designator_chars_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
556 Return the syntax code of CHARACTER, described by a character.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
557 For example, if CHARACTER is a word constituent,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
558 the character `?w' is returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 The characters that correspond to various syntax codes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 are listed in the documentation of `modify-syntax-entry'.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
561 Optional second argument SYNTAX-TABLE defaults to the current buffer's
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
564 (character, syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
566 Lisp_Object mirrortab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
568 if (NILP (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
570 character = make_char ('\000');
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 }
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
572 CHECK_CHAR_COERCE_INT (character);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
573 syntax_table = check_syntax_table (syntax_table,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
574 current_buffer->syntax_table);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
575 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
576 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
577 XCHAR (character))]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 enum syntaxcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 *multi_p_out = 1;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
586 /* !!#### get this right */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 return Spunct;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 Lisp_Object
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
593 syntax_match (Lisp_Object syntax_table, Ichar ch)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
595 Lisp_Object code = get_char_table (ch, syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 Lisp_Object code2 = code;
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 if (CONSP (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 code2 = XCAR (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
601 code = get_char_table (ch, Vstandard_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 return CONSP (code) ? XCDR (code) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
607 Return the matching parenthesis of CHARACTER, or nil if none.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
608 Optional second argument SYNTAX-TABLE defaults to the current buffer's
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
611 (character, syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
613 Lisp_Object mirrortab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 int code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
616 CHECK_CHAR_COERCE_INT (character);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
617 syntax_table = check_syntax_table (syntax_table,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
618 current_buffer->syntax_table);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
619 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
620 code = SYNTAX (mirrortab, XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 if (code == Sopen || code == Sclose || code == Sstring)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
622 return syntax_match (syntax_table, XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 /* Return 1 if there is a word boundary between two word-constituent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 characters C1 and C2 if they appear in this order, else return 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 There is no word boundary between two word-constituent ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 #define WORD_BOUNDARY_P(c1, c2) \
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
634 (!(ichar_ascii_p (c1) && ichar_ascii_p (c2)) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 && word_boundary_p (c1, c2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 /* Return the position across COUNT words from FROM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 If that many words cannot be found before the end of the buffer, return 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 COUNT negative means scan backward and stop at word beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
642 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
643 scan_words (struct buffer *buf, Charbpos from, int count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
645 Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
646 Ichar ch0, ch1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 enum syntaxcode code;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
648 struct syntax_cache *scache = setup_buffer_syntax_cache (buf, from, count);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
649
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 /* #### is it really worth it to hand expand both cases? JV */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 while (count > 0)
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 QUIT;
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 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 if (from == limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
660 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 ch0 = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
662 code = SYNTAX_FROM_CACHE (scache, ch0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
664 from++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 if (words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 && (code == Sescape || code == Scharquote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 if (code == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 break;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 QUIT;
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 while (from != limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
676 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 ch1 = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
678 code = SYNTAX_FROM_CACHE (scache, ch1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (!(words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 && (code == Sescape || code == Scharquote)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 if (code != Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 || WORD_BOUNDARY_P (ch0, ch1)
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
684 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 ch0 = ch1;
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
689 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 count--;
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 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 while (1)
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 if (from == limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
704 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 ch1 = BUF_FETCH_CHAR (buf, from - 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
706 code = SYNTAX_FROM_CACHE (scache, ch1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
707 from--;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
708
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 if (words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 && (code == Sescape || code == Scharquote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 if (code == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 break;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 while (from != limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
720 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 ch0 = BUF_FETCH_CHAR (buf, from - 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
722 code = SYNTAX_FROM_CACHE (scache, ch0);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
723
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 if (!(words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 && (code == Sescape || code == Scharquote)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 if (code != Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 || WORD_BOUNDARY_P (ch0, ch1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 ch1 = ch0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
743 DEFUN ("forward-word", Fforward_word, 0, 2, "_p", /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 Move point forward COUNT words (backward if COUNT is negative).
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
745 Normally t is returned, but if an edge of the buffer is reached,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
746 point is left there and nil is returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
748 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
749 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
750 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
751 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
752
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
753 COUNT defaults to 1, and BUFFER defaults to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (count, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
757 Charbpos val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 struct buffer *buf = decode_buffer (buffer, 0);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
759 EMACS_INT n;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
760
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
761 if (NILP (count))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
762 n = 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
763 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
764 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
765 CHECK_INT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
766 n = XINT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
767 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
769 val = scan_words (buf, BUF_PT (buf), n);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
770 if (val)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
772 BUF_SET_PT (buf, val);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
773 return Qt;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
774 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
775 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
776 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
777 BUF_SET_PT (buf, n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 static void scan_sexps_forward (struct buffer *buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 struct lisp_parse_state *,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
784 Charbpos from, Charbpos end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 int targetdepth, int stopbefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 Lisp_Object oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 int commentstop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 static int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
790 find_start_of_comment (struct buffer *buf, Charbpos from, Charbpos stop,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
791 int comstyle)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
793 Ichar c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 enum syntaxcode code;
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 /* Look back, counting the parity of string-quotes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 and recording the comment-starters seen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 When we reach a safe place, assume that's not in a string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 then step the main scan to the earliest comment-starter seen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 an even number of string quotes away from the safe place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 OFROM[I] is position of the earliest comment-starter seen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 which is I+2X quotes from the comment-end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 PARITY is current parity of quotes from the comment end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 int parity = 0;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
806 Ichar my_stringend = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 int string_lossage = 0;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
808 Charbpos comment_end = from;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
809 Charbpos comstart_pos = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 int comstart_parity = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 int styles_match_p = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
812 /* mask to match comment styles against; for ST_COMMENT_STYLE, this
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
813 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
814 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
815 struct syntax_cache *scache = buf->syntax_cache;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 /* At beginning of range to scan, we're outside of strings;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 that determines quote parity to the comment-end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 while (from != stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
821 int syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
822
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 /* Move back and examine a character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 from--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
825 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
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 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
828 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
829 code = SYNTAX_FROM_CODE (syncode);
428
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 /* is this a 1-char comment end sequence? if so, try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 to see if style matches previously extracted mask */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 if (code == Sendcomment)
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 styles_match_p =
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
836 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
428
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 /* or are we looking at a 1-char comment start sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 of the style matching mask? */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
841 else if (code == Scomment)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
843 styles_match_p =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
844 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
847 /* otherwise, is this a 2-char comment end or start sequence? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
848 else if (from > stop)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
849 do
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
850 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
851 /* 2-char comment end sequence? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
852 if (SYNTAX_CODE_END_SECOND_P (syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
853 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
854 int prev_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
855 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
856 prev_syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
857 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
858
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
859 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
860 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
861 code = Sendcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
862 styles_match_p =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
863 SYNTAX_CODES_COMMENT_MASK_END (prev_syncode,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
864 syncode) & mask;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
865 from--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
866 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
867 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
868
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
869 /* Found a comment-end sequence, so skip past the
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
870 check for a comment-start */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
871 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
872 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
873 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
874
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
875 /* 2-char comment start sequence? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
876 if (SYNTAX_CODE_START_SECOND_P (syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
877 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
878 int prev_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
879 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
880 prev_syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
881 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
882
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
883 if (SYNTAX_CODES_START_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
884 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
885 code = Scomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
886 styles_match_p =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
887 SYNTAX_CODES_COMMENT_MASK_START (prev_syncode,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
888 syncode) & mask;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
889 from--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
890 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
891 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
892 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
893 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
894 } while (0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 /* Ignore escaped characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 /* Track parity of quotes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 if (code == Sstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 parity ^= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 if (my_stringend == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 my_stringend = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 /* If we have two kinds of string delimiters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 There's no way to grok this scanning backwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 else if (my_stringend != c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 string_lossage = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
912 if (code == Sstring_fence || code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
913 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
914 parity ^= 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
915 if (my_stringend == 0)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
916 my_stringend =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
917 code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
918 /* If we have two kinds of string delimiters.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
919 There's no way to grok this scanning backwards. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
920 else if (my_stringend != (code == Sstring_fence
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
921 ? ST_STRING_STYLE : ST_COMMENT_STYLE))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
922 string_lossage = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
923 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
924
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 /* Record comment-starters according to that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 quote-parity to the comment-end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 if (code == Scomment && styles_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 comstart_parity = parity;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 comstart_pos = from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 /* If we find another earlier comment-ender,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 any comment-starts earlier than that don't count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (because they go with the earlier comment-ender). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 if (code == Sendcomment && styles_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 /* Assume a defun-start point is outside of strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 if (code == Sopen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 && (from == stop || BUF_FETCH_CHAR (buf, from - 1) == '\n'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 if (comstart_pos == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 from = comment_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 /* If the earliest comment starter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 is followed by uniform paired string quotes or none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 we know it can't be inside a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 since if it were then the comment ender would be inside one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 So it does start a comment. Skip back to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 else if (comstart_parity == 0 && !string_lossage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 from = comstart_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 /* We had two kinds of string delimiters mixed up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 together. Decode this going forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 Scan fwd from the previous comment ender
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 to the one in question; this records where we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 last passed a comment starter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 comment_end - 1, -10000, 0, Qnil, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 if (state.incomment)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
966 from = state.comstr_start;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 /* We can't grok this as a comment; scan it normally. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 from = comment_end;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
970 UPDATE_SYNTAX_CACHE_FORWARD (scache, from - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
975 static Charbpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
976 find_end_of_comment (struct buffer *buf, Charbpos from, Charbpos stop,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
977 int comstyle)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 int c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
980 int prev_code;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
981 /* mask to match comment styles against; for ST_COMMENT_STYLE, this
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
982 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
983 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
984 struct syntax_cache *scache = buf->syntax_cache;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
986 /* This is only called by functions which have already set up the
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
987 syntax_cache and are keeping it up-to-date */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 if (from == stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
994
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
995 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
997
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
998 /* Test for generic comments */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
999 if (comstyle == ST_COMMENT_STYLE)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1000 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1001 if (SYNTAX_FROM_CACHE (scache, c) == Scomment_fence)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1002 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1003 from++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1004 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1005 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1006 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1007 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1008 continue; /* No need to test other comment styles in a
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1009 generic comment */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1010 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1011 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1012
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1013 if (SYNTAX_FROM_CACHE (scache, c) == Sendcomment
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1014 && SYNTAX_CODE_MATCHES_1CHAR_P
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1015 (SYNTAX_CODE_FROM_CACHE (scache, c), mask))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 /* we have encountered a comment end of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 as the comment sequence which began this comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 section */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1019 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1020 from++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1021 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1022 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1023 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1025 prev_code = SYNTAX_CODE_FROM_CACHE (scache, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 from++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1027 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 if (from < stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1029 && SYNTAX_CODES_MATCH_END_P
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1030 (prev_code,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1031 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)),
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1032 mask)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1033
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1034 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 /* we have encountered a comment end of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 as the comment sequence which began this comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 section */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1038 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1039 from++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1040 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1041 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1042 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 /* #### between FSF 19.23 and 19.28 there are some changes to the logic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 in this function (and minor changes to find_start_of_comment(),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 above, which is part of Fforward_comment() in FSF). Attempts to port
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 that logic made this function break, so I'm leaving it out. If anyone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 ever complains about this function not working properly, take a look
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 at those changes. --ben */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1055 DEFUN ("forward-comment", Fforward_comment, 0, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1056 Move forward across up to COUNT comments, or backwards if COUNT is negative.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 Stop scanning if we find something other than a comment or whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 Set point to where scanning stops.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1059 If COUNT comments are found as expected, with nothing except whitespace
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 between them, return t; otherwise return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 Point is set in either case.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1062 COUNT defaults to 1, and BUFFER defaults to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1064 (count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1066 Charbpos from;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1067 Charbpos stop;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1068 Ichar c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 enum syntaxcode code;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1070 int syncode;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1071 EMACS_INT n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 struct buffer *buf = decode_buffer (buffer, 0);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1073 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1074
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1075 if (NILP (count))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1076 n = 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1077 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1078 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1079 CHECK_INT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1080 n = XINT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1081 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 from = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1085 scache = setup_buffer_syntax_cache (buf, from, n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1086 while (n > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 stop = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1093 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1101 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1103 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1104 code = SYNTAX_FROM_CODE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 /* we have encountered a single character comment start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 sequence, and we are ignoring all text inside comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 we must record the comment style this character begins
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 so that later, only a comment end of the same style actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 ends the comment section */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1113 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1114 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1117 else if (code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1118 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1119 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1120 code = Scomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1121 comstyle = ST_COMMENT_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1122 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1123
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 else if (from < stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1125 && SYNTAX_CODE_START_FIRST_P (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1127 int next_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1128 UPDATE_SYNTAX_CACHE_FORWARD (scache, from + 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1129 next_syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1130 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from + 1));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1131
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1132 if (SYNTAX_CODES_START_P (syncode, next_syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1133 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1134 /* we have encountered a 2char comment start sequence and we
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1135 are ignoring all text inside comments. we must record
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1136 the comment style this sequence begins so that later,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1137 only a comment end of the same style actually ends
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1138 the comment section */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1139 code = Scomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1140 comstyle =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1141 SYNTAX_CODES_COMMENT_MASK_START (syncode, next_syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1142 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1143 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1144 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1149 Charbpos newfrom = find_end_of_comment (buf, from, stop,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1150 comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 /* we stopped because from==stop */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 BUF_SET_PT (buf, stop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 /* We have skipped one comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 else if (code != Swhitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 && code != Sendcomment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 && code != Scomment )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 BUF_SET_PT (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 /* End of comment reached */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1173 n--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1176 while (n < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 stop = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1183 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1193 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1194 code = SYNTAX_FROM_CODE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 /* we have found a single char end comment. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 the comment style encountered so that later, we can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 only the proper comment begin sequence of the same style */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1201 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1202 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1203 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1204
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1205 else if (code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1206 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1207 code = Sendcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1208 comstyle = ST_COMMENT_STYLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 else if (from > stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1212 && SYNTAX_CODE_END_SECOND_P (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1214 int prev_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1215 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1216 prev_syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1217 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1218 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1219 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1220 /* We must record the comment style encountered so that
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1221 later, we can match only the proper comment begin
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1222 sequence of the same style. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1223 code = Sendcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1224 comstyle = SYNTAX_CODES_COMMENT_MASK_END
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1225 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1226 from--;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1227 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1232 from = find_start_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 else if (code != Swhitespace
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1237 && code != Scomment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1238 && code != Sendcomment)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 BUF_SET_PT (buf, from + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1245 n++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 BUF_SET_PT (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 Lisp_Object
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1254 scan_lists (struct buffer *buf, Charbpos from, int count, int depth,
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1255 int sexpflag, int noerror)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1257 Charbpos stop;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1258 Ichar c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 int quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 int mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 enum syntaxcode code;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1262 int syncode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 int min_depth = depth; /* Err out if depth gets less than this. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1264 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1265
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 if (depth > 0) min_depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1268 scache = setup_buffer_syntax_cache (buf, from, count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 while (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 stop = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1276 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1278 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1280 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1281 code = SYNTAX_FROM_CODE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 /* a 1-char comment start sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 if (code == Scomment && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1287 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) ==
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1288 SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 /* else, a 2-char comment start sequence? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 else if (from < stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1293 && SYNTAX_CODE_START_FIRST_P (syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1296 int next_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1297 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1298 next_syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1299 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1300
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1301 if (SYNTAX_CODES_START_P (syncode, next_syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1302 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1303 /* we have encountered a comment start sequence and we
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1304 are ignoring all text inside comments. we must record
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1305 the comment style this sequence begins so that later,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1306 only a comment end of the same style actually ends
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1307 the comment section */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1308 code = Scomment;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1309 comstyle = SYNTAX_CODES_COMMENT_MASK_START
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1310 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1311 from++;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1312 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1314 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1316 if (SYNTAX_CODE_PREFIX (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 switch (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 /* treat following character as a word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 if (depth || !sexpflag) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 /* This word counts as a sexp; return at end of it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1332 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1333 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1351 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1352 comstyle = ST_COMMENT_STYLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 if (!parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 break;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1356 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1358 Charbpos newfrom =
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1359 find_end_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 /* we stopped because from == stop in search forward */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 from = stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 if (depth == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 if (!sexpflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 if (from != stop && c == BUF_FETCH_CHAR (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 if (mathexit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 goto close1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 mathexit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 if (!++depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 close1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 if (!--depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 if (depth < min_depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1393 if (noerror)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 return Qnil;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1395 syntax_error ("Containing expression ends prematurely",
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1396 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1400 case Sstring_fence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1403 Ichar stringterm;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1404
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1405 if (code != Sstring_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1406 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1407 /* XEmacs change: call syntax_match on character */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1408 Ichar ch = BUF_FETCH_CHAR (buf, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1409 Lisp_Object stermobj =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1410 syntax_match (scache->current_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 stringterm = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 stringterm = ch;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1416 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1417 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1418 stringterm = '\0'; /* avoid compiler warnings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 if (from >= stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 goto lose;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1424 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1425 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1426 if (code == Sstring
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1427 ? c == stringterm
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1428 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1430
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1431 switch (SYNTAX_FROM_CACHE (scache, c))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 if (!depth && sexpflag) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 /* Reached end of buffer. Error if within object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 return nil if between */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 if (depth) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 /* End of object reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 stop = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1470 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 from--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1473 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 quoted = char_quoted (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 if (quoted)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1476 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 from--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1478 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1479 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1482 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1483 code = SYNTAX_FROM_CODE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 if (code == Sendcomment && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 /* we have found a single char end comment. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 the comment style encountered so that later, we can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 only the proper comment begin sequence of the same style */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1490 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1491 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 else if (from > stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1495 && SYNTAX_CODE_END_SECOND_P (syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 && !char_quoted (buf, from - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1499 int prev_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1500 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1501 prev_syncode =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1502 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1503
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1504 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1505 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 /* we must record the comment style encountered so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 later, we can match only the proper comment begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 sequence of the same style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 code = Sendcomment;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1510 comstyle = SYNTAX_CODES_COMMENT_MASK_END
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1511 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1514 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1516 if (SYNTAX_CODE_PREFIX (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1519 switch (quoted ? Sword : code)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 if (depth || !sexpflag) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 /* This word counts as a sexp; count object finished after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 passing it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1528 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 quoted = char_quoted (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 if (quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 if (! (quoted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 || (syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1535 SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1536 from - 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 == Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 || syncode == Ssymbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 || syncode == Squote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 if (!sexpflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 if (from != stop && c == BUF_FETCH_CHAR (buf, from - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 if (mathexit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 goto open2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 mathexit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 if (!++depth) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 open2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 if (!--depth) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 if (depth < min_depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1566 if (noerror)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 return Qnil;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1568 syntax_error ("Containing expression ends prematurely",
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1569 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1573 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1574 comstyle = ST_COMMENT_STYLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 case Sendcomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 if (parse_sexp_ignore_comments)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1577 from = find_start_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1580 case Sstring_fence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1583 Ichar stringterm;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1584
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1585 if (code != Sstring_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1586 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 /* XEmacs change: call syntax_match() on character */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1588 Ichar ch = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1589 Lisp_Object stermobj =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1590 syntax_match (scache->current_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 stringterm = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 stringterm = ch;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1596 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1597 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1598 stringterm = '\0'; /* avoid compiler warnings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 if (from == stop) goto lose;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1603
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1604 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1605 c = BUF_FETCH_CHAR (buf, from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1606
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1607 if ((code == Sstring
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1608 ? c == stringterm
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1609 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1610 && !char_quoted (buf, from - 1))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1611 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1613 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1614
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 if (!depth && sexpflag) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 /* Reached start of buffer. Error if within object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 return nil if between */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 if (depth) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 done2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 return (make_int (from));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 lose:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1638 if (!noerror)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1639 syntax_error ("Unbalanced parentheses", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1644 char_quoted (struct buffer *buf, Charbpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 enum syntaxcode code;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1647 Charbpos beg = BUF_BEGV (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 int quoted = 0;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1649 Charbpos startpos = pos;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1650 struct syntax_cache *scache = buf->syntax_cache;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1651
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1652 while (pos > beg)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1653 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1654 UPDATE_SYNTAX_CACHE_BACKWARD (scache, pos - 1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1655 code = SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, pos - 1));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1657 if (code != Scharquote && code != Sescape)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1658 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1659 pos--;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1660 quoted = !quoted;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1661 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1662
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1663 UPDATE_SYNTAX_CACHE (scache, startpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 return quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 Scan from character number FROM by COUNT lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 Returns the character number of the position thus found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 If DEPTH is nonzero, paren depth begins counting from that value,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 only places where the depth in parentheses becomes zero
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 are candidates for stopping; COUNT such places are counted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 Thus, a positive value for DEPTH means go out levels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 If the beginning or end of (the accessible part of) the buffer is reached
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 and the depth is wrong, an error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 If the depth is right but the count is not used up, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 of in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 If optional arg NOERROR is non-nil, scan-lists will return nil instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 signalling an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1688 (from, count, depth, buffer, noerror))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 struct buffer *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 CHECK_INT (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 CHECK_INT (depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0,
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1698 !NILP (noerror));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 Scan from character number FROM by COUNT balanced expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 If COUNT is negative, scan backwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 Returns the character number of the position thus found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 If the beginning or end of (the accessible part of) the buffer is reached
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 in the middle of a parenthetical grouping, an error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 If the beginning or end is reached between groupings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 but before count is used up, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 of in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 signalling an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1719 (from, count, buffer, noerror))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 CHECK_INT (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1725 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (noerror));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 Move point backward over any number of chars with prefix syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 This includes chars with "quote" or "prefix" syntax (' or p).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 Optional arg BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 struct buffer *buf = decode_buffer (buffer, 0);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1737 Charbpos beg = BUF_BEGV (buf);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1738 Charbpos pos = BUF_PT (buf);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1739 Ichar c = '\0'; /* initialize to avoid compiler warnings */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1740 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1741
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1742 scache = setup_buffer_syntax_cache (buf, pos, -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 while (pos > beg && !char_quoted (buf, pos - 1)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1745 /* Previous statement updates syntax table. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1746 && (SYNTAX_FROM_CACHE (scache, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1747 || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (scache, c))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 BUF_SET_PT (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 /* Parse forward from FROM to END,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 and return a description of the state of the parse at END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 If STOPBEFORE is nonzero, stop at the start of an atom.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 If COMMENTSTOP is nonzero, stop at the start of a comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 scan_sexps_forward (struct buffer *buf, struct lisp_parse_state *stateptr,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1763 Charbpos from, Charbpos end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 int targetdepth, int stopbefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 Lisp_Object oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 int commentstop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 struct level { int last, prev; };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 struct level levelstart[100];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 struct level *curlevel = levelstart;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 struct level *endlevel = levelstart + 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 int depth; /* Paren depth of current scanning location.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 level - levelstart equals this except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 when the depth becomes negative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 int mindepth; /* Lowest DEPTH value seen. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 int start_quoted = 0; /* Nonzero means starting after a char quote */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1780 int boundary_stop = commentstop == -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 Lisp_Object tem;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1782 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1783
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1784 scache = setup_buffer_syntax_cache (buf, from, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 if (NILP (oldstate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 state.instring = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 state.incomment = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 state.comstyle = 0; /* comment style a by default */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1791 state.comstr_start = -1; /* no comment/string seen. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 tem = Fcar (oldstate); /* elt 0, depth */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 if (!NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 depth = XINT (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 tem = Fcar (oldstate); /* elt 3, instring */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1805 state.instring = ( !NILP (tem)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1806 ? ( INTP (tem) ? XINT (tem) : ST_STRING_STYLE)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1807 : -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1809 oldstate = Fcdr (oldstate);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1810 tem = Fcar (oldstate); /* elt 4, incomment */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 state.incomment = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 tem = Fcar (oldstate); /* elt 5, follows-quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 start_quoted = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 /* if the eighth element of the list is nil, we are in comment style
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1818 a; if it is t, we are in comment style b; if it is 'syntax-table,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1819 we are in a generic comment */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 oldstate = Fcdr (oldstate);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1822 tem = Fcar (oldstate); /* elt 7, comment style a/b/fence */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1823 state.comstyle = NILP (tem) ? 0 : ( EQ (tem, Qsyntax_table)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1824 ? ST_COMMENT_STYLE : 1 );
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1825
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1826 oldstate = Fcdr (oldstate); /* elt 8, start of last comment/string */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1827 tem = Fcar (oldstate);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1828 state.comstr_start = NILP (tem) ? -1 : XINT (tem);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1829
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1830 /* elt 9, char numbers of starts-of-expression of levels
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1831 (starting from outermost). */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1832 oldstate = Fcdr (oldstate);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1833 tem = Fcar (oldstate); /* elt 9, intermediate data for
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1834 continuation of parsing (subject
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1835 to change). */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1836 while (!NILP (tem)) /* >= second enclosing sexps. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1837 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1838 curlevel->last = XINT (Fcar (tem));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1839 if (++curlevel == endlevel)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1840 stack_overflow ("Nesting too deep for parser",
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1841 make_int (curlevel - levelstart));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1842 curlevel->prev = -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1843 curlevel->last = -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1844 tem = Fcdr (tem);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1845 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 state.quoted = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 mindepth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 curlevel->prev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 curlevel->last = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 /* Enter the loop at a place appropriate for initial state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 if (state.incomment) goto startincomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 if (state.instring >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 if (start_quoted) goto startquotedinstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 goto startinstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 if (start_quoted) goto startquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 while (from < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1865 Ichar c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1866 int syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1867
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1870 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1871 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1872 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1873 code = SYNTAX_FROM_CODE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 /* record the comment style we have entered so that only the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 comment-ender sequence (or single char) of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 actually terminates the comment section. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1879 if (code == Scomment)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1880 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1881 state.comstyle =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1882 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1883 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1884 state.comstr_start = from - 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1885 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1886
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1887 /* a generic comment delimiter? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1888 else if (code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1889 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1890 state.comstyle = ST_COMMENT_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1891 state.comstr_start = from - 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1892 code = Scomment;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 else if (from < end &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1896 SYNTAX_CODE_START_FIRST_P (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1898 int next_syncode;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1899 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1900 next_syncode =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1901 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1902
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1903 if (SYNTAX_CODES_START_P (syncode, next_syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1904 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 code = Scomment;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1906 state.comstyle = SYNTAX_CODES_COMMENT_MASK_START
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1907 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1908 state.comstr_start = from - 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 from++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1910 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1911 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1914 if (SYNTAX_CODE_PREFIX (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 switch (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 startquoted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 if (from == end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 goto symstarted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 /* treat following character as a word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 symstarted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 while (from < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1934 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1935 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 if (from == end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 goto symdone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 symdone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 state.incomment = 1;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1957 if (commentstop || boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 startincomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1959 if (commentstop == 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 goto done;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1961 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1963 Charbpos newfrom = find_end_of_comment (buf, from, end,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1964 state.comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 /* we terminated search because from == end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 from = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 state.incomment = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 state.comstyle = 0; /* reset the comment style */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1975 if (boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 depth++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 /* curlevel++->last ran into compiler bug on Apollo */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 if (++curlevel == endlevel)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1984 stack_overflow ("Nesting too deep for parser",
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
1985 make_int (curlevel - levelstart));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 curlevel->prev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 curlevel->last = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 if (targetdepth == depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 depth--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 if (depth < mindepth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 mindepth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 if (curlevel != levelstart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 curlevel--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 if (targetdepth == depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 case Sstring:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2002 case Sstring_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2003 state.comstr_start = from - 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 curlevel->last = from - 1;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2006 if (code == Sstring_fence)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2008 state.instring = ST_STRING_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2009 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2010 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2011 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2012 /* XEmacs change: call syntax_match() on character */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
2013 Ichar ch = BUF_FETCH_CHAR (buf, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2014 Lisp_Object stermobj =
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2015 syntax_match (scache->current_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 state.instring = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 state.instring = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2022 if (boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 startinstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2026 enum syntaxcode temp_code;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2027
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 if (from >= end) goto done;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2029
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2030 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2031 c = BUF_FETCH_CHAR (buf, from);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2032 temp_code = SYNTAX_FROM_CACHE (scache, c);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2033
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2034 if (
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2035 state.instring != ST_STRING_STYLE &&
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2036 temp_code == Sstring &&
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2037 c == state.instring) break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2038
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2039 switch (temp_code)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2041 case Sstring_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2042 if (state.instring == ST_STRING_STYLE)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2043 goto string_end;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2044 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 startquotedinstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 if (from >= end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2058 string_end:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 state.instring = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 from++;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2062 if (boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 case Swhitespace:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 case Spunct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 case Sendcomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2072 case Scomment_fence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 case Sinherit:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 case Smax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 stop: /* Here if stopping before start of sexp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 from--; /* We have just fetched the char that starts it; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 goto done; /* but return the position before it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 endquoted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 state.quoted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 state.depth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 state.mindepth = mindepth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 state.thislevelstart = curlevel->prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 state.prevlevelstart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 state.location = from;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2093 state.levelstarts = Qnil;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2094 while (--curlevel >= levelstart)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2095 state.levelstarts = Fcons (make_int (curlevel->last),
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2096 state.levelstarts);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 *stateptr = state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 Parsing stops at TO or when certain criteria are met;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 point is set to where parsing stops.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2105 If fifth arg OLDSTATE is omitted or nil,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 parsing assumes that FROM is the beginning of a function.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2107 Value is a list of nine elements describing final state of parsing:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 0. depth in parens.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 1. character address of start of innermost containing list; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 2. character address of start of last complete sexp terminated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 3. non-nil if inside a string.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2112 (It is the character that will terminate the string,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2113 or t if the string should be terminated by an explicit
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2114 `syntax-table' property.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 4. t if inside a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 5. t if following a quote character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 6. the minimum paren-depth encountered during this scan.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2118 7. nil if in comment style a, or not in a comment; t if in comment style b;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2119 `syntax-table' if given by an explicit `syntax-table' property.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2120 8. character address of start of last comment or string; nil if none.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2121 9. Intermediate data for continuation of parsing (subject to change).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 in parentheses becomes equal to TARGETDEPTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 Fourth arg STOPBEFORE non-nil means stop when come to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 any character that starts a sexp.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2126 Fifth arg OLDSTATE is a nine-element list like what this function returns.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 It is used to initialize the state of the parse. Its second and third
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 elements are ignored.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2129 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. If it
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2130 is `syntax-table', stop after the start of a comment or a string, or after
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2131 the end of a comment or string.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2132 Seventh arg BUFFER specifies the buffer to do the parsing in, and defaults
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2133 to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 int target;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
2139 Charbpos start, end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 Lisp_Object val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 if (!NILP (targetdepth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 CHECK_INT (targetdepth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 target = XINT (targetdepth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 target = -100000; /* We won't reach this depth */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 get_buffer_range_char (buf, from, to, &start, &end, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 scan_sexps_forward (buf, &state, start, end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 target, !NILP (stopbefore), oldstate,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2154 (NILP (commentstop)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2155 ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 BUF_SET_PT (buf, state.location);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 /* reverse order */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 val = Qnil;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2160 val = Fcons (state.levelstarts, val);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2161 val = Fcons ((state.incomment || (state.instring >= 0))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2162 ? make_int (state.comstr_start) : Qnil, val);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2163 val = Fcons (state.comstyle ? (state.comstyle == ST_COMMENT_STYLE
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2164 ? Qsyntax_table : Qt) : Qnil, val);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 val = Fcons (make_int (state.mindepth), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 val = Fcons (state.quoted ? Qt : Qnil, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 val = Fcons (state.incomment ? Qt : Qnil, val);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2168 val = Fcons (state.instring < 0
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2169 ? Qnil
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2170 : (state.instring == ST_STRING_STYLE
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2171 ? Qt : make_int (state.instring)), val);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2172 val = Fcons (state.thislevelstart < 0 ? Qnil :
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2173 make_int (state.thislevelstart), val);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2174 val = Fcons (state.prevlevelstart < 0 ? Qnil :
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2175 make_int (state.prevlevelstart), val);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 val = Fcons (make_int (state.depth), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 /* Updating of the mirror syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 Each syntax table has a corresponding mirror table in it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 Whenever we make a change to a syntax table, we call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 update_syntax_table() on it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 #### We really only need to map over the changed range.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 If we change the standard syntax table, we need to map over
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 all tables because any of them could be inheriting from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 When `set-syntax-table' is called, we set the buffer's mirror
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 syntax table as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2198 static int
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2199 copy_to_mirrortab (struct chartab_range *range, Lisp_Object table,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2200 Lisp_Object val, void *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2202 Lisp_Object mirrortab = VOID_TO_LISP (arg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 if (CONSP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 val = XCAR (val);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2206 if (SYNTAX_FROM_CODE (XINT (val)) != Sinherit)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2207 put_char_table (mirrortab, range, val);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2208 return 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2209 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2210
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2211 struct cinap
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2212 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2213 Lisp_Object mirrortab;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2214 Lisp_Object bogus;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2215 };
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2216
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2217 static int
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2218 copy_if_not_already_present (struct chartab_range *range, Lisp_Object table,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2219 Lisp_Object val, void *arg)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2220 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2221 struct cinap *a = (struct cinap *) arg;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2223 if (CONSP (val))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2224 val = XCAR (val);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2225 if (SYNTAX_FROM_CODE (XINT (val)) != Sinherit)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2226 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2227 Lisp_Object existing =
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2228 get_range_char_table (range, a->mirrortab, a->bogus);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2229 if (NILP (existing))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2230 /* nothing at all */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2231 put_char_table (a->mirrortab, range, val);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2232 else if (!EQ (existing, a->bogus))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2233 /* full */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2234 ;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2235 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2236 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2237 Freset_char_table (Vtemp_table_for_use_updating_syntax_tables);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2238 copy_char_table_range
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2239 (a->mirrortab,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2240 Vtemp_table_for_use_updating_syntax_tables,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2241 range);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2242 put_char_table (a->mirrortab, range, val);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2243 copy_char_table_range
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2244 (Vtemp_table_for_use_updating_syntax_tables,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2245 a->mirrortab, range);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2246 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2248
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 static void
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2253 update_just_this_syntax_table (Lisp_Object table)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 struct chartab_range range;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2256 Lisp_Object mirrortab = XCHAR_TABLE (table)->mirror_table;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2257
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2258 range.type = CHARTAB_RANGE_ALL;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2259 Freset_char_table (mirrortab);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2260 /* First, copy the tables values other than inherit into the mirror
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2261 table. Then, for tables other than the standard syntax table, map
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2262 over the standard table, copying values into the mirror table only if
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2263 entries don't already exist in that table. (The copying step requires
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2264 another mapping.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2265 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2267 map_char_table (table, &range, copy_to_mirrortab, LISP_TO_VOID (mirrortab));
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2268 /* second clause catches bootstrapping problems when initializing the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2269 standard syntax table */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2270 if (!EQ (table, Vstandard_syntax_table) && !NILP (Vstandard_syntax_table))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2271 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2272 struct cinap cinap;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2273 struct gcpro gcpro1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2274 cinap.mirrortab = mirrortab;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2275 /* Something that won't be in the table. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2276 cinap.bogus = make_float (0.0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2277 GCPRO1 (cinap.bogus);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2278 map_char_table (Vstandard_syntax_table, &range,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2279 copy_if_not_already_present, &cinap);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2280 UNGCPRO;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2281 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2282 /* The resetting made the default be Qnil. Put it back to Spunct. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2283 set_char_table_default (mirrortab, make_int (Spunct));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 /* Called from chartab.c when a change is made to a syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 If this is the standard syntax table, we need to recompute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 *all* syntax tables (yuck). Otherwise we just recompute this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 void
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2292 update_syntax_table (Lisp_Object table)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2294 if (EQ (table, Vstandard_syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 Lisp_Object syntab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 for (syntab = Vall_syntax_tables; !NILP (syntab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 syntab = XCHAR_TABLE (syntab)->next_table)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2300 update_just_this_syntax_table (syntab);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2303 update_just_this_syntax_table (table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 syms_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
2314 DEFSYMBOL (Qsyntax_table_p);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
2315 DEFSYMBOL (Qsyntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 DEFSUBR (Fsyntax_table_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 DEFSUBR (Fsyntax_table);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2319 #ifdef DEBUG_XEMACS
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2320 DEFSUBR (Fmirror_syntax_table);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2321 DEFSUBR (Fsyntax_cache_info);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2322 #endif /* DEBUG_XEMACS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 DEFSUBR (Fstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 DEFSUBR (Fcopy_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 DEFSUBR (Fset_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 DEFSUBR (Fsyntax_designator_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 DEFSUBR (Fchar_syntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 DEFSUBR (Fmatching_paren);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 DEFSUBR (Fforward_word);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 DEFSUBR (Fforward_comment);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 DEFSUBR (Fscan_lists);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 DEFSUBR (Fscan_sexps);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 DEFSUBR (Fbackward_prefix_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 DEFSUBR (Fparse_partial_sexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 vars_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 Non-nil means `forward-sexp', etc., should treat comments as whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 */ );
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2347 parse_sexp_ignore_comments = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2349 DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /*
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2350 Non-nil means `forward-sexp', etc., respect the `syntax-table' property.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2351 This property can be placed on buffers or strings and can be used to explicitly
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2352 specify the syntax table to be used for looking up the syntax of the chars
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2353 having this property, or to directly specify the syntax of the chars.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2354
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2355 The value of this property should be either a syntax table, or a cons
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2356 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2357 syntax code, MATCHCHAR being nil or the character to match (which is
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2358 relevant only when the syntax code is open/close-type).
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2359 */ );
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2360 lookup_syntax_properties = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2361
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 Non-nil means `forward-word', etc., should treat escape chars part of words.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 */ );
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2365 words_include_escapes = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 no_quit_in_re_search = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2371 define_standard_syntax (const char *p, enum syntaxcode syn)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 for (; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 Fput_char_table (make_char (*p), make_int (syn), Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 complex_vars_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
2380 Ichar i;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2381 const char *p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 /* Set this now, so first buffer creation can refer to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 /* Make it nil before calling copy-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 so that copy-syntax-table will know not to try to copy from garbage */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 Vstandard_syntax_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 Vstandard_syntax_table = Fcopy_syntax_table (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 staticpro (&Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2389 Vtemp_table_for_use_updating_syntax_tables = Fmake_char_table (Qgeneric);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2390 staticpro (&Vtemp_table_for_use_updating_syntax_tables);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2391
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 Smax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 staticpro (&Vsyntax_designator_chars_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
2396 set_char_table_default (Vstandard_syntax_table, make_int (Spunct));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 for (i = 0; i <= 32; i++) /* Control 0 plus SPACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 Fput_char_table (make_char (i), make_int (Swhitespace),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 for (i = 127; i <= 159; i++) /* DEL plus Control 1 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 Fput_char_table (make_char (i), make_int (Swhitespace),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 define_standard_syntax ("abcdefghijklmnopqrstuvwxyz"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 "0123456789"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 "$%", Sword);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 define_standard_syntax ("\"", Sstring);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 define_standard_syntax ("\\", Sescape);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 define_standard_syntax ("_-+*/&|<>=", Ssymbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 define_standard_syntax (".,;:?!#@~^'`", Spunct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 for (p = "()[]{}"; *p; p+=2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 Fput_char_table (make_char (p[0]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 Fcons (make_int (Sopen), make_char (p[1])),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 Fput_char_table (make_char (p[1]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 Fcons (make_int (Sclose), make_char (p[0])),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 }