Merge pull request #419 from cmpitg/gh-pages

Update documentation for organizing snippets
This commit is contained in:
João Távora 2013-10-22 17:08:44 -07:00
commit 8b4ea83b50

View File

@ -65,7 +65,7 @@
</li> </li>
<li><a class="reference internal" href="#yasnippet-bundle" id="id7">YASnippet bundle</a></li> <li><a class="reference internal" href="#yasnippet-bundle" id="id7">YASnippet bundle</a></li>
<li><a class="reference internal" href="#customizable-variables" id="id8">Customizable variables</a><ul> <li><a class="reference internal" href="#customizable-variables" id="id8">Customizable variables</a><ul>
<li><a class="reference internal" href="#yas-root-directory" id="id9"><tt class="docutils literal"><span class="pre">yas/root-directory</span></tt></a></li> <li><a class="reference internal" href="#yas-snippet-dirs" id="id9"><tt class="docutils literal"><span class="pre">yas-snippet-dirs</span></tt></a></li>
<li><a class="reference internal" href="#yas-ignore-filenames-as-triggers" id="id10"><tt class="docutils literal"><span class="pre">yas/ignore-filenames-as-triggers</span></tt></a></li> <li><a class="reference internal" href="#yas-ignore-filenames-as-triggers" id="id10"><tt class="docutils literal"><span class="pre">yas/ignore-filenames-as-triggers</span></tt></a></li>
</ul> </ul>
</li> </li>
@ -82,35 +82,50 @@ intended.</p>
<p>The non-bundle version of YASnippet, once unpacked, comes with a full <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 directory of snippets, which you can copy somewhere and use. You can
also create or download more directories.</p> 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> <p>
(<span style="color: #19177C">yas/load-directory</span> <span style="color: #19177C">yas/root-directory</span>) Once these directories are in place reference them in the variable
</pre></div> <tt class="docutils literal">
<p>The point in using <tt class="docutils literal"><span class="pre">yas/root-directory</span></tt> (as opposed to calling <span class="pre">yas-snippet-dirs</span>
<tt class="docutils literal"><span class="pre">yas/load-directory</span></tt> directly) is considering &quot;~/emacs.d/mysnippets&quot; </tt>
for snippet development, so you can use commands like and then load YASnippet as usual:
<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 </p>
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>))
<span style="color: #408080; font-style: italic">;; Map `yas/load-directory&#39; to every element</span> <div class="highlight" style="background: #f8f8f8">
(<span style="color: #008000">mapc</span> <span style="color: #19177C">&#39;yas/load-directory</span> <span style="color: #19177C">yas/root-directory</span>) <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> </pre></div>
<p>In this last example, the all the directories are loaded and their
snippets considered for expansion. However development still happens <p>
in the first element, &quot;~/emacs.d/mysnippets&quot;.</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> </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"> <div class="section" id="id2">
<h1><a class="toc-backref" href="#id4">Organizing snippets</a></h1> <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 <p>Once you've setup <tt class="docutils literal"><span class="pre">yas-snippet-dirs</span></tt> , you can store snippets
inside sub-directories of these directories.</p> inside sub-directories of these directories.</p>
<p>Snippet definitions are put in plain text files. They are arranged <p>Snippet definitions are put in plain text files. They are arranged
by sub-directories, and the snippet tables are named after these by sub-directories, and the snippet tables are named after these
@ -192,15 +207,27 @@ generated this way.</p>
</div> </div>
<div class="section" id="customizable-variables"> <div class="section" id="customizable-variables">
<h1><a class="toc-backref" href="#id8">Customizable variables</a></h1> <h1><a class="toc-backref" href="#id8">Customizable variables</a></h1>
<div class="section" id="yas-root-directory"> <div class="section" id="yas-snippet-dirs">
<h2><a class="toc-backref" href="#id9"><tt class="docutils literal"><span class="pre">yas/root-directory</span></tt></a></h2>
<p>Root directory that stores the snippets for each major mode.</p> <h2>
<p>If you set this from your .emacs, can also be a list of strings, <a class="toc-backref" href="#id9"><tt class="docutils literal"><span class="pre">yas-snippet-dirs</span></tt></a>
for multiple root directories. If you make this a list, the first </h2>
element is always the user-created snippets directory. Other
directories are used for bulk reloading of all snippets using <p>
<tt class="docutils literal"><span class="pre">yas/reload-all</span></tt></p> List of directories that store the snippets for each major mode.
</p>
<p>
The first element of the list is always the user-created snippets
directory. Other directories are used for bulk reloading of all snippets
using
<tt class="docutils literal">
<span class="pre">yas/reload-all</span>
</tt>.
</p>
</div> </div>
<div class="section" id="yas-ignore-filenames-as-triggers"> <div class="section" id="yas-ignore-filenames-as-triggers">
<h2><a class="toc-backref" href="#id10"><tt class="docutils literal"><span class="pre">yas/ignore-filenames-as-triggers</span></tt></a></h2> <h2><a class="toc-backref" href="#id10"><tt class="docutils literal"><span class="pre">yas/ignore-filenames-as-triggers</span></tt></a></h2>
<p>If non-nil, don't derive tab triggers from filenames.</p> <p>If non-nil, don't derive tab triggers from filenames.</p>