annotate src/syntax.c @ 444:576fb035e263 r21-2-37

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