Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.83k stars 194 forks source link

Smartparents and LaTeX-math-* #592

Open ThibautVerron opened 8 years ago

ThibautVerron commented 8 years ago

Hi,

This is a follow-up of https://github.com/Fuco1/smartparens/issues/586. Your fix works fine when inserting the pair manually, but not when using `( (for example for \langle) using LaTeX-math-mode bindings.

After investigating, it turns out that I was using AUCTeX's mechanism for inserting closing pairs instead of smartparens when using this binding, and that smartparens now does a better job than AUCTeX at inserting spaces where needed around pairs.

The fix for me was to turn off AUCTeX's auto-insertion of right braces (e.g. setting TeX-arg-right-insert-p to nil) and add relevant macros to sp--special-self-insert-commands : LaTeX-math-langle, LaTeX-math-lceil, LaTeX-math-lfloor are enough for me because I don't have bindings for the other ones, but I guess if one wants to be completely safe, all parentheses should be added (and yes, LaTeX-math-mode creates one function for each pair...).

(Actually, is it the correct way to configure this on user-side?)

I don't think this setting can be enforced in smartparens-latex.el, because users could find themselves using both AUCTeX's and smartparens' auto-insertions, I can imagine it would cause problems.

I suggest to either make it a customizable setting smartparens-latex-override-AUCTeX (which would disable AUCTeX's auto-insertion and add the relevant pairs to the smartparens special list --- but it could be tricky to toggle back to AUCTeX automatically) or to document this kind of conflict with a suggested resolution.

Fuco1 commented 8 years ago

sp--special-self-insert-commands is not supposed to be edited by the user, but it should have all commands which do insertions when you press regular insert key, such as [ calling some magic. I'm not sure commands which insert longer text should be there.

For me, `( in math mode produces \langle|\rangle, which isn't quite correct but close.

I would rather not go down the road of adding special compat code against auctex... we did this with other packages and it is hell to maintain as everything constantly changes.

ThibautVerron commented 8 years ago

sp--special-self-insert-commands is not supposed to be edited by the user, but it should have all commands which do insertions when you press regular insert key, such as [ calling some magic. I'm not sure commands which insert longer text should be there.

Ah... Well, it seems to work. What I don't know can't hurt me I guess.

For me, `( in math mode produces \langle|\rangle, which isn't quite correct but close.

But is it smartparens operating or AUCTeX?

AUCTeX's insertion of pairs has the same problem with spaces that smartparens had (worse, actually, since it misses spaces even for insert), and it seems trickier to fix. I guess I could send a mail to the AUCTeX ML about this, but somehow it feels backwards to have packages maintaining their own code for pair insertion, where all they need to do is define pairs...

I would rather not go down the road of adding special compat code against auctex... we did this with other packages and it is hell to maintain as everything constantly changes.

Makes sense. :)