Skip to content

Commit 13091bc

Browse files
authored
Add level and is_archived to OrgHeadline (#437)
1 parent 2479971 commit 13091bc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lua/orgmode/api/headline.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local Calendar = require('orgmode.objects.calendar')
99
---@class OrgHeadline
1010
---@field title string headline title without todo keyword, tags and priority. Ex. `* TODO I am a headline :SOMETAG:` returns `I am a headline`
1111
---@field line string full headline line
12+
---@field level number headline level (number of asterisks). Example: 1
1213
---@field todo_value? string todo keyword of the headline (Example: TODO, DONE)
1314
---@field todo_type? string | "'TODO'" | "'DONE'" | "''"
1415
---@field tags string[] List of own tags
@@ -21,6 +22,7 @@ local Calendar = require('orgmode.objects.calendar')
2122
---@field file OrgFile
2223
---@field parent OrgHeadline|nil
2324
---@field priority string|nil
25+
---@field is_archived boolean headline marked with the `:ARCHIVE:` tag
2426
---@field headlines OrgHeadline[]
2527
---@field private _section Section
2628
---@field private _index number
@@ -34,6 +36,7 @@ function OrgHeadline:_new(opts)
3436
data.todo_value = opts.todo_value
3537
data.title = opts.title
3638
data.line = opts.line
39+
data.level = opts.level
3740
data.category = opts.category
3841
data.position = opts.position
3942
data.tags = opts.tags
@@ -43,6 +46,7 @@ function OrgHeadline:_new(opts)
4346
data.scheduled = opts.scheduled
4447
data.closed = opts.closed
4548
data.dates = opts.dates
49+
data.is_archived = opts.is_archived
4650
data.parent = opts.parent
4751
data.headlines = opts.headlines or {}
4852
data._section = opts._section
@@ -60,6 +64,7 @@ function OrgHeadline._build_from_internal_section(section, index)
6064
return OrgHeadline:_new({
6165
title = section.title,
6266
line = section.line,
67+
level = section.level,
6368
todo_type = section.todo_keyword.type,
6469
todo_value = section.todo_keyword.value,
6570
all_tags = { unpack(section.tags) },
@@ -72,6 +77,7 @@ function OrgHeadline._build_from_internal_section(section, index)
7277
return date:is_none()
7378
end, section.dates),
7479
priority = section.priority,
80+
is_archived = section:is_archived(),
7581
_section = section,
7682
_index = index,
7783
})

tests/plenary/api/api_spec.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Api', function()
1111
' DEADLINE: <2021-07-21 Wed 22:02>',
1212
'** TODO Second level :NESTEDTAG:',
1313
' DEADLINE: <2021-07-21 Wed 22:02>',
14-
'* DONE Some task',
14+
'* DONE Some task :ARCHIVE:',
1515
' DEADLINE: <2021-07-21 Wed 22:02>',
1616
' Unrelated date <2022-06-11 Sat 23:15>',
1717
})
@@ -22,6 +22,7 @@ describe('Api', function()
2222
assert.are.same(file, current_file.filename)
2323
assert.are.same(current_file.category, vim.fn.fnamemodify(file, ':p:t:r'))
2424
assert.are.same(3, #current_file.headlines)
25+
assert.are.same(1, current_file.headlines[1].level)
2526
assert.are.same('Test orgmode', current_file.headlines[1].title)
2627
assert.are.same('* TODO Test orgmode :WORK:OFFICE:', current_file.headlines[1].line)
2728
assert.are.same({ 'WORK', 'OFFICE' }, current_file.headlines[1].all_tags)
@@ -38,7 +39,9 @@ describe('Api', function()
3839
assert.Is.Nil(current_file.headlines[1].scheduled)
3940
assert.Is.Nil(current_file.headlines[1].closed)
4041
assert.are.same({}, current_file.headlines[1].dates)
42+
assert.Is.False(current_file.headlines[1].is_archived)
4143

44+
assert.are.same(2, current_file.headlines[2].level)
4245
assert.are.same('Second level', current_file.headlines[2].title)
4346
assert.are.same(0, #current_file.headlines[2].headlines)
4447
assert.are.same({ 'WORK', 'OFFICE', 'NESTEDTAG' }, current_file.headlines[2].all_tags)
@@ -49,12 +52,14 @@ describe('Api', function()
4952
assert.are.same(1, current_file.headlines[2].position.start_col)
5053
assert.are.same(6, current_file.headlines[2].position.end_line)
5154
assert.are.same(0, current_file.headlines[2].position.end_col)
55+
assert.Is.False(current_file.headlines[2].is_archived)
5256
assert.are.same(current_file.headlines[1], current_file.headlines[2].parent)
5357

58+
assert.are.same(1, current_file.headlines[3].level)
5459
assert.are.same('Some task', current_file.headlines[3].title)
5560
assert.are.same(0, #current_file.headlines[3].headlines)
56-
assert.are.same({}, current_file.headlines[3].all_tags)
57-
assert.are.same({}, current_file.headlines[3].tags)
61+
assert.are.same({ 'ARCHIVE' }, current_file.headlines[3].all_tags)
62+
assert.are.same({ 'ARCHIVE' }, current_file.headlines[3].tags)
5863
assert.are.same('DONE', current_file.headlines[3].todo_value)
5964
assert.are.same('DONE', current_file.headlines[3].todo_type)
6065
assert.are.same(7, current_file.headlines[3].position.start_line)
@@ -65,6 +70,7 @@ describe('Api', function()
6570
assert.are.same('2021-07-21 Wed 22:02', current_file.headlines[3].deadline:to_string())
6671
assert.Is.Nil(current_file.headlines[3].scheduled)
6772
assert.Is.Nil(current_file.headlines[3].closed)
73+
assert.Is.True(current_file.headlines[3].is_archived)
6874
assert.are.same(1, #current_file.headlines[3].dates)
6975
assert.are.same('2022-06-11 Sat 23:15', current_file.headlines[3].dates[1]:to_string())
7076
end)

0 commit comments

Comments
 (0)