annotate src/syntax.c @ 801:2b676dc88c66

[xemacs-hg @ 2002-04-01 03:58:02 by ben] bug fixes (e.g. ballooning on X windows) Makefile.in.in: Try to make the Makefile notice if its source Makefile.in.in is changed, and regenerate and run itself. Use a bigger default SHEAP_ADJUSTMENT on Cygwin; otherwise you can't compile under Mule if a Lisp file has changed. (can't run temacs) TODO.ben-mule-21-5: update. mule/mule-cmds.el: Hash the result of mswindows-get-language-environment-from-locale, since it's very expensive (and causes huge ballooning of memory under X Windows, since it's called from x-get-resource). cl-extra.el, code-files.el, files.el, simple.el, subr.el, x-faces.el: Create new string-equal-ignore-case, based on built-in compare-strings -- compare strings ignoring case without the need to generate garbage by calling downcase. Use it in equalp and elsewhere. alloc.c, bytecode.c, chartab.c, data.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-unixoid.c, extents.c, file-coding.c, fileio.c, fns.c, glyphs.c, gutter.c, lisp-union.h, lisp.h, mule-charset.c, nt.c, process-unix.c, process.c, specifier.c, symbols.c, sysdep.c, sysdep.h, text.c, toolbar.c: Try to implement GC triggering based on percentage of total memory usage. Not currently activated (percentage set to 0) because not quite working. Add `memory-usage' primitive to return XEmacs' idea of its memory usage. Add primitive compare-strings, compatible with FSF 21.1 -- can compare any part of two strings, optionally ignoring case. Improve qxe() functions in text.c for text comparison. Use RETURN_NOT_REACHED to try to avoid warnings about unreachable code. Add volatile_make_int() to fix warning in unix_send_process().
author ben
date Mon, 01 Apr 2002 03:59:04 +0000
parents 943eaba38521
children 6728e641994e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* 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.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4 Copyright (C) 2001 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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 /* Tell the regex routines which buffer to access for SYNTAX() lookups
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 and the like. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 struct buffer *regex_emacs_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
85 /* In Emacs, this is the string or buffer in which we
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
86 are matching. It is used for looking up syntax properties. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
87 Lisp_Object regex_match_object;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
88
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 Lisp_Object Vstandard_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 Lisp_Object Vsyntax_designator_chars_string;
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 /* 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
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 struct lisp_parse_state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 int depth; /* Depth at end of parsing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Emchar instring; /* -1 if not within string, else desired terminator */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 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
100 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
101 int quoted; /* Nonzero if just after an escape char at end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 parsing */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
103 Charbpos thislevelstart;/* Char number of most recent start-of-expression
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 at current level */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
105 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
106 Charbpos location; /* Char number at which parsing stopped */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 int mindepth; /* Minimum depth seen while scanning */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
108 Charbpos comstr_start; /* Position just after last comment/string starter */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
109 Lisp_Object levelstarts; /* Char numbers of starts-of-expression
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
110 of levels (starting from outermost). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 /* These variables are a cache for finding the start of a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 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
115 find_start_value is the defun start position found for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 find_start_buffer is the buffer it was found in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 find_start_begv is the BEGV value when it was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 find_start_modiff is the value of MODIFF when it was found. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
120 static Charbpos find_start_pos;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
121 static Charbpos find_start_value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 static struct buffer *find_start_buffer;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
123 static Charbpos find_start_begv;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 static int find_start_modiff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 /* 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
127 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
128 can return the same value right away. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
130 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
131 find_defun_start (struct buffer *buf, Charbpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
133 Charbpos tem;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 /* Use previous finding, if it's valid and applies to this inquiry. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 if (buf == find_start_buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 /* Reuse the defun-start even if POS is a little farther on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 POS might be in the next defun, but that's ok.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 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
140 && pos <= find_start_pos + 1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 && pos >= find_start_value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 && BUF_BEGV (buf) == find_start_begv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 && BUF_MODIFF (buf) == find_start_modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 return find_start_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 /* Back up to start of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 tem = find_next_newline (buf, pos, -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
149 SETUP_SYNTAX_CACHE (tem, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 while (tem > BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
152 UPDATE_SYNTAX_CACHE_BACKWARD(tem);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
153
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 /* Open-paren at start of line means we found our defun-start. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
155 if (SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, tem)) == Sopen)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 /* Move to beg of previous line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 tem = find_next_newline (buf, tem, -2);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /* Record what we found, for the next try. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 find_start_value = tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 find_start_buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 find_start_modiff = BUF_MODIFF (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 find_start_begv = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 find_start_pos = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 return find_start_value;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
172 Return t if OBJECT is a syntax table.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 Any vector of 256 elements will do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
175 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
177 return (CHAR_TABLEP (object)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
178 && XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_SYNTAX)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ? Qt : Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 check_syntax_table (Lisp_Object obj, Lisp_Object default_)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 if (NILP (obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 obj = default_;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 while (NILP (Fsyntax_table_p (obj)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 obj = wrong_type_argument (Qsyntax_table_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 return obj;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Return the current syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 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
195 is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 return decode_buffer (buffer, 0)->syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 Return the standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 This is the one used for new buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 return Vstandard_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
212 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
213 SYNTAX-TABLE defaults to the standard syntax table.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
215 (syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 if (NILP (Vstandard_syntax_table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 return Fmake_char_table (Qsyntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
220 syntax_table = check_syntax_table (syntax_table, Vstandard_syntax_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
221 return Fcopy_char_table (syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
225 Select SYNTAX-TABLE as the new syntax table for BUFFER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 BUFFER defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
228 (syntax_table, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 struct buffer *buf = decode_buffer (buffer, 0);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
231 syntax_table = check_syntax_table (syntax_table, Qnil);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
232 buf->syntax_table = syntax_table;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
233 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 /* Indicate that this buffer now has a specified syntax table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
236 return syntax_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
239 /* The current syntax state */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
240 struct syntax_cache syntax_cache;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
241
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
242
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
243 /*
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
244 Update syntax_cache to an appropriate setting for position POS
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
245
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
246 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
247 previously valid interval. (not currently used)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
248
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
249 `syntax_cache.*_change' are the next and previous positions at
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
250 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
251
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
252 #### Currently this code uses 'get-char-property', which will
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
253 return the "last smallest" extent at a given position. In cases
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
254 where overlapping extents are defined, this code will simply use
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
255 whatever is returned by get-char-property.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
256
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
257 It might be worth it at some point to merge provided syntax tables
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
258 outward to the current buffer. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
259
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
260 void
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
261 update_syntax_cache (int pos, int count, int init)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
262 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
263 Lisp_Object tmp_table;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
264
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
265 if (init)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
266 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
267 syntax_cache.prev_change = -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
268 syntax_cache.next_change = -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
269 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
270
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
271 if (pos > syntax_cache.prev_change &&
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
272 pos < syntax_cache.next_change)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
273 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
274 /* do nothing */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
275 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
276 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
277 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
278 if (NILP (syntax_cache.object) || EQ (syntax_cache.object, Qt))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
279 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
280 int get_change_before = pos + 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
281
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
282 tmp_table = Fget_char_property (make_int(pos), Qsyntax_table,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
283 wrap_buffer (syntax_cache.buffer), Qnil);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
284 syntax_cache.next_change =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
285 XINT (Fnext_extent_change (make_int (pos > 0 ? pos : 1),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
286 wrap_buffer (syntax_cache.buffer)));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
287
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
288 if (get_change_before < 1)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
289 get_change_before = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
290 else if (get_change_before > BUF_ZV (syntax_cache.buffer))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
291 get_change_before = BUF_ZV (syntax_cache.buffer);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
292
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
293 syntax_cache.prev_change =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
294 XINT (Fprevious_extent_change (make_int (get_change_before),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
295 wrap_buffer (syntax_cache.buffer)));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
296 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
297 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
298 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
299 int get_change_before = pos + 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
300
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
301 tmp_table = Fget_char_property (make_int(pos), Qsyntax_table,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
302 syntax_cache.object, Qnil);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
303 syntax_cache.next_change =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
304 XINT (Fnext_extent_change (make_int (pos >= 0 ? pos : 0),
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
305 syntax_cache.object));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
306
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
307 if (get_change_before < 0)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
308 get_change_before = 0;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
309 else if (get_change_before > XSTRING_LENGTH(syntax_cache.object))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
310 get_change_before = XSTRING_LENGTH(syntax_cache.object);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
311
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
312 syntax_cache.prev_change =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
313 XINT (Fprevious_extent_change (make_int (pos >= 0 ? pos : 0),
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
314 syntax_cache.object));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
315 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
316
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
317 if (EQ (Fsyntax_table_p (tmp_table), Qt))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
318 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
319 syntax_cache.use_code = 0;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
320 syntax_cache.current_syntax_table =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
321 XCHAR_TABLE (tmp_table)->mirror_table;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
322 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
323 else if (CONSP (tmp_table) && INTP (XCAR (tmp_table)))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
324 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
325 syntax_cache.use_code = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
326 syntax_cache.syntax_code = XINT (XCAR(tmp_table));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
327 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
328 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
329 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
330 syntax_cache.use_code = 0;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
331 syntax_cache.current_syntax_table =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
332 syntax_cache.buffer->mirror_syntax_table;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
333 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
334 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
335 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
336
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 /* Convert a letter which signifies a syntax code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 into the code it signifies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 This is used by modify-syntax-entry, and other things. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
341 const unsigned char syntax_spec_code[0400] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (char) Swhitespace, 0377, (char) Sstring, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (char) Smath, 0377, 0377, (char) Squote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (char) Sopen, (char) Sclose, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (char) Scomment, 0377, (char) Sendcomment, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
360 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
363 const unsigned char syntax_code_spec[] = " .w_()'\"$\\/<>@!|";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 Return a string of the recognized syntax designator chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 The chars are ordered by their internal syntax codes, which are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 numbered starting at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 return Vsyntax_designator_chars_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
376 Return the syntax code of CHARACTER, described by a character.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
377 For example, if CHARACTER is a word constituent,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
378 the character `?w' is returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 The characters that correspond to various syntax codes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 are listed in the documentation of `modify-syntax-entry'.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
381 Optional second argument SYNTAX-TABLE defaults to the current buffer's
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
384 (character, syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
386 Lisp_Char_Table *mirrortab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
388 if (NILP (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
390 character = make_char ('\000');
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 }
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
392 CHECK_CHAR_COERCE_INT (character);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
393 syntax_table = check_syntax_table (syntax_table, current_buffer->syntax_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
394 mirrortab = XCHAR_TABLE (XCHAR_TABLE (syntax_table)->mirror_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
395 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, XCHAR (character))]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 enum syntaxcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 *multi_p_out = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 /* #### get this right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 return Spunct;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
411 syntax_match (Lisp_Object syntax_table, Emchar ch)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
413 Lisp_Object code = XCHAR_TABLE_VALUE_UNSAFE (syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 Lisp_Object code2 = code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 if (CONSP (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 code2 = XCAR (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
419 code = XCHAR_TABLE_VALUE_UNSAFE (Vstandard_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 return CONSP (code) ? XCDR (code) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
425 Return the matching parenthesis of CHARACTER, or nil if none.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
426 Optional second argument SYNTAX-TABLE defaults to the current buffer's
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
429 (character, syntax_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
431 Lisp_Char_Table *mirrortab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 int code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
434 CHECK_CHAR_COERCE_INT (character);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
435 syntax_table = check_syntax_table (syntax_table, current_buffer->syntax_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
436 mirrortab = XCHAR_TABLE (XCHAR_TABLE (syntax_table)->mirror_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
437 code = SYNTAX (mirrortab, XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 if (code == Sopen || code == Sclose || code == Sstring)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
439 return syntax_match (syntax_table, XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 /* Return 1 if there is a word boundary between two word-constituent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 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
448 There is no word boundary between two word-constituent ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 #define WORD_BOUNDARY_P(c1, c2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (!(CHAR_ASCII_P (c1) && CHAR_ASCII_P (c2)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 && word_boundary_p (c1, c2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 extern int word_boundary_p (Emchar c1, Emchar c2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 /* Return the position across COUNT words from FROM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 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
459 COUNT negative means scan backward and stop at word beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
461 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
462 scan_words (struct buffer *buf, Charbpos from, int count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
464 Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 Emchar ch0, ch1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
468 SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, from, count);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
469
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 /* #### is it really worth it to hand expand both cases? JV */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 while (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 if (from == limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
480 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 ch0 = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
482 code = SYNTAX_FROM_CACHE (mirrortab, ch0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
484 from++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 if (words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 && (code == Sescape || code == Scharquote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 if (code == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 while (from != limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
496 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 ch1 = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
498 code = SYNTAX_FROM_CACHE (mirrortab, ch1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 if (!(words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 && (code == Sescape || code == Scharquote)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 if (code != Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 || WORD_BOUNDARY_P (ch0, ch1)
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
504 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 ch0 = ch1;
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
509 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 if (from == limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
524 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 ch1 = BUF_FETCH_CHAR (buf, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
526 code = SYNTAX_FROM_CACHE (mirrortab, ch1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
527 from--;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
528
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 if (words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 && (code == Sescape || code == Scharquote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 if (code == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 while (from != limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
540 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 ch0 = BUF_FETCH_CHAR (buf, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
542 code = SYNTAX_FROM_CACHE (mirrortab, ch0);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
543
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 if (!(words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 && (code == Sescape || code == Scharquote)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 if (code != Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 || WORD_BOUNDARY_P (ch0, ch1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 #endif
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 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 ch1 = ch0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
563 DEFUN ("forward-word", Fforward_word, 0, 2, "_p", /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 Move point forward COUNT words (backward if COUNT is negative).
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
565 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
566 point is left there and nil is returned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
568 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
569 \(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
570 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
571 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 460
diff changeset
572
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
573 COUNT defaults to 1, and BUFFER defaults to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (count, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
577 Charbpos val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 struct buffer *buf = decode_buffer (buffer, 0);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
579 EMACS_INT n;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
580
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
581 if (NILP (count))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
582 n = 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
583 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
584 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
585 CHECK_INT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
586 n = XINT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
587 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
589 val = scan_words (buf, BUF_PT (buf), n);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
590 if (val)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
592 BUF_SET_PT (buf, val);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
593 return Qt;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
594 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
595 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
596 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
597 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
598 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 static void scan_sexps_forward (struct buffer *buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 struct lisp_parse_state *,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
604 Charbpos from, Charbpos end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 int targetdepth, int stopbefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 Lisp_Object oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 int commentstop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 static int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
610 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
611 int comstyle)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 /* Look back, counting the parity of string-quotes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 and recording the comment-starters seen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 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
619 then step the main scan to the earliest comment-starter seen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 an even number of string quotes away from the safe place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 OFROM[I] is position of the earliest comment-starter seen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 which is I+2X quotes from the comment-end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 PARITY is current parity of quotes from the comment end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 int parity = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 Emchar my_stringend = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 int string_lossage = 0;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
628 Charbpos comment_end = from;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
629 Charbpos comstart_pos = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 int comstart_parity = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 int styles_match_p = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
632 /* mask to match comment styles against; for ST_COMMENT_STYLE, this
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
633 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
634 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 /* At beginning of range to scan, we're outside of strings;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 that determines quote parity to the comment-end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 while (from != stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
640 int syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
641
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 /* Move back and examine a character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 from--;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
644 UPDATE_SYNTAX_CACHE_BACKWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
647 code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
648 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 /* is this a 1-char comment end sequence? if so, try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 to see if style matches previously extracted mask */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 styles_match_p =
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
655 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 /* or are we looking at a 1-char comment start sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 of the style matching mask? */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
660 else if (code == Scomment)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
662 styles_match_p =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
663 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
666 /* otherwise, is this a 2-char comment end or start sequence? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
667 else if (from > stop)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
668 do
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
669 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
670 /* 2-char comment end sequence? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
671 if (SYNTAX_CODE_END_SECOND_P (syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
672 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
673 int prev_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
674 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
675 prev_syncode =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
676 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from - 1));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
677
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
678 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
679 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
680 code = Sendcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
681 styles_match_p =
627
a813963500d8 [xemacs-hg @ 2001-07-12 06:29:08 by tuck]
tuck
parents: 563
diff changeset
682 SYNTAX_CODES_COMMENT_MASK_END (prev_syncode, syncode) & mask;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
683 from--;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
684 UPDATE_SYNTAX_CACHE_BACKWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
685 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
686
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
687 /* Found a comment-end sequence, so skip past the
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
688 check for a comment-start */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
689 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
690 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
691 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
692
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
693 /* 2-char comment start sequence? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
694 if (SYNTAX_CODE_START_SECOND_P (syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
695 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
696 int prev_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
697 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
698 prev_syncode =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
699 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from - 1));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
700
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
701 if (SYNTAX_CODES_START_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
702 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
703 code = Scomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
704 styles_match_p =
627
a813963500d8 [xemacs-hg @ 2001-07-12 06:29:08 by tuck]
tuck
parents: 563
diff changeset
705 SYNTAX_CODES_COMMENT_MASK_START (prev_syncode, syncode) & mask;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
706 from--;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
707 UPDATE_SYNTAX_CACHE_BACKWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
708 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
709 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
710 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
711 } while (0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 /* Ignore escaped characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 /* Track parity of quotes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 if (code == Sstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 parity ^= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 if (my_stringend == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 my_stringend = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 /* If we have two kinds of string delimiters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 There's no way to grok this scanning backwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 else if (my_stringend != c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 string_lossage = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
729 if (code == Sstring_fence || code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
730 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
731 parity ^= 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
732 if (my_stringend == 0)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
733 my_stringend =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
734 code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
735 /* If we have two kinds of string delimiters.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
736 There's no way to grok this scanning backwards. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
737 else if (my_stringend != (code == Sstring_fence
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
738 ? ST_STRING_STYLE : ST_COMMENT_STYLE))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
739 string_lossage = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
740 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
741
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 /* Record comment-starters according to that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 quote-parity to the comment-end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 if (code == Scomment && styles_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 comstart_parity = parity;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 comstart_pos = from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 /* If we find another earlier comment-ender,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 any comment-starts earlier than that don't count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 (because they go with the earlier comment-ender). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 if (code == Sendcomment && styles_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 /* Assume a defun-start point is outside of strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 if (code == Sopen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 && (from == stop || BUF_FETCH_CHAR (buf, from - 1) == '\n'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 if (comstart_pos == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 from = comment_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 /* If the earliest comment starter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 is followed by uniform paired string quotes or none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 we know it can't be inside a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 since if it were then the comment ender would be inside one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 So it does start a comment. Skip back to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 else if (comstart_parity == 0 && !string_lossage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 from = comstart_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 /* We had two kinds of string delimiters mixed up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 together. Decode this going forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 Scan fwd from the previous comment ender
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 to the one in question; this records where we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 last passed a comment starter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 comment_end - 1, -10000, 0, Qnil, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 if (state.incomment)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
783 from = state.comstr_start;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 /* We can't grok this as a comment; scan it normally. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 from = comment_end;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
787 UPDATE_SYNTAX_CACHE_FORWARD (from - 1);
428
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 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
792 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
793 find_end_of_comment (struct buffer *buf, Charbpos from, Charbpos stop, int comstyle)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 int c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
796 int prev_code;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
797 /* mask to match comment styles against; for ST_COMMENT_STYLE, this
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
798 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
799 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
801 /* 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
802 syntax_cache and are keeping it up-to-date */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 if (from == stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
809
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
810 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
812
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
813 /* Test for generic comments */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
814 if (comstyle == ST_COMMENT_STYLE)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
815 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
816 if (SYNTAX_FROM_CACHE (mirrortab, c) == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
817 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
818 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
819 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
820 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
821 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
822 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
823 continue; /* No need to test other comment styles in a
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
824 generic comment */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
825 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
826 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
827
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
828 if (SYNTAX_FROM_CACHE (mirrortab, c) == Sendcomment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
829 && SYNTAX_CODE_MATCHES_1CHAR_P
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
830 (SYNTAX_CODE_FROM_CACHE (mirrortab, c), mask))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 /* we have encountered a comment end of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 as the comment sequence which began this comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 section */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
834 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
835 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
836 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
837 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
838 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
840 prev_code = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 from++;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
842 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 if (from < stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
844 && SYNTAX_CODES_MATCH_END_P
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
845 (prev_code,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
846 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)),
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
847 mask)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
848
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
849 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 /* we have encountered a comment end of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 as the comment sequence which began this comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 section */
460
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 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
855 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
856 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
857 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 /* #### 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
864 in this function (and minor changes to find_start_of_comment(),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 above, which is part of Fforward_comment() in FSF). Attempts to port
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 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
867 ever complains about this function not working properly, take a look
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 at those changes. --ben */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
870 DEFUN ("forward-comment", Fforward_comment, 0, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
871 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
872 Stop scanning if we find something other than a comment or whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 Set point to where scanning stops.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
874 If COUNT comments are found as expected, with nothing except whitespace
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 between them, return t; otherwise return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 Point is set in either case.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
877 COUNT defaults to 1, and BUFFER defaults to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
879 (count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
881 Charbpos from;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
882 Charbpos stop;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 enum syntaxcode code;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
885 int syncode;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
886 EMACS_INT n;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
889 if (NILP (count))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
890 n = 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
891 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
892 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
893 CHECK_INT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
894 n = XINT (count);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
895 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 from = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
899 SETUP_SYNTAX_CACHE (from, n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
900 while (n > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 stop = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
907 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 if (char_quoted (buf, from))
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 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
915 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
917 code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
918 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 /* we have encountered a single character comment start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 sequence, and we are ignoring all text inside comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 we must record the comment style this character begins
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 so that later, only a comment end of the same style actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 ends the comment section */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
927 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
928 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
931 else if (code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
932 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
933 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
934 code = Scomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
935 comstyle = ST_COMMENT_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
936 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
937
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 else if (from < stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
939 && SYNTAX_CODE_START_FIRST_P (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
941 int next_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
942 UPDATE_SYNTAX_CACHE_FORWARD (from + 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
943 next_syncode =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
944 SYNTAX_CODE_FROM_CACHE (mirrortab,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
945 BUF_FETCH_CHAR (buf, from + 1));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
946
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
947 if (SYNTAX_CODES_START_P (syncode, next_syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
948 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
949 /* we have encountered a 2char comment start sequence and we
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
950 are ignoring all text inside comments. we must record
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
951 the comment style this sequence begins so that later,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
952 only a comment end of the same style actually ends
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
953 the comment section */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
954 code = Scomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
955 comstyle =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
956 SYNTAX_CODES_COMMENT_MASK_START (syncode, next_syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
957 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
958 from++;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
959 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 }
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 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
964 Charbpos newfrom = find_end_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 /* we stopped because from==stop */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 BUF_SET_PT (buf, stop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 /* We have skipped one comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 else if (code != Swhitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 && code != Sendcomment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 && code != Scomment )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 BUF_SET_PT (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 /* End of comment reached */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
987 n--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
990 while (n < 0)
428
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 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 stop = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
997 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1007 code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1008 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 /* we have found a single char end comment. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 the comment style encountered so that later, we can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 only the proper comment begin sequence of the same style */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1015 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1016 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1017 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1018
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1019 else if (code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1020 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1021 code = Sendcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1022 comstyle = ST_COMMENT_STYLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 else if (from > stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1026 && SYNTAX_CODE_END_SECOND_P (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1028 int prev_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1029 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1030 prev_syncode =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1031 SYNTAX_CODE_FROM_CACHE (mirrortab,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1032 BUF_FETCH_CHAR (buf, from - 1));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1033 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1034 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1035 /* We must record the comment style encountered so that
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1036 later, we can match only the proper comment begin
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1037 sequence of the same style. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1038 code = Sendcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1039 comstyle = SYNTAX_CODES_COMMENT_MASK_END
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1040 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1041 from--;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1047 from = find_start_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 else if (code != Swhitespace
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1052 && code != Scomment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1053 && code != Sendcomment)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 BUF_SET_PT (buf, from + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1060 n++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 BUF_SET_PT (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 Lisp_Object
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1069 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
1070 int sexpflag, int noerror)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1072 Charbpos stop;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 int quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 int mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 enum syntaxcode code;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1077 int syncode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 int min_depth = depth; /* Err out if depth gets less than this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 if (depth > 0) min_depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1082 SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, from, count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 while (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 stop = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1090 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1092 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1094 code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1095 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 /* a 1-char comment start sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 if (code == Scomment && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1101 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) ==
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1102 SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 /* else, a 2-char comment start sequence? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 else if (from < stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1107 && SYNTAX_CODE_START_FIRST_P (syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1110 int next_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1111 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1112 next_syncode =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1113 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1114
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1115 if (SYNTAX_CODES_START_P (syncode, next_syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1116 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 /* we have encountered a comment start sequence and we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 are ignoring all text inside comments. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 the comment style this sequence begins so that later,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 only a comment end of the same style actually ends
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 the comment section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 code = Scomment;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1123 comstyle = SYNTAX_CODES_COMMENT_MASK_START
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1124 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 from++;
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 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1128 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1130 if (SYNTAX_CODE_PREFIX (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 switch (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 /* treat following character as a word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 if (depth || !sexpflag) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 /* This word counts as a sexp; return at end of it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1146 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1147 switch (SYNTAX_FROM_CACHE (mirrortab,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1148 BUF_FETCH_CHAR (buf, from)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 goto done;
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 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1166 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1167 comstyle = ST_COMMENT_STYLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 if (!parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1171 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1173 Charbpos newfrom =
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1174 find_end_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 /* we stopped because from == stop in search forward */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 from = stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 if (depth == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 from = newfrom;
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 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 if (!sexpflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 if (from != stop && c == BUF_FETCH_CHAR (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 if (mathexit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 goto close1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 mathexit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 if (!++depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 close1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 if (!--depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 if (depth < min_depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1208 if (noerror)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 return Qnil;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
1210 signal_error (Qsyntax_error, "Containing expression ends prematurely", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 break;
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 case Sstring_fence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1217 Emchar stringterm;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1218
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1219 if (code != Sstring_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1220 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 /* XEmacs change: call syntax_match on character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 Emchar ch = BUF_FETCH_CHAR (buf, from - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1223 Lisp_Object stermobj =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1224 syntax_match (syntax_cache.current_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 stringterm = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 stringterm = ch;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1230 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1231 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1232 stringterm = '\0'; /* avoid compiler warnings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 while (1)
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 if (from >= stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 goto lose;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1238 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1239 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1240 if (code == Sstring
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1241 ? c == stringterm
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1242 : SYNTAX_FROM_CACHE (mirrortab, c) == Sstring_fence)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1244
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1245 switch (SYNTAX_FROM_CACHE (mirrortab, c))
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 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 if (!depth && sexpflag) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 /* Reached end of buffer. Error if within object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 return nil if between */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 if (depth) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 /* End of object reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 stop = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1284 int comstyle = 0; /* mask for finding matching comment style */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 from--;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1287 UPDATE_SYNTAX_CACHE_BACKWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 quoted = char_quoted (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 if (quoted)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1290 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 from--;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1292 UPDATE_SYNTAX_CACHE_BACKWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1293 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 c = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1296 code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1297 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 if (code == Sendcomment && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 /* we have found a single char end comment. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 the comment style encountered so that later, we can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 only the proper comment begin sequence of the same style */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1304 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1305 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 else if (from > stop
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1309 && SYNTAX_CODE_END_SECOND_P (syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 && !char_quoted (buf, from - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1313 int prev_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1314 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1315 prev_syncode = SYNTAX_CODE_FROM_CACHE
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1316 (mirrortab, BUF_FETCH_CHAR (buf, from - 1));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1317
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1318 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1319 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 /* we must record the comment style encountered so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 later, we can match only the proper comment begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 sequence of the same style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 code = Sendcomment;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1324 comstyle = SYNTAX_CODES_COMMENT_MASK_END
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1325 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1328 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1330 if (SYNTAX_CODE_PREFIX (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1333 switch (quoted ? Sword : code)
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 Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 if (depth || !sexpflag) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 /* This word counts as a sexp; count object finished after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 passing it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1342 UPDATE_SYNTAX_CACHE_BACKWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 quoted = char_quoted (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 if (quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 if (! (quoted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 || (syncode =
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1349 SYNTAX_FROM_CACHE (mirrortab,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1350 BUF_FETCH_CHAR (buf, from - 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 == Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 || syncode == Ssymbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 || syncode == Squote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 if (!sexpflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 if (from != stop && c == BUF_FETCH_CHAR (buf, from - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 if (mathexit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 goto open2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 mathexit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 if (!++depth) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 open2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 if (!--depth) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 if (depth < min_depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1380 if (noerror)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 return Qnil;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
1382 signal_error (Qsyntax_error, "Containing expression ends prematurely", Qunbound);
428
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 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1386 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1387 comstyle = ST_COMMENT_STYLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 case Sendcomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 if (parse_sexp_ignore_comments)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1390 from = find_start_of_comment (buf, from, stop, comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1393 case Sstring_fence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1396 Emchar stringterm;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1397
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1398 if (code != Sstring_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1399 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 /* XEmacs change: call syntax_match() on character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 Emchar ch = BUF_FETCH_CHAR (buf, from);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1402 Lisp_Object stermobj =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1403 syntax_match (syntax_cache.current_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 stringterm = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 stringterm = ch;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1409 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1410 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1411 stringterm = '\0'; /* avoid compiler warnings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 if (from == stop) goto lose;
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 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1418 c = BUF_FETCH_CHAR (buf, from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1419
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1420 if ((code == Sstring
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1421 ? c == stringterm
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1422 : SYNTAX_FROM_CACHE (mirrortab, c) == Sstring_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1423 && !char_quoted (buf, from - 1))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1424 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1426 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1427
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 if (!depth && sexpflag) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 /* Reached start of buffer. Error if within object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 return nil if between */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 if (depth) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 done2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 count++;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 return (make_int (from));
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 lose:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1451 if (!noerror)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
1452 signal_error (Qsyntax_error, "Unbalanced parentheses", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 }
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 int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1457 char_quoted (struct buffer *buf, Charbpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 enum syntaxcode code;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1460 Charbpos beg = BUF_BEGV (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 int quoted = 0;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1462 Charbpos startpos = pos;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1463
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1464 while (pos > beg)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1465 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1466 UPDATE_SYNTAX_CACHE_BACKWARD (pos - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1467 code = SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, pos - 1));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1469 if (code != Scharquote && code != Sescape)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1470 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1471 pos--;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1472 quoted = !quoted;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1473 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1474
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1475 UPDATE_SYNTAX_CACHE (startpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 return quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 Scan from character number FROM by COUNT lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 Returns the character number of the position thus found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 If DEPTH is nonzero, paren depth begins counting from that value,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 only places where the depth in parentheses becomes zero
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 are candidates for stopping; COUNT such places are counted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 Thus, a positive value for DEPTH means go out levels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 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
1491 and the depth is wrong, an error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 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
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 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
1495 of in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 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
1498 signalling an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1500 (from, count, depth, buffer, noerror))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 struct buffer *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 CHECK_INT (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 CHECK_INT (depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 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
1510 !NILP (noerror));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 Scan from character number FROM by COUNT balanced expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 If COUNT is negative, scan backwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 Returns the character number of the position thus found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 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
1521 in the middle of a parenthetical grouping, an error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 If the beginning or end is reached between groupings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 but before count is used up, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 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
1526 of in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 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
1529 signalling an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1531 (from, count, buffer, noerror))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 CHECK_INT (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1537 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
1538 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 Move point backward over any number of chars with prefix syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 This includes chars with "quote" or "prefix" syntax (' or p).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 Optional arg BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 struct buffer *buf = decode_buffer (buffer, 0);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1549 Charbpos beg = BUF_BEGV (buf);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1550 Charbpos pos = BUF_PT (buf);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1551 #ifndef emacs
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1552 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1553 #endif
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1554 Emchar c = '\0'; /* initialize to avoid compiler warnings */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1555
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1556
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1557 SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, pos, -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 while (pos > beg && !char_quoted (buf, pos - 1)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1560 /* Previous statement updates syntax table. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1561 && (SYNTAX_FROM_CACHE (mirrortab, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1562 || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (mirrortab, c))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 BUF_SET_PT (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 /* Parse forward from FROM to END,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 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
1572 and return a description of the state of the parse at END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 If STOPBEFORE is nonzero, stop at the start of an atom.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 If COMMENTSTOP is nonzero, stop at the start of a comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 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
1578 Charbpos from, Charbpos end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 int targetdepth, int stopbefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 Lisp_Object oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 int commentstop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 struct level { int last, prev; };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 struct level levelstart[100];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 struct level *curlevel = levelstart;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 struct level *endlevel = levelstart + 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 int depth; /* Paren depth of current scanning location.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 level - levelstart equals this except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 when the depth becomes negative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 int mindepth; /* Lowest DEPTH value seen. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 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
1595 int boundary_stop = commentstop == -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1598 SETUP_SYNTAX_CACHE (from, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 if (NILP (oldstate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 state.instring = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 state.incomment = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 state.comstyle = 0; /* comment style a by default */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1605 state.comstr_start = -1; /* no comment/string seen. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 tem = Fcar (oldstate); /* elt 0, depth */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 if (!NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 depth = XINT (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 tem = Fcar (oldstate); /* elt 3, instring */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1619 state.instring = ( !NILP (tem)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1620 ? ( INTP (tem) ? XINT (tem) : ST_STRING_STYLE)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1621 : -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1623 oldstate = Fcdr (oldstate);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1624 tem = Fcar (oldstate); /* elt 4, incomment */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 state.incomment = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 tem = Fcar (oldstate); /* elt 5, follows-quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 start_quoted = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 /* 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
1632 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
1633 we are in a generic comment */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 oldstate = Fcdr (oldstate);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1636 tem = Fcar (oldstate); /* elt 7, comment style a/b/fence */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1637 state.comstyle = NILP (tem) ? 0 : ( EQ (tem, Qsyntax_table)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1638 ? ST_COMMENT_STYLE : 1 );
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1639
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1640 oldstate = Fcdr (oldstate); /* elt 8, start of last comment/string */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1641 tem = Fcar (oldstate);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1642 state.comstr_start = NILP (tem) ? -1 : XINT (tem);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1643
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1644 /* elt 9, char numbers of starts-of-expression of levels
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1645 (starting from outermost). */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1646 oldstate = Fcdr (oldstate);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1647 tem = Fcar (oldstate); /* elt 9, intermediate data for
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1648 continuation of parsing (subject
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1649 to change). */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1650 while (!NILP (tem)) /* >= second enclosing sexps. */
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 curlevel->last = XINT (Fcar (tem));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1653 if (++curlevel == endlevel)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
1654 signal_error (Qstack_overflow, "Nesting too deep for parser", Qunbound);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1655 curlevel->prev = -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1656 curlevel->last = -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1657 tem = Fcdr (tem);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1658 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 state.quoted = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 mindepth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 curlevel->prev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 curlevel->last = -1;
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 /* Enter the loop at a place appropriate for initial state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 if (state.incomment) goto startincomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 if (state.instring >= 0)
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 (start_quoted) goto startquotedinstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 goto startinstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 if (start_quoted) goto startquoted;
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 while (from < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1678 Emchar c;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1679 int syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1680
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1683 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1684 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1685 code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1686 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 /* record the comment style we have entered so that only the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 comment-ender sequence (or single char) of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 actually terminates the comment section. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1692 if (code == Scomment)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1693 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1694 state.comstyle =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1695 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1696 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1697 state.comstr_start = from - 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1698 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1699
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1700 /* a generic comment delimiter? */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1701 else if (code == Scomment_fence)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1702 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1703 state.comstyle = ST_COMMENT_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1704 state.comstr_start = from - 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1705 code = Scomment;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 }
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 else if (from < end &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1709 SYNTAX_CODE_START_FIRST_P (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1711 int next_syncode;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1712 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1713 next_syncode =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1714 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from));
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1715
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1716 if (SYNTAX_CODES_START_P (syncode, next_syncode))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1717 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 code = Scomment;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1719 state.comstyle = SYNTAX_CODES_COMMENT_MASK_START
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1720 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1721 state.comstr_start = from - 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 from++;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1723 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1724 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1727 if (SYNTAX_CODE_PREFIX (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 switch (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 startquoted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 if (from == end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 goto symstarted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 /* treat following character as a word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 symstarted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 while (from < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1747 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1748 switch (SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)))
428
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 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 if (from == end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 goto symdone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 symdone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 break;
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 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 state.incomment = 1;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1770 if (commentstop || boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 startincomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1772 if (commentstop == 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 goto done;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1774 UPDATE_SYNTAX_CACHE_FORWARD (from);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1776 Charbpos newfrom = find_end_of_comment (buf, from, end, state.comstyle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 /* we terminated search because from == end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 from = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 state.incomment = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 state.comstyle = 0; /* reset the comment style */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1787 if (boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 depth++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 /* curlevel++->last ran into compiler bug on Apollo */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 if (++curlevel == endlevel)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
1796 signal_error (Qstack_overflow, "Nesting too deep for parser", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 curlevel->prev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 curlevel->last = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 if (targetdepth == depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 depth--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 if (depth < mindepth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 mindepth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 if (curlevel != levelstart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 curlevel--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 if (targetdepth == depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 case Sstring:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1813 case Sstring_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1814 state.comstr_start = from - 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 curlevel->last = from - 1;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1817 if (code == Sstring_fence)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1819 state.instring = ST_STRING_STYLE;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1820 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1821 else
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1822 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1823 /* XEmacs change: call syntax_match() on character */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1824 Emchar ch = BUF_FETCH_CHAR (buf, from - 1);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1825 Lisp_Object stermobj =
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1826 syntax_match (syntax_cache.current_syntax_table, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 state.instring = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 state.instring = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1833 if (boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 startinstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1837 enum syntaxcode temp_code;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1838
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 if (from >= end) goto done;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1840
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1841 UPDATE_SYNTAX_CACHE_FORWARD (from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1842 c = BUF_FETCH_CHAR (buf, from);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1843 temp_code = SYNTAX_FROM_CACHE (mirrortab, c);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1844
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1845 if (
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1846 state.instring != ST_STRING_STYLE &&
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1847 temp_code == Sstring &&
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1848 c == state.instring) break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1849
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1850 switch (temp_code)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1852 case Sstring_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1853 if (state.instring == ST_STRING_STYLE)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1854 goto string_end;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1855 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 startquotedinstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 if (from >= end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1869 string_end:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 state.instring = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 from++;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1873 if (boundary_stop) goto done;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 break;
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 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 case Swhitespace:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 case Spunct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 case Sendcomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1883 case Scomment_fence:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 case Sinherit:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 case Smax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 stop: /* Here if stopping before start of sexp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 from--; /* We have just fetched the char that starts it; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 goto done; /* but return the position before it. */
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 endquoted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 state.quoted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 state.depth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 state.mindepth = mindepth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 state.thislevelstart = curlevel->prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 state.prevlevelstart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 state.location = from;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1904 state.levelstarts = Qnil;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1905 while (--curlevel >= levelstart)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1906 state.levelstarts = Fcons (make_int (curlevel->last),
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1907 state.levelstarts);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 *stateptr = state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 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
1914 Parsing stops at TO or when certain criteria are met;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 point is set to where parsing stops.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1916 If fifth arg OLDSTATE is omitted or nil,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 parsing assumes that FROM is the beginning of a function.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1918 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
1919 0. depth in parens.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 1. character address of start of innermost containing list; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 2. character address of start of last complete sexp terminated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 3. non-nil if inside a string.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1923 (It is the character that will terminate the string,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1924 or t if the string should be terminated by an explicit
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1925 `syntax-table' property.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 4. t if inside a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 5. t if following a quote character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 6. the minimum paren-depth encountered during this scan.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1929 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
1930 `syntax-table' if given by an explicit `syntax-table' property.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1931 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
1932 9. Intermediate data for continuation of parsing (subject to change).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 in parentheses becomes equal to TARGETDEPTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 Fourth arg STOPBEFORE non-nil means stop when come to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 any character that starts a sexp.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1937 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
1938 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
1939 elements are ignored.
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1940 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
1941 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
1942 the end of a comment or string.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 int target;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 627
diff changeset
1948 Charbpos start, end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 Lisp_Object val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 if (!NILP (targetdepth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 CHECK_INT (targetdepth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 target = XINT (targetdepth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 target = -100000; /* We won't reach this depth */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 get_buffer_range_char (buf, from, to, &start, &end, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 scan_sexps_forward (buf, &state, start, end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 target, !NILP (stopbefore), oldstate,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1963 (NILP (commentstop)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1964 ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 BUF_SET_PT (buf, state.location);
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 /* reverse order */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 val = Qnil;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1969 val = Fcons (state.levelstarts, val);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1970 val = Fcons ((state.incomment || (state.instring >= 0))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1971 ? make_int (state.comstr_start) : Qnil, val);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1972 val = Fcons (state.comstyle ? (state.comstyle == ST_COMMENT_STYLE
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1973 ? Qsyntax_table : Qt) : Qnil, val);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 val = Fcons (make_int (state.mindepth), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 val = Fcons (state.quoted ? Qt : Qnil, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 val = Fcons (state.incomment ? Qt : Qnil, val);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1977 val = Fcons (state.instring < 0
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1978 ? Qnil
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1979 : (state.instring == ST_STRING_STYLE
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1980 ? Qt : make_int (state.instring)), val);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 val = Fcons (state.thislevelstart < 0 ? Qnil : make_int (state.thislevelstart), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 val = Fcons (state.prevlevelstart < 0 ? Qnil : make_int (state.prevlevelstart), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 val = Fcons (make_int (state.depth), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 /* Updating of the mirror syntax table.
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 Each syntax table has a corresponding mirror table in it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 Whenever we make a change to a syntax table, we call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 update_syntax_table() on it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 #### We really only need to map over the changed range.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 If we change the standard syntax table, we need to map over
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 all tables because any of them could be inheriting from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 standard syntax table.
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 When `set-syntax-table' is called, we set the buffer's mirror
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 syntax table as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 struct cmst_arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 Lisp_Object mirrortab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 int check_inherit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 cmst_mapfun (struct chartab_range *range, Lisp_Object val, void *arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 struct cmst_arg *closure = (struct cmst_arg *) arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 if (CONSP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 val = XCAR (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 if (SYNTAX_FROM_CODE (XINT (val)) == Sinherit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 && closure->check_inherit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 struct cmst_arg recursive;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 recursive.mirrortab = closure->mirrortab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 recursive.check_inherit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 map_char_table (XCHAR_TABLE (Vstandard_syntax_table), range,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 cmst_mapfun, &recursive);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 put_char_table (XCHAR_TABLE (closure->mirrortab), range, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 static void
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2034 update_just_this_syntax_table (Lisp_Char_Table *ct)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 struct chartab_range range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 struct cmst_arg arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 arg.mirrortab = ct->mirror_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 arg.check_inherit = (CHAR_TABLEP (Vstandard_syntax_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 && ct != XCHAR_TABLE (Vstandard_syntax_table));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 range.type = CHARTAB_RANGE_ALL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 map_char_table (ct, &range, cmst_mapfun, &arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 /* 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
2047 If this is the standard syntax table, we need to recompute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 *all* syntax tables (yuck). Otherwise we just recompute this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 void
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2052 update_syntax_table (Lisp_Char_Table *ct)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 /* Don't be stymied at startup. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 if (CHAR_TABLEP (Vstandard_syntax_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 && ct == XCHAR_TABLE (Vstandard_syntax_table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 Lisp_Object syntab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 for (syntab = Vall_syntax_tables; !NILP (syntab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 syntab = XCHAR_TABLE (syntab)->next_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 update_just_this_syntax_table (XCHAR_TABLE (syntab));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 update_just_this_syntax_table (ct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 syms_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
2076 DEFSYMBOL (Qsyntax_table_p);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
2077 DEFSYMBOL (Qsyntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 DEFSUBR (Fsyntax_table_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 DEFSUBR (Fsyntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 DEFSUBR (Fstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 DEFSUBR (Fcopy_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 DEFSUBR (Fset_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 DEFSUBR (Fsyntax_designator_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 DEFSUBR (Fchar_syntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 DEFSUBR (Fmatching_paren);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 DEFSUBR (Fforward_word);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 DEFSUBR (Fforward_comment);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 DEFSUBR (Fscan_lists);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 DEFSUBR (Fscan_sexps);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 DEFSUBR (Fbackward_prefix_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 DEFSUBR (Fparse_partial_sexp);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 vars_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 Non-nil means `forward-sexp', etc., should treat comments as whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 */ );
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2105 parse_sexp_ignore_comments = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2107 DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /*
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2108 Non-nil means `forward-sexp', etc., grant `syntax-table' property.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2109 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
2110 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2111 syntax code, MATCHCHAR being nil or the character to match (which is
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2112 relevant only for open/close type.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2113 */ );
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2114 lookup_syntax_properties = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
2115
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 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
2118 */ );
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
2119 words_include_escapes = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 no_quit_in_re_search = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2125 define_standard_syntax (const char *p, enum syntaxcode syn)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 for (; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 Fput_char_table (make_char (*p), make_int (syn), Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 complex_vars_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 Emchar i;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2135 const char *p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 /* Set this now, so first buffer creation can refer to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 /* Make it nil before calling copy-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 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
2139 Vstandard_syntax_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 Vstandard_syntax_table = Fcopy_syntax_table (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 staticpro (&Vstandard_syntax_table);
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 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 Smax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 staticpro (&Vsyntax_designator_chars_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 fill_char_table (XCHAR_TABLE (Vstandard_syntax_table), make_int (Spunct));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 for (i = 0; i <= 32; i++) /* Control 0 plus SPACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 Fput_char_table (make_char (i), make_int (Swhitespace),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 for (i = 127; i <= 159; i++) /* DEL plus Control 1 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 Fput_char_table (make_char (i), make_int (Swhitespace),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 define_standard_syntax ("abcdefghijklmnopqrstuvwxyz"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 "0123456789"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 "$%", Sword);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 define_standard_syntax ("\"", Sstring);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 define_standard_syntax ("\\", Sescape);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 define_standard_syntax ("_-+*/&|<>=", Ssymbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 define_standard_syntax (".,;:?!#@~^'`", Spunct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 for (p = "()[]{}"; *p; p+=2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 Fput_char_table (make_char (p[0]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 Fcons (make_int (Sopen), make_char (p[1])),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 Fput_char_table (make_char (p[1]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 Fcons (make_int (Sclose), make_char (p[0])),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 }