yasnippet and autopair/paredit conflict

116 views
Skip to first unread message

Julien Cubizolles

unread,
Mar 6, 2013, 5:58:19 PM3/6/13
to smart-...@googlegroups.com
I'm trying to define a snippet to insert \left( \right) structures in
LaTeX. I'd like it to be able to choose between parentheses, brackets,
square brackets with something like:

--8<---------------cut here---------------start------------->8---
\left$1$0\right$1
--8<---------------cut here---------------end--------------->8---

The thing is that I'm also using paredit and/or autopair modes in all
LaTeX buffers and if I type "(" during the snippet expansion, the
matching ")" is also inserted.

I've tried to temporarily disable paredit/autopair from within the
snippet template with no success so far. Any idea how I should go about
setting this up ?

Julien.

João Távora

unread,
Mar 7, 2013, 6:11:26 AM3/7/13
to smart-...@googlegroups.com
At least in autopair, if you press "C-q (", it will insert a literal
"(" without autoclosing. I don't know about paredit. You can also use
a primary field transformation to allow you to choose the string to
insert (and thus choose only between the parenthesis you're interested
in). To do this look at the (quite outdated, but should work)
documentation.

Other that that, disabling a minor mode while a snippet is active
(notice that this is different from snippet expansion time), can only
be done, but not very cleanly, with `yas-exit-snippet-hook`, which to
make matters worse, is not snippet specific, so you would have to set
a variable in the snippet's body and restore it in the snippet hook.
One can't use normal lispy methods of wrapping a command call in a
dynamic environment because typing into a snippet is done in multiple
commands.
> --
> You received this message because you are subscribed to the Google Groups "smart-snippet and YASnippet" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to smart-snippe...@googlegroups.com.
> To post to this group, send email to smart-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/smart-snippet?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
João Távora

Julien Cubizolles

unread,
Mar 7, 2013, 5:14:35 PM3/7/13
to smart-...@googlegroups.com
João Távora <joaot...@gmail.com> writes:

> At least in autopair, if you press "C-q (", it will insert a literal
> "(" without autoclosing. I don't know about paredit.

It works with both, I should have thought about it. I should also have
realised that \left$1$0\right$1 would not work: it inserts two opening
parenthesis... So I defined 3 snippets, one for (, for [ and {. That's
easy enough.

> You can also use a primary field transformation to allow you to choose
> the string to insert (and thus choose only between the parenthesis
> you're interested in). To do this look at the (quite outdated, but
> should work) documentation.

I'll have a look, thanks.

Julien.

Reply all
Reply to author
Forward
0 new messages