mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
141 lines
8.2 KiB
HTML
141 lines
8.2 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.6: http://docutils.sourceforge.net/" />
|
|
<title>Frequently Asked Questions</title>
|
|
<link rel="stylesheet" href="styles.css" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div class="document" id="frequently-asked-questions">
|
|
<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">Frequently Asked Questions</h1>
|
|
</div>
|
|
<ul class="primary-links">
|
|
<li>
|
|
<a title="" href="index.html">Intro and tutorial</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="snippet-organization.html">Howto: organize</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="snippet-expansion.html">Howto: expand</a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="snippet-development.html">Howto: write </a>
|
|
</li>
|
|
<li>
|
|
<a title="" href="snippet-menu.html">Howto: menu </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">
|
|
<p>
|
|
<b>Important:</b> This documentation applies to
|
|
the <b>SVN trunk</b> of YASnippet, which you
|
|
get <a href="http://code.google.com/p/yasnippet/source/checkout">here</a>. Documentation
|
|
for other versions can be found <a title=""
|
|
href="http://code.google.com/p/yasnippet/downloads/list">here</a>.
|
|
</p>
|
|
<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 not, then try
|
|
<tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">yas/minor-mode</span></tt> to manually turn on the minor mode 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 ()
|
|
(local-set-key [tab] 'yas/expand)))
|
|
</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 this doesn't work, you can also try</p>
|
|
<div class="highlight"><pre>(defun yas/advise-indent-function (function-symbol)
|
|
(eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
|
|
,(format
|
|
"Try to expand a snippet before point, then call `%s' as usual"
|
|
function-symbol)
|
|
(let ((yas/fallback-behavior nil))
|
|
(unless (and (interactive-p)
|
|
(yas/expand))
|
|
ad-do-it)))))
|
|
|
|
(yas/advise-indent-function 'ruby-indent-line)
|
|
</pre></div>
|
|
<p>To <em>advise</em> the modes indentation function bound to TAB, (in this case
|
|
<tt class="docutils literal"><span class="pre">ruby-indent-line</span></tt>) to first try to run <tt class="docutils literal"><span class="pre">yas/expand</span></tt>.</p>
|
|
<p>If The output of <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">k</span> <span class="pre">RET</span> <span class="pre"><tab></span></tt> tells you that <tt class="docutils literal"><span class="pre"><tab></span></tt> is
|
|
indeed bound to <tt class="docutils literal"><span class="pre">yas/expand</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>.</p>
|
|
<p>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>
|