]> code.delx.au - gnu-emacs-elpa/blob - doc/faq.html
updated the faq with results from the tab key issue
[gnu-emacs-elpa] / doc / faq.html
1 <?xml version="1.0" encoding="utf-8" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
7 <title>Frequently Asked Questions</title>
8 <link rel="stylesheet" href="styles.css" type="text/css" />
9 </head>
10 <body>
11 <div class="document" id="frequently-asked-questions">
12 <div id="header-region" class="clear-block"></div>
13 <div id="wrapper">
14 <div id="container" class="clear-block">
15 <div id="header">
16 <div id="logo-floater">
17 <h1 class="title">Frequently Asked Questions</h1>
18 </div>
19 <ul class="primary-links">
20 <li>
21 <a title="" href="index.html">Intro and tutorial</a>
22 </li>
23 <li>
24 <a title="" href="snippet-organization.html">Howto: organize</a>
25 </li>
26 <li>
27 <a title="" href="snippet-expansion.html">Howto: expand</a>
28 </li>
29 <li>
30 <a title="" href="snippet-development.html">Howto: write </a>
31 </li>
32 <li>
33 <a title="" href="snippet-menu.html">Howto: menu </a>
34 </li>
35 <li>
36 <a title="" href="faq.html">FAQ</a>
37 </li>
38 <li>
39 <a title="" href="changelog.html">ChangeLog</a>
40 </li>
41 <li>
42 <a title="" href="http://code.google.com/p/yasnippet/downloads/list">Download</a>
43 </li>
44 </ul>
45 </div>
46 <div id="center">
47 <div id="squeeze">
48 <div class="right-corner">
49 <div class="left-corner">
50 <p>
51 <b>Important:</b> This documentation applies to
52 the <b>SVN trunk</b> of YASnippet, which you
53 get <a href="http://code.google.com/p/yasnippet/source/checkout">here</a>. Documentation
54 for other versions can be found <a title=""
55 href="http://code.google.com/p/yasnippet/downloads/list">here</a>.
56 </p>
57 <div class="section" id="why-is-there-an-extra-newline">
58 <h1>Why is there an extra newline?</h1>
59 <p>If you have a newline at the end of the snippet definition file, then
60 YASnippet will add a newline when you expanding a snippet. Please
61 don't add a newline at the end if you don't want it when you saving
62 the snippet file.</p>
63 <p>Note some editors will automatically add a newline for you. In Emacs,
64 if you set <tt class="docutils literal"><span class="pre">require-final-newline</span></tt> to <tt class="docutils literal"><span class="pre">t</span></tt>, it will add the final
65 newline for you automatically.</p>
66 </div>
67 <div class="section" id="why-doesn-t-tab-expand-a-snippet">
68 <h1>Why doesn't TAB expand a snippet?</h1>
69 <p>First check the mode line to see if there's <tt class="docutils literal"><span class="pre">yas</span></tt>. If not, then try
70 <tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">yas/minor-mode</span></tt> to manually turn on the minor mode and try to
71 expand the snippet again. If it works, then, you can add the following
72 code to your <tt class="docutils literal"><span class="pre">.emacs</span></tt> <em>before</em> loading YASnippet:</p>
73 <div class="highlight"><pre>(add-hook &#39;the-major-mode-hook &#39;yas/minor-mode-on)
74 </pre></div>
75 <p>where <tt class="docutils literal"><span class="pre">the-major-mode</span></tt> is the major mode in which <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt>
76 isn't enabled by default.</p>
77 <p>From YASnippet 0.6 you can also use the command <tt class="docutils literal"><span class="pre">M-x</span>
78 <span class="pre">yas/global-mode</span></tt> to turn on YASnippet automatically for <em>all</em> major
79 modes.</p>
80 <p>If <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt> is on but the snippet still not expanded. Then
81 try to see what command is bound to the <tt class="docutils literal"><span class="pre">TAB</span></tt> key: press <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">k</span></tt>
82 and then press <tt class="docutils literal"><span class="pre">TAB</span></tt>. Emacs will show you the result.</p>
83 <p>You'll see a buffer prompted by Emacs saying that <tt class="docutils literal"><span class="pre">TAB</span> <span class="pre">runs</span> <span class="pre">the</span>
84 <span class="pre">command</span> <span class="pre">...</span></tt>. Alternatively, you might see <tt class="docutils literal"><span class="pre">&lt;tab&gt;</span> <span class="pre">runs</span> <span class="pre">the</span> <span class="pre">command</span>
85 <span class="pre">...</span></tt>, note the difference between <tt class="docutils literal"><span class="pre">TAB</span></tt> and <tt class="docutils literal"><span class="pre">&lt;tab&gt;</span></tt> where the
86 latter has priority. If you see <tt class="docutils literal"><span class="pre">&lt;tab&gt;</span></tt> bound to a command other
87 than <tt class="docutils literal"><span class="pre">yas/expand</span></tt>, (e.g. in <tt class="docutils literal"><span class="pre">org-mode</span></tt>) you can try the following
88 code to work around:</p>
89 <div class="highlight"><pre>(add-hook &#39;org-mode-hook
90 (let ((original-command (lookup-key org-mode-map [tab])))
91 `(lambda ()
92 (setq yas/fallback-behavior
93 &#39;(apply ,original-command))
94 (local-set-key [tab] &#39;yas/expand))))
95 </pre></div>
96 <p>replace <tt class="docutils literal"><span class="pre">org-mode-hook</span></tt> and <tt class="docutils literal"><span class="pre">org-mode-map</span></tt> with the major mode
97 hook you are dealing with (Use <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt> to see what major mode you
98 are in).</p>
99 <p>As an alternative, you can also try</p>
100 <div class="highlight"><pre>(defun yas/advise-indent-function (function-symbol)
101 (eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
102 ,(format
103 &quot;Try to expand a snippet before point, then call `%s&#39; as usual&quot;
104 function-symbol)
105 (let ((yas/fallback-behavior nil))
106 (unless (and (interactive-p)
107 (yas/expand))
108 ad-do-it)))))
109
110 (yas/advise-indent-function &#39;ruby-indent-line)
111 </pre></div>
112 <p>To <em>advise</em> the modes indentation function bound to TAB, (in this case
113 <tt class="docutils literal"><span class="pre">ruby-indent-line</span></tt>) to first try to run <tt class="docutils literal"><span class="pre">yas/expand</span></tt>.</p>
114 <p>If the output of <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">k</span> <span class="pre">RET</span> <span class="pre">&lt;tab&gt;</span></tt> tells you that <tt class="docutils literal"><span class="pre">&lt;tab&gt;</span></tt> is
115 indeed bound to <tt class="docutils literal"><span class="pre">yas/expand</span></tt> but YASnippet still doesn't work, check
116 your configuration and you may also ask for help on the <a class="reference external" href="http://groups.google.com/group/smart-snippet">discussion
117 group</a>. See this
118 particular <a class="reference external" href="http://code.google.com/p/yasnippet/issues/detail?id=93&amp;can=1">thread</a> for
119 quite some solutions and alternatives.</p>
120 <p>Don't forget to attach the information on what command is bound to TAB
121 as well as the mode information (Can be obtained by <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt>).</p>
122 </div>
123 <div class="section" id="why-doesn-t-tab-navigation-work-with-flyspell">
124 <h1>Why doesn't TAB navigation work with flyspell</h1>
125 <p>A workaround is to inhibit flyspell overlays while the snippet is active:</p>
126 <div class="highlight"><pre>(add-hook &#39;flyspell-incorrect-hook
127 #&#39;(lambda (dummy1 dummy2 dymmy3)
128 (and yas/active-field-overlay
129 (overlay-buffer yas/active-field-overlay))))
130 </pre></div>
131 <p>This is apparently related to overlay priorities. For some reason, the
132 <tt class="docutils literal"><span class="pre">keymap</span></tt> property of flyspell's overlays always takes priority over
133 the same property in yasnippet's overlays, even if one sets the
134 latter's <tt class="docutils literal"><span class="pre">priority</span></tt> property to something big. If you know
135 emacs-lisp and can solve this problem, drop a line in the <a class="reference external" href="http://groups.google.com/group/smart-snippet">discussion
136 group</a>.</p>
137 </div>
138 <div class="section" id="how-do-i-turn-off-the-minor-mode-where-in-some-buffers">
139 <h1>How do I turn off the minor mode where in some buffers</h1>
140 <p>The best way, since version 0.6.1c, is to set the default value of the
141 variable <tt class="docutils literal"><span class="pre">yas/dont-activate</span></tt> to a lambda function like so:</p>
142 <div class="highlight"><pre>(set-default &#39;yas/dont-activate
143 #&#39;(lambda ()
144 (and yas/root-directory
145 (null (yas/get-snippet-tables)))))
146 </pre></div>
147 <p>This is also the default value starting for that version. It skips the
148 minor mode in buffers where it is not applicable (no snippet tables),
149 but only once you have setup your yas/root-directory.</p>
150 </div>
151 <div class="section" id="how-do-i-define-an-abbrev-key-containing-characters-not-supported-by-the-filesystem">
152 <h1>How do I define an abbrev key containing characters not supported by the filesystem?</h1>
153 <dl class="docutils">
154 <dt><strong>Note</strong>: This question applies if you're still defining snippets</dt>
155 <dd>whose key <em>is</em> the filename. This is behavior stil provided by
156 version 0.6 for backward compatibilty, but is somewhat deprecated...</dd>
157 </dl>
158 <p>For example, you want to define a snippet by the key <tt class="docutils literal"><span class="pre">&lt;</span></tt> which is
159 not a valid character for filename on Windows. This means you can't
160 use the filename as a trigger key in this case.</p>
161 <p>You should rather use the <tt class="docutils literal"><span class="pre">#</span> <span class="pre">key:</span></tt> directive to specify the key of
162 the defined snippet explicitly and name your snippet with an arbitrary
163 valid filename, <tt class="docutils literal"><span class="pre">lt.yasnippet</span></tt> for example, using <tt class="docutils literal"><span class="pre">&lt;</span></tt> for the
164 <tt class="docutils literal"><span class="pre">#</span> <span class="pre">key:</span></tt> directive:</p>
165 <div class="highlight"><pre>#key: &lt;
166 #name: &lt;...&gt;&lt;/...&gt;
167 # --
168 &lt;${1:div}&gt;$0&lt;/$1&gt;
169 </pre></div>
170 </div>
171 </div>
172 </div>
173 </div>
174 </div>
175 </div>
176 </div>
177 <script type="text/javascript">
178 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
179 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
180 </script>
181 <script type="text/javascript">
182 try {
183 var pageTracker = _gat._getTracker("UA-10536822-1");
184 pageTracker._trackPageview();
185 } catch(err) {}
186 </script>
187 </div>
188 </body>
189 </html>