2017-05-16 14:35:43 +03:00
|
|
|
decl -docstring "name of the client in which documentation is to be displayed" \
|
|
|
|
str docsclient
|
2016-11-03 14:57:55 +03:00
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden -params 1..2 doc-open %{
|
2016-02-02 22:15:12 +03:00
|
|
|
%sh{
|
2017-06-09 14:05:31 +03:00
|
|
|
manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX)
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-09-29 22:16:31 +03:00
|
|
|
# This option is handled by the `man-db` implementation
|
2016-11-03 14:57:55 +03:00
|
|
|
export MANWIDTH=${kak_window_width}
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2017-09-30 08:23:10 +03:00
|
|
|
if man "$1" > "${manout}" 2>/dev/null; then
|
2017-09-29 22:16:31 +03:00
|
|
|
readonly manout_noescape=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX)
|
|
|
|
|
|
|
|
sed -e $(printf 's/.\x8//g') -e 's,\x1B\[[0-9;]*[a-zA-Z],,g' "${manout}" > "${manout_noescape}"
|
|
|
|
mv -f "${manout_noescape}" "${manout}"
|
2016-02-02 22:15:12 +03:00
|
|
|
|
2016-04-23 08:47:01 +03:00
|
|
|
printf %s\\n "
|
2016-02-02 22:15:12 +03:00
|
|
|
edit! -scratch '*doc*'
|
2016-11-03 14:57:55 +03:00
|
|
|
exec |cat<space>${manout}<ret>gg
|
|
|
|
nop %sh{rm ${manout}}
|
2016-02-02 22:15:12 +03:00
|
|
|
set buffer filetype man
|
2017-09-29 22:12:09 +03:00
|
|
|
remove-hooks window man-hooks
|
2016-02-02 22:15:12 +03:00
|
|
|
"
|
|
|
|
|
|
|
|
if [ $# -gt 1 ]; then
|
2016-04-23 08:47:01 +03:00
|
|
|
needle=$(printf %s\\n "$2" | sed 's,<,<lt>,g')
|
2017-09-29 05:39:59 +03:00
|
|
|
printf %s\\n "try %{ exec '%<a-s><a-k>(?i)^\h+[^\n]*?\Q${needle}\E<ret>\z' } catch %{ exec <space>gg }"
|
2016-02-02 22:15:12 +03:00
|
|
|
fi
|
|
|
|
else
|
2017-07-19 18:18:52 +03:00
|
|
|
printf %s\\n "echo -markup %{{Error}doc '$@' failed: see *debug* buffer for details}"
|
2016-11-03 14:57:55 +03:00
|
|
|
rm ${manout}
|
2016-02-02 22:15:12 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -params 1..2 \
|
2016-08-30 17:23:42 +03:00
|
|
|
-shell-candidates %{
|
2017-09-30 08:15:14 +03:00
|
|
|
find "${kak_runtime}/doc/" -type f -name "*.gz" | while read l; do
|
2016-12-14 03:59:19 +03:00
|
|
|
basename "${l%.*}"
|
2016-02-03 22:09:17 +03:00
|
|
|
done
|
2016-02-02 22:15:12 +03:00
|
|
|
} \
|
2016-10-11 10:03:41 +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} %{
|
2016-02-02 22:15:12 +03:00
|
|
|
%sh{
|
2017-08-03 11:00:02 +03:00
|
|
|
readonly PATH_DOC="${kak_runtime}/doc/${1}.gz"
|
2016-02-02 22:15:12 +03:00
|
|
|
|
|
|
|
shift
|
2017-05-27 08:14:01 +03:00
|
|
|
if [ -f "${PATH_DOC}" ]; then
|
|
|
|
printf %s\\n "eval -try-client %opt{docsclient} doc-open ${PATH_DOC} $@"
|
|
|
|
else
|
2017-07-19 18:18:52 +03:00
|
|
|
printf %s\\n "echo -markup '{Error}No such doc file: ${PATH_DOC}'"
|
2016-02-02 22:15:12 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 21:26:19 +03:00
|
|
|
|
|
|
|
alias global help doc
|