How do I place in indent guides?

hi, i have seen @andreyorst use indent guides in kakoune:

found in kakoune-snippets issue #9.
may i ask how this was implemented? thanks!

only works for tab characters

addhl global/ show-whitespace -tab '│' -tabpad ' '

wrote something that works for spaces, although it uses replace-ranges highlighter so isn’t as nice as the built in one.

declare-option -hidden range-specs alignment_spaces_specs
define-command -hidden -override update-alignment-spaces %{
    try %[ eval -draft %{
        exec <percent> s ^ <space> <ret>
        exec w s <space> { %opt{indentwidth} } <ret> '<a-;>' ';'
        set-option window alignment_spaces_specs %val{timestamp}
        eval -itersel %{
            set-option -add window alignment_spaces_specs "%val{selection_desc}|│"
        }
    }]
}

define-command window-remove-alignment %{
    remove-highlighter window/alignment-tabs
    remove-highlighter window/alignment-spaces
    remove-highlighter window/alignment-spaces-hl
    remove-hooks window alignment
}
define-command window-enable-alignment-tabs %{
    add-highlighter window/alignment-tabs ref -passes move alignment-tabs
}
define-command window-enable-alignment-spaces %{
    hook window -group alignment NormalIdle .* update-alignment-spaces
    hook window -group alignment InsertIdle .* update-alignment-spaces
    add-highlighter window/alignment-spaces ref -passes move alignment-spaces
    add-highlighter window/alignment-spaces-hl regex \
        "( ) {%sh{ let ""x = $kak_opt_indentwidth - 1""; echo $x }}" 1:Whitespace
}

add-highlighter shared/alignment-tabs show-whitespaces -tab '│' -tabpad ' ' -spc ' ' -lf ' ' -nbsp ' '
add-highlighter shared/alignment-spaces replace-ranges alignment_spaces_specs

I imagine there’s some plugins lying around that do similar things.

3 Likes

@prion, I never got this working, thanks for the script!

thanks prion! this helped me so much.

I probably wouldn’t copy that snippet verbatim into your kakrc by the way. It’s more of a proof of concept than anything. It seems very ineffecient.

Correct, except I’ve used a different character: which is aligned with the start of the cell for better visuals.

1 Like

I’ve created a PR to build this feature into the whitespace highlighter

feel free to leave a comment on it if you want some specific behaviour

1 Like

Amazing! Thank you.