mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Automatic documentation update.
From 0.12.2
This commit is contained in:
parent
a3f4b3319e
commit
38dd3d29c0
155
faq.html
155
faq.html
@ -4,7 +4,6 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Frequently Asked Questions</title>
|
||||
<!-- 2016-04-30 Sat 22:37 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Org-mode" />
|
||||
<style type="text/css">
|
||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
||||
<nav>
|
||||
<ul class="center">
|
||||
<li> <a href="index.html">Overview</a>
|
||||
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">
|
||||
<li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
|
||||
Intro and Tutorial</a>
|
||||
<li class="center">Snippet
|
||||
<ul>
|
||||
@ -161,11 +160,10 @@ for the JavaScript code in this tag.
|
||||
<div id="text-table-of-contents">
|
||||
<ul>
|
||||
<li><a href="#sec-1">Why is there an extra newline?</a></li>
|
||||
<li><a href="#sec-2">Why doesn't TAB expand a snippet?</a></li>
|
||||
<li><a href="#sec-3">Why doesn't TAB navigation work with flyspell</a></li>
|
||||
<li><a href="#sec-4">How to I use alternative keys, i.e. not TAB?</a></li>
|
||||
<li><a href="#sec-5">How do I turn off the minor mode where in some buffers?</a></li>
|
||||
<li><a href="#sec-6">How do I define an abbrev key containing characters not supported by the filesystem?</a></li>
|
||||
<li><a href="#sec-2">Why doesn't TAB navigation work with flyspell</a></li>
|
||||
<li><a href="#sec-3">How to I use alternative keys, i.e. not TAB?</a></li>
|
||||
<li><a href="#sec-4">How do I turn off the minor mode where in some buffers?</a></li>
|
||||
<li><a href="#sec-5">How do I define an abbrev key containing characters not supported by the filesystem?</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -174,120 +172,24 @@ for the JavaScript code in this tag.
|
||||
<h2 id="sec-1">Why is there an extra newline?</h2>
|
||||
<div class="outline-text-2" id="text-1">
|
||||
<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.
|
||||
If there is a newline at the end of a snippet definition file,
|
||||
YASnippet will add a newline when expanding that snippet. When editing
|
||||
or saving a snippet file, please be careful not to accidentally add a
|
||||
terminal newline.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note some editors will automatically add a newline for you. In Emacs, if
|
||||
you set <code>require-final-newline</code> to <code>t</code>, it will add the final newline
|
||||
for you automatically.
|
||||
Note that some editors will automatically add a newline for you. In
|
||||
Emacs, if you set <code>require-final-newline</code> to <code>t</code>, it will add the
|
||||
final newline automatically.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-2" class="outline-2">
|
||||
<h2 id="sec-2">Why doesn't TAB expand a snippet?</h2>
|
||||
<h2 id="sec-2">Why doesn't TAB navigation work with flyspell</h2>
|
||||
<div class="outline-text-2" id="text-2">
|
||||
<p>
|
||||
First check the mode line to see if there's <code>yas</code>. If not, then try
|
||||
<code>M-x yas-minor-mode</code> 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 <code>.emacs</code> <i>before</i> loading YASnippet:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(add-hook 'the-major-mode-hook 'yas-minor-mode-on)
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
where <code>the-major-mode</code> is the major mode in which <a href="snippet-reference.html#yas-minor-mode"><code>yas-minor-mode</code></a> isn't
|
||||
enabled by default.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
From YASnippet 0.6 you can also use the command <code>M-x yas-global-mode</code> to
|
||||
turn on YASnippet automatically for <i>all</i> major modes.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If <a href="snippet-reference.html#yas-minor-mode"><code>yas-minor-mode</code></a> is on but the snippet still not expanded. Then try
|
||||
to see what command is bound to the <code>TAB</code> key: press <code>C-h k</code> and then
|
||||
press <code>TAB</code>. Emacs will show you the result.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You'll see a buffer prompted by Emacs saying that
|
||||
<code>TAB runs the command ...</code>. Alternatively, you might see
|
||||
<code><tab> runs the command ...</code>, note the difference between <code>TAB</code> and
|
||||
<code><tab></code> where the latter has priority. If you see <code><tab></code> bound to a
|
||||
command other than <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a>, (e.g. in <code>org-mode</code>) you can try the
|
||||
following code to work around:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(add-hook 'org-mode-hook
|
||||
(<span class="org-keyword">let</span> ((original-command (lookup-key org-mode-map [tab])))
|
||||
`(<span class="org-keyword">lambda</span> ()
|
||||
(setq yas-fallback-behavior
|
||||
'(apply ,original-command))
|
||||
(local-set-key [tab] 'yas-expand))))
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
replace <code>org-mode-hook</code> and <code>org-mode-map</code> with the major mode hook you
|
||||
are dealing with (Use <code>C-h m</code> to see what major mode you are in).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
As an alternative, you can also try
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(<span class="org-keyword">defun</span> <span class="org-function-name">yas-advise-indent-function</span> (function-symbol)
|
||||
(eval `(<span class="org-keyword">defadvice</span> ,function-symbol (around yas-try-expand-first activate)
|
||||
,(format
|
||||
<span class="org-string">"Try to expand a snippet before point, then call `</span><span class="org-string"><span class="org-constant">%s</span></span><span class="org-string">' as usual"</span>
|
||||
function-symbol)
|
||||
(<span class="org-keyword">let</span> ((yas-fallback-behavior nil))
|
||||
(<span class="org-keyword">unless</span> (and (interactive-p)
|
||||
(yas-expand))
|
||||
ad-do-it)))))
|
||||
|
||||
(yas-advise-indent-function 'ruby-indent-line)
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
To <i>advise</i> the modes indentation function bound to TAB, (in this case
|
||||
<code>ruby-indent-line</code>) to first try to run <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If the output of <code>C-h k RET <tab></code> tells you that <code><tab></code> is indeed
|
||||
bound to <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> but YASnippet still doesn't work, check your
|
||||
configuration and you may also ask for help on the <a href="http://groups.google.com/group/smart-snippet">discussion group</a>.
|
||||
See this particular <a href="http://code.google.com/p/yasnippet/issues/detail?id=93&can=1">thread</a> for quite some solutions and alternatives.
|
||||
</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 <code>C-h m</code>).
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-3" class="outline-2">
|
||||
<h2 id="sec-3">Why doesn't TAB navigation work with flyspell</h2>
|
||||
<div class="outline-text-2" id="text-3">
|
||||
<p>
|
||||
A workaround is to inhibit flyspell overlays while the snippet is
|
||||
active:
|
||||
</p>
|
||||
@ -295,8 +197,8 @@ active:
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(add-hook 'flyspell-incorrect-hook
|
||||
#'(<span class="org-keyword">lambda</span> (dummy1 dummy2 dymmy3)
|
||||
(and yas-active-field-overlay
|
||||
#'(lambda (dummy1 dummy2 dymmy3)
|
||||
(<span class="org-keyword">and</span> yas-active-field-overlay
|
||||
(overlay-buffer yas-active-field-overlay))))
|
||||
</pre>
|
||||
</div>
|
||||
@ -312,9 +214,9 @@ solve this problem, drop a line in the
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-4" class="outline-2">
|
||||
<h2 id="sec-4">How to I use alternative keys, i.e. not TAB?</h2>
|
||||
<div class="outline-text-2" id="text-4">
|
||||
<div id="outline-container-sec-3" class="outline-2">
|
||||
<h2 id="sec-3">How to I use alternative keys, i.e. not TAB?</h2>
|
||||
<div class="outline-text-2" id="text-3">
|
||||
<p>
|
||||
Edit the keymaps <a href="snippet-reference.html#yas-minor-mode-map"><code>yas-minor-mode-map</code></a> and
|
||||
<a href="snippet-reference.html#yas-keymap"><code>yas-keymap</code></a> as you would any other keymap:
|
||||
@ -324,7 +226,7 @@ Edit the keymaps <a href="snippet-reference.html#yas-minor-mode-map"><code>yas-m
|
||||
|
||||
<pre class="src src-emacs-lisp">(define-key yas-minor-mode-map (kbd <span class="org-string">"<tab>"</span>) nil)
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"TAB"</span>) nil)
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"<the new key>"</span>) 'yas-expand)
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"<the new key>"</span>) yas-maybe-expand)
|
||||
|
||||
<span class="org-comment-delimiter">;;</span><span class="org-comment">keys for navigation</span>
|
||||
(define-key yas-keymap [(tab)] nil)
|
||||
@ -338,9 +240,9 @@ Edit the keymaps <a href="snippet-reference.html#yas-minor-mode-map"><code>yas-m
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-5" class="outline-2">
|
||||
<h2 id="sec-5">How do I turn off the minor mode where in some buffers?</h2>
|
||||
<div class="outline-text-2" id="text-5">
|
||||
<div id="outline-container-sec-4" class="outline-2">
|
||||
<h2 id="sec-4">How do I turn off the minor mode where in some buffers?</h2>
|
||||
<div class="outline-text-2" id="text-4">
|
||||
<p>
|
||||
The best way, since version 0.6.1c, is to set the default value of the
|
||||
variable <a href="snippet-reference.html#yas-dont-activate"><code>yas-dont-activate</code></a> to a lambda function like so:
|
||||
@ -349,8 +251,8 @@ variable <a href="snippet-reference.html#yas-dont-activate"><code>yas-dont-activ
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(set-default 'yas-dont-activate
|
||||
#'(<span class="org-keyword">lambda</span> ()
|
||||
(and yas-root-directory
|
||||
#'(lambda ()
|
||||
(<span class="org-keyword">and</span> yas-root-directory
|
||||
(null (yas-get-snippet-tables)))))
|
||||
</pre>
|
||||
</div>
|
||||
@ -363,9 +265,9 @@ but only once you have setup your yas-root-directory.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-6" class="outline-2">
|
||||
<h2 id="sec-6">How do I define an abbrev key containing characters not supported by the filesystem?</h2>
|
||||
<div class="outline-text-2" id="text-6">
|
||||
<div id="outline-container-sec-5" class="outline-2">
|
||||
<h2 id="sec-5">How do I define an abbrev key containing characters not supported by the filesystem?</h2>
|
||||
<div class="outline-text-2" id="text-5">
|
||||
<ul class="org-ul">
|
||||
<li><b>Note</b>: This question applies if you're still defining snippets
|
||||
whose key <i>is</i> the filename. This is behavior still provided by
|
||||
@ -399,8 +301,7 @@ directive:
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10) on from df229b9ab8db87fe5a1133365fdc299a65f9be86
|
||||
</p>
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.50.5 (<a href="http://orgmode.org">Org</a> mode 8.2.10) from 0.12.2 (2017-08-29 02:08:58)</p>
|
||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -4,7 +4,6 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Yet another snippet extension</title>
|
||||
<!-- 2016-04-30 Sat 22:37 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Org-mode" />
|
||||
<style type="text/css">
|
||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
||||
<nav>
|
||||
<ul class="center">
|
||||
<li> <a href="index.html">Overview</a>
|
||||
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">
|
||||
<li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
|
||||
Intro and Tutorial</a>
|
||||
<li class="center">Snippet
|
||||
<ul>
|
||||
@ -161,7 +160,7 @@ The YASnippet documentation has been split into separate parts:
|
||||
</p>
|
||||
|
||||
<ol class="org-ol">
|
||||
<li><a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">README</a>
|
||||
<li><a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">README</a>
|
||||
|
||||
<p>
|
||||
Contains an introduction, installation instructions and other important
|
||||
@ -222,8 +221,7 @@ An automatically generated listing of all YASnippet commands,
|
||||
</ol>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10) on from df229b9ab8db87fe5a1133365fdc299a65f9be86
|
||||
</p>
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.50.5 (<a href="http://orgmode.org">Org</a> mode 8.2.10) from 0.12.2 (2017-08-29 02:08:58)</p>
|
||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -4,7 +4,6 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Writing snippets</title>
|
||||
<!-- 2016-04-30 Sat 22:37 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Org-mode" />
|
||||
<style type="text/css">
|
||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
||||
<nav>
|
||||
<ul class="center">
|
||||
<li> <a href="index.html">Overview</a>
|
||||
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">
|
||||
<li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
|
||||
Intro and Tutorial</a>
|
||||
<li class="center">Snippet
|
||||
<ul>
|
||||
@ -163,7 +162,7 @@ for the JavaScript code in this tag.
|
||||
<li><a href="#sec-1">Snippet development</a>
|
||||
<ul>
|
||||
<li><a href="#sec-1-1">Quickly finding snippets</a></li>
|
||||
<li><a href="#sec-1-2">Using the <code>snippet-mode</code> major mode</a></li>
|
||||
<li><a href="#sec-1-2">Using the <code>snippet-mode</code> major mode </a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#sec-2">File content</a>
|
||||
@ -182,7 +181,11 @@ for the JavaScript code in this tag.
|
||||
<li><a href="#sec-3">Template Syntax</a>
|
||||
<ul>
|
||||
<li><a href="#sec-3-1">Plain Text</a></li>
|
||||
<li><a href="#sec-3-2">Embedded Emacs-lisp code</a></li>
|
||||
<li><a href="#sec-3-2">Embedded Emacs-lisp code</a>
|
||||
<ul>
|
||||
<li><a href="#sec-3-2-1">Note: backquote expressions should not modify the buffer</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#sec-3-3">Tab stop fields</a></li>
|
||||
<li><a href="#sec-3-4">Placeholder fields</a></li>
|
||||
<li><a href="#sec-3-5">Mirrors </a></li>
|
||||
@ -190,6 +193,7 @@ for the JavaScript code in this tag.
|
||||
<li><a href="#sec-3-7">Fields with transformations</a></li>
|
||||
<li><a href="#sec-3-8">Choosing fields value from a list and other tricks</a></li>
|
||||
<li><a href="#sec-3-9">Nested placeholder fields</a></li>
|
||||
<li><a href="#sec-3-10">Indentation markers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@ -207,30 +211,16 @@ There are some ways you can quickly find a snippet file or create a new one:
|
||||
</p>
|
||||
|
||||
<ul class="org-ul">
|
||||
<li><code>M-x yas-new-snippet</code>
|
||||
<li><code>M-x yas-new-snippet</code>, key bindind: <code>C-c & C-n</code>
|
||||
|
||||
<p>
|
||||
Creates a new buffer with a template for making a new snippet.
|
||||
The buffer is in <code>snippet-mode</code> (see below). When you are done
|
||||
editing the new snippet, use <code>C-c C-c</code> to save it. This will
|
||||
prompt for a directory two steps: first, the snippet table
|
||||
(with a default based on the major mode you started in), and then
|
||||
then snippet collection directory (defaults to the first directory
|
||||
in <code>yas-snippet-dirs</code>. (See <a href="snippet-organization.html">Organizing Snippets</a>
|
||||
for more detail on how snippets are organized.)
|
||||
Creates a new buffer with a template for making a new snippet. The
|
||||
buffer is in <code>snippet-mode</code> (see <a href="#snippet-mode">below</a>). When you are done editing
|
||||
the new snippet, use <a href="#yas-load-snippet-buffer-and-close"><code>C-c C-c</code></a> to save it.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>M-x yas-find-snippets</code>
|
||||
|
||||
<p>
|
||||
Lets you find the snippet file in the directory the snippet was
|
||||
loaded from (if it exists) like <code>find-file-other-window</code>. The
|
||||
directory searching logic is similar to <code>M-x yas-new-snippet</code>.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>M-x yas-visit-snippet-file</code>
|
||||
<li><code>M-x yas-visit-snippet-file</code>, key binding: <code>C-c & C-v</code>
|
||||
|
||||
<p>
|
||||
Prompts you for possible snippet expansions like
|
||||
@ -241,14 +231,14 @@ to the snippet definition's file, if it exists.
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
Once you find this file it will be set to <code>snippet-mode</code> (see ahead) and
|
||||
you can start editing your snippet.
|
||||
Once you find this file it will be set to <code>snippet-mode</code> (see <a href="#snippet-mode">ahead</a>)
|
||||
and you can start editing your snippet.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-1-2" class="outline-3">
|
||||
<h3 id="sec-1-2">Using the <code>snippet-mode</code> major mode</h3>
|
||||
<h3 id="sec-1-2">Using the <code>snippet-mode</code> major mode <a id="snippet-mode" name="snippet-mode"></a></h3>
|
||||
<div class="outline-text-3" id="text-1-2">
|
||||
<p>
|
||||
There is a major mode <code>snippet-mode</code> to edit snippets. You can set the
|
||||
@ -257,26 +247,36 @@ useful syntax highlighting.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Two commands are defined in this mode:
|
||||
Three commands are defined in this mode:
|
||||
</p>
|
||||
|
||||
<ul class="org-ul">
|
||||
<li><code>M-x yas-load-snippet-buffer</code>
|
||||
<li><code>M-x yas-load-snippet-buffer</code>, key binding: <code>C-c C-l</code>
|
||||
|
||||
<p>
|
||||
When editing a snippet, this loads the snippet into the correct
|
||||
mode and menu. Bound to <code>C-c C-c</code> by default while in
|
||||
<code>snippet-mode</code>.
|
||||
Prompts for a snippet table (with a default based on snippet's
|
||||
major mode) and loads the snippet currently being edited.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>M-x yas-tryout-snippet</code>
|
||||
<li><code>M-x yas-load-snippet-buffer-and-close</code>, key binding: <code>C-c C-c</code>
|
||||
<a id="yas-load-snippet-buffer-and-close" name="yas-load-snippet-buffer-and-close"></a>
|
||||
|
||||
<p>
|
||||
Like <code>yas-load-snippet-buffer</code>, but also saves the snippet and
|
||||
calls <code>quit-window</code>. The destination is decided based on the
|
||||
chosen snippet table and snippet collection directly (defaulting to
|
||||
the first directory in <code>yas-snippet-dirs</code> (see <a href="snippet-organization.html">Organizing Snippets</a>
|
||||
for more detail on how snippets are organized).
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>M-x yas-tryout-snippet</code>, key binding: <code>C-c C-t</code>
|
||||
|
||||
<p>
|
||||
When editing a snippet, this opens a new empty buffer, sets it to
|
||||
the appropriate major mode and inserts the snippet there, so you
|
||||
can see what it looks like. This is bound to <code>C-c C-t</code> while in
|
||||
<code>snippet-mode</code>.
|
||||
can see what it looks like.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
@ -537,7 +537,7 @@ snippet being expanded.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Here's an example for c-mode` to calculate the header file guard
|
||||
Here's an example for c-mode to calculate the header file guard
|
||||
dynamically:
|
||||
</p>
|
||||
|
||||
@ -572,8 +572,44 @@ Alternatively, you can also customize the variable
|
||||
<a href="snippet-reference.html#yas-wrap-around-region"><code>yas-wrap-around-region</code></a> to <code>t</code> which will do this automatically.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-3-2-1" class="outline-4">
|
||||
<h4 id="sec-3-2-1">Note: backquote expressions should not modify the buffer</h4>
|
||||
<div class="outline-text-4" id="text-3-2-1">
|
||||
<p>
|
||||
Please note that the lisp forms in backquotes should <b>not</b> modify the
|
||||
buffer, doing so will trigger a warning. For example, instead of
|
||||
doing
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-snippet">Timestamp: `(insert (current-time-string))`
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
do this:
|
||||
</p>
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-snippet">Timestamp: `(current-time-string)`
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The warning may be suppressed with the following code in your init file:
|
||||
</p>
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(add-to-list 'warning-suppress-types '(yasnippet backquote-change))
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="outline-container-sec-3-3" class="outline-3">
|
||||
<h3 id="sec-3-3">Tab stop fields</h3>
|
||||
<div class="outline-text-3" id="text-3-3">
|
||||
@ -850,11 +886,21 @@ performs the normal Emacs <code>delete-char</code> command.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-3-10" class="outline-3">
|
||||
<h3 id="sec-3-10">Indentation markers</h3>
|
||||
<div class="outline-text-3" id="text-3-10">
|
||||
<p>
|
||||
If <a href="snippet-reference.html#yas-indent-line"><code>yas-indent-line</code></a> is <b>not</b> set to '<code>auto</code>, it's still possible to
|
||||
indent specific lines by adding an indentation marker, <code>$></code>, somewhere
|
||||
on the line.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10) on from df229b9ab8db87fe5a1133365fdc299a65f9be86
|
||||
</p>
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.50.5 (<a href="http://orgmode.org">Org</a> mode 8.2.10) from 0.12.2 (2017-08-29 02:08:58)</p>
|
||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -4,7 +4,6 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Expanding snippets</title>
|
||||
<!-- 2016-04-30 Sat 22:37 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Org-mode" />
|
||||
<style type="text/css">
|
||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
||||
<nav>
|
||||
<ul class="center">
|
||||
<li> <a href="index.html">Overview</a>
|
||||
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">
|
||||
<li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
|
||||
Intro and Tutorial</a>
|
||||
<li class="center">Snippet
|
||||
<ul>
|
||||
@ -181,7 +180,7 @@ for the JavaScript code in this tag.
|
||||
<li><a href="#sec-2">Controlling expansion</a>
|
||||
<ul>
|
||||
<li><a href="#sec-2-1">Eligible snippets</a></li>
|
||||
<li><a href="#sec-2-2">The condition system</a></li>
|
||||
<li><a href="#sec-2-2">The condition system </a></li>
|
||||
<li><a href="#sec-2-3">Multiples snippet with the same key</a>
|
||||
<ul>
|
||||
<li><a href="#sec-2-3-1">Use the X window system</a></li>
|
||||
@ -247,22 +246,42 @@ TODO: example for this
|
||||
<div class="outline-text-3" id="text-1-1">
|
||||
<p>
|
||||
<a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> tries to expand a <i>snippet abbrev</i> (also known as
|
||||
<i>snippet key</i>) before point.
|
||||
<i>snippet key</i>) before point. YASnippet also provides a <i>conditional
|
||||
binding</i> for this command: the variable <a href="snippet-reference.html#yas-expand"><code>yas-maybe-expand</code></a> contains a
|
||||
special value which, when bound in a keymap, tells Emacs to call
|
||||
<a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> if and only if there is a snippet abbrev before point.
|
||||
If there is no snippet to expand, Emacs will behave as if <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a>
|
||||
is unbound and so will run whatever command is bound to that key
|
||||
normally.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When <a href="snippet-reference.html#yas-minor-mode"><code>yas-minor-mode</code></a> is enabled, it binds <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> to <code>TAB</code> and
|
||||
<code><tab></code> by default, however, you can freely set it to some other key:
|
||||
When <a href="snippet-reference.html#yas-minor-mode"><code>yas-minor-mode</code></a> is enabled, it binds <a href="snippet-reference.html#yas-maybe-expand"><code>yas-maybe-expand</code></a> to <code>TAB</code>
|
||||
and <code><tab></code> by default, however, you can freely remove those bindings:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(define-key yas-minor-mode-map (kbd <span class="org-string">"<tab>"</span>) nil)
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"TAB"</span>) nil)
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"<the new key>"</span>) 'yas-expand)
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
And set your own:
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">Bind `</span><span class="org-comment"><span class="org-constant">SPC</span></span><span class="org-comment">' to `</span><span class="org-comment"><span class="org-constant">yas-expand</span></span><span class="org-comment">' when snippet expansion available (it</span>
|
||||
<span class="org-comment-delimiter">;; </span><span class="org-comment">will still call `</span><span class="org-comment"><span class="org-constant">self-insert-command</span></span><span class="org-comment">' otherwise).</span>
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"SPC"</span>) yas-maybe-expand)
|
||||
<span class="org-comment-delimiter">;; </span><span class="org-comment">Bind `C-c y' to `</span><span class="org-comment"><span class="org-constant">yas-expand</span></span><span class="org-comment">' ONLY.</span>
|
||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"C-c y"</span>) #'yas-expand)
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
To enable the YASnippet minor mode in all buffers globally use the
|
||||
command <a href="snippet-reference.html#yas-global-mode"><code>yas-global-mode</code></a>. This will enable a modeline indicator,
|
||||
@ -277,8 +296,8 @@ command <a href="snippet-reference.html#yas-global-mode"><code>yas-global-mode</
|
||||
|
||||
<p>
|
||||
When you use <a href="snippet-reference.html#yas-global-mode"><code>yas-global-mode</code></a> you can also selectively disable
|
||||
YASnippet in some buffers by setting the buffer-local variable
|
||||
<a href="snippet-reference.html#yas-dont-active"><code>yas-dont-active</code></a> in the buffer's mode hook.
|
||||
YASnippet in some buffers by calling <a href="snippet-reference.html#yas-minor-mode"><code>yas-minor-mode</code></a> with a negative
|
||||
argument in the buffer's mode hook.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@ -286,23 +305,9 @@ YASnippet in some buffers by setting the buffer-local variable
|
||||
<h4 id="sec-1-1-1">Fallback behaviour</h4>
|
||||
<div class="outline-text-4" id="text-1-1-1">
|
||||
<p>
|
||||
<a href="snippet-reference.html#yas-fallback-behaviour"><code>yas-fallback-behaviour</code></a> is a customization variable bound to
|
||||
'<code>call-other-command</code> by default. If <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> failed to find any
|
||||
suitable snippet to expand, it will disable the minor mode temporarily
|
||||
and find if there's any other command bound to the same key.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If found, the command will be called. Usually this works very well
|
||||
–when there's a snippet, expand it, otherwise, call whatever command
|
||||
originally bind to the trigger key.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
However, you can change this behavior by customizing the
|
||||
<a href="snippet-reference.html#yas-fallback-behavior"><code>yas-fallback-behavior</code></a> variable. If you set this variable to
|
||||
'<code>return-nil</code>, it will return <code>nil</code> instead of trying to call the
|
||||
<i>original</i> command when no snippet is found.
|
||||
YASnippet used to support a more complicated way of sharing
|
||||
keybindings before <a href="snippet-reference.html#yas-expand"><code>yas-maybe-expand</code></a> was added. This is now
|
||||
obsolete.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@ -474,21 +479,20 @@ mode. Typically, you call this from a minor mode hook, for example:
|
||||
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">When entering rinari-minor-mode, consider also the snippets in the</span>
|
||||
<span class="org-comment-delimiter">;; </span><span class="org-comment">snippet table "rails-mode"</span>
|
||||
(add-hook 'rinari-minor-mode-hook
|
||||
#'(<span class="org-keyword">lambda</span> ()
|
||||
#'(lambda ()
|
||||
(yas-activate-extra-mode 'rails-mode)))
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<ul class="org-ul">
|
||||
<li>Buffer-local
|
||||
<a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a>
|
||||
variable
|
||||
<li>Buffer-local <a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a> variable
|
||||
|
||||
<p>
|
||||
This variable provides finer grained control over what snippets can
|
||||
be expanded in the current buffer. The default value won't let you
|
||||
expand snippets inside comments or string literals for example. See
|
||||
The condition system\_ for more info.
|
||||
be expanded in the current buffer. For example, the constant
|
||||
<a href="snippet-reference.html#yas-not-string-or-comment-condition"><code>yas-not-string-or-comment-condition</code></a> has a value that disables
|
||||
snippet expansion inside comments or string literals. See <a href="#condition-system">the
|
||||
condition system</a> for more info.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
@ -496,7 +500,7 @@ The condition system\_ for more info.
|
||||
</div>
|
||||
|
||||
<div id="outline-container-sec-2-2" class="outline-3">
|
||||
<h3 id="sec-2-2">The condition system</h3>
|
||||
<h3 id="sec-2-2">The condition system <a id="condition-system" name="condition-system"></a></h3>
|
||||
<div class="outline-text-3" id="text-2-2">
|
||||
<p>
|
||||
Consider this scenario: you are an old Emacs hacker. You like the
|
||||
@ -506,36 +510,35 @@ block or a string (e.g. in <code>python-mode</code>).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you use the <code># condition :</code> directive (see
|
||||
<a href="./snippet-development.html">Writing Snippets</a>) you could just specify
|
||||
the condition for <code>if</code> to be <code>(not (python-in-string/comment))</code>. But how
|
||||
about <code>while</code>, <code>for</code>, etc. ? Writing the same condition for all the
|
||||
snippets is just boring. So has a buffer local variable
|
||||
<a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a>. You can set this variable to
|
||||
<code>(not (python-in-string/comment))</code> in <code>python-mode-hook</code>.
|
||||
If you use the <code># condition :</code> directive (see <a href="./snippet-development.html">Writing Snippets</a>) you
|
||||
could just specify the condition for <code>if</code> to be <code>(not
|
||||
(python-syntax-comment-or-string-p))</code>. But how about <code>while</code>, <code>for</code>,
|
||||
etc? Writing the same condition for all the snippets is just boring.
|
||||
So you can instead set <a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a> to <code>(not
|
||||
(python-syntax-comment-or-string-p))</code> in <code>python-mode-hook</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Then, what if you really want some particular snippet to expand even
|
||||
inside a comment? Set <a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a> like this
|
||||
inside a comment? Set <a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a> like this
|
||||
</p>
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(add-hook 'python-mode-hook
|
||||
(<span class="org-keyword">lambda</span> ()
|
||||
(setq yas-buffer-local-condition
|
||||
'(<span class="org-keyword">if</span> (python-in-string/comment)
|
||||
(<span class="org-keyword">setq</span> yas-buffer-local-condition
|
||||
'(<span class="org-keyword">if</span> (python-syntax-comment-or-string-p)
|
||||
'(require-snippet-condition . force-in-comment)
|
||||
t))))
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
… and specify the condition for a snippet that you're going to expand
|
||||
in comment to be evaluated to the symbol <code>force-in-comment</code>. Then it can
|
||||
be expanded as you expected, while other snippets like <code>if</code> still can't
|
||||
expanded in comment.
|
||||
… and for a snippet that you want to expand in comments, specify a
|
||||
condition which evaluates to the symbol <code>force-in-comment</code>. Then it
|
||||
can be expanded as you expected, while other snippets like <code>if</code> still
|
||||
can't expanded in comments.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@ -568,7 +571,7 @@ can put in your emacs-file:
|
||||
|
||||
<div class="org-src-container">
|
||||
|
||||
<pre class="src src-emacs-lisp">(setq yas-prompt-functions '(yas-x-prompt yas-dropdown-prompt))
|
||||
<pre class="src src-emacs-lisp">(<span class="org-keyword">setq</span> yas-prompt-functions '(yas-x-prompt yas-dropdown-prompt))
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@ -656,8 +659,7 @@ See the documentation on variable <a href="snippet-reference.html#yas-prompt-fun
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10) on from df229b9ab8db87fe5a1133365fdc299a65f9be86
|
||||
</p>
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.50.5 (<a href="http://orgmode.org">Org</a> mode 8.2.10) from 0.12.2 (2017-08-29 02:08:58)</p>
|
||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -4,7 +4,6 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>YASnippet menu</title>
|
||||
<!-- 2016-04-30 Sat 22:37 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Org-mode" />
|
||||
<style type="text/css">
|
||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
||||
<nav>
|
||||
<ul class="center">
|
||||
<li> <a href="index.html">Overview</a>
|
||||
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">
|
||||
<li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
|
||||
Intro and Tutorial</a>
|
||||
<li class="center">Snippet
|
||||
<ul>
|
||||
@ -284,8 +283,7 @@ variables.
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10) on from df229b9ab8db87fe5a1133365fdc299a65f9be86
|
||||
</p>
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.50.5 (<a href="http://orgmode.org">Org</a> mode 8.2.10) from 0.12.2 (2017-08-29 02:08:58)</p>
|
||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -4,7 +4,6 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>Organizing snippets</title>
|
||||
<!-- 2016-04-30 Sat 22:37 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="generator" content="Org-mode" />
|
||||
<style type="text/css">
|
||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
||||
<nav>
|
||||
<ul class="center">
|
||||
<li> <a href="index.html">Overview</a>
|
||||
<li> <a href="https://github.com/capitaomorte/yasnippet/blob/master/README.mdown">
|
||||
<li> <a href="https://github.com/joaotavora/yasnippet/blob/master/README.mdown">
|
||||
Intro and Tutorial</a>
|
||||
<li class="center">Snippet
|
||||
<ul>
|
||||
@ -228,11 +227,11 @@ out:
|
||||
|
||||
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">Develop in ~/emacs.d/mysnippets, but also</span>
|
||||
<span class="org-comment-delimiter">;; </span><span class="org-comment">try out snippets in ~/Downloads/interesting-snippets</span>
|
||||
(setq yas-snippet-dirs '(<span class="org-string">"~/emacs.d/mysnippets"</span>
|
||||
(<span class="org-keyword">setq</span> yas-snippet-dirs '(<span class="org-string">"~/emacs.d/mysnippets"</span>
|
||||
<span class="org-string">"~/Downloads/interesting-snippets"</span>))
|
||||
|
||||
<span class="org-comment-delimiter">;; </span><span class="org-comment">OR, keeping YASnippet defaults try out ~/Downloads/interesting-snippets</span>
|
||||
(setq yas-snippet-dirs (append yas-snippet-dirs
|
||||
(<span class="org-keyword">setq</span> yas-snippet-dirs (append yas-snippet-dirs
|
||||
'(<span class="org-string">"~/Downloads/interesting-snippets"</span>)))
|
||||
</pre>
|
||||
</div>
|
||||
@ -359,8 +358,7 @@ not to load snippets from there.
|
||||
</div>
|
||||
</div>
|
||||
<div id="postamble" class="status">
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10) on from df229b9ab8db87fe5a1133365fdc299a65f9be86
|
||||
</p>
|
||||
<hr><p class='creator'>Generated by <a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.50.5 (<a href="http://orgmode.org">Org</a> mode 8.2.10) from 0.12.2 (2017-08-29 02:08:58)</p>
|
||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||
</div>
|
||||
</body>
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user