2017-11-03 10:34:41 +03:00
|
|
|
declare-option -docstring "name of the client in which documentation is to be displayed" \
|
2017-05-16 14:35:43 +03:00
|
|
|
str docsclient
|
2016-11-03 14:57:55 +03:00
|
|
|
|
2017-11-08 11:32:49 +03:00
|
|
|
declare-option -hidden range-specs doc_render_ranges
|
2017-11-06 15:52:24 +03:00
|
|
|
declare-option -hidden range-specs doc_links
|
2017-11-08 11:32:49 +03:00
|
|
|
declare-option -hidden range-specs doc_anchors
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
define-command -hidden -params 4 doc-render-regex %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft %{ try %{
|
2020-06-03 15:17:32 +03:00
|
|
|
execute-keys <percent> s %arg{1} <ret>
|
2017-11-03 11:09:45 +03:00
|
|
|
execute-keys -draft s %arg{2} <ret> d
|
|
|
|
execute-keys "%arg{3}"
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2018-05-31 14:03:35 +03:00
|
|
|
face="$4"
|
2019-06-19 15:59:42 +03:00
|
|
|
eval "set -- $kak_quoted_selections_desc"
|
2020-08-23 19:55:50 +03:00
|
|
|
ranges=""
|
2018-05-31 14:03:35 +03:00
|
|
|
for desc in "$@"; do ranges="$ranges '$desc|$face'"; done
|
2017-11-08 11:32:49 +03:00
|
|
|
echo "update-option buffer doc_render_ranges"
|
2018-05-31 14:03:35 +03:00
|
|
|
echo "set-option -add buffer doc_render_ranges $ranges"
|
2017-11-02 05:03:24 +03:00
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-11-06 15:52:24 +03:00
|
|
|
define-command -hidden doc-parse-links %{
|
|
|
|
evaluate-commands -draft %{ try %{
|
2020-06-03 15:17:32 +03:00
|
|
|
execute-keys <percent> s <lt><lt>(.*?),.*?<gt><gt> <ret>
|
2017-11-06 15:52:24 +03:00
|
|
|
execute-keys -draft s <lt><lt>.*,|<gt><gt> <ret> d
|
|
|
|
execute-keys H
|
|
|
|
set-option buffer doc_links %val{timestamp}
|
2020-11-02 00:51:44 +03:00
|
|
|
update-option buffer doc_render_ranges
|
2017-11-06 15:52:24 +03:00
|
|
|
evaluate-commands -itersel %{
|
|
|
|
set-option -add buffer doc_links "%val{selection_desc}|%reg{1}"
|
2020-11-02 00:51:44 +03:00
|
|
|
set-option -add buffer doc_render_ranges "%val{selection_desc}|default+u"
|
2017-11-06 15:52:24 +03:00
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:32:49 +03:00
|
|
|
define-command -hidden doc-parse-anchors %{
|
|
|
|
evaluate-commands -draft %{ try %{
|
|
|
|
set-option buffer doc_anchors %val{timestamp}
|
|
|
|
# Find sections as add them as imlicit anchors
|
2020-06-03 15:17:32 +03:00
|
|
|
execute-keys <percent> s ^={2,}\h+([^\n]+)$ <ret>
|
2017-11-08 11:32:49 +03:00
|
|
|
evaluate-commands -itersel %{
|
2018-06-03 07:46:44 +03:00
|
|
|
set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' ""$kak_main_reg_1"" | tr '[A-Z ]' '[a-z-]'}"
|
2017-11-08 11:32:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse explicit anchors and remove their text
|
2020-06-03 15:17:32 +03:00
|
|
|
execute-keys <percent> s \[\[(.*?)\]\]\s* <ret>
|
2017-11-08 11:32:49 +03:00
|
|
|
evaluate-commands -itersel %{
|
|
|
|
set-option -add buffer doc_anchors "%val{selection_desc}|%reg{1}"
|
|
|
|
}
|
|
|
|
execute-keys d
|
|
|
|
update-option buffer doc_anchors
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2020-12-17 16:43:48 +03:00
|
|
|
define-command -hidden doc-jump-to-anchor -params 1 %{
|
2017-11-08 11:32:49 +03:00
|
|
|
update-option buffer doc_anchors
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2018-05-31 14:03:35 +03:00
|
|
|
anchor="$1"
|
2019-06-19 15:59:42 +03:00
|
|
|
eval "set -- $kak_quoted_opt_doc_anchors"
|
2018-09-30 10:43:09 +03:00
|
|
|
|
|
|
|
shift
|
2018-05-31 14:03:35 +03:00
|
|
|
for range in "$@"; do
|
2018-10-01 08:45:28 +03:00
|
|
|
if [ "${range#*|}" = "$anchor" ]; then
|
2018-05-31 14:03:35 +03:00
|
|
|
printf '%s\n' "select '${range%|*}'; execute-keys vv"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
2019-11-14 10:32:55 +03:00
|
|
|
printf "fail No such anchor '%s'\n" "${anchor}"
|
2017-11-08 11:32:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 16:43:48 +03:00
|
|
|
define-command -hidden doc-follow-link %{
|
2017-11-06 15:52:24 +03:00
|
|
|
update-option buffer doc_links
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2019-06-19 15:59:42 +03:00
|
|
|
eval "set -- $kak_quoted_opt_doc_links"
|
2018-05-31 14:03:35 +03:00
|
|
|
for link in "$@"; do
|
|
|
|
printf '%s\n' "$link"
|
|
|
|
done | awk -v FS='[.,|#]' '
|
2017-11-06 15:52:24 +03:00
|
|
|
BEGIN {
|
|
|
|
l=ENVIRON["kak_cursor_line"];
|
|
|
|
c=ENVIRON["kak_cursor_column"];
|
|
|
|
}
|
|
|
|
l >= $1 && c >= $2 && l <= $3 && c <= $4 {
|
2017-11-08 11:32:49 +03:00
|
|
|
if (NF == 6) {
|
|
|
|
print "doc " $5
|
|
|
|
if ($6 != "") {
|
|
|
|
print "doc-jump-to-anchor %{" $6 "}"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print "doc-jump-to-anchor %{" $5 "}"
|
|
|
|
}
|
2017-11-06 15:52:24 +03:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
define-command -params 1 -hidden doc-render %{
|
2017-11-08 11:32:49 +03:00
|
|
|
edit! -scratch "*doc-%sh{basename $1 .asciidoc}*"
|
2017-11-03 11:09:45 +03:00
|
|
|
execute-keys "!cat %arg{1}<ret>gg"
|
2017-09-29 22:16:31 +03:00
|
|
|
|
2017-11-08 11:32:49 +03:00
|
|
|
doc-parse-anchors
|
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
# Join paragraphs together
|
2018-12-13 11:36:23 +03:00
|
|
|
try %{
|
2020-02-18 11:25:12 +03:00
|
|
|
execute-keys -draft '%S\n{2,}|(?<lt>=\+)\n|^[^\n]+::\n|^\h*[*-]\h+<ret>' \
|
2018-12-13 11:36:23 +03:00
|
|
|
<a-K>^\h*-{2,}(\n|\z)<ret> S\n\z<ret> <a-k>\n<ret> <a-j>
|
|
|
|
}
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-11-02 05:03:24 +03:00
|
|
|
# Remove some line end markers
|
2020-06-03 15:17:32 +03:00
|
|
|
try %{ execute-keys -draft <percent> s \h*(\+|:{2,})$ <ret> d }
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-11-08 11:32:49 +03:00
|
|
|
# Setup the doc_render_ranges option
|
|
|
|
set-option buffer doc_render_ranges %val{timestamp}
|
2018-02-22 14:22:13 +03:00
|
|
|
doc-render-regex \B(?<!\\)\*(?=\S)[^\n]+?(?<=\S)(?<!\\)\*\B \A|.\z 'H' default+b
|
|
|
|
doc-render-regex \b(?<!\\)_(?=\S)[^\n]+?(?<=\S)(?<!\\)_\b \A|.\z 'H' default+i
|
2020-10-22 15:39:10 +03:00
|
|
|
doc-render-regex \B(?<!\\)`(?=\S)[^\n]+?(?<=\S)`\B \A|.\z 'H' mono
|
2017-11-02 05:03:24 +03:00
|
|
|
doc-render-regex ^=\h+[^\n]+ ^=\h+ '~' title
|
|
|
|
doc-render-regex ^={2,}\h+[^\n]+ ^={2,}\h+ '' header
|
2018-09-23 15:42:30 +03:00
|
|
|
doc-render-regex ^\h*-{2,}\n\h*.*?^\h*-{2,}\n ^\h*-{2,}\n '' block
|
2017-11-08 11:32:49 +03:00
|
|
|
|
2017-11-06 15:52:24 +03:00
|
|
|
doc-parse-links
|
2017-11-02 05:03:24 +03:00
|
|
|
|
|
|
|
# Remove escaping of * and `
|
2020-06-03 15:17:32 +03:00
|
|
|
try %{ execute-keys -draft <percent> s \\((?=\*)|(?=`)) <ret> d }
|
2021-05-02 12:24:17 +03:00
|
|
|
# Go to beginning of file
|
|
|
|
execute-keys 'gg'
|
2017-11-02 05:03:24 +03:00
|
|
|
|
|
|
|
set-option buffer readonly true
|
2018-06-28 14:08:58 +03:00
|
|
|
add-highlighter buffer/ ranges doc_render_ranges
|
|
|
|
add-highlighter buffer/ wrap -word -indent
|
2018-11-21 19:30:58 +03:00
|
|
|
map buffer normal <ret> ': doc-follow-link<ret>'
|
2016-02-02 22:15:12 +03:00
|
|
|
}
|
|
|
|
|
2021-04-26 01:13:01 +03:00
|
|
|
define-command -params 0..2 \
|
2018-09-27 00:42:01 +03:00
|
|
|
-shell-script-candidates %{
|
2021-09-16 11:47:44 +03:00
|
|
|
case "$kak_token_to_complete" in
|
|
|
|
0)
|
2020-09-03 08:06:24 +03:00
|
|
|
find -L \
|
|
|
|
"${kak_config}/autoload/" \
|
|
|
|
"${kak_runtime}/doc/" \
|
|
|
|
"${kak_runtime}/rc/" \
|
2021-09-16 11:47:44 +03:00
|
|
|
-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
|
2016-02-02 22:15:12 +03:00
|
|
|
} \
|
2020-02-03 22:53:28 +03:00
|
|
|
doc -docstring %{
|
|
|
|
doc <topic> [<keyword>]: 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
|
2020-09-04 12:20:50 +03:00
|
|
|
|
|
|
|
See `:doc doc` for details.
|
2020-02-03 22:53:28 +03:00
|
|
|
} %{
|
2018-05-07 00:29:52 +03:00
|
|
|
evaluate-commands %sh{
|
2021-04-26 01:13:01 +03:00
|
|
|
topic="doc"
|
|
|
|
if [ $# -ge 1 ]; then
|
|
|
|
topic="$1"
|
|
|
|
fi
|
2020-09-02 18:19:20 +03:00
|
|
|
page=$(
|
2020-09-03 08:06:24 +03:00
|
|
|
find -L \
|
|
|
|
"${kak_config}/autoload/" \
|
|
|
|
"${kak_runtime}/doc/" \
|
|
|
|
"${kak_runtime}/rc/" \
|
2021-09-16 11:41:25 +03:00
|
|
|
-type f -name "$topic.asciidoc" 2>/dev/null |
|
2020-09-03 08:06:24 +03:00
|
|
|
head -1
|
2020-09-02 18:19:20 +03:00
|
|
|
)
|
2017-11-02 05:03:24 +03:00
|
|
|
if [ -f "${page}" ]; then
|
2020-08-23 19:55:50 +03:00
|
|
|
jump_cmd=""
|
2017-11-08 11:32:49 +03:00
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
jump_cmd="doc-jump-to-anchor '$2'"
|
|
|
|
fi
|
|
|
|
printf %s\\n "evaluate-commands -try-client %opt{docsclient} %{ doc-render ${page}; ${jump_cmd} }"
|
2017-05-27 08:14:01 +03:00
|
|
|
else
|
2021-05-02 12:24:17 +03:00
|
|
|
printf 'fail No such doc file: %s\n' "$topic.asciidoc"
|
2016-02-02 22:15:12 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 21:26:19 +03:00
|
|
|
|
|
|
|
alias global help doc
|