smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

rjsx-mode support

Open averykimball opened this issue 7 years ago • 5 comments

Are you interested in rjsx-mode interop support?

I've cobbled together a hacky smartparens-jsx.el from smartparens-html.el and smartparens-javascript.el and eval-after-loaded it in rjsx-mode, and it works beautifully.

Seeing as how a solid 2/10 elisp programmer made this work, it seems like it would be pretty simple to just include this functionality in the codebase- heck, adding 'rjsx-mode to the sp--html-modes in smartparens.el might get you 99% there... though I don't think the smartparens-javascript.el dot-slurp protection will be enabled with that solution (and not adding spaces after dots when slurping is a must have when editing jsx files).

Is this reasonable? I'd try to make a PR, but this feature might require creating an entire smartparens-jsx.el file, and I can't even get ert-runner to work.

averykimball avatar Jul 03 '17 06:07 averykimball

Hi, thanks for your interest!

New file is not a problem. If it is a separate major mode it should have its own config file, even if that only loads stuff from other configurations.

Make sure to cask install first, then cask exec ert-runner should work.

You can open the PR and we'll look at it together.

Fuco1 avatar Jul 03 '17 10:07 Fuco1

@averykimball I'm relatively new to Emacs LISP but I've worked on a package or two, I can take a look at your code if you'd like.

Also, does anyone think we could do this in a way that supports multiple (Facebook) JSX compatible modes at once (for example: js-jsx-mode, js2-jsx-mode, and web-mode)?

nickmccurdy avatar Jul 12 '17 10:07 nickmccurdy

web-mode might get tricky as it supports loads of different templates. Maybe if it has some sort of "submodes" where it decides what kind of template it operates on we could use that and load different configurations (smartparens now supports named configuration sets independent of major modes).

We would then configure a major-mode hook in which the setup would take place.

So the stuff should probably go into smartparens-jsx.el which will then get required into smartparens-web-mode.el and the relevant code will be re-used. (and I can imagine that smartparens-web-mode.el can similarly pull config for twig, smarty, erb etc.)

Fuco1 avatar Jul 12 '17 11:07 Fuco1

rjsx-mode readme:

js2-mode does not include a JSX parser, but rather an E4X parser, which means it gets confused with certain JSX constructs. This mode extends the js2 parser to support all JSX constructs and proper syntax highlighting. … Additionally, since rjsx-mode extends the js2 AST, utilities using the parse tree gain access to the JSX structure.

It seems like it might be easier to only support JSX within rjsx-mode (not the other JSX compatible modes) because of the improvements it makes to the JSX parser (at least until the other JSX parsers improve). However, I'm not exactly sure how sp--html-modes work and overriding that might be enough if we can get slurping and barfing to work properly. Still, I wouldn't mind it if this only worked with rjsx-mode, it's the only React JSX mode I've tried (including js-jsx-mode, js2-jsx-mode, and web-mode) that has decent syntax highlighting.

nickmccurdy avatar Jul 25 '17 23:07 nickmccurdy

I just switched to web-mode from rjsx-mode, their built in smartparens support is fantastic.

nickmccurdy avatar Aug 01 '17 23:08 nickmccurdy