2013-04-18 21:07:31 +04:00
|
|
|
decl str docsclient
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=man %{
|
|
|
|
addhl group man-highlight
|
2016-02-02 09:16:23 +03:00
|
|
|
# Sections
|
2013-04-18 21:07:31 +04:00
|
|
|
addhl -group man-highlight regex ^\S.*?$ 0:blue
|
2016-02-02 09:16:23 +03: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
|
2013-04-18 21:07:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!man).* %{
|
|
|
|
rmhl man-higlight
|
|
|
|
rmhooks window man-hooks
|
|
|
|
}
|
|
|
|
|
2015-12-01 17:00:55 +03:00
|
|
|
def -hidden -params .. _man %{ %sh{
|
2014-03-07 01:33:01 +04:00
|
|
|
manout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
colout=$(mktemp /tmp/kak-man-XXXXXX)
|
|
|
|
MANWIDTH=${kak_window_width} man "$@" > $manout
|
|
|
|
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
|
2013-04-18 21:07:31 +04:00
|
|
|
echo "edit! -scratch '*man*'
|
2014-03-07 01:33:01 +04:00
|
|
|
exec |cat<space>${colout}<ret>gk
|
|
|
|
nop %sh{rm ${colout}}
|
2013-10-30 13:38:40 +04:00
|
|
|
set buffer filetype man"
|
2013-04-18 21:07:31 +04:00
|
|
|
else
|
2014-01-08 23:18:51 +04:00
|
|
|
echo "echo -color 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
|
|
|
} }
|
|
|
|
|
2015-12-01 17:00:55 +03:00
|
|
|
def -params .. \
|
2015-07-03 23:00:10 +03:00
|
|
|
-shell-completion %{
|
2016-03-14 23:59:23 +03:00
|
|
|
prefix=$(echo "$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]*})
|
2016-01-10 23:41:46 +03:00
|
|
|
pagenum=$(printf %s "$page" | sed -r 's,^.+/.+\.([1-8][^.]*)\..+$,\1,')
|
2015-07-20 15:16:05 +03:00
|
|
|
case $candidate in
|
|
|
|
*\*) ;;
|
2015-12-01 12:09:26 +03:00
|
|
|
*) echo $candidate\($pagenum\);;
|
2015-07-20 15:16:05 +03:00
|
|
|
esac
|
2015-07-03 23:00:10 +03:00
|
|
|
done
|
|
|
|
} \
|
2015-08-03 21:44:27 +03:00
|
|
|
man -docstring "Manpages viewer wrapper" %{ %sh{
|
2015-12-01 12:09:26 +03:00
|
|
|
subject=${@-$kak_selection}
|
|
|
|
|
|
|
|
## The completion suggestions display the page number, strip them if present
|
2016-03-16 15:10:47 +03:00
|
|
|
pagenum=$(expr "$subject" : '.*(\([1-8].*\))')
|
|
|
|
if [ -n "$pagenum" ]; then
|
2015-12-01 12:09:26 +03:00
|
|
|
subject=${subject%%\(*}
|
|
|
|
fi
|
|
|
|
|
2016-03-21 16:44:31 +03:00
|
|
|
echo "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject"
|
2013-12-07 17:56:56 +04:00
|
|
|
} }
|