[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
文字カテゴリーを調べる方法
- To: bep@argv.org
- Subject: 文字カテゴリーを調べる方法
- From: WATANABE Takayuki <takayuki@la.shonan-it.ac.jp>
- Date: Thu, 02 Nov 2000 22:43:39 +0900
- Delivered-To: mailing list bep@argv.org
- Mailing-List: contact bep-help@argv.org; run by ezmlm
渡辺です。
On 02 Nov 2000 10:01:41 +0900, Koichi INOUE wrote:
> 文字カテゴリーを文字から得るにはどうしたらよいのでしょう。
とりあえずひとつの例です。
ed. 2.5のELispマニュアルとEmacsソースのinternational/kinsoku.el を参考
にしました。
(defun test-char-category (char)
(interactive "sInput char-category:\n")
(if (aref (char-category-set (following-char)) (string-to-char char))
(message "yes %s" char)
(message "not %s" char)))
following-char で拾った文字のカテゴリーテーブルを、char-category-setで
表示します。カテゴリーテーブルの正体はchar-table で、?aや ?Hや ?jなど
の各要素のうち、その文字が属するカテゴリーのビットが立っています。
次に arefで このカテゴリーテーブルのインデックスがたとえば?a の要素を
取り出します。これがtだったらビンゴです。
例; たとえばカーソルを文字`a' に置いてこの関数を実行し、引数に a
(ASCIIを現わすニーモニック)を与えると "yes a"と表示します。
`あ'の上で実行すると引数が j (Japanese)や H (ひらがな)だとyesですが、
aだとnoになります。
日本語の文字カテゴリーの種別は international/characters.el を参照して
ください。
以下ELispマニュアルから抜粋
---
File: elisp, Node: Categories, Prev: Syntax Table Internals, Up:
Syntax Tables
Categories
==========
Each buffer has a "category table" which records which categories
are defined and also which characters belong to each category. Each
category table defines its own categories, but normally these are
initialized by copying from the standard categories table, so that the
standard categories are available in all modes.
Each category has a name, which is an ASCII printing character in
the range ` ' to `~'. You specify the name of a category when you
define it with `define-category'.
The category table is actually a char-table (*note Char-Tables::.).
The element of the category table at index C is a "category set"--a
bool-vector--that indicates which categories character C belongs to.
In this category set, if the element at index CAT is `t', that means
category CAT is a member of the set, and that character C belongs to
category CAT.
- Function: category-docstring CATEGORY &optional TABLE
This function returns the documentation string of category CATEGORY
in category table TABLE.
(category-docstring ?a)
=> "ASCII"
(category-docstring ?l)
=> "Latin"
- Function: char-category-set CHAR
This function returns the category set for character CHAR. This
is the bool-vector which records which categories the character
CHAR belongs to. The function `char-category-set' does not
allocate storage, because it returns the same bool-vector that
exists in the category table.
(char-category-set ?a)
=> #&128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"