Skip to content
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

WikiJournalNext, in_journal check #151

Closed
bybor opened this issue May 6, 2021 · 17 comments
Closed

WikiJournalNext, in_journal check #151

bybor opened this issue May 6, 2021 · 17 comments

Comments

@bybor
Copy link

bybor commented May 6, 2021

I'm on Windows, gVim.

I'm in journal for today, but when I do :WikiJournal and tab I can see only :WikiJournal and :WikiJournalIndex.
Expected: all "in journal" commands should be available

If you could help, how would i test what is the value of

  let b:wiki.in_journal = stridx(resolve(expand('%:p')),
        \ b:wiki.root_journal) == 0

I suspect it gives me a wrong value.

@lervag
Copy link
Owner

lervag commented May 6, 2021

Can you explain your configuration? Which options do you use for Vim? Where is your wiki located?

When you open a journal entry, what is the output of :echo b:wiki? What is the output of :echo g:wiki_journal?

@bybor
Copy link
Author

bybor commented May 7, 2021

Thank you!

It looks like my b:wiki.root_journal has forward slash : C:\Users\Alex\vimfiles\vimwiki/diary, but expand('%:p') returns path with only back slashes - C:\Users\Alex\vimfiles\vimwiki\diary\2021-05-07.wiki. This is the reason why stridx cannot match these values. Not sure how to normalize paths.

=== .vimrc

" use `date.exe` from UnxUtils
let g:wiki_date_exe = 'wikidate.exe'
" re-use diary created in vimwiki
let g:wiki_root = '~/vimfiles/vimwiki'
" to use `diary` instead of `journal`
let g:wiki_journal = {
    \ 'name': 'diary',
    \ 'frequency': 'daily',
    \ 'date_format': {
    \   'daily' : '%Y-%m-%d',
    \   'weekly' : '%Y_w%V',
    \   'monthly' : '%Y_m%m',
    \ },
    \}

let g:wiki_link_extension = ['wiki']

=== Output of :echo b:wiki

{'root': 'C:\Users\Alex\vimfiles\vimwiki', 'in_journal': 0, 'link_extension': ['wiki'], 'root_journal': 'C:\Users\Alex\vimfiles\vimwiki/diary', 'index_name': 'index', 'extension': 'wiki'}

=== Output of :echo g:wiki_journal

{'name': 'diary', 'date_format': {'weekly': '%Y_w%V', 'daily': '%Y-%m-%d', 'monthly': '%Y_m%m'}, 'frequency': 'daily'}

@lervag
Copy link
Owner

lervag commented May 7, 2021

Can you try to add set shellslash to your vimrc?

@bybor
Copy link
Author

bybor commented May 7, 2021

Thanks so much, it solved it!

@bybor bybor closed this as completed May 7, 2021
@lervag
Copy link
Owner

lervag commented May 7, 2021

Great, I'm happy to hear it. It might be I should take this into account somehow. Either an update in the docs or perhaps even try to avoid the issue altogether.

@bybor
Copy link
Author

bybor commented May 11, 2021

Though the above solution works OK, it causes an error message with Vim-Plug.

Could you please test and (if works) change one line in buffer.vim? It works without set shellslash in Windows, but don't know about Linux

  "let b:wiki.root_journal = printf('%s/%s', b:wiki.root, g:wiki_journal.name)
  let b:wiki.root_journal = globpath(b:wiki.root, g:wiki_journal.name)

@bybor bybor reopened this May 11, 2021
@bybor bybor closed this as completed May 12, 2021
@lervag
Copy link
Owner

lervag commented May 12, 2021

I would think the globpath() is not the right way to do this. But perhaps it could work to add simplify(...) around the printf(). Since you closed this, does it mean you realized this was not a problem?

@lervag
Copy link
Owner

lervag commented May 12, 2021

Hmm, I don't think simplify will work.

@bybor
Copy link
Author

bybor commented May 12, 2021

I honestly don't know. I moved on to setup CtrlPWiki integration command and ran into slash issues again among other things.

I found that since I'm on Windows I should really use let g:wiki_root = '~\vimfiles\vimwiki' with backslashes. I still have globpath() changed as above and noshellslash.

I closed this issue because I could solve it for myself and I don't want to take your time on some minor issue. I am glad I could finally find time to go through migration to wiki.vim. Thank you very much for your plugins!

Below text should be a different issue, and best of all, should come as a pull request, but I never did one. I hope I'll do it one day.

Regarding CtrlP integration, there is code that assumes g:ctrlp_user_command is set, which wasn't in my case. I couldn't find how to check if the variable is set/exists, and configured it to use fd. There was one more issue with wiki#get_root() returning path ending with \. I did a workaround change somewhere to fnamemodify(v:val, '':p'')'), call, making it :p:h (after searching for how to remove trailing slash in vim).

lervag added a commit that referenced this issue May 12, 2021
@lervag
Copy link
Owner

lervag commented May 12, 2021

I've tried to implement a fix for this now. Can you test it?

@bybor
Copy link
Author

bybor commented May 13, 2021

It now correctly finds that it's in Journal, great! As for CtrlPWiki I don't have any files listed after I issue the command.

As the result of below call (autoload\ctrlp\wiki.vim)

function! ctrlp#wiki#init()
  let s:root = wiki#get_root()

s:root has value c:\users\alex\vimfiles\vimwiki\ - ending with slash.

With below changes in autoload\wiki.vim

function! wiki#get_root_global() abort " {{{1
  if empty(g:wiki_root) | return '' | endif

  let l:root = s:is_function(g:wiki_root)
    \ ? call(g:wiki_root, [])
    \ : g:wiki_root

let l:root = fnamemodify(simplify(l:root), ':p:h')

it removes trailing slash and I see files. I don't know if it's right, but function wiki#get_root_local() above uses :p:h .

@lervag
Copy link
Owner

lervag commented May 13, 2021

Ah, no, I think it's the same issue, but I believe I have a better resolution. Adding :h is not right in this case. The problem is the following lines just after that, which looks for / explicitly.

lervag added a commit that referenced this issue May 13, 2021
@lervag
Copy link
Owner

lervag commented May 13, 2021

Please test again now.

@lervag
Copy link
Owner

lervag commented May 13, 2021

By the way, I think we the latest changes, everything should work as expected regardless of the shellslash option. Could you test that for me and report back? If I'm right, then I can remove the comment in the introduction of the docs.

@bybor
Copy link
Author

bybor commented May 13, 2021

It's perfect! I can confirm that all issues are now resolved, and it works fine without shellslash. Thank you very much!

@bybor
Copy link
Author

bybor commented May 13, 2021

I think that this "slash" thing also applies to FZF integration, but it's probably even larger can of worms. I'll try it one day. ;)

For me the greatest selling point of your wiki.vim is a possibility of using it as asciidoc (asciidoctor) wiki. Thanks so much!

@lervag
Copy link
Owner

lervag commented May 13, 2021

It's perfect! I can confirm that all issues are now resolved, and it works fine without shellslash. Thank you very much!

Great, I'm happy to hear it!

I think that this "slash" thing also applies to FZF integration, but it's probably even larger can of worms. I'll try it one day. ;)

Yes, that seems slightly more involved. I'll look at it and attempt a fix.

For me the greatest selling point of your wiki.vim is a possibility of using it as asciidoc (asciidoctor) wiki. Thanks so much!

The idea is really to be more or less filetype agnostic. It's clearly not perfect, but it does support quite a lot of types of links, including asciidoc type of links/xrefs. I'm glad you find it useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants