Skip to content

Commit 4539c1a

Browse files
fix: Setting custom configuration for vim-plug
## Details Bug report: #111 After the transition to initialization through the plugin directory we essentially made the plugin configuration dependent on initialization order. Whichever thing happens to call the setup function last determines the configuration. This works for plugin managers like lazy.nvim since the plugin directory is run before the user calls setup, so user settings will override the default. However this is not the case for vim-plug which runs setup before the plugin directory. Side not, I believe this is the way neovim is meant to work and lazy.nvim / other managers change this ordering. To fix this I have modified the main setup function to pick up the last non empty configuration. That way if plugin first runs like with lazy.nvim any later calls to setup by the user will override the configuration, there is no need to re-initialize if an empty configuration is supplied. Now if setup runs first it'll initialize the state and since the plugin directory provides an empty configuration it will be skipped instead of overwriting the user supplied configuration.
1 parent a1bcbf4 commit 4539c1a

File tree

9 files changed

+42
-20
lines changed

9 files changed

+42
-20
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
[345596b](https://github.com/MeanderingProgrammer/markdown.nvim/commit/345596bb6ef2b0c0a145c59906c2e84dbddfbbd4)
2727
- Pre-compute concealed data once per parse cycle [fcd908b](https://github.com/MeanderingProgrammer/markdown.nvim/commit/fcd908bafb96e4a30abe7bf8f502790b93ea85ac)
2828
[3bdae40](https://github.com/MeanderingProgrammer/markdown.nvim/commit/3bdae400e079a834ae12b658bf1115abf206bb4c)
29+
- Improve table parsing performance by storing state [4d046cd](https://github.com/MeanderingProgrammer/markdown.nvim/commit/4d046cdf65393a62c0eb209e01574b39f28bc01b)
30+
- Improve performance of showing / hiding marks by storing mark id [ef0c921](https://github.com/MeanderingProgrammer/markdown.nvim/commit/ef0c921858cbe079d40304200af60b6ce0c99429)
31+
- Hide code block background based on language [#110](https://github.com/MeanderingProgrammer/markdown.nvim/issues/110)
32+
[9725df2](https://github.com/MeanderingProgrammer/markdown.nvim/commit/9725df2306409a836a142244c9eabde96268d730)
33+
- Right aligned code block language hint [#73](https://github.com/MeanderingProgrammer/markdown.nvim/issues/73)
34+
[4d8b603](https://github.com/MeanderingProgrammer/markdown.nvim/commit/4d8b6032b659a45582089de8bcd839f8ccc4161d)
35+
- Obsidian like custom callout titles [#109](https://github.com/MeanderingProgrammer/markdown.nvim/issues/109)
36+
[a1bcbf4](https://github.com/MeanderingProgrammer/markdown.nvim/commit/a1bcbf4858d1834f922029b5fc6ae55a7417bd51)
2937

3038
### Bug Fixes
3139

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ Plugin to improve viewing Markdown files in Neovim
7575

7676
## rocks.nvim
7777

78+
This plugin is available on [LuaRocks](https://luarocks.org/modules/MeanderingProgrammer/markdown.nvim)
79+
7880
```vim
7981
:Rocks install markdown.nvim
8082
```
8183

82-
- [luarocks.org](https://luarocks.org/modules/MeanderingProgrammer/markdown.nvim)
83-
8484
## packer.nvim
8585

8686
```lua

benches/medium_spec.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ local util = require('benches.util')
44

55
describe('medium.md', function()
66
it('default', function()
7+
local base_marks = 2998
78
util.between(25, 75, util.setup('temp/medium.md'))
8-
util.num_marks(2998)
9+
util.num_marks(base_marks)
910

1011
util.between(0, 1, util.move_down(3))
11-
util.num_marks(3000)
12+
util.num_marks(base_marks + 2)
1213

1314
util.between(25, 50, util.insert_mode())
14-
util.num_marks(3000)
15+
util.num_marks(base_marks + 2)
1516
end)
1617
end)

benches/medium_table_spec.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ local util = require('benches.util')
44

55
describe('medium-table.md', function()
66
it('default', function()
7+
local base_marks = 30012
78
util.between(450, 600, util.setup('temp/medium-table.md'))
8-
util.num_marks(30012)
9+
util.num_marks(base_marks)
910

1011
util.between(1, 5, util.move_down(1))
11-
util.num_marks(30014)
12+
util.num_marks(base_marks + 2)
1213

1314
util.between(400, 550, util.insert_mode())
14-
util.num_marks(30014)
15+
util.num_marks(base_marks + 2)
1516
end)
1617
end)

benches/readme_spec.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ local util = require('benches.util')
44

55
describe('README.md', function()
66
it('default', function()
7+
local base_marks = 441
78
util.between(25, 75, util.setup('README.md'))
8-
util.num_marks(442)
9+
util.num_marks(base_marks)
910

1011
util.between(0, 1, util.move_down(1))
11-
util.num_marks(444)
12+
util.num_marks(base_marks + 2)
1213

1314
util.between(20, 40, util.insert_mode())
14-
util.num_marks(444)
15+
util.num_marks(base_marks + 2)
1516
end)
1617
end)

doc/render-markdown.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ LAZY.NVIM *render-markdown-install-lazy.nvim*
103103

104104
ROCKS.NVIM *render-markdown-install-rocks.nvim*
105105

106+
This plugin is available on LuaRocks
107+
<https://luarocks.org/modules/MeanderingProgrammer/markdown.nvim>
108+
106109
>vim
107110
:Rocks install markdown.nvim
108111
<
109112

110-
- luarocks.org <https://luarocks.org/modules/MeanderingProgrammer/markdown.nvim>
111-
112113

113114
PACKER.NVIM *render-markdown-install-packer.nvim*
114115

lua/render-markdown/init.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,17 @@ M.default_config = {
460460

461461
---@param opts? render.md.UserConfig
462462
function M.setup(opts)
463-
require('render-markdown.state').setup(M.default_config, opts)
464-
require('render-markdown.ui').invalidate_cache()
463+
-- This handles discrepancies in initialization order of different plugin managers, some
464+
-- run the plugin directory first (lazy.nvim) while others run setup first (vim-plug).
465+
-- To support both we want to pickup the last non-empty configuration. This works because
466+
-- the plugin directory supplies an empty configuration which will be skipped if state
467+
-- has already been initialized by the user.
468+
local state = require('render-markdown.state')
469+
if not state.initialized() or vim.tbl_count(opts or {}) > 0 then
470+
state.setup(M.default_config, opts)
471+
state.invalidate_cache()
472+
require('render-markdown.ui').invalidate_cache()
473+
end
465474
end
466475

467476
return setmetatable(M, {

lua/render-markdown/state.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ local configs = {}
1616
---@field inline_query vim.treesitter.Query
1717
local M = {}
1818

19+
---@return boolean
20+
function M.initialized()
21+
return M.config ~= nil
22+
end
23+
1924
---@param default_config render.md.Config
2025
---@param user_config? render.md.UserConfig
2126
function M.setup(default_config, user_config)
22-
-- Reset cache to pickup config changes
23-
M.invalidate_cache()
24-
25-
-- Create top level config from default & user
2627
local config = vim.tbl_deep_extend('force', default_config, user_config or {})
2728
M.config = config
2829
M.enabled = config.enabled

plugin/render-markdown.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if vim.g.loaded_render_markdown then
33
end
44
vim.g.loaded_render_markdown = true
55

6-
require('render-markdown').setup({})
6+
require('render-markdown').setup()
77
require('render-markdown.colors').setup()
88
require('render-markdown.manager').setup()
99

0 commit comments

Comments
 (0)