Categories provide an alternate way of classifying characters syntactically. You can define several categories as needed, then independently assign each character to one or more categories. Unlike syntax classes, categories are not mutually exclusive; it is normal for one character to belong to several 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
The category table is actually a char-table (see 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.
For the next three functions, the optional argument table defaults to the current buffer's category table.
This function defines a new category, with name char and documentation docstring, for the category table table.
Here's an example of defining a new category for characters that have strong right-to-left directionality (see Bidirectional Display) and using it in a special category table:(defvar special-category-table-for-bidi (let ((category-table (make-category-table)) (uniprop-table (unicode-property-table-internal 'bidi-class))) (define-category ?R "Characters of bidi-class R, AL, or RLO" category-table) (map-char-table #'(lambda (key val) (if (memq val '(R AL RLO)) (modify-category-entry key ?R category-table))) uniprop-table) category-table))
This function returns the documentation string of category category in category table table.(category-docstring ?a) ⇒ "ASCII" (category-docstring ?l) ⇒ "Latin"
This function returns a category name (a character) which is not currently defined in table. If all possible categories are in use in table, it returns
This function returns
tif object is a category table, otherwise
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 category table. Otherwise, an error is signaled if table is not a category table.
This function makes table the category table for the current buffer. It returns table.
This creates and returns an empty category table. In an empty category table, no categories have been allocated, and no characters belong to any categories.
This function returns a new category set—a bool-vector—whose initial contents are the categories listed in the string categories. The elements of categories should be category names; the new category set has
tfor each of those categories, and
nilfor all other categories.(make-category-set "al") ⇒ #&128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
This function returns the category set for character char in the current buffer's category table. This is the bool-vector which records which categories the character char belongs to. The function
char-category-setdoes 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"
This function converts the category set category-set into a string containing the characters that designate the categories that are members of the set.(category-set-mnemonics (char-category-set ?a)) ⇒ "al"
This function modifies the category set of char in category table table (which defaults to the current buffer's category table). char can be a character, or a cons cell of the form
); in the latter case, the function modifies the category sets of all characters in the range between min and max, inclusive.
Normally, it modifies a category set by adding category to it. But if reset is non-
nil, then it deletes category instead.