-
-
Notifications
You must be signed in to change notification settings - Fork 163
feat(core): enhance org-insert-link, add completion for ~/
prefix.
#749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -35,8 +35,38 @@ local function create_file_instance(lines, filename) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---@return table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local function create_agenda_files(filenames, contents) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- NOTE: content is only 1 line for 1 file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local temp_fname = vim.fn.tempname() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local temp_dir = vim.fn.fnamemodify(temp_fname, ':p:h') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- clear temp dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vim.fn.delete(temp_dir .. '/*', 'rf') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local files = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local agenda_files = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for i, filename in ipairs(filenames) do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local fname = temp_dir .. '/' .. filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fname = vim.fn.fnamemodify(fname, ':p') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if fname then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local dir = vim.fn.fnamemodify(fname, ':p:h') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vim.fn.mkdir(dir, 'p') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vim.fn.writefile({ contents[i] }, fname) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
files[filename] = fname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
table.insert(agenda_files, fname) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local cfg = vim.tbl_extend('force', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
org_agenda_files = agenda_files, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, {}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
local org = orgmode.setup(cfg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
org:init() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+38
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is, what I imagine as the modified interface of the helper function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @seflue on this. We can also add the 2nd parameter to be config, the same way we have it for |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
load_file = load_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
create_file = create_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
create_file_instance = create_file_instance, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
create_agenda_file = create_agenda_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
create_agenda_files = create_agenda_files, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -339,6 +339,39 @@ describe('Autocompletion', function() | |||||||||||||||||||||||||||||||||||
{ menu = '[Org]', word = 'Title without anchor' }, | ||||||||||||||||||||||||||||||||||||
}, result) | ||||||||||||||||||||||||||||||||||||
end) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
it('should work on relative paths', function() | ||||||||||||||||||||||||||||||||||||
local files = helpers.create_agenda_files({ | ||||||||||||||||||||||||||||||||||||
'a.org', | ||||||||||||||||||||||||||||||||||||
'b/c.org', | ||||||||||||||||||||||||||||||||||||
}, { | ||||||||||||||||||||||||||||||||||||
'[[./ ', | ||||||||||||||||||||||||||||||||||||
'[[../ ', | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to be a nitpick, but I would prefer to clean each test a bit up to be specific for the case. Makes it easier for future contributions to not be distracted by code, which is actually irrelevant for the test case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. The case here is mainly about paths, so the content does not really matter. So do you suggest me to add some extra info to the files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I had a misconception, how the So I think, this cannot be improved further with reasonable amount of effort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine, so we just keep it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also see now, that you contributed this function - I thought it already existed. I have actually one last improvement: Can you change the interface of the function in that way, that it takes a list of tables, each one for each agenda file. And that each entry in this table is again an associative table with the keys There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And sorry for the inconvenience, I use the review functions of Github actually the first time and just found the "Review in workspace" feature, which is actually great. Wished I found it earlier. |
||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||
Comment on lines
+344
to
+350
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
More specific test case A. |
||||||||||||||||||||||||||||||||||||
helpers.load_file(files['b/c.org']) | ||||||||||||||||||||||||||||||||||||
vim.fn.cursor({ 1, 6 }) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
assert.are.same({ | ||||||||||||||||||||||||||||||||||||
{ menu = '[Org]', word = '../a.org' }, | ||||||||||||||||||||||||||||||||||||
{ menu = '[Org]', word = '../b/c.org' }, | ||||||||||||||||||||||||||||||||||||
}, org.completion:omnifunc(0, '../')) | ||||||||||||||||||||||||||||||||||||
end) | ||||||||||||||||||||||||||||||||||||
it('should work on relative paths', function() | ||||||||||||||||||||||||||||||||||||
local files = helpers.create_agenda_files({ | ||||||||||||||||||||||||||||||||||||
'a.org', | ||||||||||||||||||||||||||||||||||||
'b/c.org', | ||||||||||||||||||||||||||||||||||||
}, { | ||||||||||||||||||||||||||||||||||||
'[[./ ', | ||||||||||||||||||||||||||||||||||||
'[[../ ', | ||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||
Comment on lines
+360
to
+366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
More specific test case B. |
||||||||||||||||||||||||||||||||||||
helpers.load_file(files['a.org']) | ||||||||||||||||||||||||||||||||||||
vim.fn.cursor({ 1, 5 }) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
assert.are.same({ | ||||||||||||||||||||||||||||||||||||
{ menu = '[Org]', word = './a.org' }, | ||||||||||||||||||||||||||||||||||||
{ menu = '[Org]', word = './b/c.org' }, | ||||||||||||||||||||||||||||||||||||
}, org.completion:omnifunc(0, './')) | ||||||||||||||||||||||||||||||||||||
end) | ||||||||||||||||||||||||||||||||||||
end) | ||||||||||||||||||||||||||||||||||||
end) | ||||||||||||||||||||||||||||||||||||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add realpath to annotations.