Disable comment on newline

Hitting return from a commented line inserts a newline followed by a commenting character. Can I change this behavior to only insert a newline?

tip: hit enter again, and it will close the comment.

@andreyorst I see, thanks. It doesn’t work in Python, but I can try to adapt it from the C-family kak script.

hit enter again

This doesn’t work for me, just inputs a second commented empty line.

How do I turn this off? I’m trying to fix all my kakoune indentation woes. I love this editor, but the way I have it set up right now, when I enter new lines I have no idea what they’re going to look like. :worried:

what language does this happen in?

In kakrc files, for sure :grinning:

I’ll write back after I’ve checked some other languages.

I’m pretty sure I get more comment characters in shell, though I’ll have to check that.

Is there a good reference implementation for closing the comment out the way you’re describing? If so I’ll add it to the shell module.

Hitting return from a commented line inserts a newline followed by a commenting character. Can I change this behavior to only insert a newline?

You can disable or remove the autoinsert hook; most filetype have one. They are all called like %opt{filetype}-insert, so for shell:

set-option global disabled_hooks sh-insert

3 Likes

You can also disable all of the insert hooks with the regex:

set-option global disabled_hooks '.*-insert'

Some languages still need separating of their -insert and -indent hooks, so it won’t work with all of them yet.

Also it’d be nice if all the languages also had that “press enter twice to delete on current line” like the c-family

2 Likes

Having given this some thought I don’t think it’s appropriate for languages that use a set of single-line comments to make a block comment - i.e. anything that doesn’t use something like the C family’s /*...*/ for block comments. Closing the comment after a single empty line would make it much harder for you to do something like this:

#!/bin/sh
#
# foo.sh: baz the bar real hard.

Which, frankly, would make me a very sad shell or python coder (and probably a lot of other languages that I don’t use on a daily basis). In general, block comments really should be able to have “vertical white space” to make them more readable, and anything that discourages that should be tossed.

I think a better approach would be a separate command that closed out a block comment, either by simply copying the indentation level of the previous comment line (for a language with no specific block comment syntax), or inserted the closing block syntax and copied the indentation level over. Given it’d be used in insert mode it would make sense to default to a chorded command like <a-enter> or similar.

At the very least, though, “press enter twice to delete the current line” isn’t workable for a lot of languages, even if it makes sense for some - we can’t make that the default behaviour.