lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.29k stars 386 forks source link

Treesitter alongside vimtex #2469

Closed aryabhatta-dey closed 1 year ago

aryabhatta-dey commented 1 year ago

Not really an issue rather a suggestion.

Currently, Vimtex's documentation suggests not to install markdown or latex Treesitter parsers if one wants to use Vimtex for recognizing mathzones. But this means one cannot use plugins like https://github.com/AckslD/nvim-FeMaco.lua.

So to get around the problem one can do

require("nvim-treesitter.configs").setup({
    ensure_installed = { "markdown" },
    highlight = {
        enable = true,
        disable = { "latex" },
        additional_vim_regex_highlighting = { "latex", "markdown" },
    },
    --other treesitter settings
})

I have tested this config out with small markdown files and as of the moment I can use both nvim-FeMaco and Vimtex's mathzones in the same file.

lervag commented 1 year ago

Thanks! It would be nice if you could explain what additional_vim_regex_highlighting does?

clason commented 1 year ago

It does not disable the legacy syntax engine when attaching a treesitter parser (via syntax off), i.e., it runs both treesitter and regex highlighting in parallel (completely negating any performance benefit, and possibly leading to weird results since both types of highlighting are applied, one over the other).

It's a band-aid that's not really recommended as a practical solution.

aryabhatta-dey commented 1 year ago

To quote directly from the readme of https://github.com/nvim-treesitter/nvim-treesitter "Setting this to true will run :h syntax and tree-sitter at the same time. Set this to true if you depend on 'syntax' being enabled (like for indentation). Using this option may slow down your editor, and you may see some duplicate highlights. Instead of true it can also be a list of languages".

I haven't yet experienced any negative effects but yes it's true it duplicates effort and is a band aid solution. But I prefer that loss in efficiency over loosing either nvim-FeMaco or Vimtex.

lervag commented 1 year ago

Cool, thanks for the explanations!

@aryabhatta-dey if you think we should make an update to the docs; would you care to propose a first version of this update?

aryabhatta-dey commented 1 year ago

Sure. Should I submit it as a pr with only documentation changes?

lervag commented 1 year ago

Yes, that would be great :)

aryabhatta-dey commented 1 year ago

Hey! Just made a pr https://github.com/lervag/vimtex/pull/2484. Sorry for not getting back to you so long. Please take a look and let me know what you think.

lervag commented 1 year ago

Thanks! I'll check it out now. I believe this issue can be closed now? (Feel free to reopen if I missed something.)

SeniorMars commented 1 year ago

Is there anyway to remove the message that vimtex puts out about treesitter syntax?

lervag commented 1 year ago

Yes: use let g:vimtex_syntax_enabled = 0 or vim.g.vimtex_syntax_enabled = 0.

SeniorMars commented 1 year ago

This might be a weird thing to ask, but since I use treesitter with:

        additional_vim_regex_highlighting = { "latex" },

I hoped there was a way to get rid of the message and not the support. vim.g.vimtex_syntax_enabled = 0 disables conceal on my system even with additional_vim_reg_highlighting, but I would like to get rid of the warning, not the support. Is this possible?

lervag commented 1 year ago

Ah, that's right. I agree that in this case there is no need for the warning. I've tried to update the check so that it only outputs the warning if VimTeX syntax is not active. Can you please update and check if it works?

lervag commented 1 year ago

It would be nice if you also checked if the warning is still there if you remove additional_vim_regex_highlighting. :)

SeniorMars commented 1 year ago

The warning is all gone! Thank you so much! I want to say I love this plugin so much. Is there any way we can sponsor you?

lervag commented 1 year ago

Glad to hear it, and thanks for the kind words! I don't mind donations, of course - there's a paypal badge on the README. <3

lervag commented 1 year ago

But I will also be glad if you instead choose to "pass it on" by donating to some cause you believe in, be it charity or other FOSS projects. :)