-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make calling require'lean'.setup{} idempotent #145
Labels
enhancement
New feature or request
Comments
the solution in my config local success, err = pcall(function ()
require('lean').setup{}
end)
if not success then
print(err)
end |
4e554c4c
added a commit
to 4e554c4c/lean.nvim
that referenced
this issue
Sep 6, 2022
It turns out that most of these come from the `_DEFAULTS` pattern. This is because of the following: original state: ```lua tbl = { _DEFAULTS = ... } ``` after configuration with empty table, `tbl = vim.tbl_extend(tbl._DEFAULTS, {})` which practically replaces `tbl` by `tbl._DEFAULTS`: ```lua tbl = { ... } ``` after this, the next call to `vim.tbl_extend(tbl._DEFAULTS, {})` fails, as `tbl._DEFAULTS` is nil. The solution to this is to just call `vim.tbl_extend(tbl, ...)` and store the defaults in `tbl` itself. The `._DEFAULTS` field can be preserved by copying to it after initialization. Also `command` has been replaced with `command!` in vimscript and `autocmd`s have been wrapped in an `augroup` which resets its state each call. This is also common practice that avoids duplicate autocommands. Fixes Julian#145
Merged
4e554c4c
added a commit
to 4e554c4c/lean.nvim
that referenced
this issue
Sep 7, 2022
It turns out that most of these come from the `_DEFAULTS` pattern. This is because of the following: original state: ```lua tbl = { _DEFAULTS = ... } ``` after configuration with empty table, `tbl = vim.tbl_extend(tbl._DEFAULTS, {})` which practically replaces `tbl` by `tbl._DEFAULTS`: ```lua tbl = { ... } ``` after this, the next call to `vim.tbl_extend(tbl._DEFAULTS, {})` fails, as `tbl._DEFAULTS` is nil. The solution to this is to just call `vim.tbl_extend(tbl, ...)` and store the defaults in `tbl` itself. The `._DEFAULTS` field can be preserved by copying to it after initialization. Also `command` has been replaced with `command!` in vimscript and `autocmd`s have been wrapped in an `augroup` which resets its state each call. This is also common practice that avoids duplicate autocommands. Fixes Julian#145
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Users occasionally will put this in a file they reload or re-source, so it'd be nice if it were able to be run multiple times.
Right now most of the state issues are simply with initializing global configuration, so this may not be too difficult to do.
(See #132 for some context.)
Relates to #39.
The text was updated successfully, but these errors were encountered: