Add autocmd
#89, #100
I'm considering following commands.
| command | syntax |
|---|---|
autocmd |
[au]tocmd {event} {aupat} {cmd} |
autocmd! |
[au]tocmd! {event} {aupat} {cmd} |
autocmd
It adds {cmd} into autocmd list for {aupat}, autocmd pattern, corresponding to {event}. As such as Vim, this function does not overwrite but append {cmd} into a list even if the same {cmd} has already existed in a list. The event does not allow us to use *. If you want to add a command to some events at the same time, , without after-space is available. The rule of {aupat} is based on the original Vim. Of course, registered {cmd}s will execute in order added.
autocmd!
It remove all autocmd matched {event} and {aupat}, then register {cmd} after delete. The following syntaxes are available.
au[tocmd]! {event} {aupat} {cmd}
au[tocmd]! {event} {aupat}
au[tocmd]! * {aupat}
au[tocmd]! {event}
Each features are the same as the original Vim.
Implementation
I plan to adopt the following data structure.
https://github.com/vim/vim/blob/b26592a84c8f578c8fbe83cf02ebb47453de1683/src/autocmd.c#L16-L50
figure

Considering events.
| Event | Happen |
|---|---|
| AppEnter | Select application |
| AppLeave | Unselect application |
| GNormalEnter | Enter to GUI normal mode |
| GNormalLeave | Leave from GUI normal mode |
| GVisualEnter | Enter to GUI visual mode |
| GVisualLeave | Leave from GUI visual mode |
| ENormalEnter | Enter to editor normal mode |
| ENormalLeave | Leave from editor normal mode |
| EVisualEnter | Enter to editor visual mode |
| EVisualLeave | Leave from editor visual mode |
| InsertEnter | Enter to insert mode |
| InsertLeave | Leave from insert mode |
| ResidentEnter | Enter to resident mode |
| ResidentLeave | Leave from resident mode |
| CmdLineEnter | Enter to command mode |
| CmdLineLeave | Leave from command mode |