Skip to content

Commit

Permalink
Add basic highlights to agenda view.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak authored and Kristijan Husak committed May 19, 2021
1 parent a2722cd commit 83ba614
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lua/orgmode/agenda/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ function Agenda:render()
span = string.format('%d days', span)
end
local content = {{ value = utils.capitalize(span)..'-agenda:' }}
for _, date in ipairs(dates) do
for i, date in ipairs(dates) do
local date_string = date:format(self.day_format)
local is_today = date:is_today()
if is_today then
date_string = date_string..' [Today]'
end
table.insert(content, { value = date_string })
local is_weekend = date:is_weekend()

table.insert(content, { value = date_string, highlight = (is_today or is_weekend) and 'OrgBold' or nil })
for filename, orgfile in pairs(self.files) do
local headlines = {}
if is_today then
Expand All @@ -75,13 +74,16 @@ function Agenda:render()
for _, d in ipairs(sorted_dates) do
local date_label = d:humanize(date)
local is_same_day = d:is_same(date, 'day')
local highlight = nil
if d:is_deadline() and is_same_day then
date_label = 'Deadline'
highlight = 'OrgAgendaDeadline'
if not d.date_only and is_today then
date_label = d:format('%H:%M')..'...Deadline'
end
elseif d:is_scheduled() and is_same_day then
date_label = 'Scheduled'
highlight = 'OrgAgendaSchedule'
elseif date_label == 'Today' and is_same_day then
date_label = ''
end
Expand All @@ -98,6 +100,7 @@ function Agenda:render()
id = item.headline.id,
file = filename,
line = item.headline.range.from.line,
highlight = highlight
})
end
end
Expand All @@ -117,6 +120,11 @@ function Agenda:render()
vim.api.nvim_buf_set_lines(0, 0, -1, true, vim.tbl_map(function(item) return item.value end, content))
vim.bo.modifiable = false
vim.bo.modified = false
for i, item in ipairs(content) do
if item.highlight then
utils.highlight(item.highlight, i)
end
end
end

function Agenda:open()
Expand Down
5 changes: 5 additions & 0 deletions lua/orgmode/objects/date.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ function Date:is_closed()
return self.active and self.type == 'CLOSED'
end

function Date:is_weekend()
local isoweekday = self:get_isoweekday()
return isoweekday >= 6
end

function Date:get_warning_adjustment()
if #self.adjustments == 0 then return nil end
local adj = self.adjustments[#self.adjustments]
Expand Down
5 changes: 5 additions & 0 deletions lua/orgmode/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ function utils.convert_to_isoweekday(weekday)
return weekday - 1
end

-- TODO: Figure out how to not override TODO highlights with this
function utils.highlight(group, line)
return vim.api.nvim_buf_add_highlight(0, 0, group, line - 1 , 0, -1)
end

return utils
18 changes: 18 additions & 0 deletions syntax/orgagenda.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syn match OrgTodo /\<TODO\>/
syn match OrgNext /\<NEXT\>/
syn match OrgDone /\<DONE\>/

syn match OrgAgendaDay /^\w\+\s\d\+\s\w\+\s\d\d\d\d$/

" TODO - Add better defaults
hi default link OrgTodo Red
hi default link OrgNext Blue
hi default link OrgDone Green

hi default link OrgAgendaDay Statement
hi default link OrgAgendaToday Identifier

hi default link OrgAgendaDeadline Red
hi default link OrgAgendaSchedule Green

hi OrgBold gui=bold

0 comments on commit 83ba614

Please sign in to comment.