Skip to content

Commit

Permalink
Merge branch 'master' into clock-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak authored Oct 20, 2024
2 parents 8600c50 + 05d6983 commit 4eca40f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- v0.9.5
- v0.10.0
- v0.10.1
- v0.10.2
- nightly
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion lua/orgmode/agenda/views/tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end

function AgendaTagsView:build()
local tags = vim.fn.OrgmodeInput('Match: ', self.search, function(arg_lead)
utils.prompt_autocomplete(arg_lead, self.files:get_tags())
return utils.prompt_autocomplete(arg_lead, self.files:get_tags())
end)
if vim.trim(tags) == '' then
return utils.echo_warning('Invalid tag.')
Expand Down
7 changes: 6 additions & 1 deletion lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ function Capture:refile_file_headline_to_archive(headline)
end

local destination_file = self.files:get(archive_location)
local todo_state = headline:get_todo()

local target_line = self:_refile_from_org_file({
source_headline = headline,
Expand All @@ -287,8 +288,12 @@ function Capture:refile_file_headline_to_archive(headline)
local archived_headline = archive_file:get_closest_headline({ target_line, 0 })
archived_headline:set_property('ARCHIVE_TIME', Date.now():to_string())
archived_headline:set_property('ARCHIVE_FILE', file.filename)
local outline_path = headline:get_outline_path()
if outline_path ~= '' then
archived_headline:set_property('ARCHIVE_OLPATH', outline_path)
end
archived_headline:set_property('ARCHIVE_CATEGORY', headline:get_category())
archived_headline:set_property('ARCHIVE_TODO', headline:get_todo() or '')
archived_headline:set_property('ARCHIVE_TODO', todo_state or '')
end)
end

Expand Down
22 changes: 22 additions & 0 deletions lua/orgmode/files/headline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,28 @@ function Headline:get_category()
return self.file:get_category()
end

memoize('get_outline_path')
--- @return string
function Headline:get_outline_path()
local inner_to_outer_parent_headlines = {}
local parent_section = self:node():parent():parent()

while parent_section do
local headline_node = parent_section:field('headline')[1]
if headline_node then
local headline = Headline:new(headline_node, self.file)
local headline_title = headline:get_title()
table.insert(inner_to_outer_parent_headlines, headline_title)
end
parent_section = parent_section:parent()
end

-- reverse headline order
local outer_to_inner_parent_headlines = utils.reverse(inner_to_outer_parent_headlines)
local outline_path = table.concat(outer_to_inner_parent_headlines, '/')
return outline_path
end

---@param tags string
function Headline:set_tags(tags)
---@type TSNode
Expand Down
32 changes: 32 additions & 0 deletions tests/plenary/ui/mappings/archive_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Archive', function()
' :PROPERTIES:',
' :ARCHIVE_TIME: ' .. now:to_string(),
' :ARCHIVE_FILE: ' .. file.filename,
-- no ARCHIVE_OLPATH because top-level headline
' :ARCHIVE_CATEGORY: ' .. file:get_category(),
' :ARCHIVE_TODO: ',
' :END:',
Expand Down Expand Up @@ -55,10 +56,41 @@ describe('Archive', function()
' :PROPERTIES:',
' :ARCHIVE_TIME: ' .. now:to_string(),
' :ARCHIVE_FILE: ' .. file.filename,
-- no ARCHIVE_OLPATH because top-level headline
' :ARCHIVE_CATEGORY: ' .. file:get_category(),
' :ARCHIVE_TODO: ',
' :END:',
'** baz',
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
end)

it('sets outline path when archiving lower-level headline', function()
local file = helpers.create_agenda_file({
'* foo',
'** TODO bar',
'*** TODO baz',
' Body text baz',
})

vim.cmd([[exe "norm G,o$"]])
-- Pause to finish the archiving
vim.wait(50)
assert.are.same({
'* foo',
'** TODO bar',
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))

vim.cmd(('edit %s'):format(file.filename .. '_archive'))
assert.are.same({
'* TODO baz', -- keep todo state in the title
' :PROPERTIES:',
' :ARCHIVE_TIME: ' .. Date.now():to_string(),
' :ARCHIVE_FILE: ' .. file.filename,
' :ARCHIVE_OLPATH: foo/bar', -- remove todo state in any headline in outline path
' :ARCHIVE_CATEGORY: ' .. file:get_category(),
' :ARCHIVE_TODO: TODO',
' :END:',
' Body text baz',
}, vim.api.nvim_buf_get_lines(0, 0, -1, false))
end)
end)

0 comments on commit 4eca40f

Please sign in to comment.