-
Notifications
You must be signed in to change notification settings - Fork 52
help: render-markdown is not activated when lazy loaded with vim-plug #309
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
Comments
Here's what
It says "OK markdown: highlight enabled", but it still doesn't work by default, and I still have to enable it manually with Furthermore, the titles (e.g. Thank you very much for any help! |
There's a couple things to note here, but I'll start with a a high level overview of how this plugin works to clear up some confusion. So You can setup To make writing this plugin easier and perform faster I do not do any direct parsing logic over the text. Instead I run queries against the existing This means this plugin requires you to have treesitter running with a parser for
This does not mean that the plugin will work necessarily. Instead it tells you (and me when I help debug issues for users) whether you have the necessary dependencies up & running. |
The If you want to change the color per level using I assume when you disable |
To bring this all back to your original problem, I do not recommend lazy loading this plugin in general. This plugin is already very efficient and only really does work on markdown buffers. This plugin creates an autocommand to listen for new buffers and then only By lazy loading you are saving startup time in joining your config and creating the top level autocommand. As well as a While lazy loading should work I don't explicitly support it and I don't validate that it continues to work. The issue is that different plugin managers have different ways of doing the lazy loading and depending on their implementation as well as the rest of your configuration there may be problems. |
I imagine what's happening here is related to the fact that this plugin relies on the When you try to lazy-load with vim-plug based on the filetype by the time this plugin does its setup and creates the autocommand the I would expect this to always be an issue with lazy loading but it's not a problem with |
## Details Issue: #309 Depending on how the plugin manager implements lazy loading, this plugin can miss the initial buffer that triggered it to load. This is because we setup a `FileType` autocommand to check which buffers we should attach to. If the user configures this plugin to load based on a filetype that event will not be processed by the autocommand (since it has not been created yet). Instead everything will be setup but the current buffer will end up ignored. I'm unsure why this is not an issue with `lazy.nvim`, maybe it executes autocommands after the initial load. This would make sense, but I have not verified it. To get around this attempt to attach to the current buffer at the start, similar to the command based lazy loading edge case.
I've added a small change to maybe handle this issue here: 1ba6fb7 Please update and LMK if it works! |
Thank you so much for all these explanations! I've read them twice: everything is much clearer for me now.
Exactly! If I type
Yes! It works! Thank you very much! So what would be the correct way to apply the settings when lazy loading? Here's what I've added to my
Is this the right way to do it? Thanks for the time spent explaining all this to me, and solving the problem! |
What I was getting at in all the details was that I have no suggestions for lazy loading this plugin. There are ways that will work for now, and you're welcome to use one you find but it may break in the future, both due to changes in plugin managers as well as this plugin. Just a few too many edge cases with when things load, what dependencies are available, and what events get triggered when. The fact that lazy loading worked in
I would avoid calling the setup functions every time you open a buffer (BufRead). There's some state that gets cached that we clear when setup is called, may result in some weird behaviors if you open multiple markdown files. I'm also generally confused with how this works. So while you're editing non-markdown files Then you open a I don't really have a suggestion for how to do this properly but the way you have it might cause problems. But if it works it works, so feel free to keep it. Maybe try to find another vim-plug configuration that lazy loads Again my general advice is don't lazy load and just call setup. If you're really trying to make lazy loading work
No problem, happy to help :) |
Thanks for your advice! Maybe I'll have a look at On my PC, TreeSitter and RenderMarkdown take about 100 ms to load in total. That's almost half the loading time of Neovim in my config; that's why I considered the lazy load solution. |
## Details Related issues: - #309 - #315 - #317 Okay this is getting convoluted to handle the differences in lazy loading between `lazy.nvim` and `vim-plug`. The issues are as follows: - `lazy.nvim` & Lazy Loaded: Attempting to attach to current buffer at the start will not pickup user configuration (called from plugin directory before setup) so may not listen to all needed events. This means we should not attach to current buffer and rely on the `FileType` auto command. - `vim-plug` & Lazy Loaded: The initial load swallows the `FileType` event for the current buffer (`lazy.nvim` seems to trigger the event) so first buffer will be ignored. This means we cannot rely on the `FileType` auto command and need to attach to the current buffer. To fix this we need to be aware of the plugin manager being used so we can do the right thing, which sucks, but oh well. The solution expands on our existing logic to hook into `lazy.nvim` configuration for this plugin. When the user has NOT configured lazy loading (via filetypes nor commands) we attempt to attach to the current buffer. This means if they have we will skip attaching and will rely on the `FileType` event. This solves the `lazy.nvim` problem of not using the updated user configuration. This does mean when not lazy loading with `lazy.nvim` we will attempt to attach to the current buffer. This will initially fail since the filetype will not be set for the buffer but will succeed for the buffer later once the `FileType` event is triggered. For `vim-plug` we don't have any hooks so no matter what it will look like we are NOT lazy loading. This means we will attempt to attach to the current buffer fixing the issue of lazy loading with `vim-plug`. Have also added a check that buffer is valid in the `should_attach` function. The issue related to this should be fixed from the other updates but having it in place seems like a good idea in either case.
Neovim version (nvim -v)
0.10.3
Neovim distribution
N/A
Description
Hello!
I use Neovim with ArchLinux.
Here's my~/.config/nvim/init.vim
(all of it):EDIT: I've tested with the following minimal
~/.config/nvim/init.vim
file:However, when I open a
test.md
file, render-markdown is not activated by default, and I have to enable it manually using:RenderMarkdown
.If I don't lazy-load the plugin by removing the
{ 'for': 'markdown' }
part, then when I opentest.md
it's working perfectly fine: render-markdown is activated by default.What am I doing wrong? Thank you very much for your help!
The text was updated successfully, but these errors were encountered: