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 195 forks source link

can not kill-region on arrow functions with rjsx-mode & smartparens-strict-mode #872

Closed merrickluo closed 6 months ago

merrickluo commented 6 years ago

Expected behavior

should be able to kill-region on a javascript arrow function in rjsx-mode with smartparens-strict-mode.

Actual behavior

user-error: Can not kill the region: the buffer would end up in an unbalanced state after deleting the active region

Steps to reproduce the problem

  1. create a javascript file and turn on rjsx-mode
  2. write a javascript arrow function
    const test = () => {
    console.log('test')
    }
  3. select whole function and call kill-region

Environment & version information

I think > is the problem here since it also needed to be paired in HTML, I wonder if this can be done? I really like the idea of smartparens-strict-mode, and want to use it in every mode. I can also press C-k before the function twice to do the same thing, but the muscle memory is really hard to resist(

Fuco1 commented 6 years ago

I remember we had a somewhat similar issue in the past but I'm not sure if it was javascript or rust or something else. Should not be extremly difficult to fix.

merrickluo commented 6 years ago

Looks like #789 ? if I copy sp-rust-skip-match-angle-bracket to smartparenst-html.el it works.

(defun sp-javascript-skip-match-angle-bracket (_ms _mb me)
  "Non-nil if we should ignore the bracket as valid delimiter."
  (save-excursion
    (goto-char me)
    (sp--looking-back-p (rx "=>") nil)))

(sp-with-modes sp--html-modes
  (sp-local-pair "<" ">"
                 :skip-match 'sp-javascript-skip-match-angle-bracket)
  (sp-local-tag  "<" "<_>" "</_>" :transform 'sp-match-sgml-tags :post-handlers '(sp-html-post-handler)))
Fuco1 commented 6 years ago

I think it would better fit in smartparens-javascript.el, after all the arrow is part of js syntax.

Would you be interested in creating a pull request?

merrickluo commented 6 years ago

I'd like to.

Fuco1 commented 6 months ago

Fixed in 04f94b8ce207f9476b39eb397486e87c8507c84e