annotate src/syntax.c @ 165:5a88923fcbfe r20-3b9

Import from CVS: tag r20-3b9
author cvs
date Mon, 13 Aug 2007 09:44:42 +0200
parents 3bb7ccffb0c0
children 3d6bfa290dbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* XEmacs routines to deal with syntax tables; also word and list parsing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985-1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.28. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
24 /* This file has been Mule-ized. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
25
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "syntax.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
34 /* Here is a comment from Ken'ichi HANDA <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
35 explaining the purpose of the Sextword syntax category:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
36
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
37 Japanese words are not separated by spaces, which makes finding word
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
38 boundaries very difficult. Theoretically it's impossible without
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
39 using natural language processing techniques. But, by defining
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
40 pseudo-words as below (much simplified for letting you understand it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
41 easily) for Japanese, we can have a convenient forward-word function
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
42 for Japanese.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
43
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
44 A Japanese word is a sequence of characters that consists of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
45 zero or more Kanji characters followed by zero or more
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
46 Hiragana characters.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
47
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
48 Then, the problem is that now we can't say that a sequence of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
49 word-constituents makes up a WORD. For instance, both Hiragana "A"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
50 and Kanji "KAN" are word-constituents but the sequence of these two
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
51 letters can't be a single word.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
52
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
53 So, we introduced Sextword for Japanese letters. A character of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
54 Sextword is a word-constituent but a word boundary may exist between
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
55 two such characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
56
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
57 /* Mule 2.4 doesn't seem to have Sextword - I'm removing it -- mrb */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
58
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 Lisp_Object Qsyntax_table_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 int words_include_escapes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 int parse_sexp_ignore_comments;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* The following two variables are provided to tell additional information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 to the regex routines. We do it this way rather than change the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 arguments to re_search_2() in an attempt to maintain some call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 compatibility with other versions of the regex code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 /* Tell the regex routines not to QUIT. Normally there is a QUIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 each iteration in re_search_2(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 int no_quit_in_re_search;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 /* Tell the regex routines which buffer to access for SYNTAX() lookups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 and the like. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 struct buffer *regex_emacs_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 Lisp_Object Vstandard_syntax_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 Lisp_Object Vsyntax_designator_chars_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /* This is the internal form of the parse state used in parse-partial-sexp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 struct lisp_parse_state
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
85 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
86 int depth; /* Depth at end of parsing */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
87 Emchar instring; /* -1 if not within string, else desired terminator */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
88 int incomment; /* Nonzero if within a comment at end of parsing */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
89 int comstyle; /* comment style a=0, or b=1 */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
90 int quoted; /* Nonzero if just after an escape char at end of
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 parsing */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
92 Bufpos thislevelstart;/* Char number of most recent start-of-expression
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
93 at current level */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
94 Bufpos prevlevelstart;/* Char number of start of containing expression */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
95 Bufpos location; /* Char number at which parsing stopped */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
96 int mindepth; /* Minimum depth seen while scanning */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
97 Bufpos comstart; /* Position just after last comment starter */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
98 };
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* These variables are a cache for finding the start of a defun.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
101 find_start_pos is the place for which the defun start was found.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
102 find_start_value is the defun start position found for it.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 find_start_buffer is the buffer it was found in.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
104 find_start_begv is the BEGV value when it was found.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 find_start_modiff is the value of MODIFF when it was found. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 static Bufpos find_start_pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 static Bufpos find_start_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 static struct buffer *find_start_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 static Bufpos find_start_begv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 static int find_start_modiff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 /* Find a defun-start that is the last one before POS (or nearly the last).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 We record what we find, so that another call in the same area
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 can return the same value right away. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 static Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 find_defun_start (struct buffer *buf, Bufpos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Bufpos tem;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
121 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 /* Use previous finding, if it's valid and applies to this inquiry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 if (buf == find_start_buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 /* Reuse the defun-start even if POS is a little farther on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 POS might be in the next defun, but that's ok.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 Our value may not be the best possible, but will still be usable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 && pos <= find_start_pos + 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 && pos >= find_start_value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 && BUF_BEGV (buf) == find_start_begv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 && BUF_MODIFF (buf) == find_start_modiff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 return find_start_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 /* Back up to start of line. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 tem = find_next_newline (buf, pos, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 while (tem > BUF_BEGV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 /* Open-paren at start of line means we found our defun-start. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
140 if (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, tem)) == Sopen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 /* Move to beg of previous line. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 tem = find_next_newline (buf, tem, -2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 /* Record what we found, for the next try. */
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
147 find_start_value = tem;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 find_start_buffer = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 find_start_modiff = BUF_MODIFF (buf);
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
150 find_start_begv = BUF_BEGV (buf);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
151 find_start_pos = pos;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 return find_start_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
156 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 Return t if ARG is a syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Any vector of 256 elements will do.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
159 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
160 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
162 if (CHAR_TABLEP (obj) && XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_SYNTAX)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 check_syntax_table (Lisp_Object obj, Lisp_Object def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 if (NILP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 obj = def;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 while (NILP (Fsyntax_table_p (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 obj = wrong_type_argument (Qsyntax_table_p, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 return (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
177 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 Return the current syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 This is the one specified by the current buffer, or by BUFFER if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 is non-nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
181 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
182 (buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 return decode_buffer (buffer, 0)->syntax_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
187 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 Return the standard syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 This is the one used for new buffers.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
190 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
191 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 return Vstandard_syntax_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
196 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 Construct a new syntax table and return it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 It is a copy of the TABLE, which defaults to the standard syntax table.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
199 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
200 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (NILP (Vstandard_syntax_table))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
203 return Fmake_char_table (Qsyntax);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 table = check_syntax_table (table, Vstandard_syntax_table);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
206 return Fcopy_char_table (table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
209 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Select a new syntax table for BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 One argument, a syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 BUFFER defaults to the current buffer if omitted.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
213 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
214 (table, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 table = check_syntax_table (table, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 buf->syntax_table = table;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
219 buf->mirror_syntax_table = XCHAR_TABLE (table)->mirror_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 /* Indicate that this buffer now has a specified syntax table. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 return table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 /* Convert a letter which signifies a syntax code
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
226 into the code it signifies.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
227 This is used by modify-syntax-entry, and other things. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 CONST unsigned char syntax_spec_code[0400] =
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
230 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
231 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
232 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
233 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
234 (char) Swhitespace, 0377, (char) Sstring, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
235 (char) Smath, 0377, 0377, (char) Squote,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
236 (char) Sopen, (char) Sclose, 0377, 0377,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote,
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
238 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
239 0377, 0377, 0377, 0377,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (char) Scomment, 0377, (char) Sendcomment, 0377,
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
241 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
242 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
243 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
244 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
245 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
246 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
247 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
248 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
249 };
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
251 CONST unsigned char syntax_code_spec[] = " .w_()'\"$\\/<>@";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
253 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 Return a string of the recognized syntax designator chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 The chars are ordered by their internal syntax codes, which are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 numbered starting at 0.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
257 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
258 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 return Vsyntax_designator_chars_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
263 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 Return the syntax code of CHAR, described by a character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 For example, if CHAR is a word constituent, the character `?w' is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 The characters that correspond to various syntax codes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 are listed in the documentation of `modify-syntax-entry'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 Optional second argument TABLE defaults to the current buffer's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 syntax table.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
270 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
271 (ch, table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
273 struct Lisp_Char_Table *mirrortab;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
274
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 88
diff changeset
275 if (NILP(ch))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 88
diff changeset
276 {
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 88
diff changeset
277 return Qnil;
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 88
diff changeset
278 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 CHECK_CHAR_COERCE_INT (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 table = check_syntax_table (table, current_buffer->syntax_table);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
281 mirrortab = XCHAR_TABLE (XCHAR_TABLE (table)->mirror_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
282 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, XCHAR (ch))]);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
285 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
286
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
287 enum syntaxcode
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
288 charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
289 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
290 *multi_p_out = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
291 /* #### get this right */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
292 return Spunct;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
293 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
294
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
295 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 syntax_match (Lisp_Object table, Emchar ch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
300 Lisp_Object code = CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (table), ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
301 Lisp_Object code2 = code;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
303 if (CONSP (code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
304 code2 = XCAR (code);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
305 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
306 code = CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (Vstandard_syntax_table),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
307 ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
308 if (CONSP (code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
309 return XCDR (code);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
310 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
314 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Return the matching parenthesis of CHAR, or nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Optional second argument TABLE defaults to the current buffer's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 syntax table.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
318 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
319 (ch, table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
321 struct Lisp_Char_Table *mirrortab;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 int code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
324 CHECK_CHAR_COERCE_INT (ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 table = check_syntax_table (table, current_buffer->syntax_table);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
326 mirrortab = XCHAR_TABLE (XCHAR_TABLE (table)->mirror_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
327 code = SYNTAX (mirrortab, XCHAR (ch));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 if (code == Sopen || code == Sclose || code == Sstring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 return syntax_match (table, XCHAR (ch));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
334
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
335 static int
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
336 word_constituent_p (struct buffer *buf, Bufpos pos,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
337 struct Lisp_Char_Table *tab)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
338 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
339 enum syntaxcode code = SYNTAX_UNSAFE (tab, BUF_FETCH_CHAR (buf, pos));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
340 return ((words_include_escapes &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
341 (code == Sescape || code == Scharquote))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
342 || (code == Sword));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
343 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
344
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 /* Return the position across COUNT words from FROM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 If that many words cannot be found before the end of the buffer, return 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 COUNT negative means scan backward and stop at word beginning. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 scan_words (struct buffer *buf, Bufpos from, int count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
352 Bufpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
353 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 while (count > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
360 if (from == limit)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
361 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
362 if (word_constituent_p (buf, from, mirrortab))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
369 while ((from != limit) && word_constituent_p (buf, from, mirrortab))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 count--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
375
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 while (count < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
382 if (from == limit)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
383 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
384 if (word_constituent_p (buf, from - 1, mirrortab))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
391 while ((from != limit) && word_constituent_p (buf, from - 1, mirrortab))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 return from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
401 DEFUN ("forward-word", Fforward_word, 1, 2, "_p", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 Move point forward ARG words (backward if ARG is negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Normally returns t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 If an edge of the buffer is reached, point is left there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 and nil is returned.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
406 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
407 (count, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 Bufpos val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 CHECK_INT (count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 if (!(val = scan_words (buf, BUF_PT (buf), XINT (count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 BUF_SET_PT (buf, XINT (count) > 0 ? BUF_ZV (buf) : BUF_BEGV (buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 BUF_SET_PT (buf, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 static void scan_sexps_forward (struct buffer *buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 struct lisp_parse_state *,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 Bufpos from, Bufpos end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 int targetdepth, int stopbefore,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 Lisp_Object oldstate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 int commentstop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 find_start_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int mask)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 Emchar c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 enum syntaxcode code;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
434 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 /* Look back, counting the parity of string-quotes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 and recording the comment-starters seen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 When we reach a safe place, assume that's not in a string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 then step the main scan to the earliest comment-starter seen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 an even number of string quotes away from the safe place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 OFROM[I] is position of the earliest comment-starter seen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 which is I+2X quotes from the comment-end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 PARITY is current parity of quotes from the comment end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 int parity = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Emchar my_stringend = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 int string_lossage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 Bufpos comment_end = from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 Bufpos comstart_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 int comstart_parity = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 int styles_match_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 /* At beginning of range to scan, we're outside of strings;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 that determines quote parity to the comment-end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 while (from != stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 /* Move back and examine a character. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 c = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
461 code = SYNTAX_UNSAFE (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 /* is this a 1-char comment end sequence? if so, try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 to see if style matches previously extracted mask */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 if (code == Sendcomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
467 styles_match_p = SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 /* otherwise, is this a 2-char comment end sequence? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 else if (from >= stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
472 && SYNTAX_END_P (mirrortab, c, BUF_FETCH_CHAR (buf, from+1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 code = Sendcomment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 styles_match_p =
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
476 SYNTAX_STYLES_MATCH_END_P (mirrortab, c,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 BUF_FETCH_CHAR (buf, from+1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 /* or are we looking at a 1-char comment start sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 of the style matching mask? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 else if (code == Scomment
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
484 && SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 styles_match_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 /* or possibly, a 2-char comment start sequence */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 else if (from >= stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
491 && SYNTAX_STYLES_MATCH_START_P (mirrortab, c,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 BUF_FETCH_CHAR (buf, from+1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 mask))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 code = Scomment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 styles_match_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 /* Ignore escaped characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 if (char_quoted (buf, from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 /* Track parity of quotes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 if (code == Sstring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 parity ^= 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 if (my_stringend == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 my_stringend = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 /* If we have two kinds of string delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 There's no way to grok this scanning backwards. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 else if (my_stringend != c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 string_lossage = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 /* Record comment-starters according to that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 quote-parity to the comment-end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if (code == Scomment && styles_match_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 comstart_parity = parity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 comstart_pos = from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 /* If we find another earlier comment-ender,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 any comment-starts earlier than that don't count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (because they go with the earlier comment-ender). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 if (code == Sendcomment && styles_match_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 /* Assume a defun-start point is outside of strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 if (code == Sopen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 && (from == stop || BUF_FETCH_CHAR (buf, from - 1) == '\n'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 if (comstart_pos == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 from = comment_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 /* If the earliest comment starter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 is followed by uniform paired string quotes or none,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 we know it can't be inside a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 since if it were then the comment ender would be inside one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 So it does start a comment. Skip back to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 else if (comstart_parity == 0 && !string_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 from = comstart_pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 /* We had two kinds of string delimiters mixed up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 together. Decode this going forwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 Scan fwd from the previous comment ender
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 to the one in question; this records where we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 last passed a comment starter. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 struct lisp_parse_state state;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 comment_end - 1, -10000, 0, Qnil, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 if (state.incomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 from = state.comstart;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 /* We can't grok this as a comment; scan it normally. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 from = comment_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 return from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 static Bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 find_end_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int mask)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 int c;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
568 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 if (from == stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 c = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
577 if (SYNTAX_UNSAFE (mirrortab, c) == Sendcomment
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
578 && SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 /* we have encountered a comment end of the same style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 as the comment sequence which began this comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 section */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 if (from < stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
586 && SYNTAX_STYLES_MATCH_END_P (mirrortab, c,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 BUF_FETCH_CHAR (buf, from), mask))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 /* we have encountered a comment end of the same style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 as the comment sequence which began this comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 section */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 { from++; break; }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 return from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 /* #### between FSF 19.23 and 19.28 there are some changes to the logic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 in this function (and minor changes to find_start_of_comment(),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 above, which is part of Fforward_comment() in FSF). Attempts to port
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 that logic made this function break, so I'm leaving it out. If anyone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ever complains about this function not working properly, take a look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 at those changes. --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
604 DEFUN ("forward-comment", Fforward_comment, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 Move forward across up to N comments. If N is negative, move backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 Stop scanning if we find something other than a comment or whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 Set point to where scanning stops.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 If N comments are found as expected, with nothing except whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 between them, return t; otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 Point is set in either case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 Optional argument BUFFER defaults to the current buffer.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
612 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
613 (n, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 Bufpos from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 Bufpos stop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 Emchar c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 enum syntaxcode code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 int count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 struct buffer *buf = decode_buffer (buffer, 0);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
621 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 CHECK_INT (n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 count = XINT (n);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 from = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 while (count > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 stop = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 while (from < stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 int mask = 0; /* mask for finding matching comment style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 if (char_quoted (buf, from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 c = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
644 code = SYNTAX (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 if (code == Scomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 /* we have encountered a single character comment start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 sequence, and we are ignoring all text inside comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 we must record the comment style this character begins
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 so that later, only a comment end of the same style actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ends the comment section */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
653 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 else if (from < stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
657 && SYNTAX_START_P (mirrortab, c, BUF_FETCH_CHAR (buf, from+1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 /* we have encountered a 2char comment start sequence and we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 are ignoring all text inside comments. we must record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 the comment style this sequence begins so that later,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 only a comment end of the same style actually ends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 the comment section */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 code = Scomment;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
665 mask = SYNTAX_COMMENT_MASK_START (mirrortab, c,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 BUF_FETCH_CHAR (buf, from+1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 if (code == Scomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 Bufpos newfrom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 newfrom = find_end_of_comment (buf, from, stop, mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 if (newfrom < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 /* we stopped because from==stop */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 BUF_SET_PT (buf, stop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 from = newfrom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 /* We have skipped one comment. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 else if (code != Swhitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 && code != Sendcomment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 && code != Scomment )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 BUF_SET_PT (buf, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 /* End of comment reached */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 count--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 while (count < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 stop = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 while (from > stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 int mask = 0; /* mask for finding matching comment style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 if (char_quoted (buf, from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 c = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
717 code = SYNTAX (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 if (code == Sendcomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 /* we have found a single char end comment. we must record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 the comment style encountered so that later, we can match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 only the proper comment begin sequence of the same style */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
724 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 else if (from > stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
728 && SYNTAX_END_P (mirrortab, BUF_FETCH_CHAR (buf, from - 1), c)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 && !char_quoted (buf, from - 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 /* We must record the comment style encountered so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 later, we can match only the proper comment begin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 sequence of the same style. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 code = Sendcomment;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
735 mask = SYNTAX_COMMENT_MASK_END (mirrortab,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 BUF_FETCH_CHAR (buf, from - 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 if (code == Sendcomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 from = find_start_of_comment (buf, from, stop, mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 else if (code != Swhitespace
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
748 && SYNTAX (mirrortab, c) != Scomment
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
749 && SYNTAX (mirrortab, c) != Sendcomment)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 BUF_SET_PT (buf, from + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 BUF_SET_PT (buf, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 scan_lists (struct buffer *buf, Bufpos from, int count, int depth,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 int sexpflag, int no_error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 Bufpos stop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 Emchar c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 int quoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 int mathexit = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 enum syntaxcode code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 int min_depth = depth; /* Err out if depth gets less than this. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
774 Lisp_Object syntaxtab = buf->syntax_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
775 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 if (depth > 0) min_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 while (count > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 stop = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 while (from < stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 int mask = 0; /* mask for finding matching comment style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 c = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
789 code = SYNTAX_UNSAFE (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 /* a 1-char comment start sequence */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 if (code == Scomment && parse_sexp_ignore_comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
795 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 /* else, a 2-char comment start sequence? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 else if (from < stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
800 && SYNTAX_START_P (mirrortab, c, BUF_FETCH_CHAR (buf, from))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 && parse_sexp_ignore_comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 /* we have encountered a comment start sequence and we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 are ignoring all text inside comments. we must record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 the comment style this sequence begins so that later,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 only a comment end of the same style actually ends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 the comment section */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 code = Scomment;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
809 mask = SYNTAX_COMMENT_MASK_START (mirrortab, c,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 BUF_FETCH_CHAR (buf, from));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
814 if (SYNTAX_PREFIX_UNSAFE (mirrortab, c))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 switch (code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 case Scharquote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 if (from == stop) goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 /* treat following character as a word constituent */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 case Sword:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 case Ssymbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 if (depth || !sexpflag) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 /* This word counts as a sexp; return at end of it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 while (from < stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
830 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 case Scharquote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 if (from == stop) goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 case Sword:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 case Ssymbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 case Squote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 case Scomment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 if (!parse_sexp_ignore_comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 Bufpos newfrom = find_end_of_comment (buf, from, stop, mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 if (newfrom < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 /* we stopped because from == stop in search forward */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 from = stop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 if (depth == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 from = newfrom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 case Smath:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 if (!sexpflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 if (from != stop && c == BUF_FETCH_CHAR (buf, from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 if (mathexit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 mathexit = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 goto close1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 mathexit = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 case Sopen:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 if (!++depth) goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 case Sclose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 close1:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 if (!--depth) goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 if (depth < min_depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 if (no_error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 error ("Containing expression ends prematurely");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 case Sstring:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 /* XEmacs change: call syntax_match on character */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 Emchar ch = BUF_FETCH_CHAR (buf, from - 1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
896 Lisp_Object stermobj = syntax_match (syntaxtab, ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 Emchar stringterm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 if (CHARP (stermobj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 stringterm = XCHAR (stermobj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 stringterm = ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 if (from >= stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 if (BUF_FETCH_CHAR (buf, from) == stringterm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 break;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
910 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 case Scharquote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 if (!depth && sexpflag) goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 /* Reached end of buffer. Error if within object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 return nil if between */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 if (depth) goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 /* End of object reached */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 done:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 count--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 while (count < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 stop = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 while (from > stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 int mask = 0; /* mask for finding matching comment style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 quoted = char_quoted (buf, from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 if (quoted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 c = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
957 code = SYNTAX_UNSAFE (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 if (code == Sendcomment && parse_sexp_ignore_comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 /* we have found a single char end comment. we must record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 the comment style encountered so that later, we can match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 only the proper comment begin sequence of the same style */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
964 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 else if (from > stop
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
968 && SYNTAX_END_P (mirrortab, BUF_FETCH_CHAR (buf, from-1), c)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 && !char_quoted (buf, from - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 && parse_sexp_ignore_comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 /* we must record the comment style encountered so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 later, we can match only the proper comment begin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 sequence of the same style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 code = Sendcomment;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
976 mask = SYNTAX_COMMENT_MASK_END (mirrortab,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 BUF_FETCH_CHAR (buf, from - 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
982 if (SYNTAX_PREFIX_UNSAFE (mirrortab, c))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 switch (((quoted) ? Sword : code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 case Sword:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 case Ssymbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 if (depth || !sexpflag) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 /* This word counts as a sexp; count object finished after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 passing it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 while (from > stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 enum syntaxcode syncode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 quoted = char_quoted (buf, from - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 if (quoted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 if (! (quoted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 || (syncode =
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1001 SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from - 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 == Sword
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 || syncode == Ssymbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 || syncode == Squote))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 goto done2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 goto done2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 case Smath:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 if (!sexpflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 if (from != stop && c == BUF_FETCH_CHAR (buf, from - 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 if (mathexit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 mathexit = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 goto open2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 mathexit = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 case Sclose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 if (!++depth) goto done2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 case Sopen:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 open2:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 if (!--depth) goto done2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 if (depth < min_depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 if (no_error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 error ("Containing expression ends prematurely");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 case Sendcomment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 if (parse_sexp_ignore_comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 from = find_start_of_comment (buf, from, stop, mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 case Sstring:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 /* XEmacs change: call syntax_match() on character */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 Emchar ch = BUF_FETCH_CHAR (buf, from);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1046 Lisp_Object stermobj = syntax_match (syntaxtab, ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 Emchar stringterm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 if (CHARP (stermobj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 stringterm = XCHAR (stermobj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 stringterm = ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 if (from == stop) goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 if (!char_quoted (buf, from - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 && stringterm == BUF_FETCH_CHAR (buf, from - 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 from--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 if (!depth && sexpflag) goto done2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 /* Reached start of buffer. Error if within object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 return nil if between */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 if (depth) goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 done2:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 return (make_int (from));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 lose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 if (!no_error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 error ("Unbalanced parentheses");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 char_quoted (struct buffer *buf, Bufpos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 enum syntaxcode code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 Bufpos beg = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 int quoted = 0;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1094 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 while (pos > beg
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1097 && ((code = SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 == Scharquote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 || code == Sescape))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 pos--, quoted = !quoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 return quoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1104 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 Scan from character number FROM by COUNT lists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 Returns the character number of the position thus found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 If DEPTH is nonzero, paren depth begins counting from that value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 only places where the depth in parentheses becomes zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 are candidates for stopping; COUNT such places are counted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 Thus, a positive value for DEPTH means go out levels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 If the beginning or end of (the accessible part of) the buffer is reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 and the depth is wrong, an error is signaled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 If the depth is right but the count is not used up, nil is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 of in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 If optional arg NOERROR is non-nil, scan-lists will return nil instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 signalling an error.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1124 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1125 (from, count, depth, buffer, no_error))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 struct buffer *buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 CHECK_INT (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 CHECK_INT (count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 CHECK_INT (depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 !NILP (no_error));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1138 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 Scan from character number FROM by COUNT balanced expressions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 If COUNT is negative, scan backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 Returns the character number of the position thus found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 If the beginning or end of (the accessible part of) the buffer is reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 in the middle of a parenthetical grouping, an error is signaled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 If the beginning or end is reached between groupings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 but before count is used up, nil is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 of in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 signalling an error.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1155 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1156 (from, count, buffer, no_error))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 CHECK_INT (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 CHECK_INT (count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (no_error));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1165 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 Move point backward over any number of chars with prefix syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 This includes chars with \"quote\" or \"prefix\" syntax (' or p).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 Optional arg BUFFER defaults to the current buffer.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1170 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1171 (buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 Bufpos beg = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 Bufpos pos = BUF_PT (buf);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1176 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 while (pos > beg && !char_quoted (buf, pos - 1)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1179 && (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)) == Squote
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1180 || SYNTAX_PREFIX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 pos--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 BUF_SET_PT (buf, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 /* Parse forward from FROM to END,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 and return a description of the state of the parse at END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 If STOPBEFORE is nonzero, stop at the start of an atom.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 If COMMENTSTOP is nonzero, stop at the start of a comment. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 scan_sexps_forward (struct buffer *buf, struct lisp_parse_state *stateptr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 Bufpos from, Bufpos end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 int targetdepth, int stopbefore,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 Lisp_Object oldstate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 int commentstop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 struct lisp_parse_state state;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 enum syntaxcode code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 struct level { int last, prev; };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 struct level levelstart[100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 struct level *curlevel = levelstart;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 struct level *endlevel = levelstart + 100;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 int depth; /* Paren depth of current scanning location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 level - levelstart equals this except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 when the depth becomes negative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 int mindepth; /* Lowest DEPTH value seen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 int start_quoted = 0; /* Nonzero means starting after a char quote */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 int mask; /* comment mask */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1215 Lisp_Object syntaxtab = buf->syntax_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1216 struct Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 if (NILP (oldstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 state.instring = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 state.incomment = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 state.comstyle = 0; /* comment style a by default */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 mask = SYNTAX_COMMENT_STYLE_A;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 tem = Fcar (oldstate); /* elt 0, depth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 if (!NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 depth = XINT (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 tem = Fcar (oldstate); /* elt 3, instring */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 state.instring = !NILP (tem) ? XINT (tem) : -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 oldstate = Fcdr (oldstate); /* elt 4, incomment */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 tem = Fcar (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 state.incomment = !NILP (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 tem = Fcar (oldstate); /* elt 5, follows-quote */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 start_quoted = !NILP (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 /* if the eighth element of the list is nil, we are in comment style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 a. if it is non-nil, we are in comment style b */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 oldstate = Fcdr (oldstate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 tem = Fcar (oldstate); /* elt 8, comment style a */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 state.comstyle = !NILP (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 mask = state.comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 state.quoted = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 mindepth = depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 curlevel->prev = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 curlevel->last = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 /* Enter the loop at a place appropriate for initial state. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 if (state.incomment) goto startincomment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 if (state.instring >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 if (start_quoted) goto startquotedinstring;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 goto startinstring;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 if (start_quoted) goto startquoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 while (from < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1277 code = SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 if (code == Scomment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 /* record the comment style we have entered so that only the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 comment-ender sequence (or single char) of the same style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 actually terminates the comment section. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1285 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 BUF_FETCH_CHAR (buf, from-1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 state.comstyle = (mask == SYNTAX_COMMENT_STYLE_B);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 state.comstart = from - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 else if (from < end &&
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1292 SYNTAX_START_P (mirrortab, BUF_FETCH_CHAR (buf, from-1),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 BUF_FETCH_CHAR (buf, from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 /* Record the comment style we have entered so that only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 the comment-end sequence of the same style actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 terminates the comment section. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 code = Scomment;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1299 mask = SYNTAX_COMMENT_MASK_START (mirrortab,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 BUF_FETCH_CHAR (buf, from-1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 BUF_FETCH_CHAR (buf, from));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 state.comstyle = (mask == SYNTAX_COMMENT_STYLE_B);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 state.comstart = from-1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1307 if (SYNTAX_PREFIX (mirrortab, BUF_FETCH_CHAR (buf, from - 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 switch (code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 case Scharquote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 if (stopbefore) goto stop; /* this arg means stop at sexp start */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 curlevel->last = from - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 startquoted:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 if (from == end) goto endquoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 goto symstarted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 /* treat following character as a word constituent */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 case Sword:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 case Ssymbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 if (stopbefore) goto stop; /* this arg means stop at sexp start */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 curlevel->last = from - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 symstarted:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 while (from < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1327 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 case Scharquote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 if (from == end) goto endquoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 case Sword:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 case Ssymbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 case Squote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 goto symdone;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 symdone:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 curlevel->prev = curlevel->last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 case Scomment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 state.incomment = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 startincomment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 if (commentstop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 Bufpos newfrom = find_end_of_comment (buf, from, end, mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 if (newfrom < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 /* we terminated search because from == end */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 from = end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 from = newfrom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 state.incomment = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 state.comstyle = 0; /* reset the comment style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 mask = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 case Sopen:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 if (stopbefore) goto stop; /* this arg means stop at sexp start */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 depth++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 /* curlevel++->last ran into compiler bug on Apollo */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 curlevel->last = from - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 if (++curlevel == endlevel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 error ("Nesting too deep for parser");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 curlevel->prev = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 curlevel->last = -1;
88
821dec489c24 Import from CVS: tag r20-0
cvs
parents: 78
diff changeset
1376 if (targetdepth == depth) goto done;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 case Sclose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 depth--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 if (depth < mindepth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 mindepth = depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 if (curlevel != levelstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 curlevel--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 curlevel->prev = curlevel->last;
88
821dec489c24 Import from CVS: tag r20-0
cvs
parents: 78
diff changeset
1386 if (targetdepth == depth) goto done;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 case Sstring:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 Emchar ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 if (stopbefore) goto stop; /* this arg means stop at sexp start */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 curlevel->last = from - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 /* XEmacs change: call syntax_match() on character */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 ch = BUF_FETCH_CHAR (buf, from - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1397 Lisp_Object stermobj = syntax_match (syntaxtab, ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 if (CHARP (stermobj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 state.instring = XCHAR (stermobj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 state.instring = ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 startinstring:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 if (from >= end) goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 if (BUF_FETCH_CHAR (buf, from) == state.instring) break;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1410 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 case Scharquote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 case Sescape:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 startquotedinstring:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 if (from >= end) goto endquoted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 state.instring = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 curlevel->prev = curlevel->last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 from++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 case Smath:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 case Swhitespace:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 case Spunct:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 case Squote:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 case Sendcomment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 case Sinherit:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 case Smax:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 stop: /* Here if stopping before start of sexp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 from--; /* We have just fetched the char that starts it; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 goto done; /* but return the position before it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 endquoted:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 state.quoted = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 done:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 state.depth = depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 state.mindepth = mindepth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 state.thislevelstart = curlevel->prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 state.prevlevelstart
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 state.location = from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 *stateptr = state;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1461 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 Parsing stops at TO or when certain criteria are met;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 point is set to where parsing stops.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 If fifth arg STATE is omitted or nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 parsing assumes that FROM is the beginning of a function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 Value is a list of eight elements describing final state of parsing:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 0. depth in parens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 1. character address of start of innermost containing list; nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 2. character address of start of last complete sexp terminated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 3. non-nil if inside a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (It is the character that will terminate the string.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 4. t if inside a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 5. t if following a quote character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 6. the minimum paren-depth encountered during this scan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 7. nil if in comment style a, or not in a comment; t if in comment style b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 in parentheses becomes equal to TARGETDEPTH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 Fourth arg STOPBEFORE non-nil means stop when come to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 any character that starts a sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 Fifth arg STATE is an eight-element list like what this function returns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 It is used to initialize the state of the parse. Its second and third
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 elements are ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1485 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1486 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 struct lisp_parse_state state;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 int target;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 Bufpos start, end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 struct buffer *buf = decode_buffer (buffer, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 if (!NILP (targetdepth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 CHECK_INT (targetdepth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 target = XINT (targetdepth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 target = -100000; /* We won't reach this depth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 get_buffer_range_char (buf, from, to, &start, &end, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 scan_sexps_forward (buf, &state, start, end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 target, !NILP (stopbefore), oldstate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 !NILP (commentstop));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 BUF_SET_PT (buf, state.location);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 * This junk is necessary because of a bug in SparcWorks cc 2.0.1. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 * doesn't handle functions as arguments to other functions very well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 Lisp_Object retval[8];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 retval[0] = make_int (state.depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 retval[1] = ((state.prevlevelstart < 0) ? Qnil :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 make_int (state.prevlevelstart));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 retval[2] = ((state.thislevelstart < 0) ? Qnil :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 make_int (state.thislevelstart));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 retval[3] = ((state.instring >= 0) ? make_int (state.instring) : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 retval[4] = ((state.incomment) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 retval[5] = ((state.quoted) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 retval[6] = make_int (state.mindepth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 retval[7] = ((state.comstyle) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 return (Flist (8, retval));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1530
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1531 /* Updating of the mirror syntax table.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1532
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1533 Each syntax table has a corresponding mirror table in it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1534 Whenever we make a change to a syntax table, we call
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1535 update_syntax_table() on it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1536
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1537 #### We really only need to map over the changed range.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1538
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1539 If we change the standard syntax table, we need to map over
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1540 all tables because any of them could be inheriting from the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1541 standard syntax table.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1542
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1543 When `set-syntax-table' is called, we set the buffer's mirror
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1544 syntax table as well.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1545 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1546
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1547 struct cmst_arg
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1548 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1549 Lisp_Object mirrortab;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1550 int check_inherit;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1551 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1552
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1553 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1554 cmst_mapfun (struct chartab_range *range, Lisp_Object val, void *arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1555 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1556 struct cmst_arg *closure = (struct cmst_arg *) arg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1557
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1558 if (CONSP (val))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1559 val = XCAR (val);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1560 if (SYNTAX_FROM_CODE (XINT (val)) == Sinherit
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1561 && closure->check_inherit)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1562 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1563 struct cmst_arg recursive;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1564
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1565 recursive.mirrortab = closure->mirrortab;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1566 recursive.check_inherit = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1567 map_char_table (XCHAR_TABLE (Vstandard_syntax_table), range,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1568 cmst_mapfun, &recursive);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1569 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1570 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1571 put_char_table (XCHAR_TABLE (closure->mirrortab), range, val);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1572 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1573 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1574
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1575 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1576 update_just_this_syntax_table (struct Lisp_Char_Table *ct)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1577 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1578 struct chartab_range range;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1579 struct cmst_arg arg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1580
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1581 arg.mirrortab = ct->mirror_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1582 arg.check_inherit = (CHAR_TABLEP (Vstandard_syntax_table)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1583 && ct != XCHAR_TABLE (Vstandard_syntax_table));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1584 range.type = CHARTAB_RANGE_ALL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1585 map_char_table (ct, &range, cmst_mapfun, &arg);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1586 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1587
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1588 /* Called from chartab.c when a change is made to a syntax table.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1589 If this is the standard syntax table, we need to recompute
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1590 *all* syntax tables (yuck). Otherwise we just recompute this
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1591 one. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1592
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1593 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1594 update_syntax_table (struct Lisp_Char_Table *ct)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1595 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1596 /* Don't be stymied at startup. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1597 if (CHAR_TABLEP (Vstandard_syntax_table)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1598 && ct == XCHAR_TABLE (Vstandard_syntax_table))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1599 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1600 Lisp_Object syntab;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1601
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1602 for (syntab = Vall_syntax_tables; !NILP (syntab);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1603 syntab = XCHAR_TABLE (syntab)->next_table)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1604 update_just_this_syntax_table (XCHAR_TABLE (syntab));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1605 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1606 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1607 update_just_this_syntax_table (ct);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1608 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1609
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 syms_of_syntax (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 defsymbol (&Qsyntax_table_p, "syntax-table-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1620 DEFSUBR (Fsyntax_table_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1621 DEFSUBR (Fsyntax_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1622 DEFSUBR (Fstandard_syntax_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1623 DEFSUBR (Fcopy_syntax_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1624 DEFSUBR (Fset_syntax_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1625 DEFSUBR (Fsyntax_designator_chars);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1626 DEFSUBR (Fchar_syntax);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1627 DEFSUBR (Fmatching_paren);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1628 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1629 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1631 DEFSUBR (Fforward_word);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1633 DEFSUBR (Fforward_comment);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1634 DEFSUBR (Fscan_lists);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1635 DEFSUBR (Fscan_sexps);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1636 DEFSUBR (Fbackward_prefix_chars);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1637 DEFSUBR (Fparse_partial_sexp);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 vars_of_syntax (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 Non-nil means `forward-sexp', etc., should treat comments as whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 words_include_escapes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 Non-nil means `forward-word', etc., should treat escape chars part of words.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 no_quit_in_re_search = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 complex_vars_of_syntax (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 /* Set this now, so first buffer creation can refer to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 /* Make it nil before calling copy-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 so that copy-syntax-table will know not to try to copy from garbage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 Vstandard_syntax_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 Vstandard_syntax_table = Fcopy_syntax_table (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 staticpro (&Vstandard_syntax_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 Vsyntax_designator_chars_string = make_pure_string (syntax_code_spec,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 Smax, Qnil, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 staticpro (&Vsyntax_designator_chars_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1669 fill_char_table (XCHAR_TABLE (Vstandard_syntax_table),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1670 make_int (Spunct));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1671
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1673 Emchar i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1674
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1675 for (i = 0; i <= 32; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1676 Fput_char_table (make_char (i), make_int ((int) Swhitespace),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1677 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1678 for (i = 127; i <= 159; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1679 Fput_char_table (make_char (i), make_int ((int) Swhitespace),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1680 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1681
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1682 for (i = 'a'; i <= 'z'; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1683 Fput_char_table (make_char (i), make_int ((int) Sword),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1684 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1685 for (i = 'A'; i <= 'Z'; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1686 Fput_char_table (make_char (i), make_int ((int) Sword),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1687 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1688 for (i = '0'; i <= '9'; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1689 Fput_char_table (make_char (i), make_int ((int) Sword),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1690 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1691 Fput_char_table (make_char ('$'), make_int ((int) Sword),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1692 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1693 Fput_char_table (make_char ('%'), make_int ((int) Sword),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1694 Vstandard_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1696 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1697 Fput_char_table (make_char ('('), Fcons (make_int ((int) Sopen),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1698 make_char (')')),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1699 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1700 Fput_char_table (make_char (')'), Fcons (make_int ((int) Sclose),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1701 make_char ('(')),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1702 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1703 Fput_char_table (make_char ('['), Fcons (make_int ((int) Sopen),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1704 make_char (']')),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1705 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1706 Fput_char_table (make_char (']'), Fcons (make_int ((int) Sclose),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1707 make_char ('[')),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1708 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1709 Fput_char_table (make_char ('{'), Fcons (make_int ((int) Sopen),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1710 make_char ('}')),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1711 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1712 Fput_char_table (make_char ('}'), Fcons (make_int ((int) Sclose),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1713 make_char ('{')),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1714 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1715 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1716
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1717 Fput_char_table (make_char ('"'), make_int ((int) Sstring),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1718 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1719 Fput_char_table (make_char ('\\'), make_int ((int) Sescape),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1720 Vstandard_syntax_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1722 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1723 CONST char *p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1724 for (p = "_-+*/&|<>="; *p; p++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1725 Fput_char_table (make_char (*p), make_int ((int) Ssymbol),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1726 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1727
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1728 for (p = ".,;:?!#@~^'`"; *p; p++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1729 Fput_char_table (make_char (*p), make_int ((int) Spunct),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1730 Vstandard_syntax_table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
1731 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 }