Comment change.
[bpt/emacs.git] / lispref / syntax.texi
CommitLineData
7015aca4
RS
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4@c See the file elisp.texi for copying conditions.
5@setfilename ../info/syntax
6@node Syntax Tables, Abbrevs, Searching and Matching, Top
7@chapter Syntax Tables
8@cindex parsing
9@cindex syntax table
10@cindex text parsing
11
12 A @dfn{syntax table} specifies the syntactic textual function of each
13character. This information is used by the parsing commands, the
14complex movement commands, and others to determine where words, symbols,
15and other syntactic constructs begin and end. The current syntax table
16controls the meaning of the word motion functions (@pxref{Word Motion})
17and the list motion functions (@pxref{List Motion}) as well as the
18functions in this chapter.
19
20@menu
21* Basics: Syntax Basics. Basic concepts of syntax tables.
22* Desc: Syntax Descriptors. How characters are classified.
23* Syntax Table Functions:: How to create, examine and alter syntax tables.
24* Motion and Syntax:: Moving over characters with certain syntaxes.
25* Parsing Expressions:: Parsing balanced expressions
26 using the syntax table.
27* Standard Syntax Tables:: Syntax tables used by various major modes.
28* Syntax Table Internals:: How syntax table information is stored.
29@end menu
30
31@node Syntax Basics
32@section Syntax Table Concepts
33
34@ifinfo
35 A @dfn{syntax table} provides Emacs with the information that
36determines the syntactic use of each character in a buffer. This
37information is used by the parsing commands, the complex movement
38commands, and others to determine where words, symbols, and other
39syntactic constructs begin and end. The current syntax table controls
40the meaning of the word motion functions (@pxref{Word Motion}) and the
41list motion functions (@pxref{List Motion}) as well as the functions in
42this chapter.
43@end ifinfo
44
45 A syntax table is a vector of 256 elements; it contains one entry for
bfe721d1 46each of the 256 possible characters in an 8-bit byte. Each element is
7015aca4
RS
47an integer that encodes the syntax of the character in question.
48
49 Syntax tables are used only for moving across text, not for the Emacs
50Lisp reader. Emacs Lisp uses built-in syntactic rules when reading Lisp
51expressions, and these rules cannot be changed.
52
53 Each buffer has its own major mode, and each major mode has its own
54idea of the syntactic class of various characters. For example, in Lisp
55mode, the character @samp{;} begins a comment, but in C mode, it
56terminates a statement. To support these variations, Emacs makes the
57choice of syntax table local to each buffer. Typically, each major
58mode has its own syntax table and installs that table in each buffer
7fd1911a 59that uses that mode. Changing this table alters the syntax in all
7015aca4
RS
60those buffers as well as in any buffers subsequently put in that mode.
61Occasionally several similar modes share one syntax table.
62@xref{Example Major Modes}, for an example of how to set up a syntax
63table.
64
65A syntax table can inherit the data for some characters from the
66standard syntax table, while specifying other characters itself. The
67``inherit'' syntax class means ``inherit this character's syntax from
68the standard syntax table.'' Most major modes' syntax tables inherit
69the syntax of character codes 0 through 31 and 128 through 255. This is
70useful with character sets such as ISO Latin-1 that have additional
71alphabetic characters in the range 128 to 255. Just changing the
72standard syntax for these characters affects all major modes.
73
74@defun syntax-table-p object
75This function returns @code{t} if @var{object} is a vector of length 256
76elements. This means that the vector may be a syntax table. However,
77according to this test, any vector of length 256 is considered to be a
78syntax table, no matter what its contents.
79@end defun
80
81@node Syntax Descriptors
82@section Syntax Descriptors
83@cindex syntax classes
84
85 This section describes the syntax classes and flags that denote the
86syntax of a character, and how they are represented as a @dfn{syntax
87descriptor}, which is a Lisp string that you pass to
88@code{modify-syntax-entry} to specify the desired syntax.
89
90 Emacs defines a number of @dfn{syntax classes}. Each syntax table
91puts each character into one class. There is no necessary relationship
92between the class of a character in one syntax table and its class in
93any other table.
94
7fd1911a 95 Each class is designated by a mnemonic character, which serves as the
7015aca4 96name of the class when you need to specify a class. Usually the
7fd1911a
RS
97designator character is one that is frequently in that class; however,
98its meaning as a designator is unvarying and independent of what syntax
99that character currently has.
7015aca4
RS
100
101@cindex syntax descriptor
7fd1911a 102 A syntax descriptor is a Lisp string that specifies a syntax class, a
7015aca4
RS
103matching character (used only for the parenthesis classes) and flags.
104The first character is the designator for a syntax class. The second
105character is the character to match; if it is unused, put a space there.
106Then come the characters for any desired flags. If no matching
107character or flags are needed, one character is sufficient.
108
109 For example, the descriptor for the character @samp{*} in C mode is
110@samp{@w{. 23}} (i.e., punctuation, matching character slot unused,
111second character of a comment-starter, first character of an
112comment-ender), and the entry for @samp{/} is @samp{@w{. 14}} (i.e.,
113punctuation, matching character slot unused, first character of a
114comment-starter, second character of a comment-ender).
115
116@menu
117* Syntax Class Table:: Table of syntax classes.
118* Syntax Flags:: Additional flags each character can have.
119@end menu
120
121@node Syntax Class Table
122@subsection Table of Syntax Classes
123
7fd1911a 124 Here is a table of syntax classes, the characters that stand for them,
7015aca4
RS
125their meanings, and examples of their use.
126
127@deffn {Syntax class} @w{whitespace character}
128@dfn{Whitespace characters} (designated with @w{@samp{@ }} or @samp{-})
129separate symbols and words from each other. Typically, whitespace
130characters have no other syntactic significance, and multiple whitespace
131characters are syntactically equivalent to a single one. Space, tab,
132newline and formfeed are almost always classified as whitespace.
133@end deffn
134
135@deffn {Syntax class} @w{word constituent}
136@dfn{Word constituents} (designated with @samp{w}) are parts of normal
137English words and are typically used in variable and command names in
7fd1911a 138programs. All upper- and lower-case letters, and the digits, are typically
7015aca4
RS
139word constituents.
140@end deffn
141
142@deffn {Syntax class} @w{symbol constituent}
143@dfn{Symbol constituents} (designated with @samp{_}) are the extra
144characters that are used in variable and command names along with word
145constituents. For example, the symbol constituents class is used in
146Lisp mode to indicate that certain characters may be part of symbol
147names even though they are not part of English words. These characters
148are @samp{$&*+-_<>}. In standard C, the only non-word-constituent
149character that is valid in symbols is underscore (@samp{_}).
150@end deffn
151
152@deffn {Syntax class} @w{punctuation character}
153@dfn{Punctuation characters} (@samp{.}) are those characters that are
154used as punctuation in English, or are used in some way in a programming
155language to separate symbols from one another. Most programming
156language modes, including Emacs Lisp mode, have no characters in this
157class since the few characters that are not symbol or word constituents
158all have other uses.
159@end deffn
160
161@deffn {Syntax class} @w{open parenthesis character}
162@deffnx {Syntax class} @w{close parenthesis character}
163@cindex parenthesis syntax
164Open and close @dfn{parenthesis characters} are characters used in
165dissimilar pairs to surround sentences or expressions. Such a grouping
166is begun with an open parenthesis character and terminated with a close.
167Each open parenthesis character matches a particular close parenthesis
168character, and vice versa. Normally, Emacs indicates momentarily the
169matching open parenthesis when you insert a close parenthesis.
170@xref{Blinking}.
171
172The class of open parentheses is designated with @samp{(}, and that of
173close parentheses with @samp{)}.
174
175In English text, and in C code, the parenthesis pairs are @samp{()},
176@samp{[]}, and @samp{@{@}}. In Emacs Lisp, the delimiters for lists and
177vectors (@samp{()} and @samp{[]}) are classified as parenthesis
178characters.
179@end deffn
180
181@deffn {Syntax class} @w{string quote}
182@dfn{String quote characters} (designated with @samp{"}) are used in
183many languages, including Lisp and C, to delimit string constants. The
184same string quote character appears at the beginning and the end of a
185string. Such quoted strings do not nest.
186
187The parsing facilities of Emacs consider a string as a single token.
188The usual syntactic meanings of the characters in the string are
189suppressed.
190
191The Lisp modes have two string quote characters: double-quote (@samp{"})
192and vertical bar (@samp{|}). @samp{|} is not used in Emacs Lisp, but it
193is used in Common Lisp. C also has two string quote characters:
194double-quote for strings, and single-quote (@samp{'}) for character
195constants.
196
197English text has no string quote characters because English is not a
198programming language. Although quotation marks are used in English,
199we do not want them to turn off the usual syntactic properties of
200other characters in the quotation.
201@end deffn
202
203@deffn {Syntax class} @w{escape}
204An @dfn{escape character} (designated with @samp{\}) starts an escape
205sequence such as is used in C string and character constants. The
206character @samp{\} belongs to this class in both C and Lisp. (In C, it
207is used thus only inside strings, but it turns out to cause no trouble
208to treat it this way throughout C code.)
209
210Characters in this class count as part of words if
211@code{words-include-escapes} is non-@code{nil}. @xref{Word Motion}.
212@end deffn
213
214@deffn {Syntax class} @w{character quote}
215A @dfn{character quote character} (designated with @samp{/}) quotes the
216following character so that it loses its normal syntactic meaning. This
217differs from an escape character in that only the character immediately
218following is ever affected.
219
220Characters in this class count as part of words if
221@code{words-include-escapes} is non-@code{nil}. @xref{Word Motion}.
222
e30ab160 223This class is used for backslash in @TeX{} mode.
7015aca4
RS
224@end deffn
225
226@deffn {Syntax class} @w{paired delimiter}
227@dfn{Paired delimiter characters} (designated with @samp{$}) are like
228string quote characters except that the syntactic properties of the
229characters between the delimiters are not suppressed. Only @TeX{} mode
7fd1911a
RS
230uses a paired delimiter presently---the @samp{$} that both enters and
231leaves math mode.
7015aca4
RS
232@end deffn
233
234@deffn {Syntax class} @w{expression prefix}
235An @dfn{expression prefix operator} (designated with @samp{'}) is used
236for syntactic operators that are part of an expression if they appear
237next to one. These characters in Lisp include the apostrophe, @samp{'}
238(used for quoting), the comma, @samp{,} (used in macros), and @samp{#}
239(used in the read syntax for certain data types).
240@end deffn
241
242@deffn {Syntax class} @w{comment starter}
243@deffnx {Syntax class} @w{comment ender}
244@cindex comment syntax
245The @dfn{comment starter} and @dfn{comment ender} characters are used in
246various languages to delimit comments. These classes are designated
247with @samp{<} and @samp{>}, respectively.
248
249English text has no comment characters. In Lisp, the semicolon
250(@samp{;}) starts a comment and a newline or formfeed ends one.
251@end deffn
252
253@deffn {Syntax class} @w{inherit}
254This syntax class does not specify a syntax. It says to look in the
255standard syntax table to find the syntax of this character. The
256designator for this syntax code is @samp{@@}.
257@end deffn
258
259@node Syntax Flags
260@subsection Syntax Flags
261@cindex syntax flags
262
263 In addition to the classes, entries for characters in a syntax table
264can include flags. There are six possible flags, represented by the
265characters @samp{1}, @samp{2}, @samp{3}, @samp{4}, @samp{b} and
266@samp{p}.
267
268 All the flags except @samp{p} are used to describe multi-character
269comment delimiters. The digit flags indicate that a character can
270@emph{also} be part of a comment sequence, in addition to the syntactic
271properties associated with its character class. The flags are
272independent of the class and each other for the sake of characters such
273as @samp{*} in C mode, which is a punctuation character, @emph{and} the
274second character of a start-of-comment sequence (@samp{/*}), @emph{and}
275the first character of an end-of-comment sequence (@samp{*/}).
276
277The flags for a character @var{c} are:
278
279@itemize @bullet
280@item
7fd1911a 281@samp{1} means @var{c} is the start of a two-character comment-start
7015aca4
RS
282sequence.
283
284@item
285@samp{2} means @var{c} is the second character of such a sequence.
286
287@item
7fd1911a 288@samp{3} means @var{c} is the start of a two-character comment-end
7015aca4
RS
289sequence.
290
291@item
292@samp{4} means @var{c} is the second character of such a sequence.
293
294@item
295@c Emacs 19 feature
296@samp{b} means that @var{c} as a comment delimiter belongs to the
297alternative ``b'' comment style.
298
299Emacs supports two comment styles simultaneously in any one syntax
300table. This is for the sake of C++. Each style of comment syntax has
301its own comment-start sequence and its own comment-end sequence. Each
302comment must stick to one style or the other; thus, if it starts with
303the comment-start sequence of style ``b'', it must also end with the
304comment-end sequence of style ``b''.
305
306The two comment-start sequences must begin with the same character; only
307the second character may differ. Mark the second character of the
7fd1911a 308``b''-style comment-start sequence with the @samp{b} flag.
7015aca4
RS
309
310A comment-end sequence (one or two characters) applies to the ``b''
311style if its first character has the @samp{b} flag set; otherwise, it
312applies to the ``a'' style.
313
314The appropriate comment syntax settings for C++ are as follows:
315
316@table @asis
317@item @samp{/}
318@samp{124b}
319@item @samp{*}
320@samp{23}
321@item newline
322@samp{>b}
323@end table
324
7fd1911a
RS
325This defines four comment-delimiting sequences:
326
327@table @asis
328@item @samp{/*}
329This is a comment-start sequence for ``a'' style because the
330second character, @samp{*}, does not have the @samp{b} flag.
331
332@item @samp{//}
333This is a comment-start sequence for ``b'' style because the second
334character, @samp{/}, does have the @samp{b} flag.
335
336@item @samp{*/}
337This is a comment-end sequence for ``a'' style because the first
338character, @samp{*}, does not have the @samp{b} flag
339
340@item newline
341This is a comment-end sequence for ``b'' style, because the newline
342character has the @samp{b} flag.
343@end table
7015aca4
RS
344
345@item
346@c Emacs 19 feature
347@samp{p} identifies an additional ``prefix character'' for Lisp syntax.
348These characters are treated as whitespace when they appear between
349expressions. When they appear within an expression, they are handled
350according to their usual syntax codes.
351
352The function @code{backward-prefix-chars} moves back over these
353characters, as well as over characters whose primary syntax class is
354prefix (@samp{'}). @xref{Motion and Syntax}.
355@end itemize
356
357@node Syntax Table Functions
358@section Syntax Table Functions
359
360 In this section we describe functions for creating, accessing and
361altering syntax tables.
362
363@defun make-syntax-table
364This function creates a new syntax table. Character codes 0 through
7fd1911a 36531 and 128 through 255 are set up to inherit from the standard syntax
7015aca4
RS
366table. The other character codes are set up by copying what the
367standard syntax table says about them.
368
369Most major mode syntax tables are created in this way.
370@end defun
371
372@defun copy-syntax-table &optional table
373This function constructs a copy of @var{table} and returns it. If
374@var{table} is not supplied (or is @code{nil}), it returns a copy of the
375current syntax table. Otherwise, an error is signaled if @var{table} is
376not a syntax table.
377@end defun
378
379@deffn Command modify-syntax-entry char syntax-descriptor &optional table
380This function sets the syntax entry for @var{char} according to
381@var{syntax-descriptor}. The syntax is changed only for @var{table},
382which defaults to the current buffer's syntax table, and not in any
383other syntax table. The argument @var{syntax-descriptor} specifies the
384desired syntax; this is a string beginning with a class designator
385character, and optionally containing a matching character and flags as
386well. @xref{Syntax Descriptors}.
387
388This function always returns @code{nil}. The old syntax information in
389the table for this character is discarded.
390
391An error is signaled if the first character of the syntax descriptor is not
392one of the twelve syntax class designator characters. An error is also
393signaled if @var{char} is not a character.
394
395@example
396@group
397@exdent @r{Examples:}
398
399;; @r{Put the space character in class whitespace.}
400(modify-syntax-entry ?\ " ")
401 @result{} nil
402@end group
403
404@group
405;; @r{Make @samp{$} an open parenthesis character,}
406;; @r{with @samp{^} as its matching close.}
407(modify-syntax-entry ?$ "(^")
408 @result{} nil
409@end group
410
411@group
412;; @r{Make @samp{^} a close parenthesis character,}
413;; @r{with @samp{$} as its matching open.}
414(modify-syntax-entry ?^ ")$")
415 @result{} nil
416@end group
417
418@group
419;; @r{Make @samp{/} a punctuation character,}
420;; @r{the first character of a start-comment sequence,}
421;; @r{and the second character of an end-comment sequence.}
422;; @r{This is used in C mode.}
7fd1911a 423(modify-syntax-entry ?/ ". 14")
7015aca4
RS
424 @result{} nil
425@end group
426@end example
427@end deffn
428
429@defun char-syntax character
430This function returns the syntax class of @var{character}, represented
431by its mnemonic designator character. This @emph{only} returns the
432class, not any matching parenthesis or flags.
433
434An error is signaled if @var{char} is not a character.
435
436The following examples apply to C mode. The first example shows that
437the syntax class of space is whitespace (represented by a space). The
438second example shows that the syntax of @samp{/} is punctuation. This
7fd1911a
RS
439does not show the fact that it is also part of comment-start and -end
440sequences. The third example shows that open parenthesis is in the class
7015aca4
RS
441of open parentheses. This does not show the fact that it has a matching
442character, @samp{)}.
443
444@example
445@group
446(char-to-string (char-syntax ?\ ))
447 @result{} " "
448@end group
449
450@group
451(char-to-string (char-syntax ?/))
452 @result{} "."
453@end group
454
455@group
456(char-to-string (char-syntax ?\())
457 @result{} "("
458@end group
459@end example
460@end defun
461
462@defun set-syntax-table table
463This function makes @var{table} the syntax table for the current buffer.
464It returns @var{table}.
465@end defun
466
467@defun syntax-table
468This function returns the current syntax table, which is the table for
469the current buffer.
470@end defun
471
472@node Motion and Syntax
473@section Motion and Syntax
474
475 This section describes functions for moving across characters in
476certain syntax classes. None of these functions exists in Emacs
477version 18 or earlier.
478
479@defun skip-syntax-forward syntaxes &optional limit
480This function moves point forward across characters having syntax classes
481mentioned in @var{syntaxes}. It stops when it encounters the end of
7fd1911a 482the buffer, or position @var{limit} (if specified), or a character it is
7015aca4
RS
483not supposed to skip.
484@ignore @c may want to change this.
485The return value is the distance traveled, which is a nonnegative
486integer.
487@end ignore
488@end defun
489
490@defun skip-syntax-backward syntaxes &optional limit
491This function moves point backward across characters whose syntax
492classes are mentioned in @var{syntaxes}. It stops when it encounters
7fd1911a 493the beginning of the buffer, or position @var{limit} (if specified), or a
7015aca4
RS
494character it is not supposed to skip.
495@ignore @c may want to change this.
496The return value indicates the distance traveled. It is an integer that
497is zero or less.
498@end ignore
499@end defun
500
501@defun backward-prefix-chars
502This function moves point backward over any number of characters with
503expression prefix syntax. This includes both characters in the
504expression prefix syntax class, and characters with the @samp{p} flag.
505@end defun
506
507@node Parsing Expressions
508@section Parsing Balanced Expressions
509
510 Here are several functions for parsing and scanning balanced
511expressions, also known as @dfn{sexps}, in which parentheses match in
512pairs. The syntax table controls the interpretation of characters, so
513these functions can be used for Lisp expressions when in Lisp mode and
514for C expressions when in C mode. @xref{List Motion}, for convenient
515higher-level functions for moving over balanced expressions.
516
517@defun parse-partial-sexp start limit &optional target-depth stop-before state stop-comment
518This function parses a sexp in the current buffer starting at
7fd1911a
RS
519@var{start}, not scanning past @var{limit}. It stops at position
520@var{limit} or when certain criteria described below are met, and sets
521point to the location where parsing stops. It returns a value
522describing the status of the parse at the point where it stops.
7015aca4
RS
523
524If @var{state} is @code{nil}, @var{start} is assumed to be at the top
525level of parenthesis structure, such as the beginning of a function
526definition. Alternatively, you might wish to resume parsing in the
527middle of the structure. To do this, you must provide a @var{state}
528argument that describes the initial status of parsing.
529
530@cindex parenthesis depth
531If the third argument @var{target-depth} is non-@code{nil}, parsing
532stops if the depth in parentheses becomes equal to @var{target-depth}.
533The depth starts at 0, or at whatever is given in @var{state}.
534
535If the fourth argument @var{stop-before} is non-@code{nil}, parsing
536stops when it comes to any character that starts a sexp. If
537@var{stop-comment} is non-@code{nil}, parsing stops when it comes to the
538start of a comment.
539
540@cindex parse state
541The fifth argument @var{state} is an eight-element list of the same
542form as the value of this function, described below. The return value
543of one call may be used to initialize the state of the parse on another
544call to @code{parse-partial-sexp}.
545
546The result is a list of eight elements describing the final state of
547the parse:
548
549@enumerate 0
550@item
551The depth in parentheses, counting from 0.
552
553@item
554@cindex innermost containing parentheses
7fd1911a
RS
555The character position of the start of the innermost parenthetical
556grouping containing the stopping point; @code{nil} if none.
7015aca4
RS
557
558@item
559@cindex previous complete subexpression
560The character position of the start of the last complete subexpression
561terminated; @code{nil} if none.
562
563@item
564@cindex inside string
565Non-@code{nil} if inside a string. More precisely, this is the
566character that will terminate the string.
567
568@item
569@cindex inside comment
7fd1911a 570@code{t} if inside a comment (of either style).
7015aca4
RS
571
572@item
573@cindex quote character
574@code{t} if point is just after a quote character.
575
576@item
577The minimum parenthesis depth encountered during this scan.
578
579@item
580@code{t} if inside a comment of style ``b''.
581@end enumerate
582
583Elements 0, 3, 4, 5 and 7 are significant in the argument @var{state}.
584
585@cindex indenting with parentheses
586This function is most often used to compute indentation for languages
587that have nested parentheses.
588@end defun
589
590@defun scan-lists from count depth
591This function scans forward @var{count} balanced parenthetical groupings
592from character number @var{from}. It returns the character position
593where the scan stops.
594
595If @var{depth} is nonzero, parenthesis depth counting begins from that
596value. The only candidates for stopping are places where the depth in
597parentheses becomes zero; @code{scan-lists} counts @var{count} such
598places and then stops. Thus, a positive value for @var{depth} means go
7fd1911a 599out @var{depth} levels of parenthesis.
7015aca4
RS
600
601Scanning ignores comments if @code{parse-sexp-ignore-comments} is
602non-@code{nil}.
603
7fd1911a
RS
604If the scan reaches the beginning or end of the buffer (or its
605accessible portion), and the depth is not zero, an error is signaled.
606If the depth is zero but the count is not used up, @code{nil} is
607returned.
7015aca4
RS
608@end defun
609
610@defun scan-sexps from count
611This function scans forward @var{count} sexps from character position
612@var{from}. It returns the character position where the scan stops.
613
614Scanning ignores comments if @code{parse-sexp-ignore-comments} is
615non-@code{nil}.
616
7fd1911a 617If the scan reaches the beginning or end of (the accessible part of) the
7015aca4
RS
618buffer in the middle of a parenthetical grouping, an error is signaled.
619If it reaches the beginning or end between groupings but before count is
620used up, @code{nil} is returned.
621@end defun
622
623@defvar parse-sexp-ignore-comments
624@cindex skipping comments
625If the value is non-@code{nil}, then comments are treated as
626whitespace by the functions in this section and by @code{forward-sexp}.
627
628In older Emacs versions, this feature worked only when the comment
629terminator is something like @samp{*/}, and appears only to end a
630comment. In languages where newlines terminate comments, it was
631necessary make this variable @code{nil}, since not every newline is the
632end of a comment. This limitation no longer exists.
633@end defvar
634
635You can use @code{forward-comment} to move forward or backward over
636one comment or several comments.
637
638@defun forward-comment count
639This function moves point forward across @var{count} comments (backward,
640if @var{count} is negative). If it finds anything other than a comment
641or whitespace, it stops, leaving point at the place where it stopped.
642It also stops after satisfying @var{count}.
643@end defun
644
645To move forward over all comments and whitespace following point, use
646@code{(forward-comment (buffer-size))}. @code{(buffer-size)} is a good
7fd1911a 647argument to use, because the number of comments in the buffer cannot
7015aca4
RS
648exceed that many.
649
650@node Standard Syntax Tables
651@section Some Standard Syntax Tables
652
bfe721d1
KH
653 Most of the major modes in Emacs have their own syntax tables. Here
654are several of them:
7015aca4
RS
655
656@defun standard-syntax-table
657This function returns the standard syntax table, which is the syntax
658table used in Fundamental mode.
659@end defun
660
661@defvar text-mode-syntax-table
662The value of this variable is the syntax table used in Text mode.
663@end defvar
664
665@defvar c-mode-syntax-table
666The value of this variable is the syntax table for C-mode buffers.
667@end defvar
668
669@defvar emacs-lisp-mode-syntax-table
670The value of this variable is the syntax table used in Emacs Lisp mode
671by editing commands. (It has no effect on the Lisp @code{read}
672function.)
673@end defvar
674
675@node Syntax Table Internals
676@section Syntax Table Internals
677@cindex syntax table internals
678
679 Each element of a syntax table is an integer that encodes the syntax
680of one character: the syntax class, possible matching character, and
681flags. Lisp programs don't usually work with the elements directly; the
682Lisp-level syntax table functions usually work with syntax descriptors
683(@pxref{Syntax Descriptors}).
684
685 The low 8 bits of each element of a syntax table indicate the
686syntax class.
687
688@table @asis
689@item @i{Integer}
690@i{Class}
691@item 0
692whitespace
693@item 1
694punctuation
695@item 2
696word
697@item 3
698symbol
699@item 4
700open parenthesis
701@item 5
702close parenthesis
703@item 6
704expression prefix
705@item 7
706string quote
707@item 8
708paired delimiter
709@item 9
710escape
711@item 10
712character quote
713@item 11
714comment-start
715@item 12
716comment-end
717@item 13
718inherit
719@end table
720
721 The next 8 bits are the matching opposite parenthesis (if the
722character has parenthesis syntax); otherwise, they are not meaningful.
723The next 6 bits are the flags.