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-12-06 07:49:38 +01:00
|
|
|
man-impl %val{bufname} %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
|
|
|
}
|
|
|
|
|
2018-05-06 23:29:52 +02:00
|
|
|
define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{
|
2017-12-06 07:49:38 +01:00
|
|
|
buffer_name="$1"
|
|
|
|
shift
|
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 "
|
2017-12-06 07:49:38 +01:00
|
|
|
edit -scratch '$buffer_name'
|
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 \
|
2017-12-06 07:10:10 +01:00
|
|
|
-shell-candidates %{
|
|
|
|
find /usr/share/man/ -name '*.[1-8]*' | sed 's,^.*/\(.*\)\.\([1-8][a-zA-Z]*\).*$,\1(\2),'
|
2015-07-03 22:00:10 +02:00
|
|
|
} \
|
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)} \
|
2018-05-06 23:29:52 +02:00
|
|
|
man %{ evaluate-commands %sh{
|
2017-12-06 06:23:39 +01:00
|
|
|
subject=${1-$kak_selection}
|
2015-12-01 10:09:26 +01:00
|
|
|
|
|
|
|
## 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
|
|
|
|
2018-02-24 09:02:15 +01:00
|
|
|
printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl *man* $pagenum $subject"
|
2013-12-07 14:56:56 +01:00
|
|
|
} }
|