Closed bigodel closed 2 years ago
@bigodel thank you for this
@bigodel thank you for this
you're very much welcome! web-mode
is amazing and it think it'd be even more amazingier if we could use part of its features outside of it. i haven't submitted a PR for this because i didn't manage to understand what and which parts of web-mode.el
could and should be loaded on a minor mode, though. so i did the hacky solution of just loading it and reloading the previous mode again, which seems to be working fine for navigation and most of the editing features. i think that indentation could also be handled by this proposed minor mode, but maybe as an user option (TSX with tree-sitter
won't indent the HTML-like tags or its attributes correctly, and we still don't have a working tree-sitter-indent
, but i give it a couple of months until we have something in that space).
hi! i'd like to propose implementing a
web-minor-mode
, similar to what js2-mode does with itsjs2-minor-mode
. the rationale behind it would be that for some cases, such as when editing JSX or TSX files, it would be desirable to use the major mode as ajs-mode
ortypescript-mode
derived mode in order to enabletree-sitter
on it, making use of tree-sitter objects and syntax highlighting, while at the same time having the facilities to jump and edit tags and attributes and possibly usingweb-mode
's indentation.i tried setting
tree-sitter
on aweb-mode
buffer as well, and i think that would work instead of the minor mode -- even though i still think that the minor mode could be valuable -- but it fails to ultimately highlight the buffer usingtree-sitter-hl-mode
. i tried the following (this requires that bothtree-sitter
andtree-sitter-langs
are installed).on a TSX buffer with
web-mode
as a major mode (also with a derived modetypescript-tsx-mode
, derived fromweb-mode
, and on JSX buffers in both cases as well, "pure"web-mode
and a derived mode), but it fails withwhich is, as the stacktrace points out, happening when
tree-sitter-hl-mode
tries to loadfont-lock-defaults
, which is set to'('(web-mode-fontify) t)
onweb-mode
buffers -- i think this is a typo, btw. that second quote before(web-mode-fontify)
shouldn't be here, should it?. and i also tried setting it to((web-mode-fontify) t)
but it also fails with wrong number of arguments, because font-lock is trying to call it with no arguments (don't really know how it all works, tbh), but it expects a single argument.i managed to get a hacky ad hoc
web-minor-mode
working on Emacs 28.0.90. it loadsweb-mode
without calling its hooks, and then loads the previous major-mode back, retaining most of web-mode's bindings on the minor mode