wiki.vim icon indicating copy to clipboard operation
wiki.vim copied to clipboard

How: Go to week/month summary ?

Open VimWei opened this issue 1 year ago • 30 comments

Description

    Plug 'lervag/wiki.vim'
    let g:wiki_root = expand("<sfile>:p:h:h:h") . "/Vimwiki/"
    let g:wiki_index_name = 'index'
    let g:wiki_filetypes = ['md']

scene1 - Go to week summary: fail

  1. <leader>w<leader>w open today journal
  2. <leader>wu

image

scene2 - Go to week summary: ok - but quite complex

  1. <leader>ww open wiki.vim index
  2. :cd %:p:h set pwd to index folder
  3. <leader>w<leader>w open today journal
  4. <leader>wu

image

scene3 - Go to week summary: fail - if today journal exist

  1. <leader>ww open wiki.vim index
  2. :cd %:p:h set pwd to index folder
  3. <leader>w<leader>w open today journal
  4. :wq save today joural and quit vim
  5. Repeat scene2: Nothing happened except for the undo.

image

scene4 - Go to month summary: fail

  1. <leader>w<leader>w open today journal
  2. <leader>wm

image

scene5 - Go to month summary: fail

  1. <leader>ww open wiki.vim index
  2. :cd %:p:h set pwd to index folder
  3. <leader>w<leader>w open today journal
  4. <leader>wm Nothing happened

image

VimWei avatar Mar 26 '24 09:03 VimWei

You don't need the last two options, since you are not changing them from their default values. So, this should suffice:

Plug 'lervag/wiki.vim'
let g:wiki_root = expand("<sfile>:p:h:h:h") . "/Vimwiki/"

scene1 - Go to week summary: fail

This seems to be related to the Windows specific file paths. But I'm not quite sure. I've never used wiki.vim on a Windows machine. I have tried to make it compatible, though.

I'm looking at the code, and I notice that the error comes from the date and time handlers:

https://github.com/lervag/wiki.vim/blob/121a62fcb47cd7a5230175d94df44daa8b5dcd29/autoload/wiki/date/strptime.vim#L17-L19

I believe the problem is related to the conversion between a path and the date.

scene2 - Go to week summary: ok - but quite complex

  1. :cd %:p:h set pwd to index folder

What happens if you set pwd to index folder with scene1?

scene3 - Go to week summary: fail - if today journal exist

This is very strange! I don't understand it. Is it OK if we focus on scenes 1 and 2 first?

scene4 - Go to month summary: fail

This is most likely the same error as for scene1, so let's ignore scene4 for now.

scene5 - Go to month summary: fail

I'm not sure about this one, but I propose we ignore it until we've figured out the problem with scene1. OK?

lervag avatar Mar 26 '24 22:03 lervag

Can you do this:

  1. <leader>ww open wiki.vim index
  2. <leader>w<leader>w open today journal
  3. Run :echo wiki#journal#get_current_node() - what's the output?
  4. :cd %:p:h set pwd to index folder
  5. Again, run :echo wiki#journal#get_current_node() - what's the output?

I'm also worrying that the function s:node_to_path may not work properly on Windows. To test that, you should change the function name to e.g. wiki#journal#node_to_path, then you could test it with e.g. :echo wiki#journal#node_to_path("2024-04-01"); let me know if you need more help to do that.

lervag avatar Mar 26 '24 22:03 lervag

vimrc

I have simplified vimrc as per your suggestion to the following

Plug 'lervag/wiki.vim'
let g:wiki_root = expand("<sfile>:p:h:h:h") . "/Vimwiki/"

and set shellslash for the Windows environment:

function! ToggleShellslashForVimPlug()
  if exists('g:plugs')
    autocmd User PlugBegin set noshellslash
    autocmd User PlugEnd set shellslash
  endif
endfunction

set noshellslash
call plug#begin()
.......
call plug#end()
set shellslash
call ToggleShellslashForVimPlug()

test 1:>Can you do this

  1. <leader>ww open wiki.vim index
  2. <leader>w<leader>w open today journal
  3. Run :echo wiki#journal#get_current_node() - what's the output?

d:/WeirdData/Vimwiki/journal/2024-03-27

  1. :cd %:p:h set pwd to journal folder
:pwd
D:/WeirdData/Vimwiki/journal

or :cd %:p:h:h set pwd to index folder. This adjustment does not affect the results of subsequent experiments.

:pwd
D:/WeirdData/Vimwiki
  1. Again, run :echo wiki#journal#get_current_node() - what's the output?

D:/WeirdData/Vimwiki/journal/2024-03-27

test1-absolutepath

test 2: If I change the order, the output is different

> 1. `<leader>ww` open wiki.vim index
> 4. `:cd %:p:h` set pwd to index folder
> 2. `<leader>w<leader>w` open today journal
> 3. Run `:echo wiki#journal#get_current_node()` 
  • what's the output? None blank/nothing

test2-none

test 3: If I open today journal first, the output change again:

> 2. `<leader>w<leader>w` open today journal
> 1. `<leader>ww` open wiki.vim index
> 4. `:cd %:p:h` set pwd to index folder
> 2. `<leader>w<leader>w` open today journal
> 3. Run `:echo wiki#journal#get_current_node()` 
  • what's the output? 2024-03-27

test3-ok

test 4 : Q&A

What happens if you set pwd to index folder with scene1?

  1. <leader>w<leader>w open today journal
  2. :cd %:p:h:h set pwd to index folder
  3. <leader>wu

image

test 5: FIX scene2

To run successfully, we need to first open today's journal with <leader>w<leader>w.

0. `<leader>w<leader>w` open today journal
1. `<leader>ww ` open wiki.vim index
2. `:cd %:p:h` set pwd to index folder
3. `<leader>w<leader>w`  open today journal
4. `<leader>wu` 

What's the key issue

After numerous experiments, and comparing experiments test 1-3, the crux of the issue may lie in whether the journal is activated (I don't know how to express it accurately), resulting in completely different outcomes for wiki#journal#get_current_node().

Whether journal is activated can be clearly seen in the statusline set statusline+=\ %f by whether the file path uses a relative path.

  • If journal is activated (test 3 and test 5), then a relative path is used, and the output is 2024-03-27.
  • If journal is not activated (test 1-2 adn test 4), then an absolute path is used. Even if you manually specify pwd using the cd command, the output is D:/WeirdData/Vimwiki/journal/2024-03-27 or 'None'.

To summarize, the current steps to activate wiki.vim journal are: 1. open today journal 2. open wikiroot index 3. set pwd to index 4.open today journal again.

PS: The mechanism of vimwiki is such that it automatically switches the pwd to the wiki root when opening the index, diary or any wiki file. And, the pwd remains constant. Even if you switch to other non-wiki files during use and the pwd changes, as soon as you switch back to any of the vimwiki-related pages, the pwd will automatically switch back to the index.

vimwiki

But wiki.vim does not switch the pwd automatically and even if we manually set the pwd to the index, the related pages of wiki.vim might not necessarily use a relative path..

wiki vim

VimWei avatar Mar 27 '24 02:03 VimWei

:echo wiki#journal#node_to_path("2024-04-01")

base on test 3 step:

1.  `<leader>w<leader>w` open today journal
2.  `<leader>ww` open wiki.vim index
3.  `:cd %:p:h` set pwd to index folder
4.  `<leader>w<leader>w` open today journal
5.  Run `:echo wiki#journal#node_to_path("2024-04-01")` 

E117: Unknown function: wiki#journal#node_to_path

VimWei avatar Mar 27 '24 06:03 VimWei

Based on your answer, I'm more confident that the problem is related to the Window paths. Specifically:

  1. Run :echo wiki#journal#get_current_node() - what's the output?

d:/WeirdData/Vimwiki/journal/2024-03-27

The expected output should be "2024-03-27". I've found a possible fix for this. Can you update and test this same thing again?

PS: The mechanism of vimwiki is such that it automatically switches the pwd to the wiki root when opening the index, diary or any wiki file. And, the pwd remains constant. Even if you switch to other non-wiki files during use and the pwd changes, as soon as you switch back to any of the vimwiki-related pages, the pwd will automatically switch back to the index.

But wiki.vim does not switch the pwd automatically and even if we manually set the pwd to the index, the related pages of wiki.vim might not necessarily use a relative path..

Yes, wiki.vim will not change your cwd; why should it? You can use set autochdir if you like that behaviour. The solution to this issue is not to change your cwd, but to fix the bugs in wiki.vim.

1.  `<leader>w<leader>w` open today journal
2.  `<leader>ww` open wiki.vim index
3.  `:cd %:p:h` set pwd to index folder
4.  `<leader>w<leader>w` open today journal
5.  Run `:echo wiki#journal#node_to_path("2024-04-01")` 

E117: Unknown function: wiki#journal#node_to_path

Ah, yes; for this to work I wanted you to actually change wiki.vim code first. Specifically, you must change the function named s:node_to_path to the name wiki#journal#node_to_path. But this may not be necessary if my fix was sufficient.

lervag avatar Mar 27 '24 23:03 lervag

update wiki.vim and test this same thing (test 1)

  1. <leader>ww open wiki.vim index
  2. <leader>w<leader>w open today journal
  3. Run :echo wiki#journal#get_current_node() - what's the output?

d:/WeirdData/wiki/journal/2024-03-28

  1. :cd %:p:h:h set pwd to index folder
  2. Again, run :echo wiki#journal#get_current_node() - what's the output?

D:/WeirdData/wiki/journal/2024-03-28

Notice: d: ==> D:

change the function named and repeat test 1

  • c:\Users\yourname\vimfiles\plugged\wiki.vim\autoload\wiki\journal.vim

function! s:node_to_path(node) abort " {{{1 ==> function! wiki#journal#node_to_path(node) abort " {{{1

  • repeat test 1
  1. <leader>ww open wiki.vim index
  2. <leader>w<leader>w open today journal
  3. Run :echo wiki#journal#get_current_node() - what's the output?

d:/WeirdData/wiki/journal/2024-03-28

  1. :cd %:p:h:h set pwd to index folder
  2. Again, run :echo wiki#journal#get_current_node() - what's the output?

D:/WeirdData/wiki/journal/2024-03-28

  1. echo wiki#journal#node_to_path(2024-04-01)

d:/WeirdData/wiki/journal/2019.md

image

image

And if I change [A-Z] to [a-zA-Z], the result is same.

  if has('win32') || v:true
    let l:target = substitute(l:target, '^[a-zA-Z]:', '', '')
    let l:common = substitute(l:common, '^[a-zA-Z]:', '', '')
  endif

VimWei avatar Mar 28 '24 00:03 VimWei

You can use set autochdir if you like that behaviour.

I've created a simulated implementation.

    let g:wiki_root = expand("<sfile>:p:h:h:h") . "/wiki/"
    augroup wiki_vim_autochdir
        autocmd!
        autocmd BufEnter *.md,*.wiki if getbufvar(expand('%'), '&filetype') == 'markdown' | execute 'cd ' . g:wiki_root | endif
    augroup END

VimWei avatar Mar 28 '24 03:03 VimWei

Sorry for the late reply; I'm on vacation and I'm a bit busy.

update wiki.vim and test this same thing (test 1)

  1. <leader>ww open wiki.vim index
  2. <leader>w<leader>w open today journal
  3. Run :echo wiki#journal#get_current_node() - what's the output?

d:/WeirdData/wiki/journal/2024-03-28

  1. :cd %:p:h:h set pwd to index folder
  2. Again, run :echo wiki#journal#get_current_node() - what's the output?

D:/WeirdData/wiki/journal/2024-03-28

Notice: d: ==> D:

Ok, thanks. The d -> D is not important, I think. But i's surprising that my earlier attempt at fixing this did not work; I'll look into this further.

change the function named and repeat test 1

* c:\Users\yourname\vimfiles\plugged\wiki.vim\autoload\wiki\journal.vim

function! s:node_to_path(node) abort " {{{1 ==> function! wiki#journal#node_to_path(node) abort " {{{1

Good! Notice you should either make this change of names very temporary, or make a copy of the function. If not, you are likely to break things alltogether, since a lot of other functions use s:node_to_path and expects it to exist.

  • repeat test 1

Ah, no, sorry: I did not want you to repeat the test. I wanted you to specifically execute :echo wiki#journal#node_to_path("2024-04-01") and see what the function returns. However, I see you also did that:

  1. echo wiki#journal#node_to_path(2024-04-01)

d:/WeirdData/wiki/journal/2019.md

Ah, that's not as expected at all.

What's the output of :echo wiki#get_root() (from anywhere)?

lervag avatar Mar 30 '24 16:03 lervag

I'm sorry for not being able to help with this very quickly. It's hard to pinpoint the error when I can't reproduce locally. I hope you don't mind doing some investigation based on my suggestions.

Can you do these steps and report the output of the echos?

  1. <leader>w<leader>w
  2. :echo expand('%:p')
  3. :echo wiki#get_root()
  4. :echo wiki#journal#get_root()
  5. :echo wiki#journal#get_current_node()

lervag avatar Mar 30 '24 16:03 lervag

  • <leader>w<leader>w
  • :echo expand('%:p')

D:/WeirdData/wiki/journal/2024/2024-03-31.md

  • :echo wiki#get_root()

d:/WeirdData/wiki

  • :echo wiki#journal#get_root()

d:/WeirdData/wiki/journal

  • :echo wiki#journal#get_current_node()

D:/WeirdData/wiki/journal/2024/2024-03-31

wikiecho

PS: my vimrc config: https://github.com/VimWei/vim-init

VimWei avatar Mar 30 '24 17:03 VimWei

Thanks! The expected output of :echo wiki#journal#get_current_node() is 2024/2024-03-31.

Now, please show:

  1. Just to be sure, update your plugins again.
  2. :echo fnamemodify(expand('%:p'), ':r')
  3. :echo wiki#journal#get_root()
  4. :echo wiki#paths#relative(fnamemodify(expand('%:p'), ':r'), wiki#journal#get_root())

Based on the earlier output, I expect the following:

  1. D:/WeirdData/wiki/journal/2024/2024-03-31
  2. d:/WeirdData/wiki/journal
  3. D:/WeirdData/wiki/journal/2024/2024-03-31

PS: my vimrc config: https://github.com/VimWei/vim-init

Thanks. A few comments:

  • I don't understand why you want the autochdir stuff. It shouldn't be necessary. Although, if it is a workaround for the present issue, then leave it for now. But generally, wiki.vim does not really care about your current work directory (cwd).

  • You don't need to specify settings that are already default. E.g.` you can remove lines like this. Thus, you could simplify your config to this:

    let g:wiki_journal = {
          \ 'date_format': {
          \   'daily' : '%Y/%Y-%m-%d',
          \   'weekly' : '%Y/%Y_w%V',
          \   'monthly' : '%Y/%Y_m%m',
          \ },
          \}
    let g:wiki_link_creation = {
          \ 'md': { 'link_type': 'md', 'url_extension': '' },
          \ '_': { 'link_type': 'wiki', 'url_extension': '' },
          \}
    let g:wiki_journal_index = {
          \ 'link_text_parser': { b, d, p -> wiki#toc#get_page_title(p) }
          \}
    let g:wiki_mappings_global = {
          \ '<plug>(wiki-page-toc)' : '',
          \}
    let g:wiki_mappings_local_journal = {
          \ '<plug>(wiki-journal-prev)' : '[w',
          \ '<plug>(wiki-journal-next)' : ']w',
          \}
    

Also, it is very useful to know that you've changed the date_format settings.

lervag avatar Mar 30 '24 17:03 lervag

  • Just to be sure, update your plugins again.

Yes

  • :echo fnamemodify(expand('%:p'), ':r')

D:/WeirdData/wiki/journal/2024/2024-03-31

  • :echo wiki#journal#get_root()

d:/WeirdData/wiki/journal

  • :echo wiki#paths#relative(fnamemodify(expand('%:p'), ':r'), wiki#journal#get_root())

D:/WeirdData/wiki/journal/2024/2024-03-31

VimWei avatar Mar 30 '24 17:03 VimWei

The expected output of :echo wiki#journal#get_current_node() is 2024/2024-03-31.

Yes, I understand. However, in my previous tests, there were three different outcomes, as detailed in the earlier tests 1-3.

  • If journal is activated (test 3 and test 5), then a relative path is used, and the output is 2024-03-27.
  • If journal is not activated (test 1-2 adn test 4), then an absolute path is used. Even if you manually specify pwd using the cd command, the output is D:/WeirdData/Vimwiki/journal/2024-03-27 or 'None'.

I am very grateful that you could take the time to answer my questions despite your busy schedule. I am not in a hurry to resolve this issue, so we can take our time with it. P.S.: I have completely switched from vimwiki to wiki.vim, and it now meets my daily needs. The main reason I abandoned vimwiki is that some of its bugs can cause serious garbling and result in data loss. The design philosophy of wiki.vim is excellent—focused and flexible, allowing me to choose third-party filetype and lists plugins.

VimWei avatar Mar 30 '24 17:03 VimWei

you've changed the date_format settings.

I set the date_format to be divided by year mainly because when there are many files in the same directory, the related software on Windows tends to load more slowly.

  • I don't understand why you want the autochdir stuff.

I am currently using it just to make the file path in the statusline a bit shorter, instead of always showing the long full path. It's to improve the experience.

VimWei avatar Mar 30 '24 18:03 VimWei

11. echo wiki#journal#node_to_path(2024-04-01)

d:/WeirdData/wiki/journal/2019.md

Ah, that's not as expected at all.

I found the possible source of the '2019' pattern: the earliest entry in my journal dates back to the year 2019.

VimWei avatar Mar 30 '24 18:03 VimWei

  • :echo wiki#paths#relative(fnamemodify(expand('%:p'), ':r'), wiki#journal#get_root())

D:/WeirdData/wiki/journal/2024/2024-03-31

Ok, thanks. This is very strange. I've created the following script to debug on my end:

set nocompatible
set runtimepath^=~/.local/plugged/wiki.vim
filetype plugin indent on
syntax enable

runtime plugin/wiki.vim

let s:root = 'd:/WeirdData/wiki/journal'
let s:path = 'D:/WeirdData/wiki/journal/2024/2024-03-31'

echo s:root
echo s:path
echo wiki#paths#relative(s:path, s:root)

quitall!

I run it from a terminal with vim --clean -u test.vim, in which case it outputs this:

d:/WeirdData/wiki/journal
D:/WeirdData/wiki/journal/2024/2024-03-31
2024/2024-03-31

Which is what I would expect from you as well. I pushed a new very minor update that shouldn't really have any effect on your side, but it would be useful if you still updated and tested again. And, if possible, it would be useful if you are able to reproduce the issue with the above script.


The expected output of :echo wiki#journal#get_current_node() is 2024/2024-03-31.

Yes, I understand. However, in my previous tests, there were three different outcomes, as detailed in the earlier tests 1-3.

Yes, but those were not expected outputs either.

I am very grateful that you could take the time to answer my questions despite your busy schedule. I am not in a hurry to resolve this issue, so we can take our time with it. P.S.: I have completely switched from vimwiki to wiki.vim, and it now meets my daily needs. The main reason I abandoned vimwiki is that some of its bugs can cause serious garbling and result in data loss. The design philosophy of wiki.vim is excellent—focused and flexible, allowing me to choose third-party filetype and lists plugins.

I'm glad to hear that you find wiki.vim useful! And I hope that we can figure this thing out. It may be multiple errors, in fact I think that's likely, because the wiki#paths#relative thing should not be that relevant for the s:node_to_path function.

you've changed the date_format settings.

I set the date_format to be divided by year mainly because when there are many files in the same directory, the related software on Windows tends to load more slowly.

Yes, that makes sense.

  • I don't understand why you want the autochdir stuff.

I am currently using it just to make the file path in the statusline a bit shorter, instead of always showing the long full path. It's to improve the experience.

Ah; in that case, you can also just change your statusline. But it doesn't really matter, if you find it useful then great - keep it!

  1. echo wiki#journal#node_to_path(2024-04-01)

d:/WeirdData/wiki/journal/2019.md

Ah, that's not as expected at all.

I found the possible source of the '2019' pattern: the earliest entry in my journal dates back to the year 2019.

Yes, that makes sense - sort of.

lervag avatar Mar 30 '24 18:03 lervag

set nocompatible
set runtimepath^=%USERPROFILE%/vimfiles/plugged/wiki.vim
filetype plugin indent on
syntax enable

runtime plugin/wiki.vim

let s:root = 'd:/WeirdData/wiki/journal'
let s:path = 'D:/WeirdData/wiki/journal/2024/2024-03-31'

echo s:root
echo s:path
echo wiki#paths#relative(s:path, s:root)

quitall!

"C:\Program Files\Vim\vim91\gvim.exe" --clean -u "c:\Users\chenw\vimfiles\test.vim"

image

VimWei avatar Mar 30 '24 18:03 VimWei

Ok; that's really strange. Can we go deeper here? That is:

  1. Confirm that your own autoload/vimtex/paths.vim file looks like this.

  2. Change the function by adding some echos:

    function! wiki#paths#relative(path, current) abort " {{{1
      " Note: This algorithm is based on the one presented by @Offirmo at SO,
      "       http://stackoverflow.com/a/12498485/51634
    
      let l:target = simplify(substitute(a:path, '\\', '/', 'g'))
      let l:target = substitute(l:target, '^\a:', '', '')
      let l:common = simplify(substitute(a:current, '\\', '/', 'g'))
      let l:common = substitute(l:common, '^\a:', '', '')
      if l:common[-1:] ==# '/'
        let l:common = l:common[:-2]
      endif
      echo 1 l:target
      echo 2 l:common
    
      " This only works on absolute paths
      if !wiki#paths#is_abs(l:target)
        return substitute(a:path, '^\.\/', '', '')
      endif
    
      let l:tries = 50
      let l:result = ''
      while stridx(l:target, l:common) != 0 && l:tries > 0
        let l:common = fnamemodify(l:common, ':h')
        let l:result = empty(l:result) ? '..' : '../' . l:result
        let l:tries -= 1
      endwhile
      echo 3 l:result l:tries
      echo 4 l:common
    
      if l:tries == 0 | return a:path | endif
    
      if l:common ==# '/'
        let l:result .= '/'
      endif
    
      let l:forward = strpart(l:target, strlen(l:common))
      if !empty(l:forward)
        let l:result = empty(l:result)
              \ ? l:forward[1:]
              \ : l:result . l:forward
      endif
    
      echo 5 l:result
    
  3. Repeat the script from the previous reply. On my end, the script now outputs this:

    d:/WeirdData/wiki/journal
    D:/WeirdData/wiki/journal/2024/2024-03-31
    1 /WeirdData/wiki/journal/2024/2024-03-31
    2 /WeirdData/wiki/journal
    3  50
    4 /WeirdData/wiki/journal
    5 2024/2024-03-31
    2024/2024-03-31
    

lervag avatar Mar 30 '24 20:03 lervag

There is no autoload/vimtex/paths.vim here, only plugged\wiki.vim\autoload\wiki\paths.vim. Following your guidance above, I have added 5 echo statements in plugged\wiki.vim\autoload\wiki\paths.vim.

image

The condition if !wiki#paths#is_abs(l:target) evaluates to true, and echo3-5 did not appear.

  if !wiki#paths#is_abs(l:target)
    return substitute(a:path, '^\.\/', '', '')
  endif

If I comment out the above statement, the results appear as you would expect.

image

VimWei avatar Mar 30 '24 23:03 VimWei

There is no autoload/vimtex/paths.vim here, only plugged\wiki.vim\autoload\wiki\paths.vim.

Yes, sorry about the confusion. I meant to write autoload/wiki/paths.vim!

The condition if !wiki#paths#is_abs(l:target) evaluates to true, and echo3-5 did not appear.

Ah! This is very useful! I'm pushing an update now. Revert the changes you made while debugging and update. I believe this should resolve the issue with wiki#paths#relative.

lervag avatar Mar 31 '24 10:03 lervag

I would not be surprised if there may be more things to fix, but I believe we are getting closer now.

lervag avatar Mar 31 '24 10:03 lervag

Upgrade(reinstall) wiki.vim and config with: https://github.com/VimWei/vim-init/blob/master/init/plugins.vim#L166-L203

There are still some issues:

NewTest 1

  1. restart gvim
  2. open today journal:<leader>w<leader>w
  3. open week summary: <leader>wu

Result: open a new week summary but the content is blank.

NewTest 1

NewTest 2

  1. restart gvim
  2. open wikiindex: <leader>ww
  3. open today journal:<leader>w<leader>w
  4. open week summary: <leader>wu

Result: <leader>wu can't work, just mean undo.

NewTest 2

NewTest 3

  1. restart gvim
  2. open today journal:<leader>w<leader>w
  3. open wikiindex: <leader>ww
  4. open today journal:<leader>w<leader>w
  5. open week summary: <leader>wu

Result: open a new week summary, and the content is from wiki template.

NewTest 3

VimWei avatar Mar 31 '24 12:03 VimWei

Upgrade(reinstall) wiki.vim and config with: https://github.com/VimWei/vim-init/blob/master/init/plugins.vim#L166-L203

Just a kind reminder that you can simplify your config as I explained here.

There are still some issues:

Interesting. It seems the third test yields the expected result, right?

I'll try and reproduce this on my end.

lervag avatar Mar 31 '24 14:03 lervag

A quick question: Do I understand correctly that the feature to open the current journal entry now works as expected? I.e., the current issue is now related to the weekly summaries?

lervag avatar Mar 31 '24 14:03 lervag

Sorry for writing multiple replies instead of collecting it in a single reply! Here's a list of questions for following this up:

  • Do you agree that your third test returns the expected result?
  • Do I understand correctly that the feature to open the current journal entry now works as expected? I.e., the current issue is now related to the weekly summaries?

Also, can you do this:

  1. restart gvim
  2. <leader>w<leader>w
  3. :echo wiki#journal#node_to_timestamp()
    It should return something like this: [1711839600, 'daily']
  4. :echo strftime('%Y-w%V', 1711839600) It should return something like this: 2024-w13
  5. :echo wiki#journal#node_to_date()
    It should return something like this: ['2024-03-31', 'daily']

It will help me pinpoint where the next problem is.

lervag avatar Mar 31 '24 14:03 lervag

you can simplify your config

I've simplify config: https://github.com/VimWei/vim-init/blob/master/init/plugins.vim#L166-L182

  • Do you agree that your third test returns the expected result?

Yes, the final result of the third test is what I expected. However, the preliminary steps required to trigger the third test are too complicated. In my understanding, as long as I enter the journal (such as <leader>w<leader>w), no matter what the preceding steps are, it should correctly trigger <plug>(wiki-journal-toweek) and call wiki-templates-journal-summaries.

Therefore, the ideal steps is:

  1. any operation
  2. <leader>w<leader>w: open today's journal. According to the help documentation, "the lines annotated[JOURNAL] are only available within the journal". At this point, it should satisfy the conditions within the journal.
  3. wu: open week summary, and call wiki-templates-journal-summaries
  • Do I understand correctly that the feature to open the current journal entry now works as expected? I.e., the current issue is now related to the weekly summaries?

Yes, the current issue is now related to the weekly summaries. The core issue is, "I have already met the condition of being in the journal, but why can't I correctly trigger WikiJournalToWeek?"

  • can you do this:

The results of the execution are all as you expected.

  1. restart gvim
  2. <leader>w<leader>w
  3. :echo wiki#journal#node_to_timestamp()

Result:[1711900800, 'daily']

  1. :echo strftime('%Y-w%V', 1711900800)

Result: 2024-w14

  1. :echo wiki#journal#node_to_date()

Result: ['2024-04-01', 'daily']

VimWei avatar Mar 31 '24 18:03 VimWei

  • Do you agree that your third test returns the expected result?

Yes, the final result of the third test is what I expected.

Great!

However, the preliminary steps required to trigger the third test are too complicated. …

Yes, of course - I only wanted to know if the result was as expected. I very much agree that this should work for all cases.

Yes, the current issue is now related to the weekly summaries. The core issue is, "I have already met the condition of being in the journal, but why can't I correctly trigger WikiJournalToWeek?"

:+1:

  • can you do this:

The results of the execution are all as you expected. …

Great. This is good and seems to imply that the problem is mainly with the templating function. However, in your above "NewTest 2", it seems there may be another bug as well. Can you therefore do this:

  1. restart gvim
  2. <leader>ww
  3. <leader>w<leader>w
  4. :echo wiki#journal#node_to_date()

Also, I now think that there is some bug within wiki#template#weekly_summary or any of the functions called deeper in that stack. It's a little hard to pinpoint based on the current input. But I think it could be enlightening to see some echo outputs. Could you do something like this and report the output?

function! wiki#template#weekly_summary(year, week) abort " {{{1
  let l:parser = s:summary.new()

  let l:title = copy(g:wiki_template_title_week)
  let l:title = substitute(l:title, '%(week)', a:week, 'g')
  let l:title = substitute(l:title, '%(year)', a:year, 'g')

  let l:dates = wiki#date#get_week_dates(a:week, a:year)
  unsilent echo "input " a:week "|" a:year
  unsilent echo "output" l:dates

  call append(0, [l:title] + l:parser.parse(l:dates))
  call setpos('.', [0, 3, 0, 0])
endfunction

In particular, I want to know if the week and year inputs look correct and if the dates output from wiki#date#get_week_dates seems correct.

lervag avatar Mar 31 '24 22:03 lervag

  • restart gvim
  • <leader>ww
  • <leader>w<leader>w
  • :echo wiki#journal#node_to_date()

['2024-04-01', 'daily']


  1. add two line in wiki#template#weekly_summary
  unsilent echom "input " a:week "|" a:year
  unsilent echom "output" l:dates
  1. restart gvim
  2. <leader>w<leader>w Open today journal that was previously saved.
  3. <leader>wu Open new week summary with template content.

image

  1. :messages

image

VimWei avatar Apr 01 '24 01:04 VimWei

Ok, thanks. I still don't see any unexpected results here. Can you try and reproduce the problem again, and if/when you do, can you report the related outputs in the case where it fails?

lervag avatar Apr 01 '24 09:04 lervag

After upgrading gvim to gvim9.1.0399x64_signed.exe and adjusting many vimrc configurations, I noticed some new phenomena.

Firstly, "Go to week summary" is working properly now!

  1. restart gvim
  2. <Leader>w<Leader>w
  3. <Leader>wu

week summary

Secondly, "Go to month summary" still doesn't work, although the prompt message is different from before.

  1. restart gvim
  2. <Leader>w<Leader>w
  3. <Leader>wm

month summary

Thirdly, "Go to month summary" operates the same in neovim 0.95 as in gvim.

month summary neovim

VimWei avatar May 12 '24 12:05 VimWei