js2-mode icon indicating copy to clipboard operation
js2-mode copied to clipboard

MMM-mode support

Open CyborgMaster opened this issue 11 years ago • 18 comments
trafficstars

I love js2-mode and use it a my main javascript editing mode. I would love to see support for mmm-mode so I could use it to edit script tags. How hard would this be to accomplish? I would do it myself, but I'm still a noob when it comes to elisp.

CyborgMaster avatar Nov 24 '13 21:11 CyborgMaster

What's your use case? Scripts tags usually contain small-ish amounts of code, so it's not like the highlighting of undeclared vars will be useful. Are you aiming to use skewer-mode and ac-js2?

It should be doable now, if we remove the explicit parser scheduling and register the parser function as syntax-propertize-function. But it will break some things. Off the top of my head, calling widen will be prohibited, so #114 won't be fixed anymore. js2-dynamic-idle-timer-adjust won't work, since there's no corresponding setting in font-lock. And js2-mode parser is inherently slower than than js-syntax-propertize, so, even if it works okay, it may lower the size of files you can comfortably work with using mmm-mode by an order of magnitude.

I would do it myself, but I'm still a noob when it comes to elisp.

That's a convenient turn of phrase. :)

dgutov avatar Nov 26 '13 05:11 dgutov

My main use case is that js2-mode does auto-indenting exactly the way I want it while javascript mode is quite a bit less intelligent. It doesn't make a difference when people only use small snippets of code in script tags and keep most javascript in an external file, but I just ran into a testbench for an open source project I am contributing to that has a non-trivial amount of javascript in the html file.

It may be that the correct solution in this case is simply getting my javascript mode setup to do auto indenting correctly. I was trying to avoid maintaining my setup for two javascript editing modes, but that may be the easiest solution in this case. @dgutov what do you suggest?

CyborgMaster avatar Dec 02 '13 18:12 CyborgMaster

Because js2-mode indentation code doesn't depend on the generated syntax tree (or on the parser, in general), it's been intended for move to js-mode for some time now.

If you don't mind using Emacs compiled from trunk, or waiting a few months until 24.4, or at least copying js.el from trunk to somewhere on your load path (that should work, but I'm not 100% sure), file a bug for js-mode on the Emacs tracker (M-x report-emacs-bug), preferably with examples where indentation looks broken to you.

Then I'll try to do the move. The feature-freeze for Emacs 24.4 is scheduled for the middle of December, so I'd have to finish before that.

dgutov avatar Dec 02 '13 23:12 dgutov

@CyborgMaster You can actually narrow buffer down to region inside script tags and change major mode to js2-mode.

mk0x9 avatar Jan 30 '15 18:01 mk0x9

jsx support of emacs at the moment is pretty bad. The best approach I could think of at the moment is to use html-mode and js2-mode for a jsx buffer using mmm. So an update on this would be great.

jaseemabid avatar Mar 07 '15 07:03 jaseemabid

@jaseemabid Multi-mode support with js2-mode being the primary mode is not even being discussed now. It can be done, but for JSX, it would probably be better if someone implemented some addition to the indentation code that delegates to html-mode.

dgutov avatar Mar 07 '15 20:03 dgutov

@dgutov vuejs need this. See https://github.com/CodeFalling/vue-mode.

xcodebuild avatar Apr 11 '16 06:04 xcodebuild

VueJS bump.

binary132 avatar Nov 14 '16 16:11 binary132

+1

benjcal avatar Feb 01 '17 15:02 benjcal

@CodeFalling Why do you think you really need this?

vue-mode uses js-mode, which seems like a decent choice.

dgutov avatar Feb 01 '17 15:02 dgutov

@dgutov: ES6 highlighting is super important and vuejs uses it extensively. Vue has this components that include a <template> where there's HTML, a <style> where CSS goes and a <script> where the JS is and all of that is in a single file, thus the need for MMM.

If you point me on the right direction I can looking into adding support for MMM and make a pull request :-)

benjcal avatar Feb 02 '17 10:02 benjcal

@benjcalderon If there are important ES6 constructs that are not highlighted well in js-mode in recent Emacs (25.1), please report that as bugs.

If you point me on the right direction I can looking into adding support for MMM

I don't know of a good way to provide that support, and so can't provide a good direction.

dgutov avatar Feb 02 '17 14:02 dgutov

For some suggestions, see my first comment in this thread. But having thought more about this, running the parser as often as font-lock works is likely to make Emacs too slow in larger files.

dgutov avatar Feb 02 '17 14:02 dgutov

My main use case is that js2-mode does auto-indenting exactly the way I want it while javascript mode is quite a bit less intelligent. It doesn't make a difference when people only use small snippets of code in script tags and keep most javascript in an external file, but I just ran into a testbench for an open source project I am contributing to that has a non-trivial amount of javascript in the html file.

It may be that the correct solution in this case is simply getting my javascript mode setup to do auto indenting correctly. I was trying to avoid maintaining my setup for two javascript editing modes, but that may be the easiest solution in this case. @dgutov what do you suggest?

It wasn't around when the issue was originally posted, but prettier can format such files with mixed content (js within html etc.)

ustun avatar Dec 30 '18 20:12 ustun

any change about mmm-support with js2-mode ?

osman-mohamad avatar Dec 15 '19 10:12 osman-mohamad

I also would desperately love this for editing .Vue files in vue-mode. Can we get some direction on what would have to be done for this to happen?

srcrip avatar Feb 08 '20 00:02 srcrip

I'll add another nag: Is there an estimate if/when this feature will be added? (use case is vue-mode as well) Also, @dgutov's early comments have confused me a bit, was there the intention to eventually integrate/move the functionality of js2-mode into the js-mode that emacs ships by default?

NANASHI0X74 avatar Oct 05 '20 17:10 NANASHI0X74

Is there an estimate if/when this feature will be added?

Nobody is working on it (AFAIK), so no. Sorry.

was there the intention to eventually integrate/move the functionality of js2-mode into the js-mode that emacs ships by default?

A number of features (indentation, syntax highlighting) have been ported over. But not the parser, of course.

dgutov avatar Oct 05 '20 18:10 dgutov