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

Autocommand not triggered #1

Closed
lervag opened this issue Oct 24, 2023 · 11 comments
Closed

Autocommand not triggered #1

lervag opened this issue Oct 24, 2023 · 11 comments

Comments

@lervag
Copy link
Contributor

lervag commented Oct 24, 2023

The autocommand defined here is not triggered if cmp-vimtex is loaded lazily by e.g. lazy.nvim. I think this will be a quite common situation.

A simple, but possibly good solution is to add a check if the current file is already a .tex file, and to then start the parser immediately.

I would also advice to put all code inside the setup function. That is, requireing a script should not have a side effect in itself.

@micangl
Copy link
Owner

micangl commented Oct 24, 2023

@lervag I may have fixed it on branch test_autocmd.

@lervag
Copy link
Contributor Author

lervag commented Oct 24, 2023

No, I don't think so. The FileType autocommand will also have triggered before the .setup() function is called in my particular case.

@micangl
Copy link
Owner

micangl commented Oct 24, 2023

A simple, but possibly good solution is to add a check if the current file is already a .tex file, and to then start the parser immediately.

I misunderstood this remark. What did you mean, exactly?

@lervag
Copy link
Contributor Author

lervag commented Oct 25, 2023

I can propose a PR, it might be easier to understand if I show what I mean.

@micangl
Copy link
Owner

micangl commented Oct 25, 2023

I'd appreciate it!

lervag added a commit to lervag/cmp-vimtex that referenced this issue Oct 25, 2023
@lervag
Copy link
Contributor Author

lervag commented Oct 25, 2023

See #2, specifically this commit.

@micangl
Copy link
Owner

micangl commented Oct 25, 2023

Wow, great job!

I have a doubt, though: wouldn't the parser be triggered two times if setup wasn't called by lazy.nivm, i.e. inside the init.lua or automatically? Since, in this case, both the autocmd and

if vim.opt_local.filetype:get() == "tex" then
    _start_parser()
end

would launch parser.

@lervag
Copy link
Contributor Author

lervag commented Oct 26, 2023

Wow, great job!

Thanks :)

I have a doubt, though: wouldn't the parser be triggered two times if setup wasn't called by lazy.nivm, i.e. inside the init.lua or automatically? Since, in this case, both the autocmd and

if vim.opt_local.filetype:get() == "tex" then
    _start_parser()
end

would launch parser.

No, I don't think so - and this is the problem I'm trying to solve. If you are already inside a .tex file in which the filetype option is set to "tex" when you are running the .setup function, then the FileType trigger was already executed. Thus the autocommand does not have an effect on the current buffer, and so we want to trigger the parser manually.

@micangl
Copy link
Owner

micangl commented Oct 26, 2023

No, I don't think so - and this is the problem I'm trying to solve. If you are already inside a .tex file in which the filetype option is set to "tex" when you are running the .setup function, then the FileType trigger was already executed. Thus the autocommand does not have an effect on the current buffer, and so we want to trigger the parser manually.

I understood this; what I meant was: suppose that we use a regular plugin manager, which loads plugins on startup. When setup is executed, it sets the autocommand and executes _start_parser. Since we are at startup the FileType event is triggered, which triggers the parser, again, with the autocommand.

@lervag
Copy link
Contributor Author

lervag commented Oct 26, 2023

Ah, but that's where if vim.opt_local.filetype:get() == "tex" comes in. With a regular plugin manager that loads plugins on startup, the filetype will not be "tex".

@micangl
Copy link
Owner

micangl commented Oct 26, 2023

Very interesting. I'll test and push as soon as I can.

@micangl micangl closed this as completed Oct 27, 2023
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