1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 17:02:06 +03:00
kakoune/rc/core/man.kak

76 lines
2.5 KiB
Plaintext
Raw Normal View History

decl str docsclient
decl -hidden str _manpage
hook -group man-highlight global WinSetOption filetype=man %{
2017-01-04 03:07:45 +03:00
add-highlighter group man-highlight
# Sections
2017-01-04 03:07:45 +03:00
add-highlighter -group man-highlight regex ^\S.*?$ 0:blue
# Subsections
2017-01-04 03:07:45 +03:00
add-highlighter -group man-highlight regex '^ {3}\S.*?$' 0:default+b
# Command line options
2017-01-04 03:07:45 +03:00
add-highlighter -group man-highlight regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:yellow
# References to other manpages
2017-01-04 03:07:45 +03:00
add-highlighter -group man-highlight regex [-a-zA-Z0-9_.]+\(\d\) 0:green
}
hook global WinSetOption filetype=man %{
hook -group man-hooks window WinResize .* %{
_man %opt{_manpage}
}
}
2017-01-04 03:07:45 +03:00
hook -group man-highlight global WinSetOption filetype=(?!man).* %{ remove-highlighter man-highlight }
hook global WinSetOption filetype=(?!man).* %{
2017-01-04 03:07:45 +03:00
remove-hooks window man-hooks
}
def -hidden -params 1..2 _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
printf %s\\n "
edit -scratch '*man*'
exec '%|cat<space>${colout}<ret>gk'
nop %sh{rm ${colout}}
set buffer filetype man
set window _manpage '$@'
"
else
printf %s\\n "echo -color Error %{man '$@' failed: see *debug* buffer for details }"
2014-03-07 01:33:01 +04:00
rm ${colout}
fi
} }
def -params ..1 \
-shell-completion %{
prefix=$(printf %s\\n "$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\\n "$page" | sed 's,^.*\.\([1-8].*\)\..*$,\1,')
case $candidate in
*\*) ;;
*) printf %s\\n "$candidate($pagenum)";;
esac
done
} \
-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{
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
printf %s\\n "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject"
} }