2016-02-02 22:15:12 +03:00
|
|
|
def -hidden -params 1..2 _doc-open %{
|
|
|
|
%sh{
|
|
|
|
manout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
colout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
|
2016-02-04 02:46:01 +03:00
|
|
|
MANWIDTH=${kak_window_width} man "$1" > $manout
|
2016-02-02 22:15:12 +03:00
|
|
|
retval=$?
|
|
|
|
|
|
|
|
col -b -x > ${colout} < ${manout}
|
|
|
|
rm ${manout}
|
|
|
|
|
|
|
|
if [ "${retval}" -eq 0 ]; then
|
|
|
|
echo "
|
|
|
|
edit! -scratch '*doc*'
|
|
|
|
exec |cat<space>${colout}<ret>gg
|
|
|
|
nop %sh{rm ${colout}}
|
|
|
|
set buffer filetype man
|
|
|
|
"
|
|
|
|
|
|
|
|
if [ $# -gt 1 ]; then
|
2016-04-12 10:41:16 +03:00
|
|
|
needle=$(printf %s "$2" | sed 's,<,<lt>,g')
|
|
|
|
echo "try %{ exec '%<a-s><a-k>(?i)^\h+[^\n]*?\Q${needle}\E<ret>\'' } catch %{ exec <space>gg }"
|
2016-02-02 22:15:12 +03:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "echo -color Error %{doc '$@' failed: see *debug* buffer for details}"
|
|
|
|
rm ${colout}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -params 1..2 \
|
|
|
|
-shell-completion %{
|
2016-02-04 02:46:01 +03:00
|
|
|
find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*$@*.gz" -printf '%f\n' | while read l; do
|
2016-02-03 22:09:17 +03:00
|
|
|
echo "${l%.*}"
|
|
|
|
done
|
2016-02-02 22:15:12 +03:00
|
|
|
} \
|
|
|
|
doc -docstring "Open a buffer containing the documentation about a given subject" %{
|
|
|
|
%sh{
|
2016-02-04 02:46:01 +03:00
|
|
|
readonly PATH_DOC="${kak_runtime}/../doc/kak/manpages/${1}.gz"
|
2016-02-02 22:15:12 +03:00
|
|
|
|
|
|
|
shift
|
|
|
|
if [ ! -f "${PATH_DOC}" ]; then
|
|
|
|
echo "echo -color Error No such doc file: ${PATH_DOC}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@"
|
|
|
|
}
|
|
|
|
}
|