]> code.delx.au - gnu-emacs/blob - src/syntax.h
(Fy_or_n_p, Fyes_or_no_p): using_x_p renamed to have_menus_p.
[gnu-emacs] / src / syntax.h
1 /* Declarations having to do with GNU Emacs syntax tables.
2 Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21 extern Lisp_Object Qsyntax_table_p;
22 extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table ();
23
24 /* The standard syntax table is stored where it will automatically
25 be used in all new buffers. */
26 #define Vstandard_syntax_table buffer_defaults.syntax_table
27
28 /* A syntax table is a chartable whose elements are cons cells
29 (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char
30 is not a kind of parenthesis.
31
32 The low 8 bits of CODE+FLAGS is a code, as follows: */
33
34 enum syntaxcode
35 {
36 Swhitespace, /* for a whitespace character */
37 Spunct, /* for random punctuation characters */
38 Sword, /* for a word constituent */
39 Ssymbol, /* symbol constituent but not word constituent */
40 Sopen, /* for a beginning delimiter */
41 Sclose, /* for an ending delimiter */
42 Squote, /* for a prefix character like Lisp ' */
43 Sstring, /* for a string-grouping character like Lisp " */
44 Smath, /* for delimiters like $ in Tex. */
45 Sescape, /* for a character that begins a C-style escape */
46 Scharquote, /* for a character that quotes the following character */
47 Scomment, /* for a comment-starting character */
48 Sendcomment, /* for a comment-ending character */
49 Sinherit, /* use the standard syntax table for this character */
50 Smax /* Upper bound on codes that are meaningful */
51 };
52
53 /* Fetch the syntax entry for char C from table TABLE.
54 This returns the whole entry (normally a cons cell)
55 and does not do any kind of inheritance. */
56
57 #if 1
58 #define RAW_SYNTAX_ENTRY(table, c) \
59 (XCHAR_TABLE (table)->contents[(unsigned char) (c)])
60
61 #define SET_RAW_SYNTAX_ENTRY(table, c, val) \
62 (XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val))
63 #else
64 #define RAW_SYNTAX_ENTRY(table, c) \
65 ((c) >= 128 \
66 ? raw_syntax_table_lookup (table, c) \
67 : XCHAR_TABLE (table)->contents[(unsigned char) (c)])
68
69 #define SET_RAW_SYNTAX_ENTRY(table, c, val) \
70 ((c) >= 128 \
71 ? set_raw_syntax_table_lookup (table, c, (val)) \
72 : XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val))
73 #endif
74
75 /* Extract the information from the entry for character C
76 in syntax table TABLE. Do inheritance. */
77
78 #ifdef __GNUC__
79 #define SYNTAX_ENTRY(c) \
80 ({ Lisp_Object temp, table; \
81 unsigned char cc = (c); \
82 table = current_buffer->syntax_table; \
83 while (!NILP (table)) \
84 { \
85 temp = RAW_SYNTAX_ENTRY (table, cc); \
86 if (!NILP (temp)) \
87 break; \
88 table = XCHAR_TABLE (table)->parent; \
89 } \
90 temp; })
91
92 #define SYNTAX(c) \
93 ({ Lisp_Object temp; \
94 temp = SYNTAX_ENTRY (c); \
95 (CONSP (temp) \
96 ? (enum syntaxcode) (XINT (XCONS (temp)->car) & 0xff) \
97 : wrong_type_argument (Qconsp, temp)); })
98
99 #define SYNTAX_WITH_FLAGS(c) \
100 ({ Lisp_Object temp; \
101 temp = SYNTAX_ENTRY (c); \
102 (CONSP (temp) \
103 ? XINT (XCONS (temp)->car) \
104 : wrong_type_argument (Qconsp, temp)); })
105
106 #define SYNTAX_MATCH(c) \
107 ({ Lisp_Object temp; \
108 temp = SYNTAX_ENTRY (c); \
109 (CONSP (temp) \
110 ? XINT (XCONS (temp)->cdr) \
111 : wrong_type_argument (Qconsp, temp)); })
112 #else
113 extern Lisp_Object syntax_temp;
114 extern Lisp_Object syntax_parent_lookup ();
115
116 #define SYNTAX_ENTRY(c) \
117 (syntax_temp \
118 = RAW_SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \
119 (NILP (syntax_temp) \
120 ? (syntax_temp \
121 = syntax_parent_lookup (current_buffer->syntax_table, \
122 (unsigned char) (c))) \
123 : syntax_temp))
124
125 #define SYNTAX(c) \
126 (syntax_temp = SYNTAX_ENTRY ((c)), \
127 (CONSP (syntax_temp) \
128 ? (enum syntaxcode) (XINT (XCONS (syntax_temp)->car) & 0xff) \
129 : wrong_type_argument (Qconsp, syntax_temp)))
130
131 #define SYNTAX_WITH_FLAGS(c) \
132 (syntax_temp = SYNTAX_ENTRY ((c)), \
133 (CONSP (syntax_temp) \
134 ? XINT (XCONS (syntax_temp)->car) \
135 : wrong_type_argument (Qconsp, syntax_temp)))
136
137 #define SYNTAX_MATCH(c) \
138 (syntax_temp = SYNTAX_ENTRY ((c)), \
139 (CONSP (syntax_temp) \
140 ? XINT (XCONS (syntax_temp)->cdr) \
141 : wrong_type_argument (Qconsp, syntax_temp)))
142 #endif
143
144 /* Then there are six single-bit flags that have the following meanings:
145 1. This character is the first of a two-character comment-start sequence.
146 2. This character is the second of a two-character comment-start sequence.
147 3. This character is the first of a two-character comment-end sequence.
148 4. This character is the second of a two-character comment-end sequence.
149 5. This character is a prefix, for backward-prefix-chars.
150 Note that any two-character sequence whose first character has flag 1
151 and whose second character has flag 2 will be interpreted as a comment start.
152
153 bit 6 is used to discriminate between two different comment styles.
154 Languages such as C++ allow two orthogonal syntax start/end pairs
155 and bit 6 is used to determine whether a comment-end or Scommentend
156 ends style a or b. Comment start sequences can start style a or b.
157 Style a is always the default.
158 */
159
160 #define SYNTAX_COMSTART_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 16) & 1)
161
162 #define SYNTAX_COMSTART_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 17) & 1)
163
164 #define SYNTAX_COMEND_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 18) & 1)
165
166 #define SYNTAX_COMEND_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 19) & 1)
167
168 #define SYNTAX_PREFIX(c) ((SYNTAX_WITH_FLAGS (c) >> 20) & 1)
169
170 /* extract the comment style bit from the syntax table entry */
171 #define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1)
172
173 /* This array, indexed by a character, contains the syntax code which that
174 character signifies (as a char). For example,
175 (enum syntaxcode) syntax_spec_code['w'] is Sword. */
176
177 extern unsigned char syntax_spec_code[0400];
178
179 /* Indexed by syntax code, give the letter that describes it. */
180
181 extern char syntax_code_spec[14];