From 9dd43bc6b93a6a8dedbb562da4d33be104e54431 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 25 Feb 2024 00:32:12 -0600 Subject: [PATCH 1/2] fix(mappings): use explicit bufnr for meta return in `apply_text_edits` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since https://github.com/neovim/neovim/commit/2e1f5055acdef650c27efc4afdf8606037ec021b, Neovim now explicitly requires the bufnr for `vim.lsp.util.apply_text_edits` to be fully resolved — meaning it cannot be 0 or null. --- lua/orgmode/org/mappings.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index 9c3256404..28d71bb62 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -645,7 +645,7 @@ function OrgMappings:meta_return(suffix) end if #text_edits > 0 then - vim.lsp.util.apply_text_edits(text_edits, 0, constants.default_offset_encoding) + vim.lsp.util.apply_text_edits(text_edits, vim.api.nvim_get_current_buf(), constants.default_offset_encoding) vim.fn.cursor(end_row + 1 + (add_empty_line and 1 or 0), 1) -- +1 for next line From 2ed85b9bb0d253a4fe582dece38e90a72f32c535 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sat, 24 Feb 2024 19:12:22 -0600 Subject: [PATCH 2/2] refactor(agenda): use extmarks to set tags in right column --- lua/orgmode/agenda/init.lua | 25 ++++++++++++++++++++----- lua/orgmode/agenda/views/agenda.lua | 6 ------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 1b2b3f973..7e6d79fa3 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -17,7 +17,9 @@ local Promise = require('orgmode.utils.promise') ---@field views table[] ---@field filters OrgAgendaFilter ---@field files OrgFiles -local Agenda = {} +local Agenda = { + _ns_id = vim.api.nvim_create_namespace('orgmode.ui.agenda'), +} ---@param opts? table function Agenda:new(opts) @@ -161,11 +163,24 @@ function Agenda:_render(skip_rebuild) vim.w.org_window_pos = nil end end - local lines = vim.tbl_map(function(item) - return item.line_content - end, self.content) vim.bo.modifiable = true - vim.api.nvim_buf_set_lines(0, 0, -1, true, lines) + for index, item in ipairs(self.content) do + vim.api.nvim_buf_set_lines(0, index - 1, -1, true, { item.line_content }) + if item.headline and #item.headline:get_tags() > 0 then + -- Get the first highlight group from the given item and apply it to the tag if available. If + -- not use the generic `Normal` hl group + local extmark_hls = { + (item.highlights and item.highlights[1] and item.highlights[1].hlgroup) and item.highlights[1].hlgroup + or 'Normal', + '@org.agenda.tag', + } + vim.api.nvim_buf_set_extmark(0, self._ns_id, index - 1, 0, { + virt_text = { { item.headline:tags_to_string(), extmark_hls } }, + virt_text_pos = 'right_align', + hl_mode = 'combine', + }) + end + end vim.bo.modifiable = false vim.bo.modified = false colors.highlight(self.highlights, true) diff --git a/lua/orgmode/agenda/views/agenda.lua b/lua/orgmode/agenda/views/agenda.lua index afd649957..1e3ca5978 100644 --- a/lua/orgmode/agenda/views/agenda.lua +++ b/lua/orgmode/agenda/views/agenda.lua @@ -293,12 +293,6 @@ function AgendaView.build_agenda_item_content(agenda_item, longest_category, lon todo_keyword = todo_padding .. todo_keyword local line = string.format('%s%s%s %s', category, date, todo_keyword, headline:get_title_with_priority()) local todo_keyword_pos = string.format('%s%s%s', category, date, todo_padding):len() - if #headline:get_tags() > 0 then - local tags_string = headline:tags_to_string() - local padding_length = math.max(1, win_width - vim.api.nvim_strwidth(line) - vim.api.nvim_strwidth(tags_string)) - local indent = string.rep(' ', padding_length) - line = string.format('%s%s%s', line, indent, tags_string) - end local item_highlights = {} if #agenda_item.highlights then