2017-11-03 08:34:41 +01:00
|
|
|
declare-option -docstring "name of the client in which documentation is to be displayed" \
|
2017-05-16 13:35:43 +02:00
|
|
|
str docsclient
|
2016-11-03 12:57:55 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
declare-option -hidden range-specs doc_render_ranges
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
define-command -hidden -params 4 doc-render-regex %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft %{ try %{
|
|
|
|
execute-keys \%s %arg{1} <ret>
|
|
|
|
execute-keys -draft s %arg{2} <ret> d
|
|
|
|
execute-keys "%arg{3}"
|
2017-11-02 03:03:24 +01:00
|
|
|
%sh{
|
|
|
|
ranges=$(echo "$kak_selections_desc" | sed -e "s/:/|$4:/g; s/\$/|$4/")
|
|
|
|
echo "update-option buffer doc_render_ranges"
|
2017-11-03 08:34:41 +01:00
|
|
|
echo "set-option -add buffer doc_render_ranges '$ranges'"
|
2017-11-02 03:03:24 +01:00
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
define-command -params 1 -hidden doc-render %{
|
|
|
|
edit! -scratch *doc*
|
2017-11-03 09:09:45 +01:00
|
|
|
execute-keys "!cat %arg{1}<ret>gg"
|
2017-09-29 21:16:31 +02:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
# Join paragraphs together
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \%S \n{2,}|(?<=\+)\n|^[^\n]+::\n <ret> <a-K>^-{2,}(\n|\z)<ret> S\n\z<ret> <a-k>\n<ret> <a-j> }
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
# Remove some line end markers
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \%s \h*(\+|:{2,})$ <ret> d }
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2017-11-02 03:03:24 +01:00
|
|
|
# Setup the doc_render_ranges option
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer doc_render_ranges %val{timestamp}
|
2017-11-02 03:03:24 +01:00
|
|
|
doc-render-regex \B(?<!\\)\*[^\n]+?(?<!\\)\*\B \A|.\z 'H' default+b
|
2017-11-02 10:42:16 +01:00
|
|
|
doc-render-regex \b(?<!\\)_[^\n]+?(?<!\\)_\b \A|.\z 'H' default+i
|
2017-11-02 03:03:24 +01:00
|
|
|
doc-render-regex \B(?<!\\)`[^\n]+?(?<!\\)`\B \A|.\z 'H' mono
|
|
|
|
doc-render-regex ^=\h+[^\n]+ ^=\h+ '~' title
|
|
|
|
doc-render-regex ^={2,}\h+[^\n]+ ^={2,}\h+ '' header
|
|
|
|
doc-render-regex ^-{2,}\n.*?^-{2,}\n ^-{2,}\n '' block
|
|
|
|
doc-render-regex <lt><lt>.*?<gt><gt> <lt><lt>.*,|<gt><gt> 'H' link
|
|
|
|
|
|
|
|
# Remove escaping of * and `
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \%s \\((?=\*)|(?=`)) <ret> d }
|
2017-11-02 03:03:24 +01:00
|
|
|
|
|
|
|
set-option buffer readonly true
|
|
|
|
add-highlighter buffer ranges doc_render_ranges
|
|
|
|
add-highlighter buffer wrap -word -indent
|
2016-02-02 20:15:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -params 1 \
|
2016-08-30 16:23:42 +02:00
|
|
|
-shell-candidates %{
|
2017-11-02 03:03:24 +01:00
|
|
|
find "${kak_runtime}/doc/" -type f -name "*.asciidoc" | while read l; do
|
2016-12-14 01:59:19 +01:00
|
|
|
basename "${l%.*}"
|
2016-02-03 20:09:17 +01:00
|
|
|
done
|
2016-02-02 20:15:12 +01:00
|
|
|
} \
|
2016-10-11 09:03:41 +02: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} %{
|
2016-02-02 20:15:12 +01:00
|
|
|
%sh{
|
2017-11-02 03:03:24 +01:00
|
|
|
readonly page="${kak_runtime}/doc/${1}.asciidoc"
|
2016-02-02 20:15:12 +01:00
|
|
|
|
|
|
|
shift
|
2017-11-02 03:03:24 +01:00
|
|
|
if [ -f "${page}" ]; then
|
2017-11-03 09:09:45 +01:00
|
|
|
printf %s\\n "evaluate-commands -try-client %opt{docsclient} doc-render ${page}"
|
2017-05-27 07:14:01 +02:00
|
|
|
else
|
2017-11-02 03:03:24 +01:00
|
|
|
printf %s\\n "echo -markup '{Error}No such doc file: ${page}'"
|
2016-02-02 20:15:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 19:26:19 +01:00
|
|
|
|
|
|
|
alias global help doc
|