Reputation: 8512
When using yasnippet in emacs and the there is no space before the key that should trigger a snippet the snippet is not expanded when Tab is pressed. Can it be made so that the snippet expands even if there is no space before it?
Here's a test case. Make the following snippet
# -*- mode: snippet -*-
# name: \textsubscript (from fixltx2e)
# key: tsub
# --
\textsubscript{$1}$0
and try it. Notice that it expands whenever there is a space before tsub and that it's not triggered it's not triggered when there is a letter before tsub. Also, notice that it expands correctly when there is a punctuation or brackets directly before it.
Similar behavior is also observed by http://groups.google.com/group/smart-snippet/browse_thread/thread/0d08f2c90e24a94d/0a3d7c00d993a7ce?show_docid=0a3d7c00d993a7ce
Upvotes: 3
Views: 1365
Reputation: 10032
Internally, yas/snippet uses the function skip-syntax-backward
to find the template keys. Consequently, a snippet key must be separated from the preceding text by a character in a different syntax class in order for it to be recognized. Syntax classes include 'word-constituent', 'punctuation', 'whitespace' etc. The details are in the elisp manual.
As I read it, this means that you can't use a key that is all letters (i.e., word constituents) if you want to insert the template immediately after another letter.
Not good news for you, but perhaps the following would be an acceptable work-around? In practice you'd invoke the snippet before the word that you want the subscript to be appended to, instead of after.
# -*- mode: snippet -*-
# name: \textsubscript (from fixltx2e)
# key: tsub
# --
$1\textsubscript{$2}$0
This might be worth reporting as a bug or feature request to the yasnippet maintainer.
Upvotes: 2