Skip to content

Commit 66591ca

Browse files
fix(agenda): Work with agenda buffer number instead of 0
1 parent 1425b36 commit 66591ca

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lua/orgmode/agenda/init.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ function Agenda:tags_todo()
6969
return self:tags({ todo_only = true })
7070
end
7171

72-
---@return number|nil window id
72+
---@return number|nil, number window id nand buffer id
7373
function Agenda:open_window()
7474
-- if an agenda window is already open, return it
7575
for _, win in ipairs(vim.api.nvim_list_wins()) do
76+
local buf = vim.api.nvim_win_get_buf(win)
7677
local ft = vim.api.nvim_get_option_value('filetype', {
77-
buf = vim.api.nvim_win_get_buf(win),
78+
buf = buf,
7879
})
7980
if ft == 'orgagenda' then
80-
return win
81+
return win, buf
8182
end
8283
end
8384

@@ -87,7 +88,7 @@ function Agenda:open_window()
8788
vim.cmd([[setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap nospell]])
8889
vim.w.org_window_pos = vim.fn.win_screenpos(0)
8990
config:setup_mappings('agenda')
90-
return vim.fn.win_getid()
91+
return vim.fn.win_getid(), vim.fn.bufnr()
9192
end
9293

9394
function Agenda:prompt()
@@ -147,8 +148,7 @@ function Agenda:_render(skip_rebuild)
147148
utils.concat(self.highlights, view.highlights)
148149
end
149150
end
150-
local win = self:open_window()
151-
vim.cmd(vim.fn.win_id2win(win) .. 'wincmd w')
151+
local win, bufnr = self:open_window()
152152
if vim.w.org_window_split_mode == 'horizontal' then
153153
local win_height = math.max(math.min(34, #self.content), config.org_agenda_min_height)
154154
if vim.w.org_window_pos and vim.deep_equal(vim.fn.win_screenpos(0), vim.w.org_window_pos) then
@@ -161,14 +161,14 @@ function Agenda:_render(skip_rebuild)
161161
local lines = vim.tbl_map(function(item)
162162
return item.line_content
163163
end, self.content)
164-
vim.bo.modifiable = true
165-
vim.api.nvim_buf_set_lines(0, 0, -1, true, lines)
166-
vim.bo.modifiable = false
167-
vim.bo.modified = false
168-
colors.highlight(self.highlights, true)
164+
vim.bo[bufnr].modifiable = true
165+
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
166+
vim.bo[bufnr].modifiable = false
167+
vim.bo[bufnr].modified = false
168+
colors.highlight(self.highlights, true, bufnr)
169169
vim.tbl_map(function(item)
170170
if item.highlights then
171-
return colors.highlight(item.highlights)
171+
return colors.highlight(item.highlights, false, bufnr)
172172
end
173173
end, self.content)
174174
if not skip_rebuild then

lua/orgmode/colors/init.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,21 @@ end
7373
---@param highlights table[]
7474
---@param clear? boolean
7575
---@return string
76-
M.highlight = function(highlights, clear)
76+
M.highlight = function(highlights, clear, bufnr)
77+
bufnr = bufnr or 0
7778
if clear then
78-
vim.api.nvim_buf_clear_namespace(0, namespace, 0, -1)
79+
vim.api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)
7980
end
8081
for _, hl in ipairs(highlights) do
8182
if hl.whole_line then
82-
vim.api.nvim_buf_set_extmark(0, namespace, hl.range.start_line - 1, hl.range.start_col - 1, {
83+
vim.api.nvim_buf_set_extmark(bufnr, namespace, hl.range.start_line - 1, hl.range.start_col - 1, {
8384
hl_group = hl.hlgroup,
8485
end_line = hl.range.start_line,
8586
hl_eol = true,
8687
})
8788
else
8889
vim.api.nvim_buf_add_highlight(
89-
0,
90+
bufnr,
9091
namespace,
9192
hl.hlgroup,
9293
hl.range.start_line - 1,

0 commit comments

Comments
 (0)