2017-11-03 08:34:41 +01:00
|
|
|
declare-option -docstring "name of the client in which documentation is to be displayed" \
|
2017-05-16 13:35:43 +02:00
|
|
|
str docsclient
|
2013-04-18 19:07:31 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
declare-option -hidden str manpage
|
2016-05-14 18:09:26 +02:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group man-highlight global WinSetOption filetype=man %{
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter window group man-highlight
|
2016-02-02 07:16:23 +01:00
|
|
|
# Sections
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter window/man-highlight regex ^\S.*?$ 0:blue
|
2016-02-02 07:16:23 +01:00
|
|
|
# Subsections
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter window/man-highlight regex '^ {3}\S.*?$' 0:default+b
|
2016-02-02 07:16:23 +01:00
|
|
|
# Command line options
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter window/man-highlight regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:yellow
|
2016-02-02 07:16:23 +01:00
|
|
|
# References to other manpages
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter window/man-highlight regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 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 .* %{
|
2017-05-27 08:40:47 +02:00
|
|
|
man-impl %opt{manpage}
|
2016-05-14 18:09:26 +02:00
|
|
|
}
|
2013-04-18 19:07:31 +02:00
|
|
|
}
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group man-highlight global WinSetOption filetype=(?!man).* %{ remove-highlighter window/man-highlight }
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2013-04-18 19:07:31 +02:00
|
|
|
hook global WinSetOption filetype=(?!man).* %{
|
2017-01-04 01:07:45 +01:00
|
|
|
remove-hooks window man-hooks
|
2013-04-18 19:07:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden -params 1..2 man-impl %{ %sh{
|
2017-06-09 13:05:31 +02:00
|
|
|
manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX)
|
|
|
|
colout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX)
|
2017-09-30 07:23:10 +02:00
|
|
|
MANWIDTH=${kak_window_width} man "$@" > $manout 2>/dev/null
|
2014-03-06 22:33:01 +01:00
|
|
|
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*'
|
2017-11-03 09:09:45 +01:00
|
|
|
execute-keys '%|cat<space>${colout}<ret>gk'
|
2016-05-14 18:09:26 +02:00
|
|
|
nop %sh{rm ${colout}}
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype man
|
|
|
|
set-option window manpage '$@'
|
2016-05-14 18:09:26 +02:00
|
|
|
"
|
2013-04-18 19:07:31 +02:00
|
|
|
else
|
2017-07-19 17:18:52 +02:00
|
|
|
printf %s\\n "echo -markup %{{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
|
|
|
} }
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -params ..1 \
|
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]*})
|
2017-05-23 14:59:31 +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
|
|
|
|
} \
|
2016-10-11 09:03:41 +02: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 10:09:26 +01:00
|
|
|
subject=${@-$kak_selection}
|
|
|
|
|
|
|
|
## The completion suggestions display the page number, strip them if present
|
2017-07-17 07:16:34 +02:00
|
|
|
case "${subject}" in
|
|
|
|
*\([1-8]*\))
|
|
|
|
pagenum="${subject##*(}"
|
|
|
|
pagenum="${pagenum%)}"
|
|
|
|
subject="${subject%%(*}"
|
|
|
|
;;
|
|
|
|
esac
|
2015-12-01 10:09:26 +01:00
|
|
|
|
2017-11-03 09:09:45 +01:00
|
|
|
printf %s\\n "evaluate-commands -collapse-jumps -try-client %opt{docsclient} man-impl $pagenum $subject"
|
2013-12-07 14:56:56 +01:00
|
|
|
} }
|