Skip to content

Commit 873bdee

Browse files
feat: support override based on buflisted value
## Details Discussion: #285 `lspsaga` creates a buffer than iterates through a list of buffer options to update the buffer. This makes sense however depending on the iteration order of the options different things can happen. - `filetype = markdown` then `buftype = nofile`: this will trigger the `FileType` autocommand and at the time it runs the `buftype` will be the empty string, which means overrides for `nofile` will not work. - `buftype = nofile` then `filetype = markdown`: will also trigger the `FileType` autocommand but now at the time it runs the `buftype` will be correctly set to `nofile` and overrides will work. To avoid this inconsistent behavior we need some property of the buffer that will always hold. The solution to this is to use the `buflisted` property, which gets set at the moment the buffer is created when `nvim_create_buf` is called. Users can than disable this plugin in `lspsaga` buffers by setting: ```lua require('render-markdown').setup({ overrides = { buflisted = { [false] = { enabled = false } }, }, }) ```
1 parent 786d643 commit 873bdee

File tree

8 files changed

+41
-18
lines changed

8 files changed

+41
-18
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## Pre-release
44

5+
### Features
6+
7+
- improve wiki link rendering [#284](https://github.com/MeanderingProgrammer/render-markdown.nvim/discussions/284)
8+
[7b1b15f](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7b1b15fc8891a62aeb3a0f75d0f7b1ec7fb98090)
9+
- heading icons function value [#286](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/286)
10+
[bab0663](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/bab0663ecdb06b0ff846969764d6c67719ab0fcb)
11+
12+
### Bug Fixes
13+
14+
- ensure space for table cell padding [#287](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/287)
15+
[786d643](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/786d643ac7a691515d401930b8850f596992725d)
16+
517
## 7.8.0 (2025-01-04)
618

719
### Features

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,16 @@ require('render-markdown').setup({
693693
-- heading, paragraph, code, dash, bullet, checkbox, quote, pipe_table,
694694
-- callout, link, sign, indent, latex, html, win_options
695695
overrides = {
696-
-- Overrides for different buftypes, see :h 'buftype'
696+
-- Override for different buflisted values, see :h 'buflisted'
697+
buflisted = {},
698+
-- Override for different buftype values, see :h 'buftype'
697699
buftype = {
698700
nofile = {
699701
padding = { highlight = 'NormalFloat' },
700702
sign = { enabled = false },
701703
},
702704
},
703-
-- Overrides for different filetypes, see :h 'filetype'
705+
-- Override for different filetype values, see :h 'filetype'
704706
filetype = {},
705707
},
706708
-- Mapping from treesitter language to user defined handlers

doc/render-markdown.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 January 07
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 January 09
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -749,14 +749,16 @@ Default Configuration ~
749749
-- heading, paragraph, code, dash, bullet, checkbox, quote, pipe_table,
750750
-- callout, link, sign, indent, latex, html, win_options
751751
overrides = {
752-
-- Overrides for different buftypes, see :h 'buftype'
752+
-- Override for different buflisted values, see :h 'buflisted'
753+
buflisted = {},
754+
-- Override for different buftype values, see :h 'buftype'
753755
buftype = {
754756
nofile = {
755757
padding = { highlight = 'NormalFloat' },
756758
sign = { enabled = false },
757759
},
758760
},
759-
-- Overrides for different filetypes, see :h 'filetype'
761+
-- Override for different filetype values, see :h 'filetype'
760762
filetype = {},
761763
},
762764
-- Mapping from treesitter language to user defined handlers

lua/render-markdown/debug/validator.lua

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local Iter = require('render-markdown.lib.iter')
2+
13
---@class render.md.debug.Spec
24
---@field message string
35
---@field validation fun(value: any): boolean, string?
@@ -14,22 +16,22 @@ Spec.__index = Spec
1416
---@param validator render.md.debug.Validator
1517
---@param config? table<string, any>
1618
---@param nilable boolean
17-
---@param key? string|string[]
1819
---@param path? string
20+
---@param key any
1921
---@return render.md.debug.ValidatorSpec
20-
function Spec.new(validator, config, nilable, key, path)
22+
function Spec.new(validator, config, nilable, path, key)
2123
local self = setmetatable({}, Spec)
2224
self.validator = validator
2325
self.config = config
2426
self.nilable = nilable
2527
self.path = path or ''
26-
self.specs = {}
2728
if self.config ~= nil and key ~= nil then
28-
key = type(key) == 'table' and key or { key }
29-
self.path = self.path .. '.' .. table.concat(key, '.')
30-
self.config = vim.tbl_get(self.config, unpack(key))
29+
local keys = type(key) == 'table' and key or { key }
30+
self.config = vim.tbl_get(self.config, unpack(keys))
3131
self.config = type(self.config) == 'table' and self.config or nil
32+
self.path = self.path .. '.' .. table.concat(Iter.list.map(keys, tostring), '.')
3233
end
34+
self.specs = {}
3335
return self
3436
end
3537

@@ -48,7 +50,7 @@ function Spec:nested(keys, f, nilable)
4850
end
4951
for _, key in ipairs(keys) do
5052
self:type(key, 'table')
51-
f(Spec.new(self.validator, self.config, nilable, key, self.path))
53+
f(Spec.new(self.validator, self.config, nilable, self.path, key))
5254
end
5355
return self
5456
end

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '7.8.3'
8+
M.version = '7.8.4'
99

1010
function M.check()
1111
M.start('version')

lua/render-markdown/init.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ local M = {}
224224
---@field public below? integer
225225

226226
---@class (exact) render.md.UserConfigOverrides
227+
---@field public buflisted? table<boolean, render.md.UserBufferConfig>
227228
---@field public buftype? table<string, render.md.UserBufferConfig>
228229
---@field public filetype? table<string, render.md.UserBufferConfig>
229230

@@ -790,14 +791,16 @@ M.default_config = {
790791
-- heading, paragraph, code, dash, bullet, checkbox, quote, pipe_table,
791792
-- callout, link, sign, indent, latex, html, win_options
792793
overrides = {
793-
-- Overrides for different buftypes, see :h 'buftype'
794+
-- Override for different buflisted values, see :h 'buflisted'
795+
buflisted = {},
796+
-- Override for different buftype values, see :h 'buftype'
794797
buftype = {
795798
nofile = {
796799
padding = { highlight = 'NormalFloat' },
797800
sign = { enabled = false },
798801
},
799802
},
800-
-- Overrides for different filetypes, see :h 'filetype'
803+
-- Override for different filetype values, see :h 'filetype'
801804
filetype = {},
802805
},
803806
-- Mapping from treesitter language to user defined handlers

lua/render-markdown/state.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ function M.get(buf)
8080
local config = configs[buf]
8181
if config == nil then
8282
local buf_config = M.default_buffer_config()
83-
for _, name in ipairs({ 'buftype', 'filetype' }) do
84-
local override = M.config.overrides[name][util.get('buf', buf, name)]
83+
for _, name in ipairs({ 'buflisted', 'buftype', 'filetype' }) do
84+
local value = util.get('buf', buf, name)
85+
local override = M.config.overrides[name][value]
8586
if override ~= nil then
8687
buf_config = vim.tbl_deep_extend('force', buf_config, override)
8788
end
@@ -319,7 +320,7 @@ function M.validate()
319320
end)
320321
:nested('overrides', function(overrides)
321322
overrides
322-
:nested({ 'buftype', 'filetype' }, function(override)
323+
:nested({ 'buflisted', 'buftype', 'filetype' }, function(override)
323324
override
324325
:nested('ALL', function(buffer)
325326
buffer_rules(buffer):check()

lua/render-markdown/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
---@field public below integer
171171

172172
---@class (exact) render.md.ConfigOverrides
173+
---@field public buflisted table<boolean, render.md.UserBufferConfig>
173174
---@field public buftype table<string, render.md.UserBufferConfig>
174175
---@field public filetype table<string, render.md.UserBufferConfig>
175176

0 commit comments

Comments
 (0)