summaryrefslogtreecommitdiff
path: root/devdocs/elisp/smie-setup.html
blob: 1cd4aa88d70c15b90148c650a0543adf867ac439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 <h4 class="subsubsection">SMIE Setup and Features</h4> <p>SMIE is meant to be a one-stop shop for structural navigation and various other features which rely on the syntactic structure of code, in particular automatic indentation. The main entry point is <code>smie-setup</code> which is a function typically called while setting up a major mode. </p> <dl> <dt id="smie-setup">Function: <strong>smie-setup</strong> <em>grammar rules-function &amp;rest keywords</em>
</dt> <dd>
<p>Setup SMIE navigation and indentation. <var>grammar</var> is a grammar table generated by <code>smie-prec2-&gt;grammar</code>. <var>rules-function</var> is a set of indentation rules for use on <code>smie-rules-function</code>. <var>keywords</var> are additional arguments, which can include the following keywords: </p>
<ul> <li> <code>:forward-token</code> <var>fun</var>: Specify the forward lexer to use. </li>
<li> <code>:backward-token</code> <var>fun</var>: Specify the backward lexer to use. </li>
</ul> </dd>
</dl> <p>Calling this function is sufficient to make commands such as <code>forward-sexp</code>, <code>backward-sexp</code>, and <code>transpose-sexps</code> be able to properly handle structural elements other than just the paired parentheses already handled by syntax tables. For example, if the provided grammar is precise enough, <code>transpose-sexps</code> can correctly transpose the two arguments of a <code>+</code> operator, taking into account the precedence rules of the language. </p> <p>Calling <code>smie-setup</code> is also sufficient to make <tt class="key">TAB</tt> indentation work in the expected way, extends <code>blink-matching-paren</code> to apply to elements like <code>begin...end</code>, and provides some commands that you can bind in the major mode keymap. </p> <dl> <dt id="smie-close-block">Command: <strong>smie-close-block</strong>
</dt> <dd><p>This command closes the most recently opened (and not yet closed) block. </p></dd>
</dl> <dl> <dt id="smie-down-list">Command: <strong>smie-down-list</strong> <em>&amp;optional arg</em>
</dt> <dd><p>This command is like <code>down-list</code> but it also pays attention to nesting of tokens other than parentheses, such as <code>begin...end</code>. </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/SMIE-setup.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/SMIE-setup.html</a>
  </p>
</div>