Kakoune: Is it possible to disable auto-commenting on newlines? (and leaving auto-indenting on)

Created on 7 Aug 2020  Â·  7Comments  Â·  Source: mawww/kakoune


I had a quick look at the source for some filetypes (rc/filetype/<...>.kak), and it looks like auto-comments are always part of the auto-indent commands (or that's what I understood). Is there no way to disable auto-comments without disabling auto-indenting?

Thanks!

Most helpful comment

Most language support script already distinguish between auto indent and auto insertion, putting them into different hook groups, I think setting the disabled_hooks to .*-insert should disable auto commenting (along with other automatic code insertion hooks) while preserving auto indentation, if it does not it might be that scripts are not putting the correct group onto their hook.

All 7 comments

Since auto-indent and auto-comment are both implemented using hooks, kakoune cannot distinguish the two. However, the rc/filetype/<...>.kak scripts themselves can do this. It is possible to define an option to control whether auto-comments are enabled or not. So it depends on the rc script under consideration.

Scripts in rc are not strictly part of the kakoune editor, but similar to a standard library of a programming language. Everything inside is just ordinary config that are good to have out-of-box. So if you are not happy with the behavior of a specific script, you can:

  1. Modify it and submit a PR. This does not require any internal knowledge. You can do this as long as you can write your own config file.

  2. In your own config, use remove-hooks to disable the rc script's behavior (in your case, auto-indent and auto-comment) and override it with yours (in your case, only the auto-indent part of the script)

Thank you so much for the explanation! IMO it's a good idea to separate auto-indent and auto-comment to different hooks, but there's quite a lot of rc/filetype files and I haven't seen anyone else interested in this, so for now I'm just gonna go for the second option (as soon as I figure it out).

Note that if you press Enter twice, the comment will be disabled.
I haven't gotten used to that, and always deleting empty comments doesn't seem perfect either, see #919.
So an option that works across programming languages could be nice. This could just be a naming convention for hooks to separate indentation from comment hooks. Let's track this in #3179.
We can even create a module with shared indentation functions.

Omg, I can't believe I even replied there and completely forgot about it woww. Pressing enter twice wouldn't be that bad, but it doesn't work in all languages (try sh). I agree with the a new hook for this though (as stated by myself there heh)

Most language support script already distinguish between auto indent and auto insertion, putting them into different hook groups, I think setting the disabled_hooks to .*-insert should disable auto commenting (along with other automatic code insertion hooks) while preserving auto indentation, if it does not it might be that scripts are not putting the correct group onto their hook.

But here's a problem. Our filetype scripts are completely undocumented, and it would be bad if they can't work out-of-box with zero config. In VIM for example, filetype scripts can have very fancy, customizable features, because these features are documented with VIM.

So perhaps we can have a separate :doc section for the rc scripts? Or shall we put these surrounding docs into a community maintained repo, or similar? (If this makes sense, it deserves a separate issue, though)

I agree with the above. Having some form of documentation for the rc scripts would make their usage a lot easier to understand. For comparison, most community plugins (even some small ones) _are_ documented in their README. I've never been able to find anything similar for rc scripts, and have always had to inspect the scripts myself.

Having a separate repo for rc sounds like a great way to do it too.


Most language support script already distinguish between auto indent and auto insertion, putting them into different hook groups, I think setting the disabled_hooks to .*-insert should disable auto commenting (along with other automatic code insertion hooks) while preserving auto indentation, if it does not it might be that scripts are not putting the correct group onto their hook.

I had no idea about this! Thank you! Ironically, the language I use the most (shell, don't judge me) doesn't separate these. And that's the one I've been using to test all of this. I might try making a PR on it to fix that

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexherbo2 picture alexherbo2  Â·  3Comments

akkartik picture akkartik  Â·  3Comments

alexherbo2 picture alexherbo2  Â·  4Comments

valerdi picture valerdi  Â·  4Comments

1g0rb0hm picture 1g0rb0hm  Â·  3Comments