diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/syntax-table-functions.html | |
new repository
Diffstat (limited to 'devdocs/elisp/syntax-table-functions.html')
| -rw-r--r-- | devdocs/elisp/syntax-table-functions.html | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/devdocs/elisp/syntax-table-functions.html b/devdocs/elisp/syntax-table-functions.html new file mode 100644 index 00000000..5785c8ca --- /dev/null +++ b/devdocs/elisp/syntax-table-functions.html @@ -0,0 +1,74 @@ + <h3 class="section">Syntax Table Functions</h3> <p>In this section we describe functions for creating, accessing and altering syntax tables. </p> <dl> <dt id="make-syntax-table">Function: <strong>make-syntax-table</strong> <em>&optional table</em> +</dt> <dd> +<p>This function creates a new syntax table. If <var>table</var> is non-<code>nil</code>, the parent of the new syntax table is <var>table</var>; otherwise, the parent is the standard syntax table. </p> <p>In the new syntax table, all characters are initially given the “inherit” (‘<samp>@</samp>’) syntax class, i.e., their syntax is inherited from the parent table (see <a href="syntax-class-table">Syntax Class Table</a>). </p> +</dd> +</dl> <dl> <dt id="copy-syntax-table">Function: <strong>copy-syntax-table</strong> <em>&optional table</em> +</dt> <dd><p>This function constructs a copy of <var>table</var> and returns it. If <var>table</var> is omitted or <code>nil</code>, it returns a copy of the standard syntax table. Otherwise, an error is signaled if <var>table</var> is not a syntax table. </p></dd> +</dl> <dl> <dt id="modify-syntax-entry">Command: <strong>modify-syntax-entry</strong> <em>char syntax-descriptor &optional table</em> +</dt> <dd> + <p>This function sets the syntax entry for <var>char</var> according to <var>syntax-descriptor</var>. <var>char</var> must be a character, or a cons cell of the form <code>(<var>min</var> . <var>max</var>)</code>; in the latter case, the function sets the syntax entries for all characters in the range between <var>min</var> and <var>max</var>, inclusive. </p> <p>The syntax is changed only for <var>table</var>, which defaults to the current buffer’s syntax table, and not in any other syntax table. </p> <p>The argument <var>syntax-descriptor</var> is a syntax descriptor, i.e., a string whose first character is a syntax class designator and whose second and subsequent characters optionally specify a matching character and syntax flags. See <a href="syntax-descriptors">Syntax Descriptors</a>. An error is signaled if <var>syntax-descriptor</var> is not a valid syntax descriptor. </p> <p>This function always returns <code>nil</code>. The old syntax information in the table for this character is discarded. </p> <div class="example"> <pre class="example"><span class="roman">Examples:</span> +</pre> +<pre class="example"> + +;; <span class="roman">Put the space character in class whitespace.</span> +(modify-syntax-entry ?\s " ") + ⇒ nil +</pre> + +<pre class="example">;; <span class="roman">Make ‘<samp>$</samp>’ an open parenthesis character,</span> +;; <span class="roman">with ‘<samp>^</samp>’ as its matching close.</span> +(modify-syntax-entry ?$ "(^") + ⇒ nil +</pre> + +<pre class="example">;; <span class="roman">Make ‘<samp>^</samp>’ a close parenthesis character,</span> +;; <span class="roman">with ‘<samp>$</samp>’ as its matching open.</span> +(modify-syntax-entry ?^ ")$") + ⇒ nil +</pre> + +<pre class="example">;; <span class="roman">Make ‘<samp>/</samp>’ a punctuation character,</span> +;; <span class="roman">the first character of a start-comment sequence,</span> +;; <span class="roman">and the second character of an end-comment sequence.</span> +;; <span class="roman">This is used in C mode.</span> +(modify-syntax-entry ?/ ". 14") + ⇒ nil +</pre> +</div> </dd> +</dl> <dl> <dt id="char-syntax">Function: <strong>char-syntax</strong> <em>character</em> +</dt> <dd> +<p>This function returns the syntax class of <var>character</var>, represented by its designator character (see <a href="syntax-class-table">Syntax Class Table</a>). This returns <em>only</em> the class, not its matching character or syntax flags. </p> <p>The following examples apply to C mode. (We use <code>string</code> to make it easier to see the character returned by <code>char-syntax</code>.) </p> <div class="example"> <pre class="example">;; Space characters have whitespace syntax class. +(string (char-syntax ?\s)) + ⇒ " " +</pre> + +<pre class="example">;; Forward slash characters have punctuation syntax. +;; Note that this <code>char-syntax</code> call does not reveal +;; that it is also part of comment-start and -end sequences. +(string (char-syntax ?/)) + ⇒ "." +</pre> + +<pre class="example">;; Open parenthesis characters have open parenthesis syntax. +;; Note that this <code>char-syntax</code> call does not reveal that +;; it has a matching character, ‘<samp>)</samp>’. +(string (char-syntax ?\()) + ⇒ "(" +</pre> +</div> </dd> +</dl> <dl> <dt id="set-syntax-table">Function: <strong>set-syntax-table</strong> <em>table</em> +</dt> <dd><p>This function makes <var>table</var> the syntax table for the current buffer. It returns <var>table</var>. </p></dd> +</dl> <dl> <dt id="syntax-table">Function: <strong>syntax-table</strong> +</dt> <dd><p>This function returns the current syntax table, which is the table for the current buffer. </p></dd> +</dl> <dl> <dt id="describe-syntax">Command: <strong>describe-syntax</strong> <em>&optional buffer</em> +</dt> <dd><p>This command displays the contents of the syntax table of <var>buffer</var> (by default, the current buffer) in a help buffer. </p></dd> +</dl> <dl> <dt id="with-syntax-table">Macro: <strong>with-syntax-table</strong> <em>table body…</em> +</dt> <dd> +<p>This macro executes <var>body</var> using <var>table</var> as the current syntax table. It returns the value of the last form in <var>body</var>, after restoring the old current syntax table. </p> <p>Since each buffer has its own current syntax table, we should make that more precise: <code>with-syntax-table</code> temporarily alters the current syntax table of whichever buffer is current at the time the macro execution starts. Other buffers are not affected. </p> +</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/Syntax-Table-Functions.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Functions.html</a> + </p> +</div> |
