# Highlighter in parallele of a "usermode -lock" menu

**URL:** <https://discuss.kakoune.com/t/highlighter-in-parallele-of-a-usermode-lock-menu/1762>\
**Category:** Help\
**Tags:** usermode, highlighter\
**Created:** [June 4, 2021, 4:58pm UTC](https://discuss.kakoune.com/t/highlighter-in-parallele-of-a-usermode-lock-menu/1762 "2021-06-04T16:58:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [June 4, 2021, 4:58pm UTC](https://discuss.kakoune.com/t/highlighter-in-parallele-of-a-usermode-lock-menu/1762/1 "2021-06-04T16:58:13Z")

</div>

Hello,

I have a custom usermode, that I call with the `-lock` option.

I would like to have an highlighter that appear when I enter the usermode and is removed when I leave it.

I have tried to have this behaviour with hook on `ModeChange` but didn’t went far.

Any hint on how I could make it work?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![bravekarma](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@bravekarma](https://discuss.kakoune.com/u/bravekarma)\
**Post date:** [June 4, 2021, 8:22pm UTC](https://discuss.kakoune.com/t/highlighter-in-parallele-of-a-usermode-lock-menu/1762/2 "2021-06-04T20:22:20Z")

</div>

I assume the tricky part is determining when the mode is left, since `-lock` [works a bit weird](https://github.com/mawww/kakoune/issues/4153#issuecomment-822113902) for user modes. @Screwtapello had a suggestion you can try on the linked thread by using the `NormalIdle` hook. For entering the user mode you can always add the highlighter using the `ModeChange` hook, maybe with an `-override` switch so that it doesn’t complain when the mode is re-entered.

---

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [June 4, 2021, 8:33pm UTC](https://discuss.kakoune.com/t/highlighter-in-parallele-of-a-usermode-lock-menu/1762/3 "2021-06-04T20:33:35Z")

</div>

Thanks @bravekarma !  
From your post and for the future readers, I found this solution:

```auto
hook -always global ModeChange 'push:[^:]*:next-key\[user.my_usermode\]' %{

  set-face window PrimarySelection default,rgba:00ff0080 # new color

}

hook -always global ModeChange 'pop:next-key\[user.my_usermode\]:[^:]*' %{

  set-face window PrimarySelection default,rgba:ff000080 # default color

}

```

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [June 5, 2021, 12:20am UTC](https://discuss.kakoune.com/t/highlighter-in-parallele-of-a-usermode-lock-menu/1762/4 "2021-06-05T00:20:10Z")

</div>

A minor maintainability hint: if you make the second hook do `unset-face window PrimarySelection` then you don’t have to modify this hook when you switch to a different colour scheme that uses a different default colour.
