summaryrefslogtreecommitdiff
path: root/devdocs/elisp/categories.html
blob: 45902af4a563b8bae0805a7b9e8cdfa6c3546368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 <h3 class="section">Categories</h3>   <p><em>Categories</em> 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. </p>  <p>Each buffer has a <em>category table</em> 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. </p> <p>Each category has a name, which is an <acronym>ASCII</acronym> printing character in the range ‘’ to ‘<samp>~</samp>’. You specify the name of a category when you define it with <code>define-category</code>. </p>  <p>The category table is actually a char-table (see <a href="char_002dtables">Char-Tables</a>). The element of the category table at index <var>c</var> is a <em>category set</em>—a bool-vector—that indicates which categories character <var>c</var> belongs to. In this category set, if the element at index <var>cat</var> is <code>t</code>, that means category <var>cat</var> is a member of the set, and that character <var>c</var> belongs to category <var>cat</var>. </p> <p>For the next three functions, the optional argument <var>table</var> defaults to the current buffer’s category table. </p> <dl> <dt id="define-category">Function: <strong>define-category</strong> <em>char docstring &amp;optional table</em>
</dt> <dd>
<p>This function defines a new category, with name <var>char</var> and documentation <var>docstring</var>, for the category table <var>table</var>. </p> <p>Here’s an example of defining a new category for characters that have strong right-to-left directionality (see <a href="bidirectional-display">Bidirectional Display</a>) and using it in a special category table. To obtain the information about the directionality of characters, the example code uses the ‘<samp>bidi-class</samp>’ Unicode property (see <a href="character-properties">bidi-class</a>). </p> <div class="example"> <pre class="example">(defvar special-category-table-for-bidi
  ;;     Make an empty category-table.
  (let ((category-table (make-category-table))
        ;; Create a char-table which gives the 'bidi-class' Unicode
        ;; property for each character.
        (uniprop-table
         (unicode-property-table-internal 'bidi-class)))
    (define-category ?R "Characters of bidi-class R, AL, or RLO"
                     category-table)
    ;; Modify the category entry of each character whose
    ;; 'bidi-class' Unicode property is R, AL, or RLO --
    ;; these have a right-to-left directionality.
    (map-char-table
     (lambda (key val)
       (if (memq val '(R AL RLO))
           (modify-category-entry key ?R category-table)))
     uniprop-table)
    category-table))
</pre>
</div> </dd>
</dl> <dl> <dt id="category-docstring">Function: <strong>category-docstring</strong> <em>category &amp;optional table</em>
</dt> <dd>
<p>This function returns the documentation string of category <var>category</var> in category table <var>table</var>. </p> <div class="example"> <pre class="example">(category-docstring ?a)
     ⇒ "ASCII"
(category-docstring ?l)
     ⇒ "Latin"
</pre>
</div> </dd>
</dl> <dl> <dt id="get-unused-category">Function: <strong>get-unused-category</strong> <em>&amp;optional table</em>
</dt> <dd><p>This function returns a category name (a character) which is not currently defined in <var>table</var>. If all possible categories are in use in <var>table</var>, it returns <code>nil</code>. </p></dd>
</dl> <dl> <dt id="category-table">Function: <strong>category-table</strong>
</dt> <dd><p>This function returns the current buffer’s category table. </p></dd>
</dl> <dl> <dt id="category-table-p">Function: <strong>category-table-p</strong> <em>object</em>
</dt> <dd><p>This function returns <code>t</code> if <var>object</var> is a category table, otherwise <code>nil</code>. </p></dd>
</dl> <dl> <dt id="standard-category-table">Function: <strong>standard-category-table</strong>
</dt> <dd><p>This function returns the standard category table. </p></dd>
</dl> <dl> <dt id="copy-category-table">Function: <strong>copy-category-table</strong> <em>&amp;optional table</em>
</dt> <dd><p>This function constructs a copy of <var>table</var> and returns it. If <var>table</var> is not supplied (or is <code>nil</code>), it returns a copy of the standard category table. Otherwise, an error is signaled if <var>table</var> is not a category table. </p></dd>
</dl> <dl> <dt id="set-category-table">Function: <strong>set-category-table</strong> <em>table</em>
</dt> <dd><p>This function makes <var>table</var> the category table for the current buffer. It returns <var>table</var>. </p></dd>
</dl> <dl> <dt id="make-category-table">Function: <strong>make-category-table</strong>
</dt> <dd><p>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. </p></dd>
</dl> <dl> <dt id="make-category-set">Function: <strong>make-category-set</strong> <em>categories</em>
</dt> <dd>
<p>This function returns a new category set—a bool-vector—whose initial contents are the categories listed in the string <var>categories</var>. The elements of <var>categories</var> should be category names; the new category set has <code>t</code> for each of those categories, and <code>nil</code> for all other categories. </p> <div class="example"> <pre class="example">(make-category-set "al")
     ⇒ #&amp;128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
</pre>
</div> </dd>
</dl> <dl> <dt id="char-category-set">Function: <strong>char-category-set</strong> <em>char</em>
</dt> <dd>
<p>This function returns the category set for character <var>char</var> in the current buffer’s category table. This is the bool-vector which records which categories the character <var>char</var> belongs to. The function <code>char-category-set</code> does not allocate storage, because it returns the same bool-vector that exists in the category table. </p> <div class="example"> <pre class="example">(char-category-set ?a)
     ⇒ #&amp;128"\0\0\0\0\0\0\0\0\0\0\0\0\2\20\0\0"
</pre>
</div> </dd>
</dl> <dl> <dt id="category-set-mnemonics">Function: <strong>category-set-mnemonics</strong> <em>category-set</em>
</dt> <dd>
<p>This function converts the category set <var>category-set</var> into a string containing the characters that designate the categories that are members of the set. </p> <div class="example"> <pre class="example">(category-set-mnemonics (char-category-set ?a))
     ⇒ "al"
</pre>
</div> </dd>
</dl> <dl> <dt id="modify-category-entry">Function: <strong>modify-category-entry</strong> <em>char category &amp;optional table reset</em>
</dt> <dd>
<p>This function modifies the category set of <var>char</var> in category table <var>table</var> (which defaults to the current buffer’s category table). <var>char</var> can be a character, or a cons cell of the form <code>(<var>min</var> . <var>max</var>)</code>; in the latter case, the function modifies the category sets of all characters in the range between <var>min</var> and <var>max</var>, inclusive. </p> <p>Normally, it modifies a category set by adding <var>category</var> to it. But if <var>reset</var> is non-<code>nil</code>, then it deletes <var>category</var> instead. </p>
</dd>
</dl> <dl> <dt id="describe-categories">Command: <strong>describe-categories</strong> <em>&amp;optional buffer-or-name</em>
</dt> <dd><p>This function describes the category specifications in the current category table. It inserts the descriptions in a buffer, and then displays that buffer. If <var>buffer-or-name</var> is non-<code>nil</code>, it describes the category table of that buffer instead. </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Categories.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Categories.html</a>
  </p>
</div>