[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

35.3 Syntax Table Functions

In this section we describe functions for creating, accessing and altering syntax tables.

Function: make-syntax-table &optional table

This function creates a new syntax table, with all values initialized to nil. If table is non-nil, it becomes the parent of the new syntax table, otherwise the standard syntax table is the parent. Like all char-tables, a syntax table inherits from its parent. Thus the original syntax of all characters in the returned syntax table is determined by the parent. Voir la section Char-Tables.

Most major mode syntax tables are created in this way.

Function: copy-syntax-table &optional table

This function constructs a copy of table and returns it. If table is not supplied (or is nil), it returns a copy of the standard syntax table. Otherwise, an error is signaled if table is not a syntax table.

Command: modify-syntax-entry char syntax-descriptor &optional table

This function sets the syntax entry for char according to syntax-descriptor. The syntax is changed only for table, which defaults to the current buffer's syntax table, and not in any other syntax table. The argument syntax-descriptor specifies the desired syntax; this is a string beginning with a class designator character, and optionally containing a matching character and flags as well. Voir la section Syntax Descriptors.

This function always returns nil. The old syntax information in the table for this character is discarded.

An error is signaled if the first character of the syntax descriptor is not one of the seventeen syntax class designator characters. An error is also signaled if char is not a character.

 
Examples:

;; Put the space character in class whitespace.
(modify-syntax-entry ?\s " ")
     ⇒ nil

;; Make ‘$’ an open parenthesis character,
;;   with ‘^’ as its matching close.
(modify-syntax-entry ?$ "(^")
     ⇒ nil

;; Make ‘^’ a close parenthesis character,
;;   with ‘$’ as its matching open.
(modify-syntax-entry ?^ ")$")
     ⇒ nil

;; Make ‘/’ a punctuation character,
;;   the first character of a start-comment sequence,
;;   and the second character of an end-comment sequence.
;;   This is used in C mode.
(modify-syntax-entry ?/ ". 14")
     ⇒ nil
Function: char-syntax caractère

This function returns the syntax class of character, represented by its mnemonic designator character. This returns only the class, not any matching parenthesis or flags.

An error is signaled if char is not a character.

The following examples apply to C mode. The first example shows that the syntax class of space is whitespace (represented by a space). The second example shows that the syntax of ‘/’ is punctuation. This does not show the fact that it is also part of comment-start and -end sequences. The third example shows that open parenthesis is in the class of open parentheses. This does not show the fact that it has a matching character, ‘)’.

 
(string (char-syntax ?\s))
     ⇒ " "

(string (char-syntax ?/))
     ⇒ "."

(string (char-syntax ?\())
     ⇒ "("

We use string to make it easier to see the character returned by char-syntax.

Function: set-syntax-table table

This function makes table the syntax table for the current buffer. It returns table.

Function: syntax-table

This function returns the current syntax table, which is the table for the current buffer.

Macro: with-syntax-table table corps

This macro executes body using table as the current syntax table. It returns the value of the last form in body, after restoring the old current syntax table.

Since each buffer has its own current syntax table, we should make that more precise: with-syntax-table temporarily alters the current syntax table of whichever buffer is current at the time the macro execution starts. Other buffers are not affected.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.