2016-11-03 12:57:55 +01:00
|
|
|
decl str docsclient
|
|
|
|
|
2017-01-13 01:56:30 +01:00
|
|
|
def -hidden -params 1..2 doc-open %{
|
2016-02-02 20:15:12 +01:00
|
|
|
%sh{
|
|
|
|
manout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
|
2016-11-03 12:57:55 +01:00
|
|
|
# Those options are handled by the `man-db` implementation
|
|
|
|
export MAN_KEEP_FORMATTING=y
|
|
|
|
export MANWIDTH=${kak_window_width}
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2016-12-14 02:02:53 +01:00
|
|
|
if man "$1" > "${manout}"; then
|
2016-12-20 08:54:37 +01:00
|
|
|
sed -ie $(printf 's/.\x8//g') "${manout}"
|
2016-02-02 20:15:12 +01:00
|
|
|
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "
|
2016-02-02 20:15:12 +01:00
|
|
|
edit! -scratch '*doc*'
|
2016-11-03 12:57:55 +01:00
|
|
|
exec |cat<space>${manout}<ret>gg
|
|
|
|
nop %sh{rm ${manout}}
|
2016-02-02 20:15:12 +01:00
|
|
|
set buffer filetype man
|
|
|
|
"
|
|
|
|
|
|
|
|
if [ $# -gt 1 ]; then
|
2016-04-23 07:47:01 +02:00
|
|
|
needle=$(printf %s\\n "$2" | sed 's,<,<lt>,g')
|
|
|
|
printf %s\\n "try %{ exec '%<a-s><a-k>(?i)^\h+[^\n]*?\Q${needle}\E<ret>\'' } catch %{ exec <space>gg }"
|
2016-02-02 20:15:12 +01:00
|
|
|
fi
|
|
|
|
else
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "echo -color Error %{doc '$@' failed: see *debug* buffer for details}"
|
2016-11-03 12:57:55 +01:00
|
|
|
rm ${manout}
|
2016-02-02 20:15:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -params 1..2 \
|
2016-08-30 16:23:42 +02:00
|
|
|
-shell-candidates %{
|
2016-12-14 01:59:19 +01:00
|
|
|
find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*.gz" | while read l; do
|
|
|
|
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{
|
2016-02-04 00:46:01 +01:00
|
|
|
readonly PATH_DOC="${kak_runtime}/../doc/kak/manpages/${1}.gz"
|
2016-02-02 20:15:12 +01:00
|
|
|
|
|
|
|
shift
|
|
|
|
if [ ! -f "${PATH_DOC}" ]; then
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "echo -color Error No such doc file: ${PATH_DOC}"
|
2016-02-02 20:15:12 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2017-01-13 01:56:30 +01:00
|
|
|
printf %s\\n "eval -try-client %opt{docsclient} doc-open ${PATH_DOC} $@"
|
2016-02-02 20:15:12 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-13 19:26:19 +01:00
|
|
|
|
|
|
|
alias global help doc
|