diff --git a/doc/AutoPairs.txt b/doc/AutoPairs.txt index c092ffb..f287fcf 100644 --- a/doc/AutoPairs.txt +++ b/doc/AutoPairs.txt @@ -1584,6 +1584,21 @@ raw keys, which can and will cause conflicts with typed letters if given the opportunity. Should you choose not to, though, you get to live with the consequences, if any. +WARNING: This variable must be declared before calling any auto-pairs +functions. See |autopairs-config-changes-broken| for more details. + +TL;DR: +Correct: > + let g:AutoPairsPrefix = '' + let g:AutoPairs = autopairs#AutoPairsDefine({ ... some definitions here }) +< +Incorrect: > + let g:AutoPairs = autopairs#AutoPairsDefine({ ... some definitions here }) + let g:AutoPairsPrefix = '' +< + +Note that this applies to any of auto-pairs' functions. + ------------------------------------------------------------------------------ *g:AutoPairsDefaultDisableKeybinds* @@ -1713,6 +1728,9 @@ don't want to use the standards, go ahead and omit this function. Additionally, if you want to add new types after loading, you need to use |autopairs#AutoPairsMap()| +WARNING: Functions must be called after config variable declarations. See +|autopairs-config-changes-broken| + ------------------------------------------------------------------------------ AutoPairsDefine() *autopairs#AutoPairsDefine()* *autopairs-copy-defaults* Arguments: (pairs[, pairs_to_remove]) @@ -1739,6 +1757,10 @@ files are loaded when `autopair#` functions are called. This means using, for an instance, `autopairs#AutoPairsDefine` loads the file and makes the function valid. +WARNING: Functions must be called after config variable declarations. This +means g:AutoPairs has to be the variable defined last in many cases. See +|autopairs-config-changes-broken| for more information + ------------------------------------------------------------------------------ AutoPairsMap() *autopairs#AutoPairsMap()* *auto-pairs-map-key* Arguments: (key) diff --git a/doc/AutoPairsTrouble.txt b/doc/AutoPairsTrouble.txt index 12a39fc..0897c40 100644 --- a/doc/AutoPairsTrouble.txt +++ b/doc/AutoPairsTrouble.txt @@ -24,6 +24,7 @@ Table of Contents *autopairs-troubleshooting-contents* 7. Test failures (and related errors) ... |autopairs-test-failures| 1. Autocmd and syntax errors ........ |autopairs-typescript-errors| 8. Weird auto-pairs stuff on ....... |autopairs-bad-cr| + 9. Config changes not taking effect ..... |autopairs-config-changes-broken| ============================================================================== 1. General troubleshooting *autopairs-troubleshooting-general* @@ -373,4 +374,57 @@ the last straw for the other plugin, you can uninstall the other plugin plugin. See also |autopairs-autocomplete-cr| +============================================================================== +9. Config changes not taking effect *autopairs-config-changes-broken* + +TL;DR:~ + +Correct: > + let g:AutoPairsPrefix = '' + let g:AutoPairs = autopairs#AutoPairsDefine({ ... some definitions here }) +< +Incorrect: > + let g:AutoPairs = autopairs#AutoPairsDefine({ ... some definitions here }) + let g:AutoPairsPrefix = '' +< +This applies to any of auto-pairs' functions, generally identified by the +`autopairs#` prefix. + +Long version~ +If you're making changes to auto-pairs' config variables and seeing it not +take effect, you're probably running into an initialisation order problem. +This particularly applies to |g:AutoPairsPrefix|, but may exist in other +places as well. To avoid running into these problems, it's recommended to +initialise variables before calling any of auto-pairs' functions. + +If any functions are called before variables are declared, this results in +certain internal variables being initialised in a way that makes it difficult +to change afterwards. Taking |g:AutoPairsPrefix| as an example, consider: > + let g:AutoPairs = autopairs#AutoPairsDefine({ ... some definitions here }) + let g:AutoPairsPrefix = '' +< + +In this case, all the defaults are initialised after the g:AutoPairsDefine +call. While this usually isn't a problem, all the keybind initialisations +depend on the value of |g:AutoPairsPrefix|. Because it isn't defined prior to +the function call, the function defines it as the default value. When +|g:AutoPairsPrefix| then is defined after the function call, the variable +initialisation function is not called again (and even if it was, it would +not change anything, as the dependent variables are assumed to be initialised +by the user, and won't be reinitialised). + +Simply put, if you're seeing this problem, it's caused by variables depending +on other variables during initialisation, and the value of the variable is +copied at the time of initialisation. + +This means that, as the TL;DR: stated, you need to call `autopairs#` functions +after initialising the variables you're interested in, and not before. That +way, when the variable initialisation happens, dependent variables are +initialised correctly. + +See also~ +* https://github.com/LunarWatcher/auto-pairs/issues/84 + The issue also contains a practical demonstration of this happening in + practice. + vim:ft=help