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