本節では、構文テーブルの作成、参照、および変更を行う関数について説明します。
この関数は、新しい構文テーブルを作成します。table が nil でない場合、新しい構文テーブルの親は table
となり、そうでない場合は標準の構文テーブルが親となります。
新しい構文テーブルでは、すべての文字に初期状態で「inherit」(@)構文クラスが割り当てられています。つまり、その構文は親テーブルから継承されます(構文クラス表を参照)。
この関数は table のコピーを作成して返します。table が省略されているか、あるいは nil
が指定されている場合は、標準構文テーブルのコピーを返します。それ以外の場合、table
が構文テーブルでないときはエラーが通知されます。
この関数は、syntax-descriptor に従って char の構文エントリを設定します。char は文字、または
(min . max) 形式のコンスセルである必要があります。後者の場合、この関数は min から max
までの範囲(両端を含む)にあるすべての文字の構文エントリを設定します。
構文が変更されるのはtableのみであり、これはデフォルトで現在のバッファの構文テーブルが適用され、それ以外の構文テーブルでは変更されません。
引数 syntax-descriptor は構文記述子です。すなわち、先頭文字が構文クラス指定子であり、2文字目以降の文字で任意に一致する文字と構文フラグを指定する文字列のことです。構文記述子 を参照してください。syntax-descriptor が有効な構文記述子でない場合は、エラーが通知されます。
この関数は常に nil を返します。この文字のテーブルにある古い構文情報は破棄されます。
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
この関数は、指定文字で表される character の構文クラスを返します(構文クラス表を参照)。これにより、クラスのみが返され、対応する文字や構文フラグは返されません。
以下の例はCモードに適用されます。(char-syntax
が返す文字を確認しやすくするため、string を使用しています。)
;; Space characters have whitespace syntax class.
(string (char-syntax ?\s))
⇒ " "
;; Forward slash characters have punctuation syntax.
;; Note that this char-syntax call does not reveal
;; that it is also part of comment-start and -end sequences.
(string (char-syntax ?/))
⇒ "."
;; Open parenthesis characters have open parenthesis syntax.
;; Note that this char-syntax call does not reveal that
;; it has a matching character, ‘)’.
(string (char-syntax ?\())
⇒ "("
この関数は、table を現在のバッファの構文テーブルに設定します。table を返します。
この関数は、現在のバッファに対応する現在の構文テーブルを返します。
このコマンドは、buffer(デフォルトでは現在のバッファ)の構文テーブルの内容をヘルプバッファに表示します。
このマクロは、tableを現在の構文テーブルとしてbodyを実行します。元の現在の構文テーブルを復元した後、body内の最後のフォームの値を返します。
各バッファが独自の現在の構文テーブルを持っているため、この点をより明確にしておくべきです。with-syntax-table
は、マクロの実行開始時にアクティブなバッファの現在の構文テーブルを一時的に変更します。他のバッファには影響しません。