Skip to content

Commit

Permalink
feat(dev): Update add_to_paths to behave as load_file with persist op…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
kristijanhusak committed Sep 23, 2024
1 parent 2a10172 commit fd95708
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
18 changes: 2 additions & 16 deletions lua/orgmode/files/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,10 @@ end
---@param filename string
---@return OrgPromise<OrgFile | false>
function OrgFiles:add_to_paths(filename)
filename = vim.fn.resolve(vim.fn.fnamemodify(filename, ':p'))

if self.files[filename] then
return self.files[filename]:reload()
end

return self:load_file(filename):next(function(orgfile)
if orgfile then
self.files[filename] = orgfile
local all_paths = self:_files()
if not vim.tbl_contains(all_paths, filename) then
table.insert(self.paths, filename)
end
end
return orgfile
end)
return self:load_file(filename, { persist = true })
end

---@deprecated Use `load_file_sync` with `persist` option instead
---@param filename string
---@param timeout? number
---@return OrgFile | false
Expand Down
18 changes: 0 additions & 18 deletions tests/plenary/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ describe('Init', function()
assert.is.Not.Nil(org.files.files[todo_file])
end)

it('should append files to paths', function()
local fname = vim.fn.resolve(vim.fn.tempname() .. '.org')
vim.fn.writefile({ '* Appended' }, fname)

assert.is.Nil(org.files.files[fname])
assert.are.same({}, org.files:find_headlines_by_title('Appended'))
assert.are.same({ vim.fn.getcwd() .. '/tests/plenary/fixtures/*' }, org.files.paths)

org.files:add_to_paths_sync(fname)
assert.is.Not.Nil(org.files.files[fname])
assert.are.same('Appended', org.files:find_headlines_by_title('Appended')[1]:get_title())
assert.are.same({ vim.fn.getcwd() .. '/tests/plenary/fixtures/*', fname }, org.files.paths)

org.files:add_to_paths_sync(todo_file)
-- Existing file in path not appended to paths
assert.are.same({ vim.fn.getcwd() .. '/tests/plenary/fixtures/*', fname }, org.files.paths)
end)

it('should load a file as org file if it has correct filetype', function()
local fname = vim.fn.resolve(vim.fn.tempname() .. '.txt')

Expand Down

0 comments on commit fd95708

Please sign in to comment.