Has anyone made a wiki in Kakoune?

I looked at Teddys’ wiki plugin, and while it’s cool, it seems to require configuring A Specific Wiki Path. I’d like to have any directory be a potential wiki, so I’ve started my own thing.

I would like it to be adaptable to different markup formats and link syntaxes (like AsciiDoc, ReST, etc.) and different ways of mapping page names to file paths (which characters are disallowed, whether they’re escaped or just flattened) but Kakoune is really not built for… plugability, so at least for starters I’ve decided to restrict myself to just GitHub-style wikis, and just MediaWiki-style links as described in the first post.

Currently, if you follow the example config in the README, if you edit a Markdown file and a Home.md file exists in the same directory, it maps <ret> to : wiki-follow-link, so you can hit Enter on a link to open the file it links to (again, as described in the first post).

Next, I wanted to tackle completion.

Attempt 1: static_words

I tried generating a list of page names, and inserting them into the static_words option. I immediately hit a problem: it’s easy to add items with set -add, but you can’t easily remove or update items.

Attempt 2: links in a completions option

Kakoune’s built for this kind of custom completion stuff, so we should have all the parts we need:

# Declare a completions option, and always use it
declare-option completions wiki_completions
set-option -add global completers option=wiki_completions

# while the user is typing in insert mode...
hook global InsertIdle .* %{
    eval -draft %{
        try %{
            # Move the cursor to the beginning of the previous [[, if any.
            exec <space><a-t>[hH<a-k>\[\[<ret>

            # Set up completions that include the [[
            set window wiki_completions \
                "%val{cursor_line}.%val{cursor_column}@%val{timestamp}" \
                "[[New York]]||[[New York]]" "[[London]]||[[London]]"
        } catch %{
            # No [[ before the cursor, clear out stale completions
            set window wiki_completions
        }
    }
}

If I stick that in a file and start Kakoune, it mostly works. If I just start typing, I get no completions, and the moment I type [[ I get the two completions and I can cycle through them. If I type L (the first letter of “London”) then “New York” gets removed from the completion list as I would expect.

However, if I type l, I would expect the same effect. Instead, the completion list now contains “file” and “automatically”, the two words in the default scratch buffer message containing “l”. If I then type “o” (or “d” or “n”) the scratch-buffer completions vanish and I’m back to “London” as expected.

I accept that Kakoune has a bunch of completions engines going on, and it might not always display completions in the order I expect, but I’m surprised that valid completions are sometimes hidden. Is this a bug, or some quirk of Kakoune’s design I haven’t fully appreciated yet?

EDIT: I found a workaround: if I install the completer with:

set-option global completers option=wiki_completions %opt{completers}

(that is, if I manually put my completer first, instead of using -add to put it last) then my completions always appear. The other completions don’t appear, but I don’t care about them as much since these completions are more specific. Other people might have multiple completion sources they care about, so maybe this behaviour still needs to be changed… but I’m OK with it for now.

1 Like