1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-25 10:32:19 +03:00
kakoune/rc/core/man.kak

61 lines
1.8 KiB
Plaintext
Raw Normal View History

decl str docsclient
hook global WinSetOption filetype=man %{
addhl group man-highlight
# Sections
addhl -group man-highlight regex ^\S.*?$ 0:blue
# 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
}
hook global WinSetOption filetype=(?!man).* %{
rmhl man-higlight
rmhooks window man-hooks
}
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=$?
col -b -x > ${colout} < ${manout}
2014-03-07 01:33:01 +04:00
rm ${manout}
if [ "${retval}" -eq 0 ]; then
echo "edit! -scratch '*man*'
2014-03-07 01:33:01 +04:00
exec |cat<space>${colout}<ret>gk
nop %sh{rm ${colout}}
set buffer filetype man"
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}
fi
} }
def -params .. \
-shell-completion %{
prefix=$(echo "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null)
for page in /usr/share/man/*/${prefix}*.[1-8]*; do
candidate=$(basename ${page%%.[1-8]*})
pagenum=$(printf %s "$page" | sed -r 's,^.+/.+\.([1-8][^.]*)\..+$,\1,')
case $candidate in
*\*) ;;
*) echo $candidate\($pagenum\);;
esac
done
} \
man -docstring "Manpages viewer wrapper" %{ %sh{
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
subject=${subject%%\(*}
fi
2016-03-21 16:44:31 +03:00
echo "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject"
} }