I am trying to write a yasnippet to insert code chunks into an R Markdown file. I use polymode to have multiple major modes (markdown, ESS[S]) in a single file. This is my snippet:
# -*- mode: snippet -*-
# name: chunk
# key: chunk
# --
\`\`\`{r $1}
$0
\`\`\`
When I try to insert the snippet into a .Rmd file in markdown mode, I get this error:
Error in post-command-hook (yas--post-command-handler): (error "Marker points into wrong buffer" #<marker at 7 in test.Rmd>)
The snippet does appear and my cursor is in the correct spot (right before the second curly brace):
```{r }
```
When I hit tab I get the following:
yas-next-field: Wrong type argument: overlayp, nil
I am guessing that I'm running into an interaction with polymode: I'm in markdown mode when I insert the snippet, but then polymode converts the contents of the code chunk to ESS[S] mode. It looks like there will eventually be a command to insert a new chunk in polymode, but in the meantime is there any way to get this snippet working?