From 734a7d07072b686bda7bcf7fe249e6f43ef7104e Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Sat, 20 Apr 2019 12:39:40 -0700 Subject: [PATCH 1/3] Re-implement PR #1927 - `man` bufname should indicate man page. --- rc/tools/man.kak | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rc/tools/man.kak b/rc/tools/man.kak index 41d91104..693867c7 100644 --- a/rc/tools/man.kak +++ b/rc/tools/man.kak @@ -1,7 +1,7 @@ declare-option -docstring "name of the client in which documentation is to be displayed" \ str docsclient -declare-option -hidden str manpage +declare-option -hidden str-list manpage hook -group man-highlight global WinSetOption filetype=man %{ add-highlighter window/man-highlight group @@ -18,7 +18,7 @@ hook -group man-highlight global WinSetOption filetype=man %{ } hook global WinSetOption filetype=man %{ - hook -group man-hooks window WinResize .* %{ man-impl %val{bufname} %opt{manpage} } + hook -group man-hooks window WinResize .* %{ man-impl %opt{manpage} } hook -once -always window WinSetOption filetype=.* %{ remove-hooks window man-hooks } } @@ -33,11 +33,11 @@ define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{ rm ${manout} if [ "${retval}" -eq 0 ]; then printf %s\\n " - edit -scratch '$buffer_name' + edit -scratch %{*$buffer_name ${*}*} execute-keys '%|cat${colout}gk' nop %sh{rm ${colout}} set-option buffer filetype man - set-option window manpage '$@' + set-option window manpage $buffer_name $* " else printf %s\\n "echo -markup %{{Error}man '$@' failed: see *debug* buffer for details}" @@ -64,5 +64,5 @@ The page can be a word, or a word directly followed by a section number between ;; esac - printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl *man* $pagenum $subject" + printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl man $pagenum $subject" } } From 64fd0c72ce9875646d67c9b745cb3202bb798b49 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Tue, 16 Apr 2019 14:22:42 -0700 Subject: [PATCH 2/3] Enable man command to show stderr message to the user 1. If there is no man page found (error 16), then echo stderr text. 2. For other kinds of errors, fail with stderr text so that command can propagate through a try/catch. --- rc/tools/man.kak | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rc/tools/man.kak b/rc/tools/man.kak index 693867c7..a7156ad4 100644 --- a/rc/tools/man.kak +++ b/rc/tools/man.kak @@ -26,8 +26,9 @@ define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{ buffer_name="$1" shift manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) + manerr=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) colout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) - MANWIDTH=${kak_window_width} man "$@" > $manout 2>/dev/null + MANWIDTH=${kak_window_width} man "$@" > "$manout" 2> "$manerr" retval=$? col -b -x > ${colout} < ${manout} rm ${manout} @@ -35,13 +36,20 @@ define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{ printf %s\\n " edit -scratch %{*$buffer_name ${*}*} execute-keys '%|cat${colout}gk' - nop %sh{rm ${colout}} + nop %sh{ rm ${colout}; rm ${manerr} } set-option buffer filetype man set-option window manpage $buffer_name $* " + elif [ "${retval}" -eq 16 ]; then + printf %s\\n " + echo -markup %{{Error}$(cat $manerr)} + nop %sh{ rm ${colout}; rm ${manerr} } + " else - printf %s\\n "echo -markup %{{Error}man '$@' failed: see *debug* buffer for details}" - rm ${colout} + printf %s\\n " + fail $(cat $manerr) + nop %sh{ rm ${colout}; rm ${manerr} } + " fi } } From b1602d44904fb62b61e87be91c9fc6dc0076da52 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Wed, 24 Apr 2019 12:39:26 -0700 Subject: [PATCH 3/3] Fix #2495 - Add hyperlink support to :man 1. Add commands to navigate between man page links. 2. Add command to jump to a man page by following a man page link. 3. Add key map for to jump command. 4. Add key maps for a suggested user mode. --- rc/tools/man.kak | 66 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/rc/tools/man.kak b/rc/tools/man.kak index a7156ad4..8356e173 100644 --- a/rc/tools/man.kak +++ b/rc/tools/man.kak @@ -14,7 +14,12 @@ hook -group man-highlight global WinSetOption filetype=man %{ # References to other manpages add-highlighter window/man-highlight/ regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:header - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/man-highlight } + map window normal ': man-jump' + + hook -once -always window WinSetOption filetype=.* %{ + remove-highlighter window/man-highlight + unmap window normal + } } hook global WinSetOption filetype=man %{ @@ -74,3 +79,62 @@ The page can be a word, or a word directly followed by a section number between printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl man $pagenum $subject" } } + + + +# 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 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. +define-command man-search -params 2 %{ + set-register / %arg[1] + execute-keys %arg[2] +} + +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] } + +# Expand backward and forward, and then try to search for a man page link +define-command man-link-here %{ evaluate-commands -save-regs / %{ + man-search %opt[man_link2] '\b\w?\)' +}} -hidden + +# Search current selection for a man page link +define-command man-link %{ evaluate-commands -save-regs / %{ + man-search %opt[man_link1] s +}} -hidden + +define-command -docstring 'Try to jump to a man page' \ +man-jump %{ + try %{ man-link } catch %{ man-link-here } catch %{ fail 'Not a valid man page link' } + try %{ man } catch %{ fail 'No man page link to follow' } +} + +# Suggested keymaps for a user mode +declare-user-mode man-mode + +define-command man-mode-map -params 3 %{ + map global man-mode %arg[1] %arg[2] -docstring %arg[3] +} -hidden + +man-mode-map 'g' ': man-jump' 'Jump to a man page using selected man page link' +man-mode-map 'j' ': try %{ man-link-next }' 'Go to next man page link' +man-mode-map 'k' ': try %{ man-link-prev }' 'Go to previous man page link' +man-mode-map 'm' ': man' 'Look up a man page'