todo-mode.el: Remove dependence on auto-mode-alist.
[bpt/emacs.git] / doc / lispref / syntax.texi
CommitLineData
b8d4c8d0
GM
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
ba318903 3@c Copyright (C) 1990-1995, 1998-1999, 2001-2014 Free Software
ab422c4d 4@c Foundation, Inc.
b8d4c8d0 5@c See the file elisp.texi for copying conditions.
ecc6530d 6@node Syntax Tables
b8d4c8d0
GM
7@chapter Syntax Tables
8@cindex parsing buffer text
9@cindex syntax table
10@cindex text parsing
11
4230351b
CY
12 A @dfn{syntax table} specifies the syntactic role of each character
13in a buffer. It can be used to determine where words, symbols, and
14other syntactic constructs begin and end. This information is used by
15many Emacs facilities, including Font Lock mode (@pxref{Font Lock
16Mode}) and the various complex movement commands (@pxref{Motion}).
b8d4c8d0
GM
17
18@menu
19* Basics: Syntax Basics. Basic concepts of syntax tables.
4230351b 20* Syntax Descriptors:: How characters are classified.
b8d4c8d0
GM
21* Syntax Table Functions:: How to create, examine and alter syntax tables.
22* Syntax Properties:: Overriding syntax with text properties.
d24880de 23* Motion and Syntax:: Moving over characters with certain syntaxes.
b8d4c8d0
GM
24* Parsing Expressions:: Parsing balanced expressions
25 using the syntax table.
b8d4c8d0
GM
26* Syntax Table Internals:: How syntax table information is stored.
27* Categories:: Another way of classifying character syntax.
28@end menu
29
30@node Syntax Basics
31@section Syntax Table Concepts
32
02676e5d
CY
33 A syntax table is a data structure which can be used to look up the
34@dfn{syntax class} and other syntactic properties of each character.
35Syntax tables are used by Lisp programs for scanning and moving across
36text.
b8d4c8d0 37
02676e5d
CY
38 Internally, a syntax table is a char-table (@pxref{Char-Tables}).
39The element at index @var{c} describes the character with code
40@var{c}; its value is a cons cell which specifies the syntax of the
41character in question. @xref{Syntax Table Internals}, for details.
42However, instead of using @code{aset} and @code{aref} to modify and
43inspect syntax table contents, you should usually use the higher-level
44functions @code{char-syntax} and @code{modify-syntax-entry}, which are
45described in @ref{Syntax Table Functions}.
b8d4c8d0
GM
46
47@defun syntax-table-p object
48This function returns @code{t} if @var{object} is a syntax table.
49@end defun
50
02676e5d
CY
51 Each buffer has its own major mode, and each major mode has its own
52idea of the syntax class of various characters. For example, in Lisp
53mode, the character @samp{;} begins a comment, but in C mode, it
54terminates a statement. To support these variations, the syntax table
55is local to each buffer. Typically, each major mode has its own
56syntax table, which it installs in all buffers that use that mode.
57For example, the variable @code{emacs-lisp-mode-syntax-table} holds
58the syntax table used by Emacs Lisp mode, and
59@code{c-mode-syntax-table} holds the syntax table used by C mode.
60Changing a major mode's syntax table alters the syntax in all of that
61mode's buffers, as well as in any buffers subsequently put in that
62mode. Occasionally, several similar modes share one syntax table.
63@xref{Example Major Modes}, for an example of how to set up a syntax
64table.
65
66@cindex standard syntax table
67@cindex inheritance, syntax table
68 A syntax table can @dfn{inherit} from another syntax table, which is
69called its @dfn{parent syntax table}. A syntax table can leave the
70syntax class of some characters unspecified, by giving them the
71``inherit'' syntax class; such a character then acquires the syntax
72class specified by the parent syntax table (@pxref{Syntax Class
73Table}). Emacs defines a @dfn{standard syntax table}, which is the
74default parent syntax table, and is also the syntax table used by
75Fundamental mode.
76
77@defun standard-syntax-table
78This function returns the standard syntax table, which is the syntax
79table used in Fundamental mode.
80@end defun
81
82 Syntax tables are not used by the Emacs Lisp reader, which has its
83own built-in syntactic rules which cannot be changed. (Some Lisp
84systems provide ways to redefine the read syntax, but we decided to
85leave this feature out of Emacs Lisp for simplicity.)
86
b8d4c8d0
GM
87@node Syntax Descriptors
88@section Syntax Descriptors
89@cindex syntax class
90
02676e5d 91 The @dfn{syntax class} of a character describes its syntactic role.
4230351b 92Each syntax table specifies the syntax class of each character. There
b8d4c8d0
GM
93is no necessary relationship between the class of a character in one
94syntax table and its class in any other table.
95
4230351b
CY
96 Each syntax class is designated by a mnemonic character, which
97serves as the name of the class when you need to specify a class.
98Usually, this designator character is one that is often assigned that
99class; however, its meaning as a designator is unvarying and
100independent of what syntax that character currently has. Thus,
101@samp{\} as a designator character always means ``escape character''
102syntax, regardless of whether the @samp{\} character actually has that
103syntax in the current syntax table.
104@ifnottex
02676e5d
CY
105@xref{Syntax Class Table}, for a list of syntax classes and their
106designator characters.
4230351b 107@end ifnottex
b8d4c8d0
GM
108
109@cindex syntax descriptor
4230351b 110 A @dfn{syntax descriptor} is a Lisp string that describes the syntax
02676e5d
CY
111class and other syntactic properties of a character. When you want to
112modify the syntax of a character, that is done by calling the function
113@code{modify-syntax-entry} and passing a syntax descriptor as one of
114its arguments (@pxref{Syntax Table Functions}).
115
116 The first character in a syntax descriptor must be a syntax class
117designator character. The second character, if present, specifies a
1df7defd 118matching character (e.g., in Lisp, the matching character for
02676e5d
CY
119@samp{(} is @samp{)}); a space specifies that there is no matching
120character. Then come characters specifying additional syntax
121properties (@pxref{Syntax Flags}).
4230351b
CY
122
123 If no matching character or flags are needed, only one character
124(specifying the syntax class) is sufficient.
b8d4c8d0
GM
125
126 For example, the syntax descriptor for the character @samp{*} in C
ad21a12a 127mode is @code{". 23"} (i.e., punctuation, matching character slot
b8d4c8d0
GM
128unused, second character of a comment-starter, first character of a
129comment-ender), and the entry for @samp{/} is @samp{@w{. 14}} (i.e.,
130punctuation, matching character slot unused, first character of a
131comment-starter, second character of a comment-ender).
132
6dcef6ec
CY
133 Emacs also defines @dfn{raw syntax descriptors}, which are used to
134describe syntax classes at a lower level. @xref{Syntax Table
135Internals}.
136
b8d4c8d0
GM
137@menu
138* Syntax Class Table:: Table of syntax classes.
139* Syntax Flags:: Additional flags each character can have.
140@end menu
141
142@node Syntax Class Table
143@subsection Table of Syntax Classes
8c1f51ff 144@cindex syntax class table
b8d4c8d0 145
4230351b
CY
146 Here is a table of syntax classes, the characters that designate
147them, their meanings, and examples of their use.
b8d4c8d0 148
4230351b
CY
149@table @asis
150@item Whitespace characters: @samp{@ } or @samp{-}
151Characters that separate symbols and words from each other.
152Typically, whitespace characters have no other syntactic significance,
153and multiple whitespace characters are syntactically equivalent to a
154single one. Space, tab, and formfeed are classified as whitespace in
155almost all major modes.
156
157This syntax class can be designated by either @w{@samp{@ }} or
158@samp{-}. Both designators are equivalent.
159
160@item Word constituents: @samp{w}
161Parts of words in human languages. These are typically used in
162variable and command names in programs. All upper- and lower-case
163letters, and the digits, are typically word constituents.
164
165@item Symbol constituents: @samp{_}
166Extra characters used in variable and command names along with word
167constituents. Examples include the characters @samp{$&*+-_<>} in Lisp
168mode, which may be part of a symbol name even though they are not part
169of English words. In standard C, the only non-word-constituent
b8d4c8d0 170character that is valid in symbols is underscore (@samp{_}).
b8d4c8d0 171
4230351b
CY
172@item Punctuation characters: @samp{.}
173Characters used as punctuation in a human language, or used in a
174programming language to separate symbols from one another. Some
175programming language modes, such as Emacs Lisp mode, have no
176characters in this class since the few characters that are not symbol
177or word constituents all have other uses. Other programming language
178modes, such as C mode, use punctuation syntax for operators.
179
180@item Open parenthesis characters: @samp{(}
181@itemx Close parenthesis characters: @samp{)}
182Characters used in dissimilar pairs to surround sentences or
183expressions. Such a grouping is begun with an open parenthesis
184character and terminated with a close. Each open parenthesis
185character matches a particular close parenthesis character, and vice
186versa. Normally, Emacs indicates momentarily the matching open
187parenthesis when you insert a close parenthesis. @xref{Blinking}.
188
189In human languages, and in C code, the parenthesis pairs are
190@samp{()}, @samp{[]}, and @samp{@{@}}. In Emacs Lisp, the delimiters
191for lists and vectors (@samp{()} and @samp{[]}) are classified as
192parenthesis characters.
193
194@item String quotes: @samp{"}
195Characters used to delimit string constants. The same string quote
196character appears at the beginning and the end of a string. Such
197quoted strings do not nest.
b8d4c8d0
GM
198
199The parsing facilities of Emacs consider a string as a single token.
200The usual syntactic meanings of the characters in the string are
201suppressed.
202
203The Lisp modes have two string quote characters: double-quote (@samp{"})
204and vertical bar (@samp{|}). @samp{|} is not used in Emacs Lisp, but it
205is used in Common Lisp. C also has two string quote characters:
206double-quote for strings, and single-quote (@samp{'}) for character
207constants.
208
4230351b
CY
209Human text has no string quote characters. We do not want quotation
210marks to turn off the usual syntactic properties of other characters
211in the quotation.
b8d4c8d0 212
4230351b
CY
213@item Escape-syntax characters: @samp{\}
214Characters that start an escape sequence, such as is used in string
215and character constants. The character @samp{\} belongs to this class
216in both C and Lisp. (In C, it is used thus only inside strings, but
217it turns out to cause no trouble to treat it this way throughout C
218code.)
b8d4c8d0
GM
219
220Characters in this class count as part of words if
221@code{words-include-escapes} is non-@code{nil}. @xref{Word Motion}.
b8d4c8d0 222
4230351b
CY
223@item Character quotes: @samp{/}
224Characters used to quote the following character so that it loses its
225normal syntactic meaning. This differs from an escape character in
226that only the character immediately following is ever affected.
b8d4c8d0
GM
227
228Characters in this class count as part of words if
229@code{words-include-escapes} is non-@code{nil}. @xref{Word Motion}.
230
231This class is used for backslash in @TeX{} mode.
b8d4c8d0 232
4230351b
CY
233@item Paired delimiters: @samp{$}
234Similar to string quote characters, except that the syntactic
235properties of the characters between the delimiters are not
236suppressed. Only @TeX{} mode uses a paired delimiter presently---the
237@samp{$} that both enters and leaves math mode.
238
239@item Expression prefixes: @samp{'}
240Characters used for syntactic operators that are considered as part of
241an expression if they appear next to one. In Lisp modes, these
242characters include the apostrophe, @samp{'} (used for quoting), the
243comma, @samp{,} (used in macros), and @samp{#} (used in the read
244syntax for certain data types).
245
246@item Comment starters: @samp{<}
247@itemx Comment enders: @samp{>}
b8d4c8d0 248@cindex comment syntax
4230351b
CY
249Characters used in various languages to delimit comments. Human text
250has no comment characters. In Lisp, the semicolon (@samp{;}) starts a
251comment and a newline or formfeed ends one.
b8d4c8d0 252
4230351b
CY
253@item Inherit standard syntax: @samp{@@}
254This syntax class does not specify a particular syntax. It says to
255look in the standard syntax table to find the syntax of this
256character.
b8d4c8d0 257
4230351b
CY
258@item Generic comment delimiters: @samp{!}
259Characters that start or end a special kind of comment. @emph{Any}
260generic comment delimiter matches @emph{any} generic comment
261delimiter, but they cannot match a comment starter or comment ender;
262generic comment delimiters can only match each other.
b8d4c8d0
GM
263
264This syntax class is primarily meant for use with the
4230351b
CY
265@code{syntax-table} text property (@pxref{Syntax Properties}). You
266can mark any range of characters as forming a comment, by giving the
267first and last characters of the range @code{syntax-table} properties
b8d4c8d0 268identifying them as generic comment delimiters.
b8d4c8d0 269
4230351b
CY
270@item Generic string delimiters: @samp{|}
271Characters that start or end a string. This class differs from the
272string quote class in that @emph{any} generic string delimiter can
273match any other generic string delimiter; but they do not match
274ordinary string quote characters.
b8d4c8d0
GM
275
276This syntax class is primarily meant for use with the
4230351b
CY
277@code{syntax-table} text property (@pxref{Syntax Properties}). You
278can mark any range of characters as forming a string constant, by
279giving the first and last characters of the range @code{syntax-table}
280properties identifying them as generic string delimiters.
281@end table
b8d4c8d0
GM
282
283@node Syntax Flags
284@subsection Syntax Flags
285@cindex syntax flags
286
287 In addition to the classes, entries for characters in a syntax table
7cf78aac
SM
288can specify flags. There are eight possible flags, represented by the
289characters @samp{1}, @samp{2}, @samp{3}, @samp{4}, @samp{b}, @samp{c},
290@samp{n}, and @samp{p}.
291
292 All the flags except @samp{p} are used to describe comment
293delimiters. The digit flags are used for comment delimiters made up
294of 2 characters. They indicate that a character can @emph{also} be
295part of a comment sequence, in addition to the syntactic properties
296associated with its character class. The flags are independent of the
297class and each other for the sake of characters such as @samp{*} in
298C mode, which is a punctuation character, @emph{and} the second
299character of a start-of-comment sequence (@samp{/*}), @emph{and} the
300first character of an end-of-comment sequence (@samp{*/}). The flags
301@samp{b}, @samp{c}, and @samp{n} are used to qualify the corresponding
302comment delimiter.
b8d4c8d0
GM
303
304 Here is a table of the possible flags for a character @var{c},
305and what they mean:
306
307@itemize @bullet
308@item
309@samp{1} means @var{c} is the start of a two-character comment-start
310sequence.
311
312@item
313@samp{2} means @var{c} is the second character of such a sequence.
314
315@item
316@samp{3} means @var{c} is the start of a two-character comment-end
317sequence.
318
319@item
320@samp{4} means @var{c} is the second character of such a sequence.
321
322@item
b8d4c8d0 323@samp{b} means that @var{c} as a comment delimiter belongs to the
7cf78aac
SM
324alternative ``b'' comment style. For a two-character comment starter,
325this flag is only significant on the second char, and for a 2-character
326comment ender it is only significant on the first char.
b8d4c8d0 327
7cf78aac
SM
328@item
329@samp{c} means that @var{c} as a comment delimiter belongs to the
330alternative ``c'' comment style. For a two-character comment
331delimiter, @samp{c} on either character makes it of style ``c''.
b8d4c8d0 332
7cf78aac
SM
333@item
334@samp{n} on a comment delimiter character specifies
335that this kind of comment can be nested. For a two-character
336comment delimiter, @samp{n} on either character makes it
337nestable.
b8d4c8d0 338
79b3ad55 339@cindex comment style
7cf78aac
SM
340Emacs supports several comment styles simultaneously in any one syntax
341table. A comment style is a set of flags @samp{b}, @samp{c}, and
342@samp{n}, so there can be up to 8 different comment styles.
343Each comment delimiter has a style and only matches comment delimiters
344of the same style. Thus if a comment starts with the comment-start
345sequence of style ``bn'', it will extend until the next matching
346comment-end sequence of style ``bn''.
b8d4c8d0 347
7cf78aac 348The appropriate comment syntax settings for C++ can be as follows:
b8d4c8d0
GM
349
350@table @asis
351@item @samp{/}
7cf78aac 352@samp{124}
b8d4c8d0 353@item @samp{*}
7cf78aac 354@samp{23b}
b8d4c8d0 355@item newline
7cf78aac 356@samp{>}
b8d4c8d0
GM
357@end table
358
359This defines four comment-delimiting sequences:
360
361@table @asis
362@item @samp{/*}
7cf78aac
SM
363This is a comment-start sequence for ``b'' style because the
364second character, @samp{*}, has the @samp{b} flag.
b8d4c8d0
GM
365
366@item @samp{//}
7cf78aac
SM
367This is a comment-start sequence for ``a'' style because the second
368character, @samp{/}, does not have the @samp{b} flag.
b8d4c8d0
GM
369
370@item @samp{*/}
7cf78aac 371This is a comment-end sequence for ``b'' style because the first
35a30759 372character, @samp{*}, has the @samp{b} flag.
b8d4c8d0
GM
373
374@item newline
7cf78aac
SM
375This is a comment-end sequence for ``a'' style, because the newline
376character does not have the @samp{b} flag.
b8d4c8d0
GM
377@end table
378
b8d4c8d0 379@item
b8d4c8d0
GM
380@samp{p} identifies an additional ``prefix character'' for Lisp syntax.
381These characters are treated as whitespace when they appear between
382expressions. When they appear within an expression, they are handled
383according to their usual syntax classes.
384
385The function @code{backward-prefix-chars} moves back over these
386characters, as well as over characters whose primary syntax class is
387prefix (@samp{'}). @xref{Motion and Syntax}.
388@end itemize
389
390@node Syntax Table Functions
391@section Syntax Table Functions
392
393 In this section we describe functions for creating, accessing and
394altering syntax tables.
395
396@defun make-syntax-table &optional table
02676e5d
CY
397This function creates a new syntax table. If @var{table} is
398non-@code{nil}, the parent of the new syntax table is @var{table};
399otherwise, the parent is the standard syntax table.
400
401In the new syntax table, all characters are initially given the
1df7defd 402``inherit'' (@samp{@@}) syntax class, i.e., their syntax is inherited
02676e5d 403from the parent table (@pxref{Syntax Class Table}).
b8d4c8d0
GM
404@end defun
405
406@defun copy-syntax-table &optional table
407This function constructs a copy of @var{table} and returns it. If
02676e5d
CY
408@var{table} is omitted or @code{nil}, it returns a copy of the
409standard syntax table. Otherwise, an error is signaled if @var{table}
410is not a syntax table.
b8d4c8d0
GM
411@end defun
412
413@deffn Command modify-syntax-entry char syntax-descriptor &optional table
c9358b45 414@cindex syntax entry, setting
b8d4c8d0 415This function sets the syntax entry for @var{char} according to
4230351b 416@var{syntax-descriptor}. @var{char} must be a character, or a cons
f147ff75
CY
417cell of the form @code{(@var{min} . @var{max})}; in the latter case,
418the function sets the syntax entries for all characters in the range
419between @var{min} and @var{max}, inclusive.
420
421The syntax is changed only for @var{table}, which defaults to the
4230351b
CY
422current buffer's syntax table, and not in any other syntax table.
423
1df7defd 424The argument @var{syntax-descriptor} is a syntax descriptor, i.e., a
02676e5d
CY
425string whose first character is a syntax class designator and whose
426second and subsequent characters optionally specify a matching
427character and syntax flags. @xref{Syntax Descriptors}. An error is
428signaled if @var{syntax-descriptor} is not a valid syntax descriptor.
b8d4c8d0
GM
429
430This function always returns @code{nil}. The old syntax information in
431the table for this character is discarded.
432
b8d4c8d0
GM
433@example
434@group
435@exdent @r{Examples:}
436
437;; @r{Put the space character in class whitespace.}
438(modify-syntax-entry ?\s " ")
439 @result{} nil
440@end group
441
442@group
443;; @r{Make @samp{$} an open parenthesis character,}
444;; @r{with @samp{^} as its matching close.}
445(modify-syntax-entry ?$ "(^")
446 @result{} nil
447@end group
448
449@group
450;; @r{Make @samp{^} a close parenthesis character,}
451;; @r{with @samp{$} as its matching open.}
452(modify-syntax-entry ?^ ")$")
453 @result{} nil
454@end group
455
456@group
457;; @r{Make @samp{/} a punctuation character,}
458;; @r{the first character of a start-comment sequence,}
459;; @r{and the second character of an end-comment sequence.}
460;; @r{This is used in C mode.}
461(modify-syntax-entry ?/ ". 14")
462 @result{} nil
463@end group
464@end example
465@end deffn
466
467@defun char-syntax character
468This function returns the syntax class of @var{character}, represented
02676e5d
CY
469by its designator character (@pxref{Syntax Class Table}). This
470returns @emph{only} the class, not its matching character or syntax
471flags.
b8d4c8d0 472
02676e5d
CY
473The following examples apply to C mode. (We use @code{string} to make
474it easier to see the character returned by @code{char-syntax}.)
b8d4c8d0
GM
475
476@example
477@group
02676e5d 478;; Space characters have whitespace syntax class.
b8d4c8d0
GM
479(string (char-syntax ?\s))
480 @result{} " "
481@end group
482
483@group
75e78d1e
GM
484;; Forward slash characters have punctuation syntax.
485;; Note that this @code{char-syntax} call does not reveal
486;; that it is also part of comment-start and -end sequences.
b8d4c8d0
GM
487(string (char-syntax ?/))
488 @result{} "."
489@end group
490
491@group
75e78d1e
GM
492;; Open parenthesis characters have open parenthesis syntax.
493;; Note that this @code{char-syntax} call does not reveal that
494;; it has a matching character, @samp{)}.
b8d4c8d0
GM
495(string (char-syntax ?\())
496 @result{} "("
497@end group
498@end example
499
b8d4c8d0
GM
500@end defun
501
502@defun set-syntax-table table
503This function makes @var{table} the syntax table for the current buffer.
504It returns @var{table}.
505@end defun
506
507@defun syntax-table
508This function returns the current syntax table, which is the table for
509the current buffer.
510@end defun
511
253e30aa
GM
512@deffn Command describe-syntax &optional buffer
513This command displays the contents of the syntax table of
514@var{buffer} (by default, the current buffer) in a help buffer.
515@end deffn
516
151d9088 517@defmac with-syntax-table table body@dots{}
b8d4c8d0
GM
518This macro executes @var{body} using @var{table} as the current syntax
519table. It returns the value of the last form in @var{body}, after
520restoring the old current syntax table.
521
522Since each buffer has its own current syntax table, we should make that
523more precise: @code{with-syntax-table} temporarily alters the current
524syntax table of whichever buffer is current at the time the macro
525execution starts. Other buffers are not affected.
526@end defmac
527
528@node Syntax Properties
529@section Syntax Properties
530@kindex syntax-table @r{(text property)}
531
532When the syntax table is not flexible enough to specify the syntax of
4230351b
CY
533a language, you can override the syntax table for specific character
534occurrences in the buffer, by applying a @code{syntax-table} text
535property. @xref{Text Properties}, for how to apply text properties.
b8d4c8d0 536
4230351b 537 The valid values of @code{syntax-table} text property are:
b8d4c8d0
GM
538
539@table @asis
540@item @var{syntax-table}
541If the property value is a syntax table, that table is used instead of
4230351b
CY
542the current buffer's syntax table to determine the syntax for the
543underlying text character.
b8d4c8d0
GM
544
545@item @code{(@var{syntax-code} . @var{matching-char})}
6dcef6ec
CY
546A cons cell of this format is a raw syntax descriptor (@pxref{Syntax
547Table Internals}), which directly specifies a syntax class for the
548underlying text character.
b8d4c8d0
GM
549
550@item @code{nil}
551If the property is @code{nil}, the character's syntax is determined from
552the current syntax table in the usual way.
553@end table
554
555@defvar parse-sexp-lookup-properties
4230351b
CY
556If this is non-@code{nil}, the syntax scanning functions, like
557@code{forward-sexp}, pay attention to syntax text properties.
558Otherwise they use only the current syntax table.
559@end defvar
560
561@defvar syntax-propertize-function
562This variable, if non-@code{nil}, should store a function for applying
563@code{syntax-table} properties to a specified stretch of text. It is
564intended to be used by major modes to install a function which applies
565@code{syntax-table} properties in some mode-appropriate way.
566
567The function is called by @code{syntax-ppss} (@pxref{Position Parse}),
568and by Font Lock mode during syntactic fontification (@pxref{Syntactic
569Font Lock}). It is called with two arguments, @var{start} and
570@var{end}, which are the starting and ending positions of the text on
571which it should act. It is allowed to call @code{syntax-ppss} on any
572position before @var{end}. However, it should not call
573@code{syntax-ppss-flush-cache}; so, it is not allowed to call
574@code{syntax-ppss} on some position and later modify the buffer at an
575earlier position.
576@end defvar
577
578@defvar syntax-propertize-extend-region-functions
579This abnormal hook is run by the syntax parsing code prior to calling
580@code{syntax-propertize-function}. Its role is to help locate safe
581starting and ending buffer positions for passing to
582@code{syntax-propertize-function}. For example, a major mode can add
583a function to this hook to identify multi-line syntactic constructs,
584and ensure that the boundaries do not fall in the middle of one.
585
586Each function in this hook should accept two arguments, @var{start}
587and @var{end}. It should return either a cons cell of two adjusted
588buffer positions, @code{(@var{new-start} . @var{new-end})}, or
589@code{nil} if no adjustment is necessary. The hook functions are run
590in turn, repeatedly, until they all return @code{nil}.
b8d4c8d0
GM
591@end defvar
592
593@node Motion and Syntax
594@section Motion and Syntax
595
596 This section describes functions for moving across characters that
597have certain syntax classes.
598
599@defun skip-syntax-forward syntaxes &optional limit
600This function moves point forward across characters having syntax
601classes mentioned in @var{syntaxes} (a string of syntax class
602characters). It stops when it encounters the end of the buffer, or
603position @var{limit} (if specified), or a character it is not supposed
604to skip.
605
606If @var{syntaxes} starts with @samp{^}, then the function skips
607characters whose syntax is @emph{not} in @var{syntaxes}.
608
609The return value is the distance traveled, which is a nonnegative
610integer.
611@end defun
612
613@defun skip-syntax-backward syntaxes &optional limit
614This function moves point backward across characters whose syntax
615classes are mentioned in @var{syntaxes}. It stops when it encounters
616the beginning of the buffer, or position @var{limit} (if specified), or
617a character it is not supposed to skip.
618
619If @var{syntaxes} starts with @samp{^}, then the function skips
620characters whose syntax is @emph{not} in @var{syntaxes}.
621
622The return value indicates the distance traveled. It is an integer that
623is zero or less.
624@end defun
625
626@defun backward-prefix-chars
627This function moves point backward over any number of characters with
628expression prefix syntax. This includes both characters in the
629expression prefix syntax class, and characters with the @samp{p} flag.
630@end defun
631
632@node Parsing Expressions
633@section Parsing Expressions
634
635 This section describes functions for parsing and scanning balanced
a037c171
CY
636expressions. We will refer to such expressions as @dfn{sexps},
637following the terminology of Lisp, even though these functions can act
638on languages other than Lisp. Basically, a sexp is either a balanced
1df7defd 639parenthetical grouping, a string, or a ``symbol'' (i.e., a sequence
a037c171 640of characters whose syntax is either word constituent or symbol
4230351b
CY
641constituent). However, characters in the expression prefix syntax
642class (@pxref{Syntax Class Table}) are treated as part of the sexp if
643they appear next to it.
b8d4c8d0
GM
644
645 The syntax table controls the interpretation of characters, so these
646functions can be used for Lisp expressions when in Lisp mode and for C
647expressions when in C mode. @xref{List Motion}, for convenient
648higher-level functions for moving over balanced expressions.
649
650 A character's syntax controls how it changes the state of the
651parser, rather than describing the state itself. For example, a
652string delimiter character toggles the parser state between
16152b76 653``in-string'' and ``in-code'', but the syntax of characters does not
b8d4c8d0
GM
654directly say whether they are inside a string. For example (note that
65515 is the syntax code for generic string delimiters),
656
657@example
658(put-text-property 1 9 'syntax-table '(15 . nil))
659@end example
660
661@noindent
662does not tell Emacs that the first eight chars of the current buffer
663are a string, but rather that they are all string delimiters. As a
664result, Emacs treats them as four consecutive empty string constants.
665
666@menu
667* Motion via Parsing:: Motion functions that work by parsing.
668* Position Parse:: Determining the syntactic state of a position.
669* Parser State:: How Emacs represents a syntactic state.
670* Low-Level Parsing:: Parsing across a specified region.
671* Control Parsing:: Parameters that affect parsing.
672@end menu
673
674@node Motion via Parsing
675@subsection Motion Commands Based on Parsing
676
677 This section describes simple point-motion functions that operate
678based on parsing expressions.
679
680@defun scan-lists from count depth
7b926f3f
CY
681This function scans forward @var{count} balanced parenthetical
682groupings from position @var{from}. It returns the position where the
683scan stops. If @var{count} is negative, the scan moves backwards.
684
685If @var{depth} is nonzero, treat the starting position as being
686@var{depth} parentheses deep. The scanner moves forward or backward
687through the buffer until the depth changes to zero @var{count} times.
688Hence, a positive value for @var{depth} has the effect of moving out
689@var{depth} levels of parenthesis from the starting position, while a
690negative @var{depth} has the effect of moving deeper by @var{-depth}
691levels of parenthesis.
b8d4c8d0
GM
692
693Scanning ignores comments if @code{parse-sexp-ignore-comments} is
694non-@code{nil}.
695
7b926f3f
CY
696If the scan reaches the beginning or end of the accessible part of the
697buffer before it has scanned over @var{count} parenthetical groupings,
698the return value is @code{nil} if the depth at that point is zero; if
699the depth is non-zero, a @code{scan-error} error is signaled.
b8d4c8d0
GM
700@end defun
701
702@defun scan-sexps from count
703This function scans forward @var{count} sexps from position @var{from}.
704It returns the position where the scan stops. If @var{count} is
705negative, the scan moves backwards.
706
707Scanning ignores comments if @code{parse-sexp-ignore-comments} is
708non-@code{nil}.
709
710If the scan reaches the beginning or end of (the accessible part of) the
711buffer while in the middle of a parenthetical grouping, an error is
712signaled. If it reaches the beginning or end between groupings but
713before count is used up, @code{nil} is returned.
714@end defun
715
716@defun forward-comment count
717This function moves point forward across @var{count} complete comments
718 (that is, including the starting delimiter and the terminating
719delimiter if any), plus any whitespace encountered on the way. It
720moves backward if @var{count} is negative. If it encounters anything
721other than a comment or whitespace, it stops, leaving point at the
722place where it stopped. This includes (for instance) finding the end
723of a comment when moving forward and expecting the beginning of one.
724The function also stops immediately after moving over the specified
725number of complete comments. If @var{count} comments are found as
726expected, with nothing except whitespace between them, it returns
727@code{t}; otherwise it returns @code{nil}.
728
729This function cannot tell whether the ``comments'' it traverses are
730embedded within a string. If they look like comments, it treats them
731as comments.
b8d4c8d0
GM
732
733To move forward over all comments and whitespace following point, use
4230351b
CY
734@code{(forward-comment (buffer-size))}. @code{(buffer-size)} is a
735good argument to use, because the number of comments in the buffer
736cannot exceed that many.
737@end defun
b8d4c8d0
GM
738
739@node Position Parse
740@subsection Finding the Parse State for a Position
741
742 For syntactic analysis, such as in indentation, often the useful
743thing is to compute the syntactic state corresponding to a given buffer
744position. This function does that conveniently.
745
746@defun syntax-ppss &optional pos
4230351b
CY
747This function returns the parser state that the parser would reach at
748position @var{pos} starting from the beginning of the buffer.
749@iftex
750See the next section for
751@end iftex
752@ifnottex
753@xref{Parser State},
754@end ifnottex
755for a description of the parser state.
756
757The return value is the same as if you call the low-level parsing
758function @code{parse-partial-sexp} to parse from the beginning of the
759buffer to @var{pos} (@pxref{Low-Level Parsing}). However,
760@code{syntax-ppss} uses a cache to speed up the computation. Due to
761this optimization, the second value (previous complete subexpression)
762and sixth value (minimum parenthesis depth) in the returned parser
763state are not meaningful.
764
765This function has a side effect: it adds a buffer-local entry to
766@code{before-change-functions} (@pxref{Change Hooks}) for
767@code{syntax-ppss-flush-cache} (see below). This entry keeps the
768cache consistent as the buffer is modified. However, the cache might
769not be updated if @code{syntax-ppss} is called while
b8d4c8d0 770@code{before-change-functions} is temporarily let-bound, or if the
4230351b
CY
771buffer is modified without running the hook, such as when using
772@code{inhibit-modification-hooks}. In those cases, it is necessary to
773call @code{syntax-ppss-flush-cache} explicitly.
774@end defun
b8d4c8d0 775
106e6894
CY
776@defun syntax-ppss-flush-cache beg &rest ignored-args
777This function flushes the cache used by @code{syntax-ppss}, starting
778at position @var{beg}. The remaining arguments, @var{ignored-args},
779are ignored; this function accepts them so that it can be directly
780used on hooks such as @code{before-change-functions} (@pxref{Change
781Hooks}).
b8d4c8d0
GM
782@end defun
783
784 Major modes can make @code{syntax-ppss} run faster by specifying
785where it needs to start parsing.
786
787@defvar syntax-begin-function
788If this is non-@code{nil}, it should be a function that moves to an
789earlier buffer position where the parser state is equivalent to
790@code{nil}---in other words, a position outside of any comment,
791string, or parenthesis. @code{syntax-ppss} uses it to further
792optimize its computations, when the cache gives no help.
793@end defvar
794
795@node Parser State
796@subsection Parser State
797@cindex parser state
798
4230351b
CY
799 A @dfn{parser state} is a list of ten elements describing the state
800of the syntactic parser, after it parses the text between a specified
801starting point and a specified end point in the buffer. Parsing
802functions such as @code{syntax-ppss}
803@ifnottex
804(@pxref{Position Parse})
805@end ifnottex
806return a parser state as the value. Some parsing functions accept a
807parser state as an argument, for resuming parsing.
808
809 Here are the meanings of the elements of the parser state:
b8d4c8d0
GM
810
811@enumerate 0
812@item
813The depth in parentheses, counting from 0. @strong{Warning:} this can
814be negative if there are more close parens than open parens between
4230351b 815the parser's starting point and end point.
b8d4c8d0
GM
816
817@item
818@cindex innermost containing parentheses
819The character position of the start of the innermost parenthetical
820grouping containing the stopping point; @code{nil} if none.
821
822@item
823@cindex previous complete subexpression
824The character position of the start of the last complete subexpression
825terminated; @code{nil} if none.
826
827@item
828@cindex inside string
829Non-@code{nil} if inside a string. More precisely, this is the
830character that will terminate the string, or @code{t} if a generic
831string delimiter character should terminate it.
832
833@item
834@cindex inside comment
4230351b
CY
835@code{t} if inside a non-nestable comment (of any comment style;
836@pxref{Syntax Flags}); or the comment nesting level if inside a
837comment that can be nested.
b8d4c8d0
GM
838
839@item
840@cindex quote character
4230351b 841@code{t} if the end point is just after a quote character.
b8d4c8d0
GM
842
843@item
844The minimum parenthesis depth encountered during this scan.
845
846@item
4230351b
CY
847What kind of comment is active: @code{nil} if not in a comment or in a
848comment of style @samp{a}; 1 for a comment of style @samp{b}; 2 for a
849comment of style @samp{c}; and @code{syntax-table} for a comment that
850should be ended by a generic comment delimiter character.
b8d4c8d0
GM
851
852@item
853The string or comment start position. While inside a comment, this is
854the position where the comment began; while inside a string, this is the
855position where the string began. When outside of strings and comments,
856this element is @code{nil}.
857
858@item
859Internal data for continuing the parsing. The meaning of this
860data is subject to change; it is used if you pass this list
861as the @var{state} argument to another call.
862@end enumerate
863
864 Elements 1, 2, and 6 are ignored in a state which you pass as an
865argument to continue parsing, and elements 8 and 9 are used only in
4230351b
CY
866trivial cases. Those elements are mainly used internally by the
867parser code.
b8d4c8d0
GM
868
869 One additional piece of useful information is available from a
870parser state using this function:
871
872@defun syntax-ppss-toplevel-pos state
873This function extracts, from parser state @var{state}, the last
874position scanned in the parse which was at top level in grammatical
875structure. ``At top level'' means outside of any parentheses,
876comments, or strings.
877
878The value is @code{nil} if @var{state} represents a parse which has
879arrived at a top level position.
880@end defun
881
b8d4c8d0
GM
882@node Low-Level Parsing
883@subsection Low-Level Parsing
884
885 The most basic way to use the expression parser is to tell it
886to start at a given position with a certain state, and parse up to
887a specified end position.
888
889@defun parse-partial-sexp start limit &optional target-depth stop-before state stop-comment
890This function parses a sexp in the current buffer starting at
891@var{start}, not scanning past @var{limit}. It stops at position
892@var{limit} or when certain criteria described below are met, and sets
893point to the location where parsing stops. It returns a parser state
52404181
CY
894@ifinfo
895(@pxref{Parser State})
896@end ifinfo
b8d4c8d0
GM
897describing the status of the parse at the point where it stops.
898
899@cindex parenthesis depth
900If the third argument @var{target-depth} is non-@code{nil}, parsing
901stops if the depth in parentheses becomes equal to @var{target-depth}.
902The depth starts at 0, or at whatever is given in @var{state}.
903
904If the fourth argument @var{stop-before} is non-@code{nil}, parsing
905stops when it comes to any character that starts a sexp. If
906@var{stop-comment} is non-@code{nil}, parsing stops when it comes to the
907start of a comment. If @var{stop-comment} is the symbol
908@code{syntax-table}, parsing stops after the start of a comment or a
909string, or the end of a comment or a string, whichever comes first.
910
911If @var{state} is @code{nil}, @var{start} is assumed to be at the top
912level of parenthesis structure, such as the beginning of a function
913definition. Alternatively, you might wish to resume parsing in the
914middle of the structure. To do this, you must provide a @var{state}
915argument that describes the initial status of parsing. The value
916returned by a previous call to @code{parse-partial-sexp} will do
917nicely.
918@end defun
919
920@node Control Parsing
921@subsection Parameters to Control Parsing
922
923@defvar multibyte-syntax-as-symbol
924If this variable is non-@code{nil}, @code{scan-sexps} treats all
925non-@acronym{ASCII} characters as symbol constituents regardless
926of what the syntax table says about them. (However, text properties
927can still override the syntax.)
928@end defvar
929
930@defopt parse-sexp-ignore-comments
931@cindex skipping comments
932If the value is non-@code{nil}, then comments are treated as
933whitespace by the functions in this section and by @code{forward-sexp},
934@code{scan-lists} and @code{scan-sexps}.
935@end defopt
936
937@vindex parse-sexp-lookup-properties
938The behavior of @code{parse-partial-sexp} is also affected by
939@code{parse-sexp-lookup-properties} (@pxref{Syntax Properties}).
940
941You can use @code{forward-comment} to move forward or backward over
942one comment or several comments.
943
b8d4c8d0
GM
944@node Syntax Table Internals
945@section Syntax Table Internals
946@cindex syntax table internals
947
02676e5d
CY
948 Syntax tables are implemented as char-tables (@pxref{Char-Tables}),
949but most Lisp programs don't work directly with their elements.
950Syntax tables do not store syntax data as syntax descriptors
951(@pxref{Syntax Descriptors}); they use an internal format, which is
952documented in this section. This internal format can also be assigned
953as syntax properties (@pxref{Syntax Properties}).
954
955@cindex syntax code
6dcef6ec
CY
956@cindex raw syntax descriptor
957 Each entry in a syntax table is a @dfn{raw syntax descriptor}: a
958cons cell of the form @code{(@var{syntax-code}
959. @var{matching-char})}. @var{syntax-code} is an integer which
960encodes the syntax class and syntax flags, according to the table
961below. @var{matching-char}, if non-@code{nil}, specifies a matching
962character (similar to the second character in a syntax descriptor).
963
964 Here are the syntax codes corresponding to the various syntax
965classes:
02676e5d
CY
966
967@multitable @columnfractions .2 .3 .2 .3
b8d4c8d0 968@item
6dcef6ec 969@i{Code} @tab @i{Class} @tab @i{Code} @tab @i{Class}
b8d4c8d0 970@item
02676e5d 9710 @tab whitespace @tab 8 @tab paired delimiter
b8d4c8d0 972@item
02676e5d 9731 @tab punctuation @tab 9 @tab escape
b8d4c8d0 974@item
02676e5d 9752 @tab word @tab 10 @tab character quote
b8d4c8d0 976@item
02676e5d 9773 @tab symbol @tab 11 @tab comment-start
b8d4c8d0 978@item
02676e5d 9794 @tab open parenthesis @tab 12 @tab comment-end
b8d4c8d0 980@item
02676e5d
CY
9815 @tab close parenthesis @tab 13 @tab inherit
982@item
9836 @tab expression prefix @tab 14 @tab generic comment
984@item
9857 @tab string quote @tab 15 @tab generic string
b8d4c8d0
GM
986@end multitable
987
02676e5d
CY
988@noindent
989For example, in the standard syntax table, the entry for @samp{(} is
6dcef6ec 990@code{(4 . 41)}. 41 is the character code for @samp{)}.
b8d4c8d0 991
02676e5d
CY
992 Syntax flags are encoded in higher order bits, starting 16 bits from
993the least significant bit. This table gives the power of two which
b8d4c8d0
GM
994corresponds to each syntax flag.
995
02676e5d
CY
996@multitable @columnfractions .15 .3 .15 .3
997@item
998@i{Prefix} @tab @i{Flag} @tab @i{Prefix} @tab @i{Flag}
b8d4c8d0 999@item
02676e5d 1000@samp{1} @tab @code{(lsh 1 16)} @tab @samp{p} @tab @code{(lsh 1 20)}
b8d4c8d0 1001@item
02676e5d 1002@samp{2} @tab @code{(lsh 1 17)} @tab @samp{b} @tab @code{(lsh 1 21)}
b8d4c8d0 1003@item
02676e5d 1004@samp{3} @tab @code{(lsh 1 18)} @tab @samp{n} @tab @code{(lsh 1 22)}
b8d4c8d0 1005@item
02676e5d 1006@samp{4} @tab @code{(lsh 1 19)}
b8d4c8d0
GM
1007@end multitable
1008
151d9088 1009@defun string-to-syntax desc
6dcef6ec
CY
1010Given a syntax descriptor @var{desc} (a string), this function returns
1011the corresponding raw syntax descriptor.
b8d4c8d0
GM
1012@end defun
1013
1014@defun syntax-after pos
6dcef6ec
CY
1015This function returns the raw syntax descriptor for the character in
1016the buffer after position @var{pos}, taking account of syntax
1017properties as well as the syntax table. If @var{pos} is outside the
1018buffer's accessible portion (@pxref{Narrowing, accessible portion}),
1019the return value is @code{nil}.
b8d4c8d0
GM
1020@end defun
1021
1022@defun syntax-class syntax
6dcef6ec
CY
1023This function returns the syntax code for the raw syntax descriptor
1024@var{syntax}. More precisely, it takes the raw syntax descriptor's
1025@var{syntax-code} component, masks off the high 16 bits which record
1026the syntax flags, and returns the resulting integer.
1027
1028If @var{syntax} is @code{nil}, the return value is returns @code{nil}.
1029This is so that the expression
b8d4c8d0
GM
1030
1031@example
1032(syntax-class (syntax-after pos))
1033@end example
1034
1035@noindent
6dcef6ec
CY
1036evaluates to @code{nil} if @code{pos} is outside the buffer's
1037accessible portion, without throwing errors or returning an incorrect
1038code.
b8d4c8d0
GM
1039@end defun
1040
1041@node Categories
1042@section Categories
1043@cindex categories of characters
1044@cindex character categories
1045
1046 @dfn{Categories} provide an alternate way of classifying characters
1047syntactically. You can define several categories as needed, then
1048independently assign each character to one or more categories. Unlike
1049syntax classes, categories are not mutually exclusive; it is normal for
1050one character to belong to several categories.
1051
1052@cindex category table
1053 Each buffer has a @dfn{category table} which records which categories
1054are defined and also which characters belong to each category. Each
1055category table defines its own categories, but normally these are
1056initialized by copying from the standard categories table, so that the
1057standard categories are available in all modes.
1058
1059 Each category has a name, which is an @acronym{ASCII} printing character in
1060the range @w{@samp{ }} to @samp{~}. You specify the name of a category
1061when you define it with @code{define-category}.
1062
9e73b242 1063@cindex category set
b8d4c8d0
GM
1064 The category table is actually a char-table (@pxref{Char-Tables}).
1065The element of the category table at index @var{c} is a @dfn{category
1066set}---a bool-vector---that indicates which categories character @var{c}
1067belongs to. In this category set, if the element at index @var{cat} is
1068@code{t}, that means category @var{cat} is a member of the set, and that
1069character @var{c} belongs to category @var{cat}.
1070
1071For the next three functions, the optional argument @var{table}
1072defaults to the current buffer's category table.
1073
1074@defun define-category char docstring &optional table
1075This function defines a new category, with name @var{char} and
1076documentation @var{docstring}, for the category table @var{table}.
1ea897d5
EZ
1077
1078Here's an example of defining a new category for characters that have
1079strong right-to-left directionality (@pxref{Bidirectional Display})
1080and using it in a special category table:
1081
1082@example
1083(defvar special-category-table-for-bidi
1084 (let ((category-table (make-category-table))
1085 (uniprop-table (unicode-property-table-internal 'bidi-class)))
1086 (define-category ?R "Characters of bidi-class R, AL, or RLO"
1087 category-table)
1088 (map-char-table
1089 #'(lambda (key val)
1090 (if (memq val '(R AL RLO))
1091 (modify-category-entry key ?R category-table)))
1092 uniprop-table)
1093 category-table))
1094@end example
b8d4c8d0
GM
1095@end defun
1096
1097@defun category-docstring category &optional table
1098This function returns the documentation string of category @var{category}
1099in category table @var{table}.
1100
1101@example
1102(category-docstring ?a)
1103 @result{} "ASCII"
1104(category-docstring ?l)
1105 @result{} "Latin"
1106@end example
1107@end defun
1108
1109@defun get-unused-category &optional table
1110This function returns a category name (a character) which is not
1111currently defined in @var{table}. If all possible categories are in use
1112in @var{table}, it returns @code{nil}.
1113@end defun
1114
1115@defun category-table
1116This function returns the current buffer's category table.
1117@end defun
1118
1119@defun category-table-p object
1120This function returns @code{t} if @var{object} is a category table,
1121otherwise @code{nil}.
1122@end defun
1123
1124@defun standard-category-table
1125This function returns the standard category table.
1126@end defun
1127
1128@defun copy-category-table &optional table
1129This function constructs a copy of @var{table} and returns it. If
1130@var{table} is not supplied (or is @code{nil}), it returns a copy of the
1131standard category table. Otherwise, an error is signaled if @var{table}
1132is not a category table.
1133@end defun
1134
1135@defun set-category-table table
1136This function makes @var{table} the category table for the current
1137buffer. It returns @var{table}.
1138@end defun
1139
1140@defun make-category-table
1141This creates and returns an empty category table. In an empty category
1142table, no categories have been allocated, and no characters belong to
1143any categories.
1144@end defun
1145
1146@defun make-category-set categories
1147This function returns a new category set---a bool-vector---whose initial
1148contents are the categories listed in the string @var{categories}. The
1149elements of @var{categories} should be category names; the new category
1150set has @code{t} for each of those categories, and @code{nil} for all
1151other categories.
1152
1153@example
1154(make-category-set "al")
1155 @result{} #&128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
1156@end example
1157@end defun
1158
1159@defun char-category-set char
1160This function returns the category set for character @var{char} in the
1161current buffer's category table. This is the bool-vector which
1162records which categories the character @var{char} belongs to. The
1163function @code{char-category-set} does not allocate storage, because
1164it returns the same bool-vector that exists in the category table.
1165
1166@example
1167(char-category-set ?a)
1168 @result{} #&128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
1169@end example
1170@end defun
1171
1172@defun category-set-mnemonics category-set
1173This function converts the category set @var{category-set} into a string
1174containing the characters that designate the categories that are members
1175of the set.
1176
1177@example
1178(category-set-mnemonics (char-category-set ?a))
1179 @result{} "al"
1180@end example
1181@end defun
1182
f147ff75
CY
1183@defun modify-category-entry char category &optional table reset
1184This function modifies the category set of @var{char} in category
b8d4c8d0 1185table @var{table} (which defaults to the current buffer's category
f147ff75
CY
1186table). @var{char} can be a character, or a cons cell of the form
1187@code{(@var{min} . @var{max})}; in the latter case, the function
1188modifies the category sets of all characters in the range between
1189@var{min} and @var{max}, inclusive.
b8d4c8d0 1190
f147ff75 1191Normally, it modifies a category set by adding @var{category} to it.
b8d4c8d0
GM
1192But if @var{reset} is non-@code{nil}, then it deletes @var{category}
1193instead.
1194@end defun
1195
1196@deffn Command describe-categories &optional buffer-or-name
1197This function describes the category specifications in the current
1198category table. It inserts the descriptions in a buffer, and then
1199displays that buffer. If @var{buffer-or-name} is non-@code{nil}, it
1200describes the category table of that buffer instead.
1201@end deffn