chrisbra / matchit

The matchit plugin from Vim
61 stars 9 forks source link

make sure internal state of script is preserved #28

Closed lacygoill closed 3 years ago

lacygoill commented 3 years ago

The autoload script doesn't contain any anti-reinclusion guard. It might not be necessary, but coding defensively can reduce the time spent in debugging weird issues later.

In the past, I've had several sporadic issues which were fixed by such guards. vim-fugitive uses one too.

As an example – with an old Vim version – calling a public function with a typo might cause Vim to source the autoloaded script twice, which would reset some script-local variables, which in turn could lead to hard-to-debug issues.

That's no longer possible since the patch 8.2.1398 though. Still, maybe the autoloaded script could be accidentally re-sourced in some other way (e.g. a :source or :runtime command with a wrong file argument).

What do you think? Good idea, or too much?

chrisbra commented 3 years ago

In general, I do not like to add loading guards to the autoload section of vimplugins, because I do prefer to test something by simply re-sourcing the autoload script. Therefore, let's just keep it as is.