define-command show-cursor-out-of-scope -docstring 'Show cursor out of scope' %{
# Restore _t_ (top) and _b_ (bottom) registers.
evaluate-commands -save-regs 'tb' %{
# Window top line:
evaluate-commands -draft %{
execute-keys 'gt'
set-register t %val{cursor_line}
}
# Window bottom line:
evaluate-commands -draft %{
execute-keys 'gb'
set-register b %val{cursor_line}
}
# Proceed selections
evaluate-commands %sh{
selection_above_count=0
selection_below_count=0
window_top_line=$kak_reg_t
window_bottom_line=$kak_reg_b
eval "set -- $kak_selections_desc"
# Selection description format: {anchor-line}.{anchor-column},{cursor-line}.{cursor-column}
for selection do
cursor=${selection#*,}
cursor_line=${cursor%.*}
cursor_column=${cursor#*.}
if test "$cursor_line" -lt "$window_top_line"; then
selection_above_count=$((selection_above_count + 1))
elif test "$cursor_line" -gt "$window_bottom_line"; then
selection_below_count=$((selection_below_count + 1))
fi
done
# Display message:
if test "$selection_above_count" -gt 0 -o "$selection_below_count" -gt 0; then
printf 'echo -markup {Information} ↑ (%d) | ↓ (%d)' "$selection_above_count" "$selection_below_count"
fi
}
}
}
Probably not the best hook, but enough to try:
hook -group show-cursor-out-of-scope global NormalIdle .* show-cursor-out-of-scope