Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fd95708

Browse files
feat(dev): Update add_to_paths to behave as load_file with persist option
1 parent 2a10172 commit fd95708

File tree

2 files changed

+2
-34
lines changed

2 files changed

+2
-34
lines changed

lua/orgmode/files/init.lua

+2-16
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,10 @@ end
5959
---@param filename string
6060
---@return OrgPromise<OrgFile | false>
6161
function OrgFiles:add_to_paths(filename)
62-
filename = vim.fn.resolve(vim.fn.fnamemodify(filename, ':p'))
63-
64-
if self.files[filename] then
65-
return self.files[filename]:reload()
66-
end
67-
68-
return self:load_file(filename):next(function(orgfile)
69-
if orgfile then
70-
self.files[filename] = orgfile
71-
local all_paths = self:_files()
72-
if not vim.tbl_contains(all_paths, filename) then
73-
table.insert(self.paths, filename)
74-
end
75-
end
76-
return orgfile
77-
end)
62+
return self:load_file(filename, { persist = true })
7863
end
7964

65+
---@deprecated Use `load_file_sync` with `persist` option instead
8066
---@param filename string
8167
---@param timeout? number
8268
---@return OrgFile | false

tests/plenary/init_spec.lua

-18
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,6 @@ describe('Init', function()
5858
assert.is.Not.Nil(org.files.files[todo_file])
5959
end)
6060

61-
it('should append files to paths', function()
62-
local fname = vim.fn.resolve(vim.fn.tempname() .. '.org')
63-
vim.fn.writefile({ '* Appended' }, fname)
64-
65-
assert.is.Nil(org.files.files[fname])
66-
assert.are.same({}, org.files:find_headlines_by_title('Appended'))
67-
assert.are.same({ vim.fn.getcwd() .. '/tests/plenary/fixtures/*' }, org.files.paths)
68-
69-
org.files:add_to_paths_sync(fname)
70-
assert.is.Not.Nil(org.files.files[fname])
71-
assert.are.same('Appended', org.files:find_headlines_by_title('Appended')[1]:get_title())
72-
assert.are.same({ vim.fn.getcwd() .. '/tests/plenary/fixtures/*', fname }, org.files.paths)
73-
74-
org.files:add_to_paths_sync(todo_file)
75-
-- Existing file in path not appended to paths
76-
assert.are.same({ vim.fn.getcwd() .. '/tests/plenary/fixtures/*', fname }, org.files.paths)
77-
end)
78-
7961
it('should load a file as org file if it has correct filetype', function()
8062
local fname = vim.fn.resolve(vim.fn.tempname() .. '.txt')
8163

0 commit comments

Comments
 (0)