mooz / js2-mode

Improved JavaScript editing mode for GNU Emacs
GNU General Public License v3.0
1.32k stars 186 forks source link

MMM-mode support #124

Open CyborgMaster opened 10 years ago

CyborgMaster commented 10 years ago

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.

dgutov commented 10 years ago

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. :)

CyborgMaster commented 10 years ago

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?

dgutov commented 10 years ago

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.

mk0x9 commented 9 years ago

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

jaseemabid commented 9 years ago

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.

dgutov commented 9 years ago

@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.

xcodebuild commented 8 years ago

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

binary132 commented 7 years ago

VueJS bump.

benjcal commented 7 years ago

+1

dgutov commented 7 years ago

@CodeFalling Why do you think you really need this?

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

benjcal commented 7 years ago

@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 :-)

dgutov commented 7 years ago

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

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.

ustun commented 5 years ago

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.)

osman-mohamad commented 4 years ago

any change about mmm-support with js2-mode ?

srcrip commented 4 years ago

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?

NANASHI0X74 commented 3 years ago

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?

dgutov commented 3 years ago

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.