kakoune/rc/core/doc.kak
Frank LENORMAND f6a2925950 Fix, complete and add docstring documentation to builtin commands
Level out the builtin commands loaded at startup in terms of format and
expressiveness. The following convention was followed:
* commands that take more than one argument have to be described along
  with their parameters prior to the actual documentation, otherwise the
  docstring consists in a capitalized sentence
  e.g. `command <arg1>: do something`
* optional arguments are enclosed in square brackets, to comply with the
  format used for hardcoded commands
  e.g. `cd [<directory>]`
* describe the effects of the command in the documentation string and
  omit implementation details unless they are relevant. Usually command
  names include the name of the tool they use, so they don't need to be
  redundantly mentioned
  e.g. `tmux-new-pane <arguments>: open a new pane`
* document the format the parameters to the commands, or list them if
  they are to be chosen among a list of static values (c.f. `spell.kak`)
2016-10-11 10:26:17 +03:00

51 lines
1.6 KiB
Plaintext

def -hidden -params 1..2 _doc-open %{
%sh{
manout=$(mktemp /tmp/kak-man-XXXXXX)
colout=$(mktemp /tmp/kak-man-XXXXXX)
MANWIDTH=${kak_window_width} man "$1" > $manout
retval=$?
col -b -x > ${colout} < ${manout}
rm ${manout}
if [ "${retval}" -eq 0 ]; then
printf %s\\n "
edit! -scratch '*doc*'
exec |cat<space>${colout}<ret>gg
nop %sh{rm ${colout}}
set buffer filetype man
"
if [ $# -gt 1 ]; then
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 }"
fi
else
printf %s\\n "echo -color Error %{doc '$@' failed: see *debug* buffer for details}"
rm ${colout}
fi
}
}
def -params 1..2 \
-shell-candidates %{
find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*.gz" -printf '%f\n' | while read l; do
printf %s\\n "${l%.*}"
done
} \
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} %{
%sh{
readonly PATH_DOC="${kak_runtime}/../doc/kak/manpages/${1}.gz"
shift
if [ ! -f "${PATH_DOC}" ]; then
printf %s\\n "echo -color Error No such doc file: ${PATH_DOC}"
exit
fi
printf %s\\n "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@"
}
}