Kakoune: man.kak - WinResize for filetype man calls function `man-impl` with incorrect # of parameters

Created on 26 Mar 2020  路  3Comments  路  Source: mawww/kakoune

Steps

Use kak as a man page viewer (I am using fish shell):

set -gx MANPAGER 'col -b -x | kak -e "map global normal q :quit<ret>; set buffer filetype man; $@"'

Then type man sed:

$ man sed

Outcome

That leads to the following error message printed in the **debug** buffer:

Screenshot 2020-03-26 at 14 19 15

Viewing the *debug* buffer gives the following outcome:

*** This is the debug buffer, where debug info will be written ***
error running hook WinResize(65.155)/man-hooks: 1:2: 'man-impl' wrong argument count

Looking at man.kak the following is the case (NOTE how WinResize calls man-impl with one argument but man-impl wants -params 2..3:

hook global WinSetOption filetype=man %{
    hook -group man-hooks window WinResize .* %{ man-impl %opt{manpage} }
    hook -once -always window WinSetOption filetype=.* %{ remove-hooks window man-hooks }
}

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)
    env MANWIDTH=${kak_window_range##* } man "$@" > "$manout" 2> "$manerr"
    retval=$?
    col -b -x > ${colout} < ${manout}
    rm ${manout}
    if [ "${retval}" -eq 0 ]; then
        printf %s\\n "
                edit -scratch %{*$buffer_name ${*}*}
                execute-keys '%|cat<space>${colout}<ret>gk'
                nop %sh{ rm ${colout}; rm ${manerr} }
                set-option buffer filetype man
                set-option window manpage $buffer_name $*
        "
    else
        printf '
            fail %%{%s}
            nop %%sh{ rm "%s"; rm "%s" }
        ' "$(cat "$manerr")" "${colout}" "${manerr}"
    fi
} }

Expected

No error should be printed in the *debug* buffer when using kak as a man pager.

bug

Most helpful comment

#!/bin/sh

col -b -x | kak -e 'set buffer filetype man; remove-hooks window man-hooks; map buffer normal q :q<ret>'

this one works

All 3 comments

It looks like the man filetype is intended to call man internally, as opposed to just formatting the output of man, which does let it do things like properly render the text when the window is resized (which is what you are running up against). Maybe there should be a "plain" man filetype?

For a workaround, using a function instead of modifying the MANPAGER environment variable works:

function man
    kak -e "map global normal q :quit<ret>; man $argv"
end

This does have the downside of not handling the man <section> <topic> (e.g. man 1 echo) case at all, however man <topic>.<section> (man echo.1) works fine.

#!/bin/sh

col -b -x | kak -e 'set buffer filetype man; remove-hooks window man-hooks; map buffer normal q :q<ret>'

this one works

@losnappas: Thanks. I can confirm this resolves the issue.

I will leave the BUG opened as I am not sure how the developers would categorize this (i.e. bug with workaround or improper use in the first place).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akkartik picture akkartik  路  3Comments

Delapouite picture Delapouite  路  4Comments

alexherbo2 picture alexherbo2  路  3Comments

abitofalchemy picture abitofalchemy  路  3Comments

a12l picture a12l  路  3Comments