Display all faces in the current color scheme

If you’ve worked on a color scheme for Vim, you’ll be familiar with Vim’s :hi command, which (without any additional arguments) lists all the text styles Vim knows about, along with the definition of that style and an example:

:hi
ErrorMsg       xxx term=reverse cterm=reverse ctermfg=124 guifg=White guibg=Red
...

(it’s not apparent from that black-and-white screenshot, but in my Vim the “xxx” text is displayed black-on-red, an example of what that somewhat obtuse definition actually means)

If I want to pick a useful style for a highlighter, I can run :hi and browse the list looking for one that looks about right, and which is more-or-less semantically appropriate.

In Kakoune, the closest equivalent we have is the :debug faces command, which dumps faces and their definitions to the *debug* buffer, but does not display what the face looks like:

Faces:
 * Default: default,default
 * PrimarySelection: white,blue+Ffga
 * SecondarySelection: black,blue+Ffga
...

And so, here’s a little command that fixes that problem. Just call :color-faces and you’ll be taken to the *debug* buffer with all the face-names highlighted in the appropriate face:

declare-option range-specs face_colors

define-command color-faces %{
    buffer *debug*
    debug faces
    try %{ remove-highlighter buffer/face-colors }
    set-option buffer face_colors %val{timestamp}

    evaluate-commands -draft %{
        execute-keys '%' s^Faces:\n(<space>\*<space>[^\n]*\n)*<ret>
        execute-keys s ^<space>\*<space><ret>
        execute-keys lt:

        evaluate-commands -itersel %{
            eval %sh{
                printf "set-option -add buffer face_colors %s|%s\n" \
                "$kak_selection_desc" "$kak_selection"
            }
        }
    }

    add-highlighter buffer/face-colors ranges face_colors
}
5 Likes

Slightly tangential… in Vim I use a plugin called HiLinkTrace that shows the highlighting group of the character under the cursor (and updates in real time as you move around the document). This was indispensable for me when working on themeing the editor. Does anything similar exist for kak?

Not built-in to Kakoune, but there is the Kakoune Ink website.