# Filetype hilight hooks

**URL:** <https://discuss.kakoune.com/t/filetype-hilight-hooks/1894>\
**Category:** Help\
**Tags:** scripting, plugins\
**Created:** [September 25, 2021, 8:23am UTC](https://discuss.kakoune.com/t/filetype-hilight-hooks/1894 "2021-09-25T08:23:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![almr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/almr/32/934_2.png) [@almr](https://discuss.kakoune.com/u/almr)\
**Post date:** [September 25, 2021, 8:23am UTC](https://discuss.kakoune.com/t/filetype-hilight-hooks/1894/1 "2021-09-25T08:23:48Z")

</div>

Like all good plugin writers (who define highlighters) I’ve copied over (and of course adapted) this, from `grep.kak`

```auto
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/grep }

```

What is the purpose of this code; what disaster is it trying to avoid?

---

<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:** [September 25, 2021, 8:47am UTC](https://discuss.kakoune.com/t/filetype-hilight-hooks/1894/2 "2021-09-25T08:47:31Z")

</div>

Imagine you’re working on a highlighter for the fictional “greo” file type. While developing it, you open your `foo.greo` test file, and try out your highlighter plugin with `:set window filetype grep`.

Oh no, you accidentally typed `grep` instead of `greo`! You can immediately try `:set window filetype greo`, but since you’ve already set the filetype to `grep`, all the `WinSetOption filetype=grep` hooks have fired and added various mappings and highlighters that will interfere with the mappings and highlighters you _want_ to test.

Except, the grep plugin uses that hook you pointed out. That hook is installed _inside_ the `WinSetOption filetype=grep` hook, so that when the `filetype` option is set to anything else, all the grep-related things will be removed and the new filetype has a clean slate to work from. Note that it has the `-once` flag, so once the cleanup occurs the hook is automatically removed. It also has the `-always` flag, so it will still be run if you happen to change the filetype in no-hooks mode (by pressing `\`).
