From b8fdcff7b00182dbe23c37715c230cb490aeef14 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 8 Nov 2017 17:20:37 +0800 Subject: [PATCH] doc.kak: anchor/section completion support --- rc/core/doc.kak | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rc/core/doc.kak b/rc/core/doc.kak index e91cc60d..847e93bd 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -122,7 +122,17 @@ define-command -params 1 -hidden doc-render %{ define-command -params 1..2 \ -shell-candidates %{ - find "${kak_runtime}/doc/" -type f -name "*.asciidoc" | sed 's,.*/,,; s/\.[^/]*$//' + if [ "$kak_token_to_complete" -eq 0 ]; then + find "${kak_runtime}/doc/" -type f -name "*.asciidoc" | sed 's,.*/,,; s/\.[^/]*$//' + elif [ "$kak_token_to_complete" -eq 1 ]; then + readonly page="${kak_runtime}/doc/${1}.asciidoc" + if [ -f "${page}" ]; then + awk ' + /^==+ +/ { sub(/^==+ +/, ""); print } + /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } + ' < $page + fi + fi } \ doc -docstring %{doc []: open a buffer containing documentation about a given topic An optional keyword argument can be passed to the function, which will be automatically selected in the documentation} %{