smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

Smartparens and NXML

Open pronobis opened this issue 11 years ago • 9 comments

When closing the tags in nxml-mode, smartparens will conflict with the nxml tag completion and result in double closing >> for a tag. Example:

<tag>
|

then

<tag>
<|>

then

<tag>
</tag>|>

pronobis avatar Dec 13 '14 18:12 pronobis

You can disable smartparent's autocompletion of >, look at sp-local-pair.

Fuco1 avatar Dec 17 '14 08:12 Fuco1

Wouldn't that disable autocompletion of > also for the opening tag? Is there a way to only do it for the closing tag?

pronobis avatar Dec 17 '14 18:12 pronobis

Btw. it's company-nxml that completes the closing tag, so maybe one could also disable adding the closing bracket there.

pronobis avatar Dec 17 '14 19:12 pronobis

Hm. Can you please once again explain what keys exactly you type? The problem might also be in the code that checks skipping closed pairs in SP, but I'm not sure yet.

Fuco1 avatar Dec 17 '14 19:12 Fuco1

Ok, so assume that:

  • you have company with comapny-nxml enabled
  • you type < and sp completes to <|>, then you type the tag name and get <tag|>. Everything good so far.
  • then, you type < again and SP completes to <|>. Now typing / will make company (it seems) complete the closing tag to </tag>|>.

So, in fact, in this case, it would be enough if company completed /tag instead of /tag> and thinking about it more it does not really look like an SP bug.

pronobis avatar Dec 17 '14 19:12 pronobis

Hmm, although after some more testing, it seems that company-nxml only proposes /tag as the completion. Positioning the cursor in the closing tag brackets <tag><|> and typing manually: company-complete will nicely result in <tag></tag>. But when I just type <tag></| then we get the problem again. Not sure what is adding the additional >.

pronobis avatar Dec 17 '14 19:12 pronobis

Ok, it seems that I'm getting closer to the problem. It's the nxml-mode autocomplete function (https://www.gnu.org/software/emacs/manual/html_node/nxml-mode/Inserting-end_002dtags.html) that adds /tag> not company. When setting nxml-slash-auto-complete-flag to nil, I don't get the autocompletion of the ending tags and in principle the problem goes away. Still, it would be nice to get the nxml autocompletion of ending tags work with smartparens.

Basically, to reproduce:

  1. Create a new xml file test.xml
  2. Switch to nxml-mode
  3. Enable auto-completion of end tags (setq nxml-slash-auto-complete-flag t)
  4. Type <tag>
  5. Type </ Observe that you get </tag>>

pronobis avatar Feb 02 '15 01:02 pronobis

A workaround is to set (setq nxml-slash-auto-complete-flag nil). In this case, you must do an additional keystroke for each closing tag. Namely, at step 5 above, type the slash, and at new step 6, do completion-at-point which is commonly bound to C-M-i aka M-tab.

albcorp avatar Jun 11 '19 22:06 albcorp

Easier solution might be to add a hook to smartparens that deletes the closing > when you enter / right after <

(sp-local-pair 'nxml-mode "<" ">" :post-handlers '(("[d1]" "/")))

Fuco1 avatar Jun 11 '19 23:06 Fuco1