mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
111 lines
6.7 KiB
HTML
111 lines
6.7 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
|
<title>How to define a snippet ?</title>
|
|
<meta name="author" content="pluskid" />
|
|
<meta name="date" content="2008-03-20" />
|
|
<link rel="stylesheet" href="styles.css" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div class="document" id="how-to-define-a-snippet">
|
|
<div id="header-region" class="clear-block"></div>
|
|
<div id="wrapper">
|
|
<div id="container" class="clear-block">
|
|
<div id="header">
|
|
<div id="logo-floater">
|
|
<h1 class="title">How to define a snippet ?</h1>
|
|
</div>
|
|
<ul class="primary-links">
|
|
<li>
|
|
<a title="" href="index.html">Home</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="define_snippet.html">Howto</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="faq.html">FAQ</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="changelog.html">ChangeLog</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="http://code.google.com/p/yasnippet/downloads/list">Download</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div id="center">
|
|
<div id="squeeze">
|
|
<div class="right-corner">
|
|
<div class="left-corner">
|
|
<div class="section" id="why-there-s-an-extra-newline">
|
|
<h1>Why there's an extra newline?</h1>
|
|
<p>If you have a newline at the end of the snippet definition file, then
|
|
YASnippet will add a newline when you expanding a snippet. Please
|
|
don't add a newline at the end if you don't want it when you saving
|
|
the snippet file.</p>
|
|
<p>Note some editors will automatically add a newline for you. In Emacs,
|
|
if you set <tt class="docutils literal"><span class="pre">require-final-newline</span></tt> to <tt class="docutils literal"><span class="pre">t</span></tt>, it will add the final
|
|
newline for you automatically.</p>
|
|
</div>
|
|
<div class="section" id="why-tab-key-doesn-t-expand-a-snippet">
|
|
<h1>Why TAB key doesn't expand a snippet?</h1>
|
|
<p>First check the mode line to see if there's <tt class="docutils literal"><span class="pre">yas</span></tt>. If no, then try
|
|
<tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">yas/minor-mode-on</span></tt> to manually turn on <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt> and
|
|
try to expand the snippet again. If it works, then, you can add the
|
|
following code to your <tt class="docutils literal"><span class="pre">.emacs</span></tt> <em>before</em> loading YASnippet:</p>
|
|
<div class="highlight"><pre>(add-hook 'the-major-mode-hook 'yas/minor-mode-on)
|
|
</pre></div>
|
|
<p>where <tt class="docutils literal"><span class="pre">the-major-mode</span></tt> is the major mode in which <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt>
|
|
isn't enabled by default.</p>
|
|
<p>From YASnippet 0.6 you can also use the command <tt class="docutils literal"><span class="pre">M-x</span>
|
|
<span class="pre">yas/global-mode</span></tt> to turn on YASnippet automatically for <em>all</em> major
|
|
modes.</p>
|
|
<p>If <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt> is on but the snippet still not expanded. Then
|
|
try to see what command is bound to the <tt class="docutils literal"><span class="pre">TAB</span></tt> key: press <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">k</span></tt>
|
|
and then press <tt class="docutils literal"><span class="pre">TAB</span></tt>. Emacs will show you the result.</p>
|
|
<p>You'll see a buffer prompted by Emacs saying that <tt class="docutils literal"><span class="pre">TAB</span> <span class="pre">runs</span> <span class="pre">the</span>
|
|
<span class="pre">command</span> <span class="pre">...</span></tt>. Alternatively, you might see <tt class="docutils literal"><span class="pre"><tab></span> <span class="pre">runs</span> <span class="pre">the</span> <span class="pre">command</span>
|
|
<span class="pre">...</span></tt>, note the difference between <tt class="docutils literal"><span class="pre">TAB</span></tt> and <tt class="docutils literal"><span class="pre"><tab></span></tt> where the
|
|
latter has priority. If you see <tt class="docutils literal"><span class="pre"><tab></span></tt> bound to a command other
|
|
than <tt class="docutils literal"><span class="pre">yas/expand</span></tt>, (e.g. in <tt class="docutils literal"><span class="pre">org-mode</span></tt>) you can try the following
|
|
code to work around:</p>
|
|
<div class="highlight"><pre>(add-hook 'org-mode-hook
|
|
'(lambda ()
|
|
(make-variable-buffer-local 'yas/trigger-key)
|
|
(setq yas/trigger-key [tab])))
|
|
</pre></div>
|
|
<p>replace <tt class="docutils literal"><span class="pre">org-mode-hook</span></tt> with the major mode hook you are dealing
|
|
with (<tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt> to see what major mode you are in).</p>
|
|
<p>If it says <tt class="docutils literal"><span class="pre">TAB</span></tt> but YASnippet still doesn't work, check your
|
|
configuration and you may also ask for help on the <a class="reference external" href="http://groups.google.com/group/smart-snippet">discussion group</a>. Don't forget to
|
|
attach the information on what command is bound to TAB as well as the
|
|
mode information (Can be obtained by <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt>).</p>
|
|
</div>
|
|
<div class="section" id="how-to-define-snippets-with-named-by-characters-not-supported-by-the-filesystem">
|
|
<h1>How to define snippets with named by characters not supported by the filesystem?</h1>
|
|
<p>For example, you want to define a snippet by the key <tt class="docutils literal"><span class="pre"><</span></tt> which is not a
|
|
valid character for filename on Windows. In this case, you may use
|
|
<tt class="docutils literal"><span class="pre">yas/define</span></tt> to define the snippet. If you want to enjoy defining
|
|
snippets in a file, you can use the <tt class="docutils literal"><span class="pre">key</span></tt> property to specify the key of
|
|
the defined snippet explicitly.</p>
|
|
<p>Just name your snippet with an arbitrary valid filename, <tt class="docutils literal"><span class="pre">lt</span></tt> for
|
|
example. and specify <tt class="docutils literal"><span class="pre"><</span></tt> for the <tt class="docutils literal"><span class="pre">key</span></tt> property:</p>
|
|
<div class="highlight"><pre>#key: <
|
|
#name: <...></...>
|
|
# --
|
|
<${1:div}>$0</$1>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|