mirror of
https://github.com/joaotavora/yasnippet.git
synced 2026-02-04 14:32:26 +00:00
* Fixed issue 98, issue 93 and issues related to the customization group
* Added workaround for issue 97 in the FAQ * Minor updates in the documentation
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<title>Writing snippets</title>
|
||||
<link rel="stylesheet" href="styles.css" type="text/css" />
|
||||
</head>
|
||||
@@ -262,13 +262,17 @@ newlines.</p>
|
||||
<p>To override the keymap choice based on the major mode name. Use a cons
|
||||
cell where the first element specifies the name of the keymap where
|
||||
you want to record the keybinding.</p>
|
||||
<div class="highlight"><pre>
|
||||
<div class="highlight"><pre>#name : <p>...</p>
|
||||
#binding: (rinari-minor-mode-map . "C-c C-c C-m")
|
||||
# --
|
||||
<p>`(when yas/prefix "\n")`$0`(when yas/prefix "\n")`</p>
|
||||
</pre></div>
|
||||
<p>Note that this feature is still experimental and should be used with
|
||||
caution: It is easy to override important keybindings for many basic
|
||||
modes and it is hard to undefine them. In particular, the variable
|
||||
<p><em>Note</em> that this feature is still <strong>experimental</strong>, it might go away,
|
||||
be changed in future release, and should be used with caution: It is
|
||||
easy to override important keybindings for many basic modes and it is
|
||||
hard to undefine them. For the moment, the variable
|
||||
<tt class="docutils literal"><span class="pre">yas/active-keybinding</span></tt> can tell you what snippet keybindings are
|
||||
active and the function <tt class="docutils literal"><span class="pre">yas/kill-snippet-keybindings</span></tt> will try to
|
||||
active and the function <tt class="docutils literal"><span class="pre">yas/kill-snippet-keybindings</span></tt> will attempt to
|
||||
undefine all the keybindings.</p>
|
||||
</div>
|
||||
<div class="section" id="contributor-snippet-author">
|
||||
@@ -354,11 +358,13 @@ as the field and others mirrors.</p>
|
||||
</div>
|
||||
<div class="section" id="mirrors-with-transformations">
|
||||
<span id="transformations"></span><h2><a class="toc-backref" href="#id19">Mirrors with transformations</a></h2>
|
||||
<p>If the default value of a field starts with <tt class="docutils literal"><span class="pre">$</span></tt>, then it is interpreted
|
||||
as the transformation code instead of default value. A transformation
|
||||
is some arbitrary Emacs-lisp code that will get evaluated in an environment
|
||||
when the variable text is bind to the inputted text of the
|
||||
field. Here's an example for Objective-C:</p>
|
||||
<p>If the value of an <tt class="docutils literal"><span class="pre">${n:</span></tt>-construct starts with and contains <tt class="docutils literal"><span class="pre">$(</span></tt>,
|
||||
then it is interpreted as a mirror for field <tt class="docutils literal"><span class="pre">n</span></tt> with a
|
||||
transformation. The mirror's text content is calculated according to
|
||||
this transformation, which is Emacs-lisp code that gets evaluated in
|
||||
an environment where the variable <tt class="docutils literal"><span class="pre">text</span></tt> (or <tt class="docutils literal"><span class="pre">yas/text</span></tt>) is bound
|
||||
to the text content (string) contained in the field <tt class="docutils literal"><span class="pre">n</span></tt>.Here's an
|
||||
example for Objective-C:</p>
|
||||
<div class="highlight"><pre>- (${1:id})${2:foo}
|
||||
{
|
||||
return $2;
|
||||
@@ -371,13 +377,13 @@ field. Here's an example for Objective-C:</p>
|
||||
}
|
||||
$0
|
||||
</pre></div>
|
||||
<p>Look at <tt class="docutils literal"><span class="pre">${2:$(capitalize</span> <span class="pre">text)}</span></tt>, it is a transformation instead of
|
||||
a placeholder. The actual placeholder is at the first line:
|
||||
<tt class="docutils literal"><span class="pre">${2:foo}</span></tt>. When you type text in <tt class="docutils literal"><span class="pre">${2:foo}</span></tt>, the transformation
|
||||
will be evaluated and the result will be placed there as the
|
||||
transformed text. So in this example, if you type "baz" in the field,
|
||||
the transformed text will be "Baz". This example is also available in
|
||||
the screencast.</p>
|
||||
<p>Look at <tt class="docutils literal"><span class="pre">${2:$(capitalize</span> <span class="pre">text)}</span></tt>, it is a mirror with
|
||||
transformation instead of a field. The actual field is at the first
|
||||
line: <tt class="docutils literal"><span class="pre">${2:foo}</span></tt>. When you type text in <tt class="docutils literal"><span class="pre">${2:foo}</span></tt>, the
|
||||
transformation will be evaluated and the result will be placed there
|
||||
as the transformed text. So in this example, if you type "baz" in the
|
||||
field, the transformed text will be "Baz". This example is also
|
||||
available in the screencast.</p>
|
||||
<p>Another example is for <tt class="docutils literal"><span class="pre">rst-mode</span></tt>. In reStructuredText, the document
|
||||
title can be some text surrounded by "===" below and above. The "==="
|
||||
should be at least as long as the text. So</p>
|
||||
|
||||
Reference in New Issue
Block a user