MMM-mode support
CyborgMaster opened this issue ยท 18 comments
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.
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. :)
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?
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.
@CyborgMaster You can actually narrow buffer down to region inside script tags and change major mode to js2-mode.
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 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 vuejs
need this. See https://github.com/CodeFalling/vue-mode.
VueJS bump.
+1
@codefalling Why do you think you really need this?
vue-mode
uses js-mode
, which seems like a decent choice.
@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 :-)
@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.
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.
My main use case is that
js2-mode
does auto-indenting exactly the way I want it whilejavascript
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.)
any change about mmm-support with js2-mode ?
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?
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?
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.