Closed lervag closed 10 months ago
@lervag I may have fixed it on branch test_autocmd.
No, I don't think so. The FileType
autocommand will also have triggered before the .setup()
function is called in my particular case.
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?
I can propose a PR, it might be easier to understand if I show what I mean.
I'd appreciate it!
See #2, specifically this commit.
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.
Wow, great job!
Thanks :)
I have a doubt, though: wouldn't the parser be triggered two times if
setup
wasn't called bylazy.nivm
, i.e. inside theinit.lua
or automatically? Since, in this case, both the autocmd andif 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.
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.
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"
.
Very interesting. I'll test and push as soon as I can.
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,
require
ing a script should not have a side effect in itself.