Skip to content

Commit f187721

Browse files
fix: update window options on alternate buffer switch
## Details Issue: #177 Reported as an issue when using telescope but is a general problem when opening a different file in the current window then switching back using the alternate buffer `<C-6>` keymap. This occurs because changing the buffer in the current window resets the local window options. However we have logic to only set window options on a state change. Essentially we were not capturing the idea that options are reset when opening a different buffer in the current window. To fix this remove the logic that gates setting window options on a state change and instead always update the window options based on the current state. This shouldn't have much performance impact to users. Minor other changes: - Add distribtion input to issue templates - Add `info` log level which provides some more high level information than `error` but not as much noise as `debug` - Remove level specific methods from `log` and instead take level as an input argument and compare levels as integers to decide whether to log
1 parent edd919c commit f187721

File tree

14 files changed

+69
-60
lines changed

14 files changed

+69
-60
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ body:
99
placeholder: 0.10.0
1010
validations:
1111
required: true
12+
- type: input
13+
attributes:
14+
label: Neovim distribution
15+
placeholder: N/A, LazyVim, NvChad
16+
validations:
17+
required: true
1218
- type: input
1319
attributes:
1420
label: Operating system

.github/ISSUE_TEMPLATE/help.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ description: Advice on how to do something
33
title: "help: "
44
labels: [question]
55
body:
6+
- type: input
7+
attributes:
8+
label: Neovim version (nvim -v)
9+
placeholder: 0.10.0
10+
validations:
11+
required: true
12+
- type: input
13+
attributes:
14+
label: Neovim distribution
15+
placeholder: N/A, LazyVim, NvChad
16+
validations:
17+
required: true
618
- type: textarea
719
attributes:
820
label: Description

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 September 21
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 September 22
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/buffer_state.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
---@field private buf integer
33
---@field private timer uv_timer_t
44
---@field private running boolean
5-
---@field state? 'default'|'rendered'
65
---@field marks? render.md.Extmark[]
76
local BufferState = {}
87
BufferState.__index = BufferState
@@ -14,7 +13,6 @@ function BufferState.new(buf)
1413
self.buf = buf
1514
self.timer = (vim.uv or vim.loop).new_timer()
1615
self.running = false
17-
self.state = nil
1816
self.marks = nil
1917
return self
2018
end

lua/render-markdown/core/context.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function Context:query(root, query, callback)
133133
for id, node in query:iter_captures(root, self.buf, self.top, self.bottom) do
134134
local capture = query.captures[id]
135135
local info = NodeInfo.new(self.buf, node)
136-
log.debug_node_info(capture, info)
136+
log.node_info(capture, info)
137137
callback(capture, info)
138138
end
139139
end

lua/render-markdown/core/list.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ function Marks:add(conceal, start_row, start_col, opts)
3232
opts = opts,
3333
}
3434
if opts.virt_text_pos == 'inline' and not util.has_10 then
35-
log.error('inline marks require neovim >= 0.10.0', mark)
35+
log.add('error', 'inline marks require neovim >= 0.10.0', mark)
3636
return false
3737
end
3838
if opts.virt_text_repeat_linebreak ~= nil and not util.has_10 then
39-
log.error('repeat linebreak marks require neovim >= 0.10.0', mark)
39+
log.add('error', 'repeat linebreak marks require neovim >= 0.10.0', mark)
4040
return false
4141
end
42-
log.debug('mark', mark)
42+
log.add('debug', 'mark', mark)
4343
table.insert(self.marks, mark)
4444
return true
4545
end

lua/render-markdown/core/log.lua

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ end
3131

3232
---@param capture string
3333
---@param info render.md.NodeInfo
34-
function M.debug_node_info(capture, info)
35-
M.debug('node info', {
34+
function M.node_info(capture, info)
35+
M.add('debug', 'node info', {
3636
capture = capture,
3737
text = info.text,
3838
rows = { info.start_row, info.end_row },
@@ -44,52 +44,32 @@ end
4444
---@param group string
4545
---@param capture string
4646
function M.unhandled_capture(group, capture)
47-
M.error('unhandled capture', string.format('%s -> %s', group, capture))
47+
M.add('error', 'unhandled capture', string.format('%s -> %s', group, capture))
4848
end
4949

5050
---Encountered if new type is seen for a particular group
5151
---@param language string
5252
---@param group string
5353
---@param value string
5454
function M.unhandled_type(language, group, value)
55-
M.error('unhandled type', string.format('%s -> %s -> %s', language, group, value))
56-
end
57-
58-
---@param name string
59-
---@param buf integer
60-
---@param ... any
61-
function M.debug_buf(name, buf, ...)
62-
M.debug(string.format('%s %d', name, buf), ...)
63-
end
64-
65-
---@param name string
66-
---@param ... any
67-
function M.debug(name, ...)
68-
if vim.tbl_contains({ 'debug' }, M.level) then
69-
M.add('debug', name, ...)
70-
end
55+
M.add('error', 'unhandled type', string.format('%s -> %s -> %s', language, group, value))
7156
end
7257

58+
---@param level render.md.config.LogLevel
7359
---@param name string
7460
---@param buf integer
7561
---@param ... any
76-
function M.error_buf(name, buf, ...)
77-
M.error(string.format('%s %d', name, buf), ...)
78-
end
79-
80-
---@param name string
81-
---@param ... any
82-
function M.error(name, ...)
83-
if vim.tbl_contains({ 'debug', 'error' }, M.level) then
84-
M.add('error', name, ...)
85-
end
62+
function M.buf(level, name, buf, ...)
63+
M.add(level, string.format('%s %d', name, buf), ...)
8664
end
8765

88-
---@private
8966
---@param level render.md.config.LogLevel
9067
---@param name string
9168
---@param ... any
9269
function M.add(level, name, ...)
70+
if M.level_value(level) < M.level_value(M.level) then
71+
return
72+
end
9373
local messages = {}
9474
local args = vim.F.pack_len(...)
9575
for i = 1, args.n do
@@ -110,6 +90,21 @@ function M.add(level, name, ...)
11090
end
11191
end
11292

93+
---@private
94+
---@param level render.md.config.LogLevel
95+
---@return integer
96+
function M.level_value(level)
97+
if level == 'debug' then
98+
return 1
99+
elseif level == 'info' then
100+
return 2
101+
elseif level == 'error' then
102+
return 3
103+
else
104+
return 0
105+
end
106+
end
107+
113108
function M.flush()
114109
if #M.entries == 0 then
115110
return

lua/render-markdown/core/ui.lua

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ end
7272
---@param event string
7373
---@param change boolean
7474
function M.debounce_update(buf, win, event, change)
75-
log.debug_buf('update', buf, string.format('event %s', event), string.format('change %s', change))
75+
log.buf('info', 'update', buf, string.format('event %s', event), string.format('change %s', change))
7676
if not util.valid(buf, win) then
7777
return
7878
end
@@ -101,14 +101,12 @@ function M.update(buf, win, parse)
101101

102102
local config, buffer_state = state.get(buf), Cache.get(buf)
103103
local mode, row = util.mode(), util.row(buf, win)
104-
105104
local next_state = M.next_state(config, win, mode)
106-
if next_state ~= buffer_state.state then
107-
for name, value in pairs(config.win_options) do
108-
util.set_win(win, name, value[next_state])
109-
end
105+
106+
log.buf('info', 'state', buf, next_state)
107+
for name, value in pairs(config.win_options) do
108+
util.set_win(win, name, value[next_state])
110109
end
111-
buffer_state.state = next_state
112110

113111
if next_state == 'rendered' then
114112
if buffer_state.marks == nil or parse then
@@ -156,7 +154,7 @@ end
156154
function M.parse_buffer(buf, win)
157155
local has_parser, parser = pcall(vim.treesitter.get_parser, buf)
158156
if not has_parser then
159-
log.error_buf('fail', buf, 'no treesitter parser found')
157+
log.buf('error', 'fail', buf, 'no treesitter parser found')
160158
return {}
161159
end
162160
-- Reset buffer context
@@ -187,23 +185,23 @@ end
187185
---@param root TSNode
188186
---@return render.md.Mark[]
189187
function M.parse_tree(buf, language, root)
190-
log.debug_buf('language', buf, language)
188+
log.buf('debug', 'language', buf, language)
191189
if not Context.get(buf):contains_node(root) then
192190
return {}
193191
end
194192

195193
local marks = {}
196194
local user = state.custom_handlers[language]
197195
if user ~= nil then
198-
log.debug_buf('running handler', buf, 'user')
196+
log.buf('debug', 'running handler', buf, 'user')
199197
vim.list_extend(marks, user.parse(root, buf))
200198
if not user.extends then
201199
return marks
202200
end
203201
end
204202
local builtin = builtin_handlers[language]
205203
if builtin ~= nil then
206-
log.debug_buf('running handler', buf, 'builtin')
204+
log.buf('debug', 'running handler', buf, 'builtin')
207205
vim.list_extend(marks, builtin.parse(root, buf))
208206
end
209207
return marks

lua/render-markdown/handler/latex.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function M.parse(root, buf)
1919
return {}
2020
end
2121
if vim.fn.executable(latex.converter) ~= 1 then
22-
log.debug('executable not found', latex.converter)
22+
log.add('debug', 'executable not found', latex.converter)
2323
return {}
2424
end
2525

2626
local info = NodeInfo.new(buf, root)
27-
log.debug_node_info('latex', info)
27+
log.node_info('latex', info)
2828

2929
local expressions = cache[info.text]
3030
if expressions == nil then

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.1.3'
7+
M.version = '7.1.4'
88

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

0 commit comments

Comments
 (0)