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.82k stars 194 forks source link

smartparens breaks LaTeX quotation marks mechanism for language styles #1100

Open vitaminace33 opened 3 years ago

vitaminace33 commented 3 years ago

Expected behavior

Press ["] once to get «.», twice for "." (or vice-versa if TeX-quote-after-quote is non-nil).

Notes

Actual behavior

Press ["] once, depending on the value of TeX-quote-after-quote and if TeX-quote-open and TeX-quote-close are single or double characters, different behavior are present. Worst case scenario is that only part of the quote string is inserted, moreover partly in the previous line and partly in the current, while deleting a previous character. Refer to syl20bnr/spacemacs#15003 for specific "experiments".

Steps to reproduce the problem

  1. On vanilla Emacs, install auctex and smartparens.
  2. Open a .tex file including \usepackage[german]{babel} (parsing on load must be activated to successfully load the language style).
  3. Write any quote. Again, refer to syl20bnr/spacemacs#15003 for specific "experiments".

I leave here my .emacs for reference.

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(require 'smartparens-config)
(setq TeX-parse-self t) ; Enable parse on load.
(setq TeX-auto-save t)  ; Enable parse on save.
(custom-set-variables
 '(package-selected-packages '(smartparens auctex)))

Workaround

A workaround has been documented in syl20bnr/spacemacs#15003 that allows the use smartparens.

Environment & version information

thobl commented 1 year ago

The above mentioned workaround improves the behavior for German quotes (by a lot) but does not resolve the issues completely.

When pressing ", it inserts "`▂'(with ▂ being the cursor) instead of "`▂"'. When finishing the quote and pressing " again, it correctly inserts "' at the end, but leaves the additional ' from before, i.e., typing "foo" gives me "`foo"'▂' instead of "`foo"'▂.

For better reproducibility, here is my tex-code:

\documentclass{article}
\usepackage{ngerman}
\begin{document}
"`foo"'
\end{document}

And here the value I have set TeX-quote-language-alist to:

'(("ngerman" "\"`" "\"'" nil) ("german" "\"`" "\"'" nil))
dschrempf commented 1 year ago

Hi, I just want to state that this is still an issue.

Fuco1 commented 1 year ago

Since TeX-insert-quote provides its own behaviours, the easiest would be to disable smartparens handling of quotes if you prefer the auctex way.

(sp-local-pair 'latex-mode "`" nil :actions nil)
(sp-local-pair 'latex-mode "\"" nil :actions nil)
(sp-local-pair 'latex-mode "``" nil :actions nil)

I'm sure it could be made to work together, for example by dynamically adding pairs based on TeX-quote-language, then if you insert the opening smartparens would insert the ending. But I guess this is also somehow implemented in auctex itself.

To be completely honest, I don't really use tex anymore so this is not very high priority for me. Plus I don't understand how auctex handles this and what users expect, so it's really hard to create a good solution. We can brainstorm some ideas and if there is consensus something can be implemented. But a safe way would be to defer the quote handling to auctex.

dschrempf commented 1 year ago

Hi!

Thanks for your reply. I have played around a bit, and I sincerely do not understand what is going on.

Using

(sp-local-pair '(tex-mode plain-tex-mode latex-mode LaTeX-mode) "``" nil :actions nil)

I can normally write a single double quote " in the comments, but NOT in the rest of the document. For example, typing " would insert a triple of ``` I can not see how smartparens distinguishes comments from non-comments. It could be that AucTeX mode is doing some magic behind the scenes, but well.

Then, further deactivating

(sp-local-tag '(tex-mode plain-tex-mode latex-mode LaTeX-mode) "\"" nil nil :actions nil)

doesn't really change things (which is a further indication that we are observing a weird interaction with AucTeX).

Finally, deactivating

(sp-local-pair '(tex-mode plain-tex-mode latex-mode LaTeX-mode) "`" nil :actions nil)

leads to classic AucTeX behavior: In LaTeX comments, insertion is unchanged. In the document (non-comments), a single ` or ' are inserted without further changes. A double quote " is changed to a double `` quote at the beginning of a word, and a double '' (two ' quotes) at the end of a word, as expected (only the insertion has to be manual, and not automatic like with smartparens)

So in the end, I think it is probably best to deactivate all three quotes in smartparens-mode, as you suggested (but use all four modes like in this comment). I can create a PR, if you like.

Finally, I do not understand what this statement does in smartparens-latex.el:

  (sp-local-tag "\"" "``" "''" :actions '(wrap))

Should we also remove it?

Fuco1 commented 1 year ago

Yea, tags no longer exist