Skip to content

Commit

Permalink
Auto format code with stylua.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristijan Husak committed Jul 20, 2021
1 parent 1eb42ae commit 0b14c09
Show file tree
Hide file tree
Showing 49 changed files with 1,702 additions and 1,166 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: JohnnyMorganz/stylua-action@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
# CLI arguments
args: --check lua/ tests/
- name: Install Plenary
uses: actions/checkout@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ test:
nvim --headless --noplugin -u tests/minimal_init.vim -c "PlenaryBustedDirectory tests/plenary/ {minimal_init = 'tests/minimal_init.vim'}"
docs:
md2vim -desc "*orgmode* *orgmode.nvim*\n* NOTE: This file is autogenerated from DOCS.md file" DOCS.md doc/orgmode.txt
format:
stylua lua/ tests/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ make test
### Documentation
Vim documentation is auto generated from [DOCS.md](DOCS.md) file with [md2vim](https://github.com/FooSoft/md2vim).

### Formatting
Formatting is done via [StyLua](https://github.com/JohnnyMorganz/StyLua). To format everything run:
```
make format
```

### Parser
Parser is written manually from scratch. It doesn't follow any parser writing patterns (AFAIK), because I don't have
much experience with those. Any help on this topic is appreciated.
Expand Down
60 changes: 40 additions & 20 deletions lua/orgmode/agenda/agenda_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ local hl_map = Highlights.get_agenda_hl_map()
local config = require('orgmode.config')
local FUTURE_DEADLINE_AS_WARNING_DAYS = math.floor(config.org_deadline_warning_days / 2)
local function add_padding(datetime)
if datetime:len() >= 11 then return datetime..' ' end
return datetime..string.rep('.', 11 - datetime:len())..' '
if datetime:len() >= 11 then
return datetime .. ' '
end
return datetime .. string.rep('.', 11 - datetime:len()) .. ' '
end

---@class AgendaItem
Expand All @@ -20,7 +22,6 @@ end
---@field highlights table[]
local AgendaItem = {}


---@param headline_date Date single date in a headline
---@param headline Headline
---@param date Date date for which item should be rendered
Expand Down Expand Up @@ -60,25 +61,38 @@ function AgendaItem:_process()
end

function AgendaItem:_is_valid_for_today()
if not self.headline_date.active or self.headline_date:is_closed() or self.headline_date:is_obsolete_range_end() then return false end
if not self.headline_date.active or self.headline_date:is_closed() or self.headline_date:is_obsolete_range_end() then
return false
end
if self.headline_date:is_none() then
return self.is_same_day or self.is_in_date_range
end

if self.headline_date:is_deadline() then
if self.headline:is_done() and config.org_agenda_skip_deadline_if_done then return false end
if self.is_same_day then return true end
if self.headline:is_done() and config.org_agenda_skip_deadline_if_done then
return false
end
if self.is_same_day then
return true
end
if self.headline_date:is_before(self.date, 'day') then
return not self.headline:is_done()
end
return not self.headline:is_done() and self.date:is_between(self.headline_date:get_adjusted_date(), self.headline_date, 'day')
return not self.headline:is_done()
and self.date:is_between(self.headline_date:get_adjusted_date(), self.headline_date, 'day')
end

if self.headline:is_done() and config.org_agenda_skip_scheduled_if_done then return false end
if self.headline:is_done() and config.org_agenda_skip_scheduled_if_done then
return false
end

if not self.headline_date:get_negative_adjustment() then
if self.is_same_day then return true end
if self.headline_date:is_before(self.date, 'day') and not self.headline:is_done() then return true end
if self.is_same_day then
return true
end
if self.headline_date:is_before(self.date, 'day') and not self.headline:is_done() then
return true
end
return false
end

Expand All @@ -90,7 +104,9 @@ function AgendaItem:_is_valid_for_today()
end

function AgendaItem:_is_valid_for_date()
if not self.headline_date.active or self.headline_date:is_closed() or self.headline_date:is_obsolete_range_end() then return false end
if not self.headline_date.active or self.headline_date:is_closed() or self.headline_date:is_obsolete_range_end() then
return false
end

if self.headline:is_done() then
if self.headline_date:is_deadline() and config.org_agenda_skip_deadline_if_done then
Expand All @@ -112,33 +128,35 @@ function AgendaItem:_generate_label()
local time = not self.headline_date.date_only and add_padding(self.headline_date:format_time()) or ''
if self.headline_date:is_deadline() then
if self.is_same_day then
return time..'Deadline:'
return time .. 'Deadline:'
end
return self.headline_date:humanize(self.date)..':'
return self.headline_date:humanize(self.date) .. ':'
end

if self.headline_date:is_scheduled() then
if self.is_same_day then
return time..'Scheduled:'
return time .. 'Scheduled:'
end

local diff = math.abs(self.date:diff(self.headline_date))

return 'Sched. '..diff..'x:'
return 'Sched. ' .. diff .. 'x:'
end

if self.headline_date.is_date_range_start then
if not self.is_in_date_range then return time end
if not self.is_in_date_range then
return time
end
local range = string.format('(%d/%d):', self.date:diff(self.headline_date) + 1, self.date_range_days)
if not self.is_same_day then
return range
end
return time..range
return time .. range
end

if self.headline_date.is_date_range_end then
local range = string.format('(%d/%d):', self.date_range_days, self.date_range_days)
return time..range
return time .. range
end

return time
Expand Down Expand Up @@ -172,12 +190,14 @@ function AgendaItem:_generate_highlight()
end

function AgendaItem:_add_keyword_highlight()
if self.headline.todo_keyword.value == '' then return end
if self.headline.todo_keyword.value == '' then
return
end
local hlgroup = hl_map[self.headline.todo_keyword.value]
if hlgroup then
table.insert(self.highlights, {
hlgroup = hlgroup,
todo_keyword = self.headline.todo_keyword.value
todo_keyword = self.headline.todo_keyword.value,
})
end
end
Expand Down
Loading

0 comments on commit 0b14c09

Please sign in to comment.