Closed KaranAhlawat closed 3 weeks ago
What would be needed to use the indentation engine tuareg provides in another major mode?
Hard to know without trying but at least:
tuareg.el
into Emacs.indent-line-function
.tuareg-mode
.syntax-propertize-function
as well.The use case is using the indentation engine with
ocaml-ts-mode
.
Count me baffled, since I thought the main benefit of TreeSitter is for indentation.
A similar case is
python-ts-mode
, which usespython-indent-line-function
for indentation inpython-ts-mode
instead of using treesitter for indentation.
I haven't looked at python-ts-mode
but at least Python's
indentation-significant syntax gives me a good reason to think that it
might be "unusual". Can't think of any reason why OCaml's indentation
wouldn't benefit from an actual AST like the one Tree Sitter
can provide. Is it that Tree Sitter's OCaml grammar sucks?
- Set
indent-line-function
. For this, I wasn't really sure how to set theindent-line-function
sincetuareg-mode
seems to be wrapping the existing function in an advice only. But where does the existing function come from in the first place?Count me baffled, since I thought the main benefit of TreeSitter is for indentation. It's not that it can't be used for indentation, but quite a few users of Tuareg mode like it's indentation engine, and I'd like to save some duplicated effort if possible (read: I'm being a bit lazy).
Can't think of any reason why OCaml's indentation wouldn't benefit from an actual AST like the one Tree Sitter can provide. Is it that Tree Sitter's OCaml grammar sucks? I don't think the grammar sucks (from my experiments with it). But, isn't Ocaml a little leaning to indentation based syntax as well? For example, if you have multiple let bindings in a file, you can define them without a
;;
. Anyways, I digress.
If you can help me figure out the indent-line-function
I think we might be going somewhere
- Set
indent-line-function
. For this, I wasn't really sure how to set theindent-line-function
sincetuareg-mode
seems to be wrapping the existing function in an advice only. But where does the existing function come from in the first place?
It's set by smie-setup
.
Count me baffled, since I thought the main benefit of TreeSitter is for indentation. It's not that it can't be used for indentation, but quite a few users of Tuareg mode like it's indentation engine, and I'd like to save some duplicated effort if possible (read: I'm being a bit lazy).
As the "main" original author of that indentation code, I'm happy to hear it, but it would be nice to try and reproduce its behavior using Tree Sitter.
I don't think the grammar sucks (from my experiments with it). But, isn't Ocaml a little leaning to indentation based syntax as well? For example, if you have multiple let bindings in a file, you can define them without a
;;
. Anyways, I digress.
It can feel a bit magical, indeed, but this is disambiguated without any recourse to indentation information. 🙂
Oookay, so, I was able to set it up and it works pretty much the same as tuareg-mode
, but the rest of the mode is enhanced by tree-sitter
(syntax highlighting, imenu, usage with third party packages such as combobulate, textobjects etc etc).
If I find free time over the weekend, I'll try to add some indentation using tree-sitter itself, we can compare which one feels nicer overall.
Oookay, so, I was able to set it up and it works pretty much the same as
tuareg-mode
, but the rest of the mode is enhanced bytree-sitter
(syntax highlighting, imenu, usage with third party packages such as combobulate, textobjects etc etc).
👍🏾
If I find free time over the weekend, I'll try to add some indentation using tree-sitter itself, we can compare which one feels nicer overall.
That will compare your Tree Sitter indentation rules to the SMIE indentation rules, rather than comparing Tree Sitter to SMIE. IOW, which is better will largely depend on which one got more effort put into it.
We can close this now, thank you so much for your help :)
What would be needed to use the indentation engine tuareg provides in another major mode? The use case is using the indentation engine with
ocaml-ts-mode
.A similar case is
python-ts-mode
, which usespython-indent-line-function
for indentation inpython-ts-mode
instead of using treesitter for indentation.