def autocmd(name, pattern='*', sync=False, eval=None):
    def dec(f):
        f._nvim_rpc_method_name = 'autocmd:{0}:{1}'.format(name, pattern)
        f._nvim_rpc_sync = sync
        f._nvim_bind = True
        f._nvim_prefix_plugin_path = True

        opts = {
            'pattern': pattern
        }

        if eval:
            opts['eval'] = eval

        f._nvim_rpc_spec = {
            'type': 'autocmd',
            'name': name,
            'sync': sync,
            'opts': opts
        }
        return f
    return dec
Tag a function or plugin method as a Nvim autocommand handler.
dataset/ETHPy150Open neovim/python-client/neovim/plugin/decorators.py/autocmd