# Help to build pluggin show cursor out of scope

**URL:** <https://discuss.kakoune.com/t/help-to-build-pluggin-show-cursor-out-of-scope/1125>\
**Category:** Plugins\
**Created:** [July 1, 2020, 10:54pm UTC](https://discuss.kakoune.com/t/help-to-build-pluggin-show-cursor-out-of-scope/1125 "2020-07-01T22:54:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [July 1, 2020, 11:49pm UTC](https://discuss.kakoune.com/t/help-to-build-pluggin-show-cursor-out-of-scope/1125/2 "2020-07-01T23:49:43Z")

</div>

```auto
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:

```auto
hook -group show-cursor-out-of-scope global NormalIdle .* show-cursor-out-of-scope

```

---

_[View the full topic](https://discuss.kakoune.com/t/help-to-build-pluggin-show-cursor-out-of-scope/1125)._
