Skip to content

Commit 1e2e9a3

Browse files
feat: wrap nvim_buf_set_extmark in pcall use notify_once if it errors
## Details Related to issues like #382 We use a version check like `vim.fn.has('nvim-0.11') == 1` before adding any `extmarks` that use version specific options like `conceal_lines`. By doing this we avoid ever getting to the API call that adds the marks and can add fallback behavior for certain decorations like code borders. However this version check has to make the assumption that the user has all the features of the released version, which should be safe for most people. However anyone using a dev version could have built it at a time where the version check passes but before that feature was introduced. This should be somewhat rare as it relies on someone having a dev build and not upgrading when a release occurs. In the event of an error we use `vim.notify_once` to inform the user that they should update their build or switch to the released version while not spamming errors at them. Minor other changes: - use `vim.o` to get options instead of `nvim_get_option_value` - update `colorcolumn` suggestions to use option value
1 parent 92256e0 commit 1e2e9a3

File tree

8 files changed

+43
-23
lines changed

8 files changed

+43
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,15 +766,15 @@ require('render-markdown').setup({
766766
-- @see :h 'conceallevel'
767767
conceallevel = {
768768
-- Used when not being rendered, get user setting.
769-
default = vim.api.nvim_get_option_value('conceallevel', {}),
769+
default = vim.o.conceallevel,
770770
-- Used when being rendered, concealed text is completely hidden.
771771
rendered = 3,
772772
},
773773
-- @see :h 'concealcursor'
774774
concealcursor = {
775775
-- Used when not being rendered, get user setting.
776-
default = vim.api.nvim_get_option_value('concealcursor', {}),
777-
-- Used when being rendered, disable concealing text in all modes.
776+
default = vim.o.concealcursor,
777+
-- Used when being rendered, show concealed text in all modes.
778778
rendered = '',
779779
},
780780
},

doc/limitations.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Below are a few things to try out to improve the aesthetic:
4949
```lua
5050
require('render-markdown').setup({
5151
win_options = {
52-
colorcolumn = { default = '80', rendered = '' },
52+
colorcolumn = { default = vim.o.colorcolumn, rendered = '' },
5353
},
5454
})
5555
```
@@ -58,13 +58,20 @@ require('render-markdown').setup({
5858

5959
```lua
6060
require('render-markdown').setup({
61-
heading = { width = 'block', min_width = 80 },
62-
code = { width = 'block', min_width = 80 },
61+
heading = { width = 'block', min_width = tonumber(vim.o.colorcolumn) },
62+
code = { width = 'block', min_width = tonumber(vim.o.colorcolumn) },
6363
})
6464
```
6565

6666
- Do not use `block` width, keep the default value of `full`
6767

68+
```lua
69+
require('render-markdown').setup({
70+
heading = { width = 'full' },
71+
code = { width = 'full' },
72+
})
73+
```
74+
6875
## `latex` Formula Positioning
6976

7077
[ISSUE #6](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/6)

doc/render-markdown.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.11.0 Last change: 2025 March 31
1+
*render-markdown.txt* For 0.11.0 Last change: 2025 April 01
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -831,15 +831,15 @@ Default Configuration ~
831831
-- @see :h 'conceallevel'
832832
conceallevel = {
833833
-- Used when not being rendered, get user setting.
834-
default = vim.api.nvim_get_option_value('conceallevel', {}),
834+
default = vim.o.conceallevel,
835835
-- Used when being rendered, concealed text is completely hidden.
836836
rendered = 3,
837837
},
838838
-- @see :h 'concealcursor'
839839
concealcursor = {
840840
-- Used when not being rendered, get user setting.
841-
default = vim.api.nvim_get_option_value('concealcursor', {}),
842-
-- Used when being rendered, disable concealing text in all modes.
841+
default = vim.o.concealcursor,
842+
-- Used when being rendered, show concealed text in all modes.
843843
rendered = '',
844844
},
845845
},

doc/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Create a new `markdown` file locally with the following content:
5858

5959
Run `:InspectTree` which should output the following:
6060

61-
```text
61+
```query
6262
(document ; [0, 0] - [8, 0]
6363
(section ; [0, 0] - [8, 0]
6464
(atx_heading ; [0, 0] - [1, 0]

lua/render-markdown/core/extmark.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,33 @@ end
3131
---@param ns integer
3232
---@param buf integer
3333
function Extmark:show(ns, buf)
34-
if self.id == nil then
35-
local mark = self.mark
36-
mark.opts.strict = false
37-
self.id = vim.api.nvim_buf_set_extmark(buf, ns, mark.start_row, mark.start_col, mark.opts)
34+
if self.id ~= nil then
35+
return
36+
end
37+
local mark = self.mark
38+
mark.opts.strict = false
39+
local ok, id = pcall(vim.api.nvim_buf_set_extmark, buf, ns, mark.start_row, mark.start_col, mark.opts)
40+
if ok then
41+
self.id = id
42+
else
43+
local message = {
44+
string.format('render-markdown.nvim set extmark error (%s)', id),
45+
'you are running an old build of neovim that has now been released',
46+
'your build does not have all the features that are in the release',
47+
'update your build or switch to the release version',
48+
}
49+
vim.notify_once(table.concat(message, '\n'), vim.log.levels.ERROR)
3850
end
3951
end
4052

4153
---@param ns integer
4254
---@param buf integer
4355
function Extmark:hide(ns, buf)
44-
if self.id ~= nil then
45-
vim.api.nvim_buf_del_extmark(buf, ns, self.id)
46-
self.id = nil
56+
if self.id == nil then
57+
return
4758
end
59+
vim.api.nvim_buf_del_extmark(buf, ns, self.id)
60+
self.id = nil
4861
end
4962

5063
return Extmark

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
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 = '8.2.1'
8+
M.version = '8.2.2'
99

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

lua/render-markdown/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,15 +947,15 @@ M.default_config = {
947947
-- @see :h 'conceallevel'
948948
conceallevel = {
949949
-- Used when not being rendered, get user setting.
950-
default = vim.api.nvim_get_option_value('conceallevel', {}),
950+
default = vim.o.conceallevel,
951951
-- Used when being rendered, concealed text is completely hidden.
952952
rendered = 3,
953953
},
954954
-- @see :h 'concealcursor'
955955
concealcursor = {
956956
-- Used when not being rendered, get user setting.
957-
default = vim.api.nvim_get_option_value('concealcursor', {}),
958-
-- Used when being rendered, disable concealing text in all modes.
957+
default = vim.o.concealcursor,
958+
-- Used when being rendered, show concealed text in all modes.
959959
rendered = '',
960960
},
961961
},

lua/render-markdown/lib/env.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function M.file_size_mb(file)
4141
local ok, stats = pcall(function()
4242
return M.uv.fs_stat(file)
4343
end)
44-
if not (ok and stats) then
44+
if not ok or stats == nil then
4545
return 0
4646
end
4747
return stats.size / (1024 * 1024)

0 commit comments

Comments
 (0)