I use yasnippet's defined in ~/.emacs.d/plugins/yasnippet-0.6.1c/snippets/text-mode/latex-mode to insert small pieces of code when working with LaTeX. I recently started to use Sweave and therefore work on .Rnw files. However, I noticed that the (ya)snippets don't work anymore - hitting TAB after a trigger word just does not expand the defined snippet. Instead, nothing happens. I thought that's a simple problem to solve, just copy the snippets to ~/.emacs.d/plugins/yasnippet-0.6.1c/snippets/text-mode/rnw-mode or .../noweb-mode. But that did not work either (meaning that hitting TAB does not expand trigger words). What I can do, however, is M-x yas/expand right after the trigger word, so it's working, but just not with TAB.
How can I use yasnippets from .Rnw files?
Update 1
I found http://groups.google.com/group/smart-snippet/browse_thread/thread/8206a23037f598b1/39ed819692df63ad?lnk=gst&q=rnw#39ed819692df63ad
I have exactly that problem -- <tab> is bound by noweb-mode. However, the solution posted in the last post does not work for me/does not seem to have an effect on the problem (so, as above, TAB-expansion of trigger words does not work).
As described in that post, the mode changes from LaTeX to noweb depending on where the point is in the .Rnw file. I only need my LaTeX macros to expand when in LaTeX mode (of course).
In case this matters, I work with Emacs 24 on Mac OS X 10.7.3.
Update 2
C-h k TAB leads to (either with or without the solution posted on the above line):
<tab> runs the command noweb-indent-line, which is an interactive Lisp function
in `noweb-mode.el'.
It is bound to <tab>.
(noweb-indent-line)
Indent the current line according to mode, after narrowing to this chunk.
So obviously, TAB is used by noweb.
Update 3
When the point is in a LaTeX part of the .Rnw file, then the modes displayed in the mode line are: LaTeX/MP Ref Fly yas pair vl Wrap Fill Noweb NWFL. If the point is in an R chunk of the file, then the modes are: ESS[S] [none] Rox Fly ElDoc pair vl Wrap Noweb NWFL. So indeed, the modes change when out of/within R chunks. However, I still can't TAB-expand snippets. My .emacs contains (which is obviously not working as expected):
(add-hook 'LaTeX-mode-hook
'(lambda ()
(make-variable-buffer-local 'yas/trigger-key)
(setq yas/trigger-key [tab])))
TAB". So I have a snippetalignwhich expands to analign*-environment. If I typealignand hitTAB, nothing is expanded. What I can do isM-x yas/expandand then thealign*-environment is expanded, but justTABdoes not work anymore as described in the post under Update – Marius Hofert Mar 26 '12 at 15:55yas/expandto another key than Tan in rnw- and noweb-mode suffice? – N.N. Mar 26 '12 at 15:58