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

Smartparens and NXML #397

Open pronobis opened 9 years ago

pronobis commented 9 years ago

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>|>
Fuco1 commented 9 years ago

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

pronobis commented 9 years ago

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

pronobis commented 9 years ago

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

Fuco1 commented 9 years ago

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.

pronobis commented 9 years ago

Ok, so assume that:

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 commented 9 years ago

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 commented 9 years ago

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) 3) Type <tag> 4) Type </ Observe that you get </tag>>

albcorp commented 5 years ago

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.

Fuco1 commented 5 years ago

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]" "/")))