2013-04-18 19:07:31 +02:00
|
|
|
decl str docsclient
|
|
|
|
|
2016-05-14 18:09:26 +02:00
|
|
|
decl -hidden str _manpage
|
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group man-highlight global WinSetOption filetype=man %{
|
2013-04-18 19:07:31 +02:00
|
|
|
addhl group man-highlight
|
2016-02-02 07:16:23 +01:00
|
|
|
# Sections
|
2013-04-18 19:07:31 +02:00
|
|
|
addhl -group man-highlight regex ^\S.*?$ 0:blue
|
2016-02-02 07:16:23 +01:00
|
|
|
# Subsections
|
|
|
|
addhl -group man-highlight regex '^ {3}\S.*?$' 0:default+b
|
|
|
|
# Command line options
|
|
|
|
addhl -group man-highlight regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:yellow
|
|
|
|
# References to other manpages
|
|
|
|
addhl -group man-highlight regex [-a-zA-Z0-9_.]+\(\d\) 0:green
|
2016-09-25 15:15:07 +02:00
|
|
|
}
|
2016-05-14 18:09:26 +02:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook global WinSetOption filetype=man %{
|
2016-05-14 18:09:26 +02:00
|
|
|
hook -group man-hooks window WinResize .* %{
|
|
|
|
_man %opt{_manpage}
|
|
|
|
}
|
2013-04-18 19:07:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!man).* %{
|
|
|
|
rmhl man-higlight
|
|
|
|
rmhooks window man-hooks
|
|
|
|
}
|
|
|
|
|
2016-05-14 18:09:26 +02:00
|
|
|
def -hidden -params 1..2 _man %{ %sh{
|
2014-03-06 22:33:01 +01:00
|
|
|
manout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
colout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
MANWIDTH=${kak_window_width} man "$@" > $manout
|
|
|
|
retval=$?
|
2016-02-02 07:16:23 +01:00
|
|
|
col -b -x > ${colout} < ${manout}
|
2014-03-06 22:33:01 +01:00
|
|
|
rm ${manout}
|
|
|
|
if [ "${retval}" -eq 0 ]; then
|
2016-05-14 18:09:26 +02:00
|
|
|
printf %s\\n "
|
|
|
|
edit -scratch '*man*'
|
|
|
|
exec '%|cat<space>${colout}<ret>gk'
|
|
|
|
nop %sh{rm ${colout}}
|
|
|
|
set buffer filetype man
|
|
|
|
set window _manpage '$@'
|
|
|
|
"
|
2013-04-18 19:07:31 +02:00
|
|
|
else
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "echo -color Error %{man '$@' failed: see *debug* buffer for details }"
|
2014-03-06 22:33:01 +01:00
|
|
|
rm ${colout}
|
2013-04-18 19:07:31 +02:00
|
|
|
fi
|
2013-12-07 14:56:56 +01:00
|
|
|
} }
|
|
|
|
|
2015-12-01 15:00:55 +01:00
|
|
|
def -params .. \
|
2015-07-03 22:00:10 +02:00
|
|
|
-shell-completion %{
|
2016-04-23 07:47:01 +02:00
|
|
|
prefix=$(printf %s\\n "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null)
|
2015-09-11 13:55:55 +02:00
|
|
|
for page in /usr/share/man/*/${prefix}*.[1-8]*; do
|
|
|
|
candidate=$(basename ${page%%.[1-8]*})
|
2016-04-23 07:47:01 +02:00
|
|
|
pagenum=$(printf %s\\n "$page" | sed 's,^.*\.\([1-8].*\)\..*$,\1,')
|
2015-07-20 14:16:05 +02:00
|
|
|
case $candidate in
|
|
|
|
*\*) ;;
|
2016-04-23 07:47:01 +02:00
|
|
|
*) printf %s\\n "$candidate($pagenum)";;
|
2015-07-20 14:16:05 +02:00
|
|
|
esac
|
2015-07-03 22:00:10 +02:00
|
|
|
done
|
|
|
|
} \
|
2015-08-03 20:44:27 +02:00
|
|
|
man -docstring "Manpages viewer wrapper" %{ %sh{
|
2015-12-01 10:09:26 +01:00
|
|
|
subject=${@-$kak_selection}
|
|
|
|
|
|
|
|
## The completion suggestions display the page number, strip them if present
|
2016-03-16 13:10:47 +01:00
|
|
|
pagenum=$(expr "$subject" : '.*(\([1-8].*\))')
|
|
|
|
if [ -n "$pagenum" ]; then
|
2015-12-01 10:09:26 +01:00
|
|
|
subject=${subject%%\(*}
|
|
|
|
fi
|
|
|
|
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject"
|
2013-12-07 14:56:56 +01:00
|
|
|
} }
|