From e43c7d6abab8e6400d61bcf273c026ed0d555ab4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 19 Oct 2022 20:35:05 +1100 Subject: [PATCH] Use complete-command for the :doc command --- rc/tools/doc.kak | 56 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak index d561dd05..b4a3b45b 100644 --- a/rc/tools/doc.kak +++ b/rc/tools/doc.kak @@ -134,34 +134,7 @@ define-command -params 1 -hidden doc-render %{ map buffer normal :doc-follow-link } -define-command -params 0..2 \ - -shell-script-candidates %{ - case "$kak_token_to_complete" in - 0) - find -L \ - "${kak_config}/autoload/" \ - "${kak_runtime}/doc/" \ - "${kak_runtime}/rc/" \ - -type f -name "*.asciidoc" 2>/dev/null | - sed 's,.*/,,; s/\.[^.]*$//';; - 1) - page=$( - find -L \ - "${kak_config}/autoload/" \ - "${kak_runtime}/doc/" \ - "${kak_runtime}/rc/" \ - -type f -name "$1.asciidoc" 2>/dev/null | - head -1 - ) - if [ -f "${page}" ]; then - awk ' - /^==+ +/ { sub(/^==+ +/, ""); print } - /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } - ' < $page | tr '[A-Z ]' '[a-z-]' - fi;; - esac - } -menu \ - doc -docstring %{ +define-command doc -params 0..2 -menu -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 @@ -192,4 +165,31 @@ define-command -params 0..2 \ } } +complete-command doc shell-script-candidates %{ + case "$kak_token_to_complete" in + 0) + find -L \ + "${kak_config}/autoload/" \ + "${kak_runtime}/doc/" \ + "${kak_runtime}/rc/" \ + -type f -name "*.asciidoc" 2>/dev/null | + sed 's,.*/,,; s/\.[^.]*$//';; + 1) + page=$( + find -L \ + "${kak_config}/autoload/" \ + "${kak_runtime}/doc/" \ + "${kak_runtime}/rc/" \ + -type f -name "$1.asciidoc" 2>/dev/null | + head -1 + ) + if [ -f "${page}" ]; then + awk ' + /^==+ +/ { sub(/^==+ +/, ""); print } + /^\[\[[^\]]+\]\]/ { sub(/^\[\[/, ""); sub(/\]\].*/, ""); print } + ' < $page | tr '[A-Z ]' '[a-z-]' + fi;; + esac +} + alias global help doc