mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +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">
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Frequently Asked Questions</title>
|
<title>Frequently Asked Questions</title>
|
||||||
<!-- 2016-04-30 Sat 22:37 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<meta name="generator" content="Org-mode" />
|
<meta name="generator" content="Org-mode" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="center">
|
<ul class="center">
|
||||||
<li> <a href="index.html">Overview</a>
|
<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>
|
Intro and Tutorial</a>
|
||||||
<li class="center">Snippet
|
<li class="center">Snippet
|
||||||
<ul>
|
<ul>
|
||||||
@ -161,11 +160,10 @@ for the JavaScript code in this tag.
|
|||||||
<div id="text-table-of-contents">
|
<div id="text-table-of-contents">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#sec-1">Why is there an extra newline?</a></li>
|
<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-2">Why doesn't TAB navigation work with flyspell</a></li>
|
||||||
<li><a href="#sec-3">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 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 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>
|
||||||
<li><a href="#sec-6">How do I define an abbrev key containing characters not supported by the filesystem?</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -174,120 +172,24 @@ for the JavaScript code in this tag.
|
|||||||
<h2 id="sec-1">Why is there an extra newline?</h2>
|
<h2 id="sec-1">Why is there an extra newline?</h2>
|
||||||
<div class="outline-text-2" id="text-1">
|
<div class="outline-text-2" id="text-1">
|
||||||
<p>
|
<p>
|
||||||
If you have a newline at the end of the snippet definition file, then
|
If there is a newline at the end of a snippet definition file,
|
||||||
YASnippet will add a newline when you expanding a snippet. Please don't
|
YASnippet will add a newline when expanding that snippet. When editing
|
||||||
add a newline at the end if you don't want it when you saving the
|
or saving a snippet file, please be careful not to accidentally add a
|
||||||
snippet file.
|
terminal newline.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Note some editors will automatically add a newline for you. In Emacs, if
|
Note that some editors will automatically add a newline for you. In
|
||||||
you set <code>require-final-newline</code> to <code>t</code>, it will add the final newline
|
Emacs, if you set <code>require-final-newline</code> to <code>t</code>, it will add the
|
||||||
for you automatically.
|
final newline automatically.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="outline-container-sec-2" class="outline-2">
|
<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">
|
<div class="outline-text-2" id="text-2">
|
||||||
<p>
|
<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
|
A workaround is to inhibit flyspell overlays while the snippet is
|
||||||
active:
|
active:
|
||||||
</p>
|
</p>
|
||||||
@ -295,8 +197,8 @@ active:
|
|||||||
<div class="org-src-container">
|
<div class="org-src-container">
|
||||||
|
|
||||||
<pre class="src src-emacs-lisp">(add-hook 'flyspell-incorrect-hook
|
<pre class="src src-emacs-lisp">(add-hook 'flyspell-incorrect-hook
|
||||||
#'(<span class="org-keyword">lambda</span> (dummy1 dummy2 dymmy3)
|
#'(lambda (dummy1 dummy2 dymmy3)
|
||||||
(and yas-active-field-overlay
|
(<span class="org-keyword">and</span> yas-active-field-overlay
|
||||||
(overlay-buffer yas-active-field-overlay))))
|
(overlay-buffer yas-active-field-overlay))))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -312,9 +214,9 @@ solve this problem, drop a line in the
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="outline-container-sec-4" class="outline-2">
|
<div id="outline-container-sec-3" class="outline-2">
|
||||||
<h2 id="sec-4">How to I use alternative keys, i.e. not TAB?</h2>
|
<h2 id="sec-3">How to I use alternative keys, i.e. not TAB?</h2>
|
||||||
<div class="outline-text-2" id="text-4">
|
<div class="outline-text-2" id="text-3">
|
||||||
<p>
|
<p>
|
||||||
Edit the keymaps <a href="snippet-reference.html#yas-minor-mode-map"><code>yas-minor-mode-map</code></a> and
|
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:
|
<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)
|
<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">"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>
|
<span class="org-comment-delimiter">;;</span><span class="org-comment">keys for navigation</span>
|
||||||
(define-key yas-keymap [(tab)] nil)
|
(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>
|
</div>
|
||||||
|
|
||||||
<div id="outline-container-sec-5" class="outline-2">
|
<div id="outline-container-sec-4" class="outline-2">
|
||||||
<h2 id="sec-5">How do I turn off the minor mode where in some buffers?</h2>
|
<h2 id="sec-4">How do I turn off the minor mode where in some buffers?</h2>
|
||||||
<div class="outline-text-2" id="text-5">
|
<div class="outline-text-2" id="text-4">
|
||||||
<p>
|
<p>
|
||||||
The best way, since version 0.6.1c, is to set the default value of the
|
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:
|
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">
|
<div class="org-src-container">
|
||||||
|
|
||||||
<pre class="src src-emacs-lisp">(set-default 'yas-dont-activate
|
<pre class="src src-emacs-lisp">(set-default 'yas-dont-activate
|
||||||
#'(<span class="org-keyword">lambda</span> ()
|
#'(lambda ()
|
||||||
(and yas-root-directory
|
(<span class="org-keyword">and</span> yas-root-directory
|
||||||
(null (yas-get-snippet-tables)))))
|
(null (yas-get-snippet-tables)))))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -363,9 +265,9 @@ but only once you have setup your yas-root-directory.
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="outline-container-sec-6" class="outline-2">
|
<div id="outline-container-sec-5" class="outline-2">
|
||||||
<h2 id="sec-6">How do I define an abbrev key containing characters not supported by the filesystem?</h2>
|
<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-6">
|
<div class="outline-text-2" id="text-5">
|
||||||
<ul class="org-ul">
|
<ul class="org-ul">
|
||||||
<li><b>Note</b>: This question applies if you're still defining snippets
|
<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
|
whose key <i>is</i> the filename. This is behavior still provided by
|
||||||
@ -399,8 +301,7 @@ directive:
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="postamble" class="status">
|
<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
|
<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>
|
|
||||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Yet another snippet extension</title>
|
<title>Yet another snippet extension</title>
|
||||||
<!-- 2016-04-30 Sat 22:37 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<meta name="generator" content="Org-mode" />
|
<meta name="generator" content="Org-mode" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="center">
|
<ul class="center">
|
||||||
<li> <a href="index.html">Overview</a>
|
<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>
|
Intro and Tutorial</a>
|
||||||
<li class="center">Snippet
|
<li class="center">Snippet
|
||||||
<ul>
|
<ul>
|
||||||
@ -161,7 +160,7 @@ The YASnippet documentation has been split into separate parts:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ol class="org-ol">
|
<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>
|
<p>
|
||||||
Contains an introduction, installation instructions and other important
|
Contains an introduction, installation instructions and other important
|
||||||
@ -222,8 +221,7 @@ An automatically generated listing of all YASnippet commands,
|
|||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<div id="postamble" class="status">
|
<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
|
<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>
|
|
||||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Writing snippets</title>
|
<title>Writing snippets</title>
|
||||||
<!-- 2016-04-30 Sat 22:37 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<meta name="generator" content="Org-mode" />
|
<meta name="generator" content="Org-mode" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="center">
|
<ul class="center">
|
||||||
<li> <a href="index.html">Overview</a>
|
<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>
|
Intro and Tutorial</a>
|
||||||
<li class="center">Snippet
|
<li class="center">Snippet
|
||||||
<ul>
|
<ul>
|
||||||
@ -163,7 +162,7 @@ for the JavaScript code in this tag.
|
|||||||
<li><a href="#sec-1">Snippet development</a>
|
<li><a href="#sec-1">Snippet development</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#sec-1-1">Quickly finding snippets</a></li>
|
<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>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="#sec-2">File content</a>
|
<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>
|
<li><a href="#sec-3">Template Syntax</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#sec-3-1">Plain Text</a></li>
|
<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-3">Tab stop fields</a></li>
|
||||||
<li><a href="#sec-3-4">Placeholder fields</a></li>
|
<li><a href="#sec-3-4">Placeholder fields</a></li>
|
||||||
<li><a href="#sec-3-5">Mirrors </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-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-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-9">Nested placeholder fields</a></li>
|
||||||
|
<li><a href="#sec-3-10">Indentation markers</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -207,30 +211,16 @@ There are some ways you can quickly find a snippet file or create a new one:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ul class="org-ul">
|
<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>
|
<p>
|
||||||
Creates a new buffer with a template for making a new snippet.
|
Creates a new buffer with a template for making a new snippet. The
|
||||||
The buffer is in <code>snippet-mode</code> (see below). When you are done
|
buffer is in <code>snippet-mode</code> (see <a href="#snippet-mode">below</a>). When you are done editing
|
||||||
editing the new snippet, use <code>C-c C-c</code> to save it. This will
|
the new snippet, use <a href="#yas-load-snippet-buffer-and-close"><code>C-c C-c</code></a> to save it.
|
||||||
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.)
|
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li><code>M-x yas-find-snippets</code>
|
<li><code>M-x yas-visit-snippet-file</code>, key binding: <code>C-c & C-v</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>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Prompts you for possible snippet expansions like
|
Prompts you for possible snippet expansions like
|
||||||
@ -241,14 +231,14 @@ to the snippet definition's file, if it exists.
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Once you find this file it will be set to <code>snippet-mode</code> (see ahead) and
|
Once you find this file it will be set to <code>snippet-mode</code> (see <a href="#snippet-mode">ahead</a>)
|
||||||
you can start editing your snippet.
|
and you can start editing your snippet.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="outline-container-sec-1-2" class="outline-3">
|
<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">
|
<div class="outline-text-3" id="text-1-2">
|
||||||
<p>
|
<p>
|
||||||
There is a major mode <code>snippet-mode</code> to edit snippets. You can set the
|
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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Two commands are defined in this mode:
|
Three commands are defined in this mode:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ul class="org-ul">
|
<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>
|
<p>
|
||||||
When editing a snippet, this loads the snippet into the correct
|
Prompts for a snippet table (with a default based on snippet's
|
||||||
mode and menu. Bound to <code>C-c C-c</code> by default while in
|
major mode) and loads the snippet currently being edited.
|
||||||
<code>snippet-mode</code>.
|
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</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>
|
<p>
|
||||||
When editing a snippet, this opens a new empty buffer, sets it to
|
When editing a snippet, this opens a new empty buffer, sets it to
|
||||||
the appropriate major mode and inserts the snippet there, so you
|
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
|
can see what it looks like.
|
||||||
<code>snippet-mode</code>.
|
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -537,7 +537,7 @@ snippet being expanded.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<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:
|
dynamically:
|
||||||
</p>
|
</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.
|
<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>
|
</p>
|
||||||
</div>
|
</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>
|
</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">
|
<div id="outline-container-sec-3-3" class="outline-3">
|
||||||
<h3 id="sec-3-3">Tab stop fields</h3>
|
<h3 id="sec-3-3">Tab stop fields</h3>
|
||||||
<div class="outline-text-3" id="text-3-3">
|
<div class="outline-text-3" id="text-3-3">
|
||||||
@ -850,11 +886,21 @@ performs the normal Emacs <code>delete-char</code> command.
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
<div id="postamble" class="status">
|
<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
|
<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>
|
|
||||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Expanding snippets</title>
|
<title>Expanding snippets</title>
|
||||||
<!-- 2016-04-30 Sat 22:37 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<meta name="generator" content="Org-mode" />
|
<meta name="generator" content="Org-mode" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="center">
|
<ul class="center">
|
||||||
<li> <a href="index.html">Overview</a>
|
<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>
|
Intro and Tutorial</a>
|
||||||
<li class="center">Snippet
|
<li class="center">Snippet
|
||||||
<ul>
|
<ul>
|
||||||
@ -181,7 +180,7 @@ for the JavaScript code in this tag.
|
|||||||
<li><a href="#sec-2">Controlling expansion</a>
|
<li><a href="#sec-2">Controlling expansion</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#sec-2-1">Eligible snippets</a></li>
|
<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>
|
<li><a href="#sec-2-3">Multiples snippet with the same key</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#sec-2-3-1">Use the X window system</a></li>
|
<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">
|
<div class="outline-text-3" id="text-1-1">
|
||||||
<p>
|
<p>
|
||||||
<a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> tries to expand a <i>snippet abbrev</i> (also known as
|
<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>
|
||||||
|
|
||||||
<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
|
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>
|
||||||
<code><tab></code> by default, however, you can freely set it to some other key:
|
and <code><tab></code> by default, however, you can freely remove those bindings:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="org-src-container">
|
<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)
|
<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">"TAB"</span>) nil)
|
||||||
(define-key yas-minor-mode-map (kbd <span class="org-string">"<the new key>"</span>) 'yas-expand)
|
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</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>
|
<p>
|
||||||
To enable the YASnippet minor mode in all buffers globally use the
|
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,
|
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>
|
<p>
|
||||||
When you use <a href="snippet-reference.html#yas-global-mode"><code>yas-global-mode</code></a> you can also selectively disable
|
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
|
YASnippet in some buffers by calling <a href="snippet-reference.html#yas-minor-mode"><code>yas-minor-mode</code></a> with a negative
|
||||||
<a href="snippet-reference.html#yas-dont-active"><code>yas-dont-active</code></a> in the buffer's mode hook.
|
argument in the buffer's mode hook.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -286,23 +305,9 @@ YASnippet in some buffers by setting the buffer-local variable
|
|||||||
<h4 id="sec-1-1-1">Fallback behaviour</h4>
|
<h4 id="sec-1-1-1">Fallback behaviour</h4>
|
||||||
<div class="outline-text-4" id="text-1-1-1">
|
<div class="outline-text-4" id="text-1-1-1">
|
||||||
<p>
|
<p>
|
||||||
<a href="snippet-reference.html#yas-fallback-behaviour"><code>yas-fallback-behaviour</code></a> is a customization variable bound to
|
YASnippet used to support a more complicated way of sharing
|
||||||
'<code>call-other-command</code> by default. If <a href="snippet-reference.html#yas-expand"><code>yas-expand</code></a> failed to find any
|
keybindings before <a href="snippet-reference.html#yas-expand"><code>yas-maybe-expand</code></a> was added. This is now
|
||||||
suitable snippet to expand, it will disable the minor mode temporarily
|
obsolete.
|
||||||
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.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
<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>
|
<span class="org-comment-delimiter">;; </span><span class="org-comment">snippet table "rails-mode"</span>
|
||||||
(add-hook 'rinari-minor-mode-hook
|
(add-hook 'rinari-minor-mode-hook
|
||||||
#'(<span class="org-keyword">lambda</span> ()
|
#'(lambda ()
|
||||||
(yas-activate-extra-mode 'rails-mode)))
|
(yas-activate-extra-mode 'rails-mode)))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="org-ul">
|
<ul class="org-ul">
|
||||||
<li>Buffer-local
|
<li>Buffer-local <a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a> variable
|
||||||
<a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a>
|
|
||||||
variable
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This variable provides finer grained control over what snippets can
|
This variable provides finer grained control over what snippets can
|
||||||
be expanded in the current buffer. The default value won't let you
|
be expanded in the current buffer. For example, the constant
|
||||||
expand snippets inside comments or string literals for example. See
|
<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
|
||||||
The condition system\_ for more info.
|
snippet expansion inside comments or string literals. See <a href="#condition-system">the
|
||||||
|
condition system</a> for more info.
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -496,7 +500,7 @@ The condition system\_ for more info.
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="outline-container-sec-2-2" class="outline-3">
|
<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">
|
<div class="outline-text-3" id="text-2-2">
|
||||||
<p>
|
<p>
|
||||||
Consider this scenario: you are an old Emacs hacker. You like the
|
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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If you use the <code># condition :</code> directive (see
|
If you use the <code># condition :</code> directive (see <a href="./snippet-development.html">Writing Snippets</a>) you
|
||||||
<a href="./snippet-development.html">Writing Snippets</a>) you could just specify
|
could just specify the condition for <code>if</code> to be <code>(not
|
||||||
the condition for <code>if</code> to be <code>(not (python-in-string/comment))</code>. But how
|
(python-syntax-comment-or-string-p))</code>. But how about <code>while</code>, <code>for</code>,
|
||||||
about <code>while</code>, <code>for</code>, etc. ? Writing the same condition for all the
|
etc? Writing the same condition for all the snippets is just boring.
|
||||||
snippets is just boring. So has a buffer local variable
|
So you can instead set <a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a> to <code>(not
|
||||||
<a href="snippet-reference.html#yas-buffer-local-condition"><code>yas-buffer-local-condition</code></a>. You can set this variable to
|
(python-syntax-comment-or-string-p))</code> in <code>python-mode-hook</code>.
|
||||||
<code>(not (python-in-string/comment))</code> in <code>python-mode-hook</code>.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Then, what if you really want some particular snippet to expand even
|
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>
|
</p>
|
||||||
|
|
||||||
<div class="org-src-container">
|
<div class="org-src-container">
|
||||||
|
|
||||||
<pre class="src src-emacs-lisp">(add-hook 'python-mode-hook
|
<pre class="src src-emacs-lisp">(add-hook 'python-mode-hook
|
||||||
(<span class="org-keyword">lambda</span> ()
|
(<span class="org-keyword">lambda</span> ()
|
||||||
(setq yas-buffer-local-condition
|
(<span class="org-keyword">setq</span> yas-buffer-local-condition
|
||||||
'(<span class="org-keyword">if</span> (python-in-string/comment)
|
'(<span class="org-keyword">if</span> (python-syntax-comment-or-string-p)
|
||||||
'(require-snippet-condition . force-in-comment)
|
'(require-snippet-condition . force-in-comment)
|
||||||
t))))
|
t))))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
… and specify the condition for a snippet that you're going to expand
|
… and for a snippet that you want to expand in comments, specify a
|
||||||
in comment to be evaluated to the symbol <code>force-in-comment</code>. Then it can
|
condition which evaluates to the symbol <code>force-in-comment</code>. Then it
|
||||||
be expanded as you expected, while other snippets like <code>if</code> still can't
|
can be expanded as you expected, while other snippets like <code>if</code> still
|
||||||
expanded in comment.
|
can't expanded in comments.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -568,7 +571,7 @@ can put in your emacs-file:
|
|||||||
|
|
||||||
<div class="org-src-container">
|
<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>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -656,8 +659,7 @@ See the documentation on variable <a href="snippet-reference.html#yas-prompt-fun
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="postamble" class="status">
|
<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
|
<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>
|
|
||||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>YASnippet menu</title>
|
<title>YASnippet menu</title>
|
||||||
<!-- 2016-04-30 Sat 22:37 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<meta name="generator" content="Org-mode" />
|
<meta name="generator" content="Org-mode" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="center">
|
<ul class="center">
|
||||||
<li> <a href="index.html">Overview</a>
|
<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>
|
Intro and Tutorial</a>
|
||||||
<li class="center">Snippet
|
<li class="center">Snippet
|
||||||
<ul>
|
<ul>
|
||||||
@ -284,8 +283,7 @@ variables.
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="postamble" class="status">
|
<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
|
<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>
|
|
||||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Organizing snippets</title>
|
<title>Organizing snippets</title>
|
||||||
<!-- 2016-04-30 Sat 22:37 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<meta name="generator" content="Org-mode" />
|
<meta name="generator" content="Org-mode" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -140,7 +139,7 @@ for the JavaScript code in this tag.
|
|||||||
<nav>
|
<nav>
|
||||||
<ul class="center">
|
<ul class="center">
|
||||||
<li> <a href="index.html">Overview</a>
|
<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>
|
Intro and Tutorial</a>
|
||||||
<li class="center">Snippet
|
<li class="center">Snippet
|
||||||
<ul>
|
<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>
|
<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>
|
<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-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>
|
<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>)))
|
'(<span class="org-string">"~/Downloads/interesting-snippets"</span>)))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -359,8 +358,7 @@ not to load snippets from there.
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="postamble" class="status">
|
<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
|
<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>
|
|
||||||
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
<p class='xhtml-validation'><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user