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.8k stars 193 forks source link

Adding \left\langle, \right\rangle breaks things in latex #1193

Open ultronozm opened 3 months ago

ultronozm commented 3 months ago

Expected behavior

Modify smartparens-latex.el to contain the following additional local pair definition:

(sp-local-pair "\\left\\langle" "\\right\\rangle"
                   :post-handlers '(sp-latex-insert-spaces-inside-pair))

Open a LaTeX-mode buffer containing $\left\langle \right\rangle$. Put the cursor in the middle of the brackets and do M-x sp-up-sexp. This should move the point to the rightmost $.

Actual behavior

The point does not move; we are dealt the message "Search failed: there is an unmatched expression somewhere or we are at the beginning/end of file."

Backtraces if necessary (M-x toggle-debug-on-error)

No error.

Environment & version information

ultronozm commented 3 months ago

Sorry, I should have seen in the manual the rule about pairs having to be prefix-free, so please feel free to close this issue -- I'll just note that both \langle, \rangle and \left\langle, \right\rangle appear often for me, so it's a significant issue.

Fuco1 commented 3 months ago

The prefix-free note is not entirely correct anymore. I should revise it.

You can in fact have two pairs, let's say \langle and \rangle and what you have. The pairs then highlight a bit weirdly, but somewhat work. The fact that the navigation doesn't work I would consider a bug, because at the least it should recognize the "inside" pair (langle rangle) and jump out of that. So I think this is a valid report.

image

image

image

ultronozm commented 2 months ago

Just FYI, after submitting this report, I worked out some ad-hoc parenthesis-based navigation just for tex modes: https://github.com/ultronozm/tex-parens.el. I'm happy with this, so please feel free to deprioritize my report (at least as far as I'm concerned). I'd also be happy to try to incorporate my solution into smartparens if you thought that it made sense to do so, but it's not clear to me how feasible that would be. Anyway, thanks again for taking a look at this report and noting the issue.