4 ms·
That should be easy to build. In 2002 I built harmonia-mode, which did that for the harmonia research project that inspired tree-sitter. It did that.
by toomim 2y ago
That should be easy to build. In 2002 I built harmonia-mode, which did that for the harmonia research project that inspired tree-sitter. It did that.
- pama 2y agoI would contribute to a repo that works towards this goal.
- toomim 2y agoThe best way forward is similar to how you describe. Instead of making one mode per language -- just make a generic "tree-sitter" mode, and attach that mode to all the filetypes you want it load via regexp patterns in `auto-mode-alist`. Then when the file goes into tree-sitter-mode, you can check the filetype again, and map that into the language to load into tree-sitter. Keep a buffer-local variable to remember that current language, so that you can use it for any additional language-specific customization that you want as well. Keep in mind that there's nothing about a major mode in Emacs that has to be specific to a programming language. It's totally cool to have a major mode that works for multiple programming languages!
- vzaliva 2y agoI think the main problem is that highligthing framework used by tree-sitter (https://github.com/tree-sitter/tree-sitter/tree/master/highlight https://github.com/tree-sitter/tree-sitter/tree/master/highl...) is not easily pluggable into emacs font-lock-mode.
- toomim 2y agoI wrote similar code in emacs for harmonia-mode in the past. Let me find and share the source code. We don't need font-lock. We can just borrow the styles it uses. *Update:* I found the code. Instead of using font-lock, we simply draw our own overlays over the text and color them, which is what font-lock does. Font-lock IIRC is specifically designed to use regexps to parse the text. We don't need that. So throw font-lock away. Tree-Sitter itself knows how the parse tree maps to text regions. Just use that information to draw the overlays directly. It's way simpler that way. Lemme know if anyone wants the code.
- vzaliva 2y agoIt's starting to sound like it's time to create a GitHub repository and start putting it all together. My elisp skills are basic, so I could help more with testing, coordination, publishing packages, or documentation. Shall I create the repo?
- vzaliva 2y agorepo created. I've sent you a request on github.