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
|
|
|
|
|
2019-04-20 21:39:40 +02:00
|
|
|
|
declare-option -hidden str-list 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 %{
|
2018-07-05 10:00:37 +02:00
|
|
|
|
add-highlighter window/man-highlight group
|
2016-02-02 07:16:23 +01:00
|
|
|
|
# Sections
|
2018-08-09 11:27:40 +02:00
|
|
|
|
add-highlighter window/man-highlight/ regex ^\S.*?$ 0:title
|
2016-02-02 07:16:23 +01:00
|
|
|
|
# Subsections
|
2018-07-05 10:00:37 +02:00
|
|
|
|
add-highlighter window/man-highlight/ regex '^ {3}\S.*?$' 0:default+b
|
2016-02-02 07:16:23 +01:00
|
|
|
|
# Command line options
|
2018-08-09 11:27:40 +02:00
|
|
|
|
add-highlighter window/man-highlight/ regex '^ {7}-[^\s,]+(,\s+-[^\s,]+)*' 0:list
|
2016-02-02 07:16:23 +01:00
|
|
|
|
# References to other manpages
|
2018-08-09 11:27:40 +02:00
|
|
|
|
add-highlighter window/man-highlight/ regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:header
|
2016-05-14 18:09:26 +02:00
|
|
|
|
|
2022-07-30 22:28:02 +02:00
|
|
|
|
map window normal <ret> :man-jump<ret>
|
2019-04-24 21:39:26 +02:00
|
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{
|
|
|
|
|
remove-highlighter window/man-highlight
|
|
|
|
|
unmap window normal <ret>
|
|
|
|
|
}
|
2013-04-18 19:07:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 10:39:07 +01:00
|
|
|
|
hook global WinSetOption filetype=man %{
|
2019-04-20 21:39:40 +02:00
|
|
|
|
hook -group man-hooks window WinResize .* %{ man-impl %opt{manpage} }
|
2018-12-11 00:11:35 +01:00
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window man-hooks }
|
2013-04-18 19:07:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 14:47:46 +02:00
|
|
|
|
define-command -hidden -params ..3 man-impl %{ evaluate-commands %sh{
|
2017-12-06 07:49:38 +01:00
|
|
|
|
buffer_name="$1"
|
2020-06-03 14:47:46 +02:00
|
|
|
|
if [ -z "${buffer_name}" ]; then
|
|
|
|
|
exit
|
|
|
|
|
fi
|
2017-12-06 07:49:38 +01:00
|
|
|
|
shift
|
2020-11-30 12:24:06 +01:00
|
|
|
|
manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man.XXXXXX)
|
|
|
|
|
manerr=$(mktemp "${TMPDIR:-/tmp}"/kak-man.XXXXXX)
|
|
|
|
|
colout=$(mktemp "${TMPDIR:-/tmp}"/kak-man.XXXXXX)
|
2019-10-20 21:38:58 +02:00
|
|
|
|
env MANWIDTH=${kak_window_range##* } man "$@" > "$manout" 2> "$manerr"
|
2014-03-06 22:33:01 +01:00
|
|
|
|
retval=$?
|
2021-01-25 07:09:59 +01:00
|
|
|
|
if command -v col >/dev/null; then
|
|
|
|
|
col -b -x > ${colout} < ${manout}
|
|
|
|
|
else
|
|
|
|
|
sed 's/.//g' > ${colout} < ${manout}
|
|
|
|
|
fi
|
2014-03-06 22:33:01 +01:00
|
|
|
|
rm ${manout}
|
2021-01-25 07:09:59 +01:00
|
|
|
|
|
2014-03-06 22:33:01 +01:00
|
|
|
|
if [ "${retval}" -eq 0 ]; then
|
2016-05-14 18:09:26 +02:00
|
|
|
|
printf %s\\n "
|
2019-04-20 21:39:40 +02:00
|
|
|
|
edit -scratch %{*$buffer_name ${*}*}
|
2017-11-03 09:09:45 +01:00
|
|
|
|
execute-keys '%|cat<space>${colout}<ret>gk'
|
2019-04-16 23:22:42 +02:00
|
|
|
|
nop %sh{ rm ${colout}; rm ${manerr} }
|
2017-11-03 08:34:41 +01:00
|
|
|
|
set-option buffer filetype man
|
2019-04-20 21:39:40 +02:00
|
|
|
|
set-option window manpage $buffer_name $*
|
2016-05-14 18:09:26 +02:00
|
|
|
|
"
|
2013-04-18 19:07:31 +02:00
|
|
|
|
else
|
2019-11-14 08:32:55 +01:00
|
|
|
|
printf '
|
|
|
|
|
fail %%{%s}
|
|
|
|
|
nop %%sh{ rm "%s"; rm "%s" }
|
|
|
|
|
' "$(cat "$manerr")" "${colout}" "${manerr}"
|
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 \
|
2020-02-03 20:53:28 +01:00
|
|
|
|
-shell-script-candidates %{
|
2023-11-18 09:12:05 +01:00
|
|
|
|
find /usr/share/man/ $(printf %s "${MANPATH}" |
|
|
|
|
|
sed 's/:/ /') -name '*.[1-8]*' |
|
|
|
|
|
sed 's,^.*/\(.*\)\.\([1-8][a-zA-Z]*\).*$,\1(\2),' |
|
|
|
|
|
sort
|
2020-02-03 20:53:28 +01: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 %{ 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]*\))
|
2019-06-07 21:34:21 +02:00
|
|
|
|
pagenum="${subject##*\(}"
|
|
|
|
|
pagenum="${pagenum%\)}"
|
|
|
|
|
subject="${subject%%\(*}"
|
2017-07-17 07:16:34 +02:00
|
|
|
|
;;
|
2020-08-23 18:55:50 +02:00
|
|
|
|
*)
|
|
|
|
|
pagenum=""
|
|
|
|
|
;;
|
2017-07-17 07:16:34 +02:00
|
|
|
|
esac
|
2015-12-01 10:09:26 +01:00
|
|
|
|
|
2019-04-20 21:39:40 +02:00
|
|
|
|
printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl man $pagenum $subject"
|
2013-12-07 14:56:56 +01:00
|
|
|
|
} }
|
2019-04-24 21:39:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# The following section of code enables a user
|
|
|
|
|
# to go to next or previous man page links and to follow man page links,
|
|
|
|
|
# for example, apropos(1), that would normally appear in SEE ALSO sections.
|
|
|
|
|
# The user would position the cursor on any character of the link
|
|
|
|
|
# and then press <ret> to change to a buffer showing the man page.
|
|
|
|
|
|
|
|
|
|
# Regex pattern defining a man page link.
|
|
|
|
|
# Used for determining if a selection, which may just be a link, is a link.
|
|
|
|
|
declare-option -hidden regex man_link1 \
|
|
|
|
|
[\w_.:-]+\(\d[a-z]*\)
|
|
|
|
|
|
|
|
|
|
# Same as above but with lookbehind and lookahead patterns.
|
|
|
|
|
# Used for searching for a man page link.
|
|
|
|
|
declare-option -hidden regex man_link2 \
|
|
|
|
|
"(?:^|(?<=\W))%opt{man_link1}(?=\W)"
|
|
|
|
|
|
|
|
|
|
# Define a useful command sequence for searching a given regex
|
|
|
|
|
# and a given sequence of search keys.
|
2022-07-29 20:26:43 +02:00
|
|
|
|
define-command -hidden man-search -params 2 %{
|
2021-11-04 05:31:43 +01:00
|
|
|
|
set-register / %arg[1]
|
|
|
|
|
try %{
|
|
|
|
|
execute-keys %arg[2]
|
|
|
|
|
} catch %{
|
|
|
|
|
fail "Could not find man page link"
|
|
|
|
|
}
|
2019-04-24 21:39:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
define-command -docstring 'Go to next man page link' \
|
|
|
|
|
man-link-next %{ man-search %opt[man_link2] n }
|
|
|
|
|
|
|
|
|
|
define-command -docstring 'Go to previous man page link' \
|
|
|
|
|
man-link-prev %{ man-search %opt[man_link2] <a-n> }
|
|
|
|
|
|
|
|
|
|
define-command -docstring 'Try to jump to a man page' \
|
|
|
|
|
man-jump %{
|
2022-07-29 20:42:59 +02:00
|
|
|
|
try %{ execute-keys <a-a><a-w> s %opt[man_link1] <ret> } catch %{ fail 'Not a valid man page link' }
|
2019-04-24 21:39:26 +02:00
|
|
|
|
try %{ man } catch %{ fail 'No man page link to follow' }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Suggested keymaps for a user mode
|
2021-11-04 05:15:43 +01:00
|
|
|
|
declare-user-mode man
|
2019-04-24 21:39:26 +02:00
|
|
|
|
|
2022-07-30 22:28:02 +02:00
|
|
|
|
map global man 'g' -docstring 'Jump to a man page using selected man page link' :man-jump<ret>
|
|
|
|
|
map global man 'j' -docstring 'Go to next man page link' :man-link-next<ret>
|
|
|
|
|
map global man 'k' -docstring 'Go to previous man page link' :man-link-prev<ret>
|
|
|
|
|
map global man 'm' -docstring 'Look up a man page' :man<space>
|