title: Creating a user defined event in Vim
body: <p>I use a couple of auto commands to do highlighting of extraneous whitespace in my vim setup on <code>InsertLeave</code> and <code>BufReadPost</code> events. I recently started using a plugin to highlight indentation as well (<a href="https://github.com/nathanaelkane/vim-indent-guides" rel="noreferrer">https://github.com/nathanaelkane/vim-indent-guides</a>)</p>
  
  <p>The issue is that if there is an empty line with indentation, it gets highlighted by the indent-guides plugin but not by my auto commands.  What I would like to do is add a custom event to the plugin so that when it is done highlighting I can set my autocommands to trigger and overwrite that highlighting in the cases where it should.</p>
  
  <p>For example, this is the type of flow I would like (or at least something similar):</p>
  
  <pre><code>indent-guides plugin activates
  indent-guides plugin highlights all indentation
  indent-guides plugin triggers custom event signaling it is done
  indent-guides plugin exits
  auto command whitespace highlighter is triggered by indent-guides completion event
  </code></pre>
  
  <p>Here are the auto commands I am using for whitespace highlight:</p>
  
  <pre><code>autocmd InsertEnter * syn clear EOLWS | syn match EOLWS excludenl /\s\+\%#\@!$/
  autocmd InsertLeave,BufReadPost * syn clear EOLWS | syn match EOLWS excludenl /\s\+$/
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I have solved this issue another way (by editing a different plugin). This still doesn't answer this specific question, so I won't be posting that as a solution.</p>
  
  <p><strong>My solution to the problem as a plugin: <a href="https://github.com/ntpeters/vim-better-whitespace" rel="noreferrer">https://github.com/ntpeters/vim-better-whitespace</a></strong></p>