smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

sp-kill-hybrid-sexp doesn't respect closing tags in html.

Open AmaiKinono opened this issue 6 years ago • 3 comments

Expected behavior

In an html file like this:

<p>some|thing</p>

call sp-kill-hybrid-sexp should give this:

<p>some</p>

Actual behavior

In html-mode:

<p>some

In web-mode:

<p>somep>

I don't know if I have to do some customization to make this work. I didn't find related information on the internet.

Steps to reproduce the problem

Eval this:

;; These are where straight.el build my packages to.
(add-to-list 'load-path "~/.emacs.d/straight/build/smartparens")
(add-to-list 'load-path "~/.emacs.d/straight/build/dash")
(add-to-list 'load-path "~/.emacs.d/straight/build/web-mode")

(require 'dash)
(require 'smartparens)
(require 'smartparens-config)
(require 'web-mode)
(smartparens-global-strict-mode)

Open a new buffer, and try the above example in html-mode and web-mode.

Environment & version information

  • smartparens version: commit https://github.com/Fuco1/smartparens/commit/7080e7fba9f478c2e5d4c18a325c3a5d60f6be76
  • Active major-mode: html-mode or web-mode
  • Smartparens strict mode: t
  • Emacs version (M-x emacs-version): GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.8) of 2019-04-13
  • starterkit: Vanilla (I'm using emacs -Q)
  • OS: gnu/linux

AmaiKinono avatar Aug 21 '19 15:08 AmaiKinono

I've found https://github.com/Fuco1/smartparens/issues/555, https://github.com/Fuco1/smartparens/issues/756 and https://github.com/Fuco1/smartparens/issues/865. Seems this is the reason, but other commands except sp-kill-hybrid-sexp works well as far as I can tell. I guess I would advise it to use command from tagedit when between tags.

AmaiKinono avatar Aug 23 '19 03:08 AmaiKinono

Same issue. Do you know, how one can execute the tagedit command, only when between tags and otherwise the smartparens command? Or did you just bind the tagedit command to your key-combo, instead of sp-kill-hybrid-sexp?

EDIT: Also, for me tagedit-kill doesn't do the trick, it just kills to the end of the line...

phuhl avatar Dec 11 '20 10:12 phuhl

how one can execute the tagedit command, only when between tags and otherwise the smartparens command?

I actually haven't tried hacking it since I post this issue. My idea is like this:

(defun in-between-tags ()
  (let ((pt (point))
        (end (save-excursion
               (sgml-skip-tag-forward)
               (point)))
        (beg (save-excursion
               (sgml-skip-tag-backward)
               (point))))
    (< beg pt end)))

(define-advice sp-kill-hybrid-sexp (:around (fn) fix-html)
  (if (in-between-tags)
      (tagedit-kill)
    (funcall fn)))

Note that in-between-tags returns t when you are inside a tag. The predicate really depends on what are the situations that tagedit-kill deal with, so you may need to revise the code to suit your own need.

EDIT: Also, for me tagedit-kill doesn't do the trick, it just kills to the end of the line...

I tested it and yes, you are right. You may want to look at web-mode-edit-element instead, but I can't ensure it will work.

Also, if you could figure out how to move from the end of a tag to the beginning of it, and combine it with sgml-skip-tag-forward, it should be easy to write your own smart kill command. Maybe web-mode has some goodies on this...

AmaiKinono avatar Dec 11 '20 14:12 AmaiKinono