Fix docs, organizing snippet section: using yas-snippet-dirs instead of the deprecated yas/root-directory

This commit is contained in:
Duong H. Nguyen 2013-10-23 04:25:45 +07:00
parent 4f3f185912
commit b19daa31ca

View File

@ -82,32 +82,47 @@ intended.</p>
<p>The non-bundle version of YASnippet, once unpacked, comes with a full
directory of snippets, which you can copy somewhere and use. You can
also create or download more directories.</p>
<p>Once these directories are in place reference them in the variable
<tt class="docutils literal"><span class="pre">yas/root-directory</span></tt> and load them with <tt class="docutils literal"><span class="pre">yas/load-directory</span></tt>:</p>
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #408080; font-style: italic">;; Develop and keep personal snippets under ~/emacs.d/mysnippets</span>
(<span style="color: #008000; font-weight: bold">setq</span> <span style="color: #19177C">yas/root-directory</span> <span style="color: #BA2121">&quot;~/emacs.d/mysnippets&quot;</span>)
<span style="color: #408080; font-style: italic">;; Load the snippets</span>
(<span style="color: #19177C">yas/load-directory</span> <span style="color: #19177C">yas/root-directory</span>)
</pre></div>
<p>The point in using <tt class="docutils literal"><span class="pre">yas/root-directory</span></tt> (as opposed to calling
<tt class="docutils literal"><span class="pre">yas/load-directory</span></tt> directly) is considering &quot;~/emacs.d/mysnippets&quot;
for snippet development, so you can use commands like
<tt class="docutils literal"><span class="pre">yas/new-snippet</span></tt> and others described in section <a class="reference external" href="snippet-development.html">Writing
Snippets</a>.</p>
<p>You can make this variable a list and store more items into it:</p>
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #408080; font-style: italic">;; Develop in ~/emacs.d/mysnippets, but also</span>
<span style="color: #408080; font-style: italic">;; try out snippets in ~/Downloads/interesting-snippets</span>
(<span style="color: #008000; font-weight: bold">setq</span> <span style="color: #19177C">yas/root-directory</span> <span style="color: #666666">&#39;</span>(<span style="color: #BA2121">&quot;~/emacs.d/mysnippets&quot;</span>
<span style="color: #BA2121">&quot;~/Downloads/interesting-snippets&quot;</span>))
<p>
Once these directories are in place reference them in the variable
<tt class="docutils literal">
<span class="pre">yas-snippet-dirs</span>
</tt>
and then load YASnippet as usual:
</p>
<span style="color: #408080; font-style: italic">;; Map `yas/load-directory&#39; to every element</span>
(<span style="color: #008000">mapc</span> <span style="color: #19177C">&#39;yas/load-directory</span> <span style="color: #19177C">yas/root-directory</span>)
<div class="highlight" style="background: #f8f8f8">
<pre style="line-height: 125%"><span style="color: #408080; font-style: italic">;; Develop and keep personal snippets under ~/emacs.d/mysnippets</span>
(<span style="color: #008000; font-weight: bold">setq</span> <span style="color: #19177C">yas-snippet-dirs</span> <span style="color: #666666">&#39;</span>(<span style="color: #BA2121">&quot;~/emacs.d/mysnippets&quot;</span>))
<span style="color: #408080; font-style: italic">;; Load yasnippet</span>
(<span style="color: #19177C">yas-global-mode</span> <span style="color: #19177C">1</span>)
</pre></div>
<p>In this last example, the all the directories are loaded and their
snippets considered for expansion. However development still happens
in the first element, &quot;~/emacs.d/mysnippets&quot;.</p>
<p>
The point in using
<tt class="docutils literal">
<span class="pre">yas-snippet-dirs</span>
</tt>
is considering &quot;~/emacs.d/mysnippets&quot; for snippet development, so
you can use commands like
<tt class="docutils literal">
<span class="pre">yas/new-snippet</span>
</tt>
and others described in section
<a class="reference external" href="snippet-development.html">Writing Snippets</a>.
</p>
</div>
<p>
<strong>Note:</strong> In the past,
<tt class="docutils literal">
<span class="pre">yas/root-directory</span>
</tt>
is the variable that stores the list of snippet directories. This method is
deprecated and only exists for backward-compatibility reason.
</p>
<div class="section" id="id2">
<h1><a class="toc-backref" href="#id4">Organizing snippets</a></h1>
<p>Once you've setup <tt class="docutils literal"><span class="pre">yas/root-directory</span></tt> , you can store snippets