Fix issue with delimitMate/vim-plug (fix #48)
Fix issue with delimitMate/vim-plug (fix #48)

Fix the issue reported in [GitHub issue ticket #48], whereby, if one —

  - used [vim-plug] to load rust.vim, using vim-plug's `'for'` option to
    only load rust.vim for buffers with `filetype=rust`, and also
  - used [delimitMate]

— an error message would be produced each time one opened a new Rust
buffer.

This error was apparently caused by rust.vim, under the afore-described
conditions, calling into delimitMate (apparently to advise it not to
treat the U+0027 APOSTROPHE characters in Rust's lifetime syntax as
single quotation marks to be automatically closed) before the latter
plug-in had completed its necessary initialization, causing delimitMate
to overconfidently attempt to access as-yet-uninitialized internal
state, raising the error with whose aforementioned message this chain of
events would result in the user being unceremoniously presented.

This commit attempts to fix this issue by moving rust.vim's call into
delimitMate into a buffer-local autocommand set to run when delimitMate
issues the `User delimitMate_map` event in the autocommand system, which
event delimitMate thus issues to signal that it has reached —
disregarding the particulars — a stage in its initialization at which it
would be appropriate for other plug-ins to interface with it.

In short, by letting delimitMate tell rust.vim when the former is ready
to be interfaced with, and only then interfacing with it, this commit
allows rust.vim to avoid the afore-described error-raising case of
interfacing with delimitMate when the latter is not thus ready.

This commit also sets a buffer-local autocommand to run when delimitMate
issues the `User delimitMate_unmap` event in the autocommand system,
which autocommand is to clean up after the modifications of
delimitMate's state made by the aforementioned `User delimitMate_map`
autocommand.

Furthermore, this commit adds `augroup`, `autocmd!`, and `augroup!`
commands as necessary and proper in attempting to make its use of
autocommands adhere to norms, propriety, and idioms recommended in the
documentation of the autocommand system.

Additionally, this commit updates the "Last Change" date listed at the
top of the script that it modifies to reflect its modification.

The changes made in this commit appear to fix the afore-described issue
for [me], and do not, to my knowledge, introduce any untoward behavior;
however, this fix has not, to my knowledge, been tested by anyone else.

I affirm that the changes made in this commit are based solely on —

  - the existing script that these changes change;
  - the public documentation of Vim;
  - the public documentation of delimitMate; and
  - comments on [GitHub issue ticket #48];

— and not on any other software or other work.

I publish these changes under the same licensing terms as those under
which rust.vim in general is published at this time (2016-06-08), i.e.,
dual-licensed under the MIT and Apache-2.0 licences.

[GitHub issue ticket #48]: <https://github.com/rust-lang/rust.vim/issues/48>
[vim-plug]: <https://github.com/junegunn/vim-plug>
[delimitMate]: <https://github.com/Raimondi/delimitMate>
[me]: <https://github.com/8573>

rust-lang/rust.vim