2017-05-16 14:35:43 +03:00
|
|
|
decl -docstring "name of the client in which documentation is to be displayed" \
|
|
|
|
str docsclient
|
2013-04-18 21:07:31 +04:00
|
|
|
|
2017-05-27 09:40:47 +03:00
|
|
|
decl -hidden str manpage
|
2016-05-14 19:09:26 +03:00
|
|
|
|
2016-09-25 16:15:07 +03:00
|
|
|
hook -group man-highlight global WinSetOption filetype=man %{
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter window group man-highlight
|
2016-02-02 09:16:23 +03:00
|
|
|
# Sections
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter window/man-highlight regex ^\S.*?$ 0:blue
|
2016-02-02 09:16:23 +03:00
|
|
|
# Subsections
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter window/man-highlight regex '^ {3}\S.*?$' 0:default+b
|
2016-02-02 09:16:23 +03:00
|
|
|
# Command line options
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter window/man-highlight regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:yellow
|
2016-02-02 09:16:23 +03:00
|
|
|
# References to other manpages
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter window/man-highlight regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:green
|
2016-09-25 16:15:07 +03:00
|
|
|
}
|
2016-05-14 19:09:26 +03:00
|
|
|
|
2016-09-25 16:15:07 +03:00
|
|
|
hook global WinSetOption filetype=man %{
|
2016-05-14 19:09:26 +03:00
|
|
|
hook -group man-hooks window WinResize .* %{
|
2017-05-27 09:40:47 +03:00
|
|
|
man-impl %opt{manpage}
|
2016-05-14 19:09:26 +03:00
|
|
|
}
|
2013-04-18 21:07:31 +04:00
|
|
|
}
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
hook -group man-highlight global WinSetOption filetype=(?!man).* %{ remove-highlighter window/man-highlight }
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2013-04-18 21:07:31 +04:00
|
|
|
hook global WinSetOption filetype=(?!man).* %{
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks window man-hooks
|
2013-04-18 21:07:31 +04:00
|
|
|
}
|
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
def -hidden -params 1..2 man-impl %{ %sh{
|
2017-06-09 14:05:31 +03:00
|
|
|
manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX)
|
|
|
|
colout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX)
|
2017-09-30 08:23:10 +03:00
|
|
|
MANWIDTH=${kak_window_width} man "$@" > $manout 2>/dev/null
|
2014-03-07 01:33:01 +04:00
|
|
|
retval=$?
|
2016-02-02 09:16:23 +03:00
|
|
|
col -b -x > ${colout} < ${manout}
|
2014-03-07 01:33:01 +04:00
|
|
|
rm ${manout}
|
|
|
|
if [ "${retval}" -eq 0 ]; then
|
2016-05-14 19:09:26 +03:00
|
|
|
printf %s\\n "
|
|
|
|
edit -scratch '*man*'
|
|
|
|
exec '%|cat<space>${colout}<ret>gk'
|
|
|
|
nop %sh{rm ${colout}}
|
|
|
|
set buffer filetype man
|
2017-05-27 09:40:47 +03:00
|
|
|
set window manpage '$@'
|
2016-05-14 19:09:26 +03:00
|
|
|
"
|
2013-04-18 21:07:31 +04:00
|
|
|
else
|
2017-07-19 18:18:52 +03:00
|
|
|
printf %s\\n "echo -markup %{{Error}man '$@' failed: see *debug* buffer for details}"
|
2014-03-07 01:33:01 +04:00
|
|
|
rm ${colout}
|
2013-04-18 21:07:31 +04:00
|
|
|
fi
|
2013-12-07 17:56:56 +04:00
|
|
|
} }
|
|
|
|
|
2016-10-11 10:03:41 +03:00
|
|
|
def -params ..1 \
|
2015-07-03 23:00:10 +03:00
|
|
|
-shell-completion %{
|
2016-04-23 08:47:01 +03:00
|
|
|
prefix=$(printf %s\\n "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null)
|
2015-09-11 14:55:55 +03:00
|
|
|
for page in /usr/share/man/*/${prefix}*.[1-8]*; do
|
|
|
|
candidate=$(basename ${page%%.[1-8]*})
|
2017-05-23 15:59:31 +03:00
|
|
|
pagenum=$(printf %s\\n "$page" | sed 's,^.*\.\([1-8][^.]*\).*$,\1,')
|
2015-07-20 15:16:05 +03:00
|
|
|
case $candidate in
|
|
|
|
*\*) ;;
|
2016-04-23 08:47:01 +03:00
|
|
|
*) printf %s\\n "$candidate($pagenum)";;
|
2015-07-20 15:16:05 +03:00
|
|
|
esac
|
2015-07-03 23:00:10 +03:00
|
|
|
done
|
|
|
|
} \
|
2016-10-11 10:03:41 +03:00
|
|
|
-docstring %{man [<page>]: manpage viewer wrapper
|
|
|
|
If no argument is passed to the command, the selection will be used as page
|
|
|
|
The page can be a word, or a word directly followed by a section number between parenthesis, e.g. kak(1)} \
|
|
|
|
man %{ %sh{
|
2015-12-01 12:09:26 +03:00
|
|
|
subject=${@-$kak_selection}
|
|
|
|
|
|
|
|
## The completion suggestions display the page number, strip them if present
|
2017-07-17 08:16:34 +03:00
|
|
|
case "${subject}" in
|
|
|
|
*\([1-8]*\))
|
|
|
|
pagenum="${subject##*(}"
|
|
|
|
pagenum="${pagenum%)}"
|
|
|
|
subject="${subject%%(*}"
|
|
|
|
;;
|
|
|
|
esac
|
2015-12-01 12:09:26 +03:00
|
|
|
|
2017-01-13 03:56:30 +03:00
|
|
|
printf %s\\n "eval -collapse-jumps -try-client %opt{docsclient} man-impl $pagenum $subject"
|
2013-12-07 17:56:56 +04:00
|
|
|
} }
|