mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.97k stars 714 forks source link

Embedded language indentation? #3546

Open tmccombs opened 4 years ago

tmccombs commented 4 years ago

It seems the pattern for language plugins is to define hooks on character insertion to automatically indent the next line, and those hooks are activated by a filetype hook. That is fine for many languages, but if you have something like html, php, erb, or even kak, where you have multiple languages in the same file, it means the auto-indentation is useless in the embedded contexts (such as a script tag in html).

I suppose it would be possible to write hooks for InsertChar that figure out if you are in an embedded section, and then determine which indent command defined by the plugin for the embedded language to use. Besides being messy, this introduces a tight coupling between the top level and embedded language, since, for example, the html plugin needs to know what indentation functions the javascript plugin uses, and what characters they are triggered on. Or you could duplicate the logic of javascript indentation in the html indenters.

I'm not sure what a good solution for this would be that is in-line with kakoune's philosophy though. Having some visibility into what highlight regions the inserted character is in might reduce some complexity and duplication in figuring out which language to use for indenting. (ex. if we are in a script region, use the javascript indenting). I'm not really sure how to handle inconsistent indent commands/hooks though.

mawww commented 4 years ago

I would love to find a clean and simple solution to this problem, but I am afraid it does not exist.