michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
555 stars 72 forks source link

:ZettelCapture bad filenames and file counts #102

Closed geblanco closed 2 years ago

geblanco commented 3 years ago

Hello!

First of all, thanks for this great package you're crafting!

I write this as a separate issue to #10 because it seems to be a somewhat different error.

When running ZettelCapture on a file that is not saved yet, it outputs:

Error detected while processing function zettel#vimwiki#zettel_capture[13]..zettel#vimwiki#get_title:

though it saves the file to my zettel wiki.

When running it with the file saved (e.g.: in /tmp/my_zettel_to_capture.txt), it doesn't fail, but I think there are some filename parsing problems. For me, intuitively, it should gather the filename (my_zettel_to_capture.txt) and use it as title, though examining the code, it seems to parse something in the form = title: <> = inside the file?. Having this inside it doesn't seem to work (maybe I'm miswriting it?)

Example file:

= title:variational_inference =
Variational Inference

In Variational Inference we try to approximate complex probability densities, instead of statically calculate them.

And, in any case, setting the file_no fails. I have two separate wikis, one for non-zettel stuff (my previous wiki) and another one for zettel (just started using it). I think it is properly configured to use the second wiki (~/zettel directory), but when setting the file_no from ZettelCapture, it uses the count from the main wiki. Here is the zettel-related config from my .vimrc:

""" plugin section
Plugin 'https://github.com/vimwiki/vimwiki'
Plugin 'https://github.com/tbabej/taskwiki'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
Plugin 'michal-h21/vim-zettel'

""" zettel config
let g:vimwiki_auto_tags = 1
let g:vimwiki_list = [
  \ {'path':'~/vimwiki'}, 
  \ {"path":"~/zettel", "auto_toc": 1, "links_space_char": "_", "disable_front_matter": 1}]
let g:zettel_options = [{}, {"template": "~/.config/zettel/default.tpl"}]
let g:zettel_format = "%y%m%d-%file_alpha%file_no-%title"

I think it has to do with the default wiki number, when inside the wiki (operating with the zettelkasten), one can run ZettelSetActiveWiki with the proper number, and (I guess) everything works well, but, without calling it, or running from the outside, it is not properly configured. Again, inspecting the code, I see that vimwiki_wiki_nr is just a buff variable. I'm guessing this can be appropriate when editing different zettels stored in different wikis, though it seems like an extreme use case, maybe it could be better to store it as an option in .vimrc and avoid this kind of issues? E.g.:

""" Zero indexed wiki number
let g:zettel_default_wiki_number = 1

Maybe I can prepare a PR if we settle on some of these.

What do you think?

Best,

geblanco commented 3 years ago

I have been researching a little bit more the wiki_nr. When entering wiki mode from any zettel function, the default is set to 0 (because getbufvar("%", "vimwiki_wiki_nr") == -1 evaluates to true, afterwards, when the file is saved, the wiki plugin sets the wiki_nr to the index of the wiki where the file is saved, that is, in case of non-0 zettel wiki, defaulting to 0 results in a bad file_no count, but, after saving, the wiki_nr is set correctly. This happens here, inserting a call to echo vimwiki#vars#get_wikilocal('path') before and after the save call helps visualizing this effect.

I have fixed this in my fork of this project and sent a PR!

Best,