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
Generate links when diary & wiki directory are the same #879
Conversation
When generating links, we first check that the file is not a diary file as we don't want to include those in the list. That work is delegated to the `is_diary_file` function. Prior to this change, the function always returned true if the file was in the diary directory. This approach gives false positives for a wiki which has a flat structure and the wiki files and diary files share a directory. eg: let wiki.diary_rel_path = './' This change reuses existing diary functions from the diary.vim module to get an exact list of diary files to check against.
@@ -391,9 +391,11 @@ function! vimwiki#base#generate_links(create) abort | |||
call sort(links) | |||
|
|||
let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' ' | |||
let l:diary_file_paths = vimwiki#diary#get_diary_files() | |||
|
|||
for link in links |
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.
Because we are in a loop here, vimwiki#base#is_diary_file
is called for each file in the wiki. is_diary_file
needs a list of diary files, which it gets by calling vimwiki#diary#get_diary_files()
. This function also loops through all the files to check each against a matching diary file regex. That results in O(n2) operation.
Instead, we can get the diary files just once up front (line 394) and reuse that list inside the for
loop. We pass the diary list as the optional second argument to is_diary_file
.
Feedback: Excelent job. The best PR I've ever seen (I got only 4 years experience but still)
Now specifically:
Once again, very good work. This movated me to get hands on a make the travis.yml (so pushers and maiteners can see if tests pass or fail) |
Hi @tinmarino, thanks for your quick response. ๐
Thanks! ๐ I attempted to write some tests but couldn't run the test suite. Calling
I'll need to investigate this a bit more.
I see your point. However, checking for a diary directory first and using the existing method would still hide any files nested in the diary directory.
Is this ok?
Good pick up ๐ I didn't consider directories ending with a |
This change reverts the original regex and simply adds a second regex which is called on the result. '/\./' is one literal forward slash, one literal fullstop (escaped with a leading backslash), and one literal forward slash. In plain text, `/./` will be replaced with `/`.
Ok for the overhead. Anyway locating all files is not so slow for less than 10.000 files and seems fair when re-indexing. Conclusion: As the introduction, awesome work! Feel free to make other pull requests, big or small. |
Ah, nice pick up. I appreciate the summary and the extra commit ๐ |
๐ฆ Why
Generating links with the
:VimwikiGenerateLinks
command fails to add any links when the diary directory is the same as the wiki directory. When generating links, we first check that the file is not a diary file as we don't want to include those in the list. That work is delegated to theis_diary_file
function. Prior to this change, that function always returned true if the file was in the diary directory. This approach gives false positives for a wiki which has a flat structure and the wiki files and diary files share a directory.Sharing a directory is common when the wiki structure is flat and all files are at the same level. If
diary_rel_path
is set to'./'
then the root directory of the wiki will also be the diary directory.โจ What
This change ensures that
is_diary_file
can check the given file name against an exact list of diary files. This results in:VimwikiGenerateLinks
working correctly, even when the diary and the wiki share a directory.Also:
s:get_diary_files
->vimwiki#diary#get_diary_files
๐ต How
vimwiki#base#is_diary_file
to compare the given file against an exact list of diary filesvimwiki#diary#get_diary_files
vimwiki#path#normalize
vimwiki#path#normalize
to normalise file paths that include a single/./
. e.g./Users/me/wiki/./diary/
๐ญ Who
๐ Hi, my name is Pat. I'm a first-time contributor. Feedback welcome!
๐ผ๏ธ Random diary GIF
๐ Checklist
dev
branchdoc/vimwiki.txt
updated including the changelog and contributors sections.