jannis-baum / vivify.vim

Live Markdown viewer for Vim and Neovim powered by Vivify
https://github.com/jannis-baum/vivify
12 stars 3 forks source link

Make filetypes with auto-syncing customizable #1

Closed azic0 closed 11 months ago

azic0 commented 11 months ago

Hi,

first of all thanks for the plugin, I really like functionality and the lightweight and structured way all of vivify is written.

However, it unfortunately seems to be incompatible with the vimwiki plugin. Whenever I activate it (using vims native plugin manager), the synchronisation ceases to work. After disabling vimwiki's autocommands using :au! vimwiki and reloading the buffer using :e, synchronisation automatically resumes.

Do you by any chance know why this could be?

All the best.

jannis-baum commented 11 months ago

Hey there! I'm happy to hear you like Vivify :)

Can you provide some more instructions for how to reproduce the issue? If I edit a markdown file and then run packadd vimwiki, Vivify's synchronization still works for me.

azic0 commented 11 months ago

Thanks for the quick and sorry for the late reply!

Does the synchronisation still work if you reload via :e after :packadd vimwiki?

I did modify vivify.vim and vivify.vim somewhat, but not in places that I would think to matter to this problem.

However, if I replace the

        autocmd CursorHold,CursorHoldI *
            \ if &filetype == 'markdown' | call vivify#sync_content() | endif
        autocmd CursorMoved,CursorMovedI *
            \ if &filetype == 'markdown' | call vivify#sync_cursor() | endif

in plugin/vivify.vim with

        autocmd CursorHold,CursorHoldI *.md call vivify#sync_content()
        autocmd CursorMoved,CursorMovedI *.md call vivify#sync_cursor()

my synchronisation issue is fixed.

Is there a specific reason why you used the former approach and do you think I can expect bad things to happen if I stick to the latter?

jannis-baum commented 11 months ago

Oh, of course, that makes sense! Vimwiki breaks the filetype: once you have Vimwiki loaded, it will set the filetype of Markdown files to vimwiki, i.e. Vim doesn't know anymore that it is a Markdown file. You can check this with :set ft?.

I can imagine that this breaks other things/plugins as well, so it might be something they should fix.

That being said, the reason I don't use *.md as you suggested but rather check the filetype is that there are other file extensions for markdown files, and using *.md works only with .md, while Vim's filetype is much more versatile, increasing compatibility.


My best idea for fixing this would be to introduce an option to vivify.vim that allows users to customize which filetypes should sync, by checking if the &filetype is in that list in the autocommand's condition.

In your case you could just add vimwiki then. If you want to implement this, a PR is very welcome; otherwise I'll do it at some point when I find the time :)

azic0 commented 11 months ago

Great!

I don't have a lot of experience with vimscript yet, but I will definitely try to implement your solution and send a pull request when I find the time :)

azic0 commented 11 months ago

I opened a pull request which should close this issue :) Details can be found in the commit messages.

In short, the issue is closed in two ways. One can set either of

to ensure compatibility between vivify.vim and vimwiki.

Unfortunately I can't seem to link the pull request to this issue, but apart from this, everything is set.

jannis-baum commented 11 months ago

Thanks!

azic0 commented 11 months ago

My pleasure!