doomemacs/snippets

Accidently triggering nested snippets in LaTeX math

ymarco opened this issue · 1 comments

Example:
Say I wanted to write $\frac{c}{2}$. I would do the following:
$frac|$ -> TAB -> frac snippet expansion: $\frac{|}{}$
now I write c and press TAB to move the cursor to the denumenator:
$frac{c|}{}$ -> TAB -> $\frac{\cite{|}}{}$
The cite snippet expanded accidently!

This is solely an issue with a single-trigger-letter snippets inside math: pretty match only in math you'd write a single letter and press tab, NOT expecting the letter to expand into a snippet.

Possible workarounds:

  • Disable nested snippet expansion: inconvinient, they are generally very useful
  • Add a condition to the single-letter snippets so they don't expand in math envs:
    I tried Doing that using (texmathp) from auctex, but it doesn't work while inside a nested snippet; something in yasnippet messes that up. I haven't look into what exacly yet tho.
  • Change the trigger key of snippets cite, gls... not to be a single letter

I've got it! finally!
In nested expansion, the condition runs in a narrowed buffer, so surrounding (texmathp) with (save-restriction (widen) ...) gives the correct behaviour. This should probably be reported to yasnippet. Meanwhile, I'll add the condition to the short-key snippets.