@@ -17,7 +17,9 @@ local Promise = require('orgmode.utils.promise')
17
17
--- @field views table[]
18
18
--- @field filters OrgAgendaFilter
19
19
--- @field files OrgFiles
20
- local Agenda = {}
20
+ local Agenda = {
21
+ _ns_id = vim .api .nvim_create_namespace (' orgmode.ui.agenda' ),
22
+ }
21
23
22
24
--- @param opts ? table
23
25
function Agenda :new (opts )
@@ -161,11 +163,24 @@ function Agenda:_render(skip_rebuild)
161
163
vim .w .org_window_pos = nil
162
164
end
163
165
end
164
- local lines = vim .tbl_map (function (item )
165
- return item .line_content
166
- end , self .content )
167
166
vim .bo .modifiable = true
168
- vim .api .nvim_buf_set_lines (0 , 0 , - 1 , true , lines )
167
+ for index , item in ipairs (self .content ) do
168
+ vim .api .nvim_buf_set_lines (0 , index - 1 , - 1 , true , { item .line_content })
169
+ if item .headline and # item .headline :get_tags () > 0 then
170
+ -- Get the first highlight group from the given item and apply it to the tag if available. If
171
+ -- not use the generic `Normal` hl group
172
+ local extmark_hls = {
173
+ (item .highlights and item .highlights [1 ] and item .highlights [1 ].hlgroup ) and item .highlights [1 ].hlgroup
174
+ or ' Normal' ,
175
+ ' @org.agenda.tag' ,
176
+ }
177
+ vim .api .nvim_buf_set_extmark (0 , self ._ns_id , index - 1 , 0 , {
178
+ virt_text = { { item .headline :tags_to_string (), extmark_hls } },
179
+ virt_text_pos = ' right_align' ,
180
+ hl_mode = ' combine' ,
181
+ })
182
+ end
183
+ end
169
184
vim .bo .modifiable = false
170
185
vim .bo .modified = false
171
186
colors .highlight (self .highlights , true )
0 commit comments