Skip to content

Commit 40fff90

Browse files
feat: improve debug command
## Details When debugging marks on current row we used the `config:hidden` method which would return `nil` if anti conceal was disabled. Probably fairly uncommon, but still, there is no need to rely on this. So instead we create the `Range` for the current row directly when debugging marks, bypassing any logic inside `config`. This logic has also been almost entirely moved to the debug marks module and out of ui. To support this ui publicly exposes what used to be in `Cache.get(buf)` from which we can get `extmarks` using `get_marks()`. Other minor changes: - make `cache` part of each module rather than local variables - move creation of main config into `Config` module - replace `string.<method>(<s>, ...)` -> `(<s>):<method>(...)` - rename `bg_to_fg` -> `bg_as_fg` - rename `release_notification` -> `release` - use local change of panvimdoc to pull `vim-version` dynamically - update changelog
1 parent 5eaa6c2 commit 40fff90

29 files changed

+268
-293
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
[7f75b16](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7f75b162dbe1e1b9daf1b1201b97a93481169614)
99
- support function for paragraph.left_margin [#401](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/401)
1010
[dfc1299](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/dfc1299d9f32b53b34b7ac6c3a7553b5fd29977f)
11+
- include removed values in config diff [6531aa7](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/6531aa7f615926de1962102d90fff69665b672d7)
12+
- support wiki style media links, improve custom links [#410](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/410)
13+
[6910fe1](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/6910fe12a9634be5ce4e19aff4d3b45abf3f0dd3)
14+
- combine highlights for links [#413](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/413)
15+
[da3e146](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/da3e146acaf2069a0e975d675d172ac94d1e2f88)
16+
- set quote highlights for 6 levels of nesting [7051859](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/70518594a4bf1a35d4e331677dd86bc065e599a4)
17+
[cyberdream](https://github.com/scottmckendry/cyberdream.nvim/pull/182)
18+
- use conceal lines for setext heading underline [78ffe3b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/78ffe3b0500bbc7e37fabde723d96661538e8b32)
1119

1220
### Bug Fixes
1321

@@ -16,6 +24,10 @@
1624
- disable line wrapping in LSP hover docs in some cases [#408](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/408)
1725
[080104e](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/080104e4dce26819efb4f4c83d1b7b2d82b96f7c)
1826

27+
### Collaborator Shoutouts
28+
29+
- @scottmckendry
30+
1931
## 8.3.0 (2025-04-15)
2032

2133
### Features

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ require('render-markdown').setup({
535535
ordered_icons = function(ctx)
536536
local value = vim.trim(ctx.value)
537537
local index = tonumber(value:sub(1, #value - 1))
538-
return string.format('%d.', index > 1 and index or ctx.index)
538+
return ('%d.'):format(index > 1 and index or ctx.index)
539539
end,
540540
-- Padding to add to the left of bullet point.
541541
-- Output is evaluated depending on the type.
@@ -1154,7 +1154,7 @@ require('render-markdown').setup({
11541154
ordered_icons = function(ctx)
11551155
local value = vim.trim(ctx.value)
11561156
local index = tonumber(value:sub(1, #value - 1))
1157-
return string.format('%d.', index > 1 and index or ctx.index)
1157+
return ('%d.'):format(index > 1 and index or ctx.index)
11581158
end,
11591159
-- Padding to add to the left of bullet point.
11601160
-- Output is evaluated depending on the type.

benches/util.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ end
1919
---@return number
2020
function M.move_down(n)
2121
return M.time(function()
22-
M.feed(string.format('%dj', n))
22+
M.feed(('%dj'):format(n))
2323
-- Unsure why, but the CursorMoved event needs to be triggered manually
2424
vim.api.nvim_exec_autocmds('CursorMoved', {})
2525
end)
@@ -53,7 +53,7 @@ end
5353
---@param actual number
5454
---@param max number
5555
function M.less_than(actual, max)
56-
True(actual < max, string.format('expected %f < %f', actual, max))
56+
True(actual < max, ('expected %f < %f'):format(actual, max))
5757
end
5858

5959
---@param expected integer

doc/render-markdown.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.11.0 Last change: 2025 April 27
1+
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 April 28
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -600,7 +600,7 @@ Default Configuration ~
600600
ordered_icons = function(ctx)
601601
local value = vim.trim(ctx.value)
602602
local index = tonumber(value:sub(1, #value - 1))
603-
return string.format('%d.', index > 1 and index or ctx.index)
603+
return ('%d.'):format(index > 1 and index or ctx.index)
604604
end,
605605
-- Padding to add to the left of bullet point.
606606
-- Output is evaluated depending on the type.
@@ -1209,7 +1209,7 @@ Bullet Point Configuration ~
12091209
ordered_icons = function(ctx)
12101210
local value = vim.trim(ctx.value)
12111211
local index = tonumber(value:sub(1, #value - 1))
1212-
return string.format('%d.', index > 1 and index or ctx.index)
1212+
return ('%d.'):format(index > 1 and index or ctx.index)
12131213
end,
12141214
-- Padding to add to the left of bullet point.
12151215
-- Output is evaluated depending on the type.

justfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ update:
99
# https://github.com/kdheepak/panvimdoc
1010
../../open-source/panvimdoc/panvimdoc.sh \
1111
--project-name render-markdown \
12-
--input-file README.md \
13-
--vim-version 0.11.0
12+
--input-file README.md
1413

1514
test:
1615
just busted "tests"

lua/render-markdown/colors.lua

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
---@class render.md.colors.Cache
2-
---@field combine table<string, { fg: string, bg: string }>
3-
---@field bg_to_fg table<string, { hl: string }>
4-
local Cache = {
5-
combine = {},
6-
bg_to_fg = {},
7-
}
8-
91
---@class render.md.Colors
102
local M = {}
113

@@ -69,6 +61,14 @@ M.colors = {
6961
Error = 'DiagnosticError',
7062
}
7163

64+
---@private
65+
---@class render.md.colors.Cache
66+
M.cache = {}
67+
---@type table<string, { fg: string, bg: string }>
68+
M.cache.combine = {}
69+
---@type table<string, { hl: string }>
70+
M.cache.bg_as_fg = {}
71+
7272
---called from plugin directory
7373
function M.init()
7474
for name, link in pairs(M.colors) do
@@ -86,11 +86,12 @@ end
8686

8787
---@private
8888
function M.reload()
89-
for _, color in pairs(Cache.combine) do
89+
vim.print(M.cache)
90+
for _, color in pairs(M.cache.combine) do
9091
M.combine(color.fg, color.bg, true)
9192
end
92-
for _, color in pairs(Cache.bg_to_fg) do
93-
M.bg_to_fg(color.hl, true)
93+
for _, color in pairs(M.cache.bg_as_fg) do
94+
M.bg_as_fg(color.hl, true)
9495
end
9596
end
9697

@@ -99,32 +100,32 @@ end
99100
---@param force? boolean
100101
---@return string
101102
function M.combine(foreground, background, force)
102-
local name = string.format('%s_%s_%s', M.prefix, foreground, background)
103-
if Cache.combine[name] == nil or force then
103+
local name = ('%s_%s_%s'):format(M.prefix, foreground, background)
104+
if M.cache.combine[name] == nil or force then
104105
local fg, bg = M.get_hl(foreground), M.get_hl(background)
105106
vim.api.nvim_set_hl(0, name, {
106107
fg = fg.fg,
107108
bg = bg.bg,
108109
ctermfg = fg.ctermfg,
109110
ctermbg = bg.ctermbg,
110111
})
111-
Cache.combine[name] = { fg = foreground, bg = background }
112+
M.cache.combine[name] = { fg = foreground, bg = background }
112113
end
113114
return name
114115
end
115116

116117
---@param highlight string
117118
---@param force? boolean
118119
---@return string
119-
function M.bg_to_fg(highlight, force)
120-
local name = string.format('%s_bgtofg_%s', M.prefix, highlight)
121-
if Cache.bg_to_fg[name] == nil or force then
120+
function M.bg_as_fg(highlight, force)
121+
local name = ('%s_%s_bg_as_fg'):format(M.prefix, highlight)
122+
if M.cache.bg_as_fg[name] == nil or force then
122123
local hl = M.get_hl(highlight)
123124
vim.api.nvim_set_hl(0, name, {
124125
fg = hl.bg,
125126
ctermfg = hl.ctermbg,
126127
})
127-
Cache.bg_to_fg[name] = { hl = highlight }
128+
M.cache.bg_as_fg[name] = { hl = highlight }
128129
end
129130
return name
130131
end

lua/render-markdown/command.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ function M.init()
2727
end
2828

2929
---@private
30-
---@param opts { fargs: string[] }
31-
function M.command(opts)
32-
local args, err = opts.fargs, nil
33-
if #args == 0 or #args == 1 then
34-
local command = #args == 0 and api.enable or api[args[1]]
30+
---@param args vim.api.keyset.create_user_command.command_args
31+
function M.command(args)
32+
local fargs, err = args.fargs, nil
33+
if #fargs == 0 or #fargs == 1 then
34+
local command = #fargs == 0 and api.enable or api[fargs[1]]
3535
if command ~= nil then
3636
command()
3737
else
38-
err = string.format('unexpected command: %s', args[1])
38+
err = ('unexpected command: %s'):format(fargs[1])
3939
end
4040
else
41-
err = string.format('unexpected # arguments: %d', #args)
41+
err = ('unexpected # arguments: %d'):format(#fargs)
4242
end
4343
if err ~= nil then
44-
vim.notify(string.format('%s: %s', M.plugin, err), vim.log.levels.ERROR)
44+
vim.notify(('%s: %s'):format(M.plugin, err), vim.log.levels.ERROR)
4545
end
4646
end
4747

lua/render-markdown/config.lua

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,45 @@ local Range = require('render-markdown.core.range')
1111
local Config = {}
1212
Config.__index = Config
1313

14-
---@param config render.md.buffer.Config
14+
---@param root render.md.Config
15+
---@param buf integer
1516
---@return render.md.main.Config
16-
function Config.new(config)
17+
function Config.new(root, buf)
18+
---@type render.md.buffer.Config
19+
local config = {
20+
enabled = true,
21+
render_modes = root.render_modes,
22+
max_file_size = root.max_file_size,
23+
debounce = root.debounce,
24+
anti_conceal = root.anti_conceal,
25+
bullet = root.bullet,
26+
callout = root.callout,
27+
checkbox = root.checkbox,
28+
code = root.code,
29+
dash = root.dash,
30+
document = root.document,
31+
heading = root.heading,
32+
html = root.html,
33+
indent = root.indent,
34+
inline_highlight = root.inline_highlight,
35+
latex = root.latex,
36+
link = root.link,
37+
padding = root.padding,
38+
paragraph = root.paragraph,
39+
pipe_table = root.pipe_table,
40+
quote = root.quote,
41+
sign = root.sign,
42+
win_options = root.win_options,
43+
}
44+
config = vim.deepcopy(config)
45+
for _, name in ipairs({ 'buflisted', 'buftype', 'filetype' }) do
46+
local value = Env.buf.get(buf, name)
47+
local override = root.overrides[name][value]
48+
if override ~= nil then
49+
config = vim.tbl_deep_extend('force', config, override)
50+
end
51+
end
52+
1753
-- super set of render modes across top level and individual components
1854
local modes = config.render_modes
1955
for _, component in pairs(config) do
@@ -33,33 +69,6 @@ function Config.new(config)
3369
return setmetatable(instance, Config)
3470
end
3571

36-
-- stylua: ignore
37-
---@param spec render.md.debug.ValidatorSpec
38-
function Config.validate(spec)
39-
require('render-markdown.config.base').validate(spec)
40-
spec:type('max_file_size', 'number')
41-
spec:type('debounce', 'number')
42-
spec:nested('anti_conceal', require('render-markdown.config.anti_conceal').validate)
43-
spec:nested('bullet', require('render-markdown.config.bullet').validate)
44-
spec:nested('callout', require('render-markdown.config.callout').validate)
45-
spec:nested('checkbox', require('render-markdown.config.checkbox').validate)
46-
spec:nested('code', require('render-markdown.config.code').validate)
47-
spec:nested('dash', require('render-markdown.config.dash').validate)
48-
spec:nested('document', require('render-markdown.config.document').validate)
49-
spec:nested('heading', require('render-markdown.config.heading').validate)
50-
spec:nested('html', require('render-markdown.config.html').validate)
51-
spec:nested('indent', require('render-markdown.config.indent').validate)
52-
spec:nested('inline_highlight', require('render-markdown.config.inline_highlight').validate)
53-
spec:nested('latex', require('render-markdown.config.latex').validate)
54-
spec:nested('link', require('render-markdown.config.link').validate)
55-
spec:nested('padding', require('render-markdown.config.padding').validate)
56-
spec:nested('paragraph', require('render-markdown.config.paragraph').validate)
57-
spec:nested('pipe_table', require('render-markdown.config.pipe_table').validate)
58-
spec:nested('quote', require('render-markdown.config.quote').validate)
59-
spec:nested('sign', require('render-markdown.config.sign').validate)
60-
spec:nested('win_options', require('render-markdown.config.win_options').validate)
61-
end
62-
6372
---@private
6473
---@param acc render.md.Modes
6574
---@param new? render.md.Modes
@@ -95,6 +104,33 @@ function Config.normalize(components)
95104
return result
96105
end
97106

107+
-- stylua: ignore
108+
---@param spec render.md.debug.ValidatorSpec
109+
function Config.validate(spec)
110+
require('render-markdown.config.base').validate(spec)
111+
spec:type('max_file_size', 'number')
112+
spec:type('debounce', 'number')
113+
spec:nested('anti_conceal', require('render-markdown.config.anti_conceal').validate)
114+
spec:nested('bullet', require('render-markdown.config.bullet').validate)
115+
spec:nested('callout', require('render-markdown.config.callout').validate)
116+
spec:nested('checkbox', require('render-markdown.config.checkbox').validate)
117+
spec:nested('code', require('render-markdown.config.code').validate)
118+
spec:nested('dash', require('render-markdown.config.dash').validate)
119+
spec:nested('document', require('render-markdown.config.document').validate)
120+
spec:nested('heading', require('render-markdown.config.heading').validate)
121+
spec:nested('html', require('render-markdown.config.html').validate)
122+
spec:nested('indent', require('render-markdown.config.indent').validate)
123+
spec:nested('inline_highlight', require('render-markdown.config.inline_highlight').validate)
124+
spec:nested('latex', require('render-markdown.config.latex').validate)
125+
spec:nested('link', require('render-markdown.config.link').validate)
126+
spec:nested('padding', require('render-markdown.config.padding').validate)
127+
spec:nested('paragraph', require('render-markdown.config.paragraph').validate)
128+
spec:nested('pipe_table', require('render-markdown.config.pipe_table').validate)
129+
spec:nested('quote', require('render-markdown.config.quote').validate)
130+
spec:nested('sign', require('render-markdown.config.sign').validate)
131+
spec:nested('win_options', require('render-markdown.config.win_options').validate)
132+
end
133+
98134
---@param mode string
99135
---@return boolean
100136
function Config:render(mode)
@@ -123,7 +159,7 @@ function Config:hidden(mode, row)
123159
if not config.enabled or row == nil then
124160
return nil
125161
end
126-
if vim.tbl_contains({ 'v', 'V', '\22' }, mode) then
162+
if Env.mode.is(mode, { 'v', 'V', '\22' }) then
127163
local start = vim.fn.getpos('v')[2] - 1
128164
return Range.new(math.min(row, start), math.max(row, start))
129165
else

lua/render-markdown/config/bullet.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ M.default = {
4848
ordered_icons = function(ctx)
4949
local value = vim.trim(ctx.value)
5050
local index = tonumber(value:sub(1, #value - 1))
51-
return string.format('%d.', index > 1 and index or ctx.index)
51+
return ('%d.'):format(index > 1 and index or ctx.index)
5252
end,
5353
-- Padding to add to the left of bullet point.
5454
-- Output is evaluated depending on the type.

lua/render-markdown/core/context.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,33 @@ function Context:for_each(callback)
194194
end
195195
end
196196

197-
---@class render.md.context.Cache: { [integer]: render.md.Context }
198-
local Cache = {}
199-
200197
---@class render.md.context.Manager
201198
local M = {}
202199

200+
---@private
201+
---@type table<integer, render.md.Context>
202+
M.cache = {}
203+
203204
---@param buf integer
204205
---@param win integer
205206
---@return boolean
206207
function M.contains(buf, win)
207-
local context = Cache[buf]
208+
local context = M.cache[buf]
208209
return context ~= nil and context:contains(win)
209210
end
210211

211212
---@param props render.md.context.Props
213+
---@return render.md.Context
212214
function M.reset(props)
213-
Cache[props.buf] = Context.new(props, 10)
215+
local context = Context.new(props, 10)
216+
M.cache[props.buf] = context
217+
return context
214218
end
215219

216220
---@param buf integer
217221
---@return render.md.Context
218222
function M.get(buf)
219-
return Cache[buf]
223+
return assert(M.cache[buf], 'missing context')
220224
end
221225

222226
return M

lua/render-markdown/core/extmark.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local Compat = require('render-markdown.lib.compat')
2-
31
---@class render.md.Extmark
42
---@field private id? integer
53
---@field private mark render.md.Mark
@@ -54,8 +52,8 @@ function Extmark:show(ns, buf)
5452
if ok then
5553
self.id = id
5654
else
57-
local cause = string.format('nvim_buf_set_extmark error (%s)', id)
58-
Compat.release_notification(cause)
55+
local Compat = require('render-markdown.lib.compat')
56+
Compat.release(('nvim_buf_set_extmark error (%s)'):format(id))
5957
end
6058
end
6159

0 commit comments

Comments
 (0)