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
|
<h3 class="section">Char-Tables</h3> <p>A char-table is much like a vector, except that it is indexed by character codes. Any valid character code, without modifiers, can be used as an index in a char-table. You can access a char-table’s elements with <code>aref</code> and <code>aset</code>, as with any array. In addition, a char-table can have <em>extra slots</em> to hold additional data not associated with particular character codes. Like vectors, char-tables are constants when evaluated, and can hold elements of any type. </p> <p>Each char-table has a <em>subtype</em>, a symbol, which serves two purposes: </p> <ul> <li> The subtype provides an easy way to tell what the char-table is for. For instance, display tables are char-tables with <code>display-table</code> as the subtype, and syntax tables are char-tables with <code>syntax-table</code> as the subtype. The subtype can be queried using the function <code>char-table-subtype</code>, described below. </li>
<li> The subtype controls the number of <em>extra slots</em> in the char-table. This number is specified by the subtype’s <code>char-table-extra-slots</code> symbol property (see <a href="symbol-properties">Symbol Properties</a>), whose value should be an integer between 0 and 10. If the subtype has no such symbol property, the char-table has no extra slots. </li>
</ul> <p>A char-table can have a <em>parent</em>, which is another char-table. If it does, then whenever the char-table specifies <code>nil</code> for a particular character <var>c</var>, it inherits the value specified in the parent. In other words, <code>(aref <var>char-table</var> <var>c</var>)</code> returns the value from the parent of <var>char-table</var> if <var>char-table</var> itself specifies <code>nil</code>. </p> <p>A char-table can also have a <em>default value</em>. If so, then <code>(aref <var>char-table</var> <var>c</var>)</code> returns the default value whenever the char-table does not specify any other non-<code>nil</code> value. </p> <dl> <dt id="make-char-table">Function: <strong>make-char-table</strong> <em>subtype &optional init</em>
</dt> <dd>
<p>Return a newly-created char-table, with subtype <var>subtype</var> (a symbol). Each element is initialized to <var>init</var>, which defaults to <code>nil</code>. You cannot alter the subtype of a char-table after the char-table is created. </p> <p>There is no argument to specify the length of the char-table, because all char-tables have room for any valid character code as an index. </p> <p>If <var>subtype</var> has the <code>char-table-extra-slots</code> symbol property, that specifies the number of extra slots in the char-table. This should be an integer between 0 and 10; otherwise, <code>make-char-table</code> raises an error. If <var>subtype</var> has no <code>char-table-extra-slots</code> symbol property (see <a href="property-lists">Property Lists</a>), the char-table has no extra slots. </p>
</dd>
</dl> <dl> <dt id="char-table-p">Function: <strong>char-table-p</strong> <em>object</em>
</dt> <dd><p>This function returns <code>t</code> if <var>object</var> is a char-table, and <code>nil</code> otherwise. </p></dd>
</dl> <dl> <dt id="char-table-subtype">Function: <strong>char-table-subtype</strong> <em>char-table</em>
</dt> <dd><p>This function returns the subtype symbol of <var>char-table</var>. </p></dd>
</dl> <p>There is no special function to access default values in a char-table. To do that, use <code>char-table-range</code> (see below). </p> <dl> <dt id="char-table-parent">Function: <strong>char-table-parent</strong> <em>char-table</em>
</dt> <dd><p>This function returns the parent of <var>char-table</var>. The parent is always either <code>nil</code> or another char-table. </p></dd>
</dl> <dl> <dt id="set-char-table-parent">Function: <strong>set-char-table-parent</strong> <em>char-table new-parent</em>
</dt> <dd><p>This function sets the parent of <var>char-table</var> to <var>new-parent</var>. </p></dd>
</dl> <dl> <dt id="char-table-extra-slot">Function: <strong>char-table-extra-slot</strong> <em>char-table n</em>
</dt> <dd><p>This function returns the contents of extra slot <var>n</var> (zero based) of <var>char-table</var>. The number of extra slots in a char-table is determined by its subtype. </p></dd>
</dl> <dl> <dt id="set-char-table-extra-slot">Function: <strong>set-char-table-extra-slot</strong> <em>char-table n value</em>
</dt> <dd><p>This function stores <var>value</var> in extra slot <var>n</var> (zero based) of <var>char-table</var>. </p></dd>
</dl> <p>A char-table can specify an element value for a single character code; it can also specify a value for an entire character set. </p> <dl> <dt id="char-table-range">Function: <strong>char-table-range</strong> <em>char-table range</em>
</dt> <dd>
<p>This returns the value specified in <var>char-table</var> for a range of characters <var>range</var>. Here are the possibilities for <var>range</var>: </p> <dl compact> <dt><code>nil</code></dt> <dd>
<p>Refers to the default value. </p> </dd> <dt><var>char</var></dt> <dd>
<p>Refers to the element for character <var>char</var> (supposing <var>char</var> is a valid character code). </p> </dd> <dt><code>(<var>from</var> . <var>to</var>)</code></dt> <dd><p>A cons cell refers to all the characters in the inclusive range ‘<samp>[<var>from</var>..<var>to</var>]</samp>’. </p></dd> </dl> </dd>
</dl> <dl> <dt id="set-char-table-range">Function: <strong>set-char-table-range</strong> <em>char-table range value</em>
</dt> <dd>
<p>This function sets the value in <var>char-table</var> for a range of characters <var>range</var>. Here are the possibilities for <var>range</var>: </p> <dl compact> <dt><code>nil</code></dt> <dd>
<p>Refers to the default value. </p> </dd> <dt><code>t</code></dt> <dd>
<p>Refers to the whole range of character codes. </p> </dd> <dt><var>char</var></dt> <dd>
<p>Refers to the element for character <var>char</var> (supposing <var>char</var> is a valid character code). </p> </dd> <dt><code>(<var>from</var> . <var>to</var>)</code></dt> <dd><p>A cons cell refers to all the characters in the inclusive range ‘<samp>[<var>from</var>..<var>to</var>]</samp>’. </p></dd> </dl> </dd>
</dl> <dl> <dt id="map-char-table">Function: <strong>map-char-table</strong> <em>function char-table</em>
</dt> <dd>
<p>This function calls its argument <var>function</var> for each element of <var>char-table</var> that has a non-<code>nil</code> value. The call to <var>function</var> is with two arguments, a key and a value. The key is a possible <var>range</var> argument for <code>char-table-range</code>—either a valid character or a cons cell <code>(<var>from</var> . <var>to</var>)</code>, specifying a range of characters that share the same value. The value is what <code>(char-table-range <var>char-table</var> <var>key</var>)</code> returns. </p> <p>Overall, the key-value pairs passed to <var>function</var> describe all the values stored in <var>char-table</var>. </p> <p>The return value is always <code>nil</code>; to make calls to <code>map-char-table</code> useful, <var>function</var> should have side effects. For example, here is how to examine the elements of the syntax table: </p> <div class="example"> <pre class="example">(let (accumulator)
(map-char-table
(lambda (key value)
(setq accumulator
(cons (list
(if (consp key)
(list (car key) (cdr key))
key)
value)
accumulator)))
(syntax-table))
accumulator)
⇒
(((2597602 4194303) (2)) ((2597523 2597601) (3))
... (65379 (5 . 65378)) (65378 (4 . 65379)) (65377 (1))
... (12 (0)) (11 (3)) (10 (12)) (9 (0)) ((0 8) (3)))
</pre>
</div> </dd>
</dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 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/Char_002dTables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Char_002dTables.html</a>
</p>
</div>
|