-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indentation and fontlocking in javascript blocks #143
Comments
Hi! If you're familiar with edebug, I suggest you instrument On the surface of it, without your submode structure (multiline blocks) it should be dispatched fine, but the indentation function itself could get confused by the surrounding syntax. Anyway, the first step is to check which function gets called. P.S. js2-mode is not adapted for multi-mode context, so it's better to use the other option. Not sure why |
Thanks for your reply! Regarding A couple of further observations;
|
If the correct function is called but js-indent-line is still confused by the surrounding code, you could try this:
It uses a simple approach (narrowing) which often works well enough, but not in all cases. There's also an option of writing some custom indentation code (there is example inside
Sorry, better highlighting than some other editor, or...?
There is a separate report here (#142 (comment)) which features a usable alternative setup using treesit.el's own functionality. It should be faster than mmm-mode in those cases, though it might support a different subset of features overall.
That's interesting. With debug mode, do you see all the same highlighting, but faster? |
I would prefer to avoid custom indentation code, mainly because of the maintenance burden. I think I'll try integrating directly with treesitter as in your suggestion below, and if it turns out to be difficult I'll revisit the narrowed approach.
Well, that too - other editors don't usually support multi-mode highlighting. However, it seemed that I get better syntax highlighting inside of the mmm block as compared with copying the block to a temporary buffer and setting the mode there. e.g. in an html block that also contained script or style tags. I had those highlighted as well. Likely
Thanks! I've actually seen that but haven't gotten around to setting it up yet. I guess this is the way forward...
Correct. I also don't see emacs CPU usage spiking to 100% like I do when debug is off. |
Yup, that happens.
Thanks, this sounds worth investigating. Could be a bug in jit-lock (which leads to the performance drop), or a bug in the debug mode (which disables something important, improving the performance by doing less work 😅). |
Hello!
Thanks for your work on this package!
I've been trying to set up this mode for use inside
julia-mode
andjulia-ts-mode
. It seems to work well for inline html and markdown(
html"""<>"""
andmd"""<>"""
) including indentation and font locking, but breaks down for javascript. As for font-locking, it works when I set the submode tojavascript-mode
, but not when I set it tojs-mode
which the former is an alias for, nor if I set it to usejs2-mode
. Both of the latter work fine on plain.js
files.Indentation is more quirky and I haven't been able to make it work at all for javascript - in
md
andhtml
blocks it works fine, but injs
blocks it seems to revert to julia's indentation function - pressing tab results in a[No matches]
message unlesstab-always-indent
has been set tot
ornil
, whereas tab seems to do nothing (since julia does not want to indent that line).Furthermore, the same happens in
julia-ts-mode
. In that case I get nice fontlocking inside of<script language="Javascript">
tags inside ofhtml"""
- but indentation seems to revert to the indentation of the html block (ie all code is indented one indent further than the script tag itself, but not further, eg inside a function). In that case I also notice that emacs is lagging, eg scrolling is much slower than whenmmm-mode
is turned off. I also get promptw regarding a missing linter and a missing lsp server which lets ignore for now.emacs 29.2 from emacsforosx.com on macos 14.6 aarch64 with
mmm-mode
20240222 from melpa,julia-mode
20240506.1205 from melap,julia-ts-mode
20230921.1433 from melpa, built-in js-ts-mode,js2-mode
20240418.6, and built-injs-mode
.[EDIT]
sample code:
configuration:
[EDIT 2]:
Interestingly, but not entirely related, I notice that vscode fontifies the js block but not the html or markdown blocks.
The text was updated successfully, but these errors were encountered: