brennier / quicktex

A vim plugin for writing Latex quickly.
http://brennier.com/projects
MIT License
116 stars 17 forks source link

Lazy-loading `quicktex` via `lazy.nvim` #31

Open make-github-pseudonymous-again opened 2 months ago

make-github-pseudonymous-again commented 2 months ago

Lazily loading quicktex with a custom ftplugin configuration works via lazy.nvim using the following configuration, provided you have put your custom configuration under ~/.config/nvim/after/ftplugin/...:

{
  'brennier/quicktex',
  lazy = true,
  ft = { 'tex', 'latex' },
}

Since quicktex is only meaningful in insert mode, it would make sense to load it on event = 'InsertEnter *.tex':

{
  'brennier/quicktex',
  lazy = true,
  event = 'InsertEnter *.tex',
}

But this does not seem to work, because then the default dictionaries of quicktex get loaded last.

Is there any way to load quicktex with a custom configuration when entering insert mode for the first time?

brennier commented 2 months ago

I'm not familiar with lazy.nvim, so I'm not sure how it works.

I believe you're saying that your custom dictionaries are loaded first and then the default dictionaries are loaded afterwards, which overwrites your custom dictionaries. Is that correct? If so, you should be able to disable the default dictionaries by setting let g:quicktex_usedefault = 0.

If that doesn't work, another possible alternative is to load your custom dictionaries after loading quicktex.

make-github-pseudonymous-again commented 2 months ago

Thanks Bennett! Looks like I was wrong, root cause was the FileType autocmd that sets up quicktex via AssignExpander not being triggered after InsertEnter. Here is what works for me (disabling the defaults in init seems unnecessary):

{
  'brennier/quicktex',
  lazy = true,
  event = 'InsertEnter *.tex',
  init = function()
    -- Probably unnecessary.
    vim.g.quicktex_usedefault = 0
  end,
  config = function()
    vim.api.nvim_exec_autocmds('FileType', { pattern = '<buffer>' })
  end,
}

Two questions:

  1. Instead of g:quicktex_usedefault, could we just make the defaults autodetect that the globals have already been assigned?
  2. How would one trigger AssignExpander without creating a synthetic FileType event?

Also, wanted to say I wrote my thesis using your plugin.

brennier commented 2 months ago

Instead of g:quicktex_usedefault, could we just make the defaults autodetect that the globals have already been assigned?

The plugin already does this. Setting the variable g:quicktex_usedefault is unnecessary for the vast majority of users. A few people requested this variable because they wanted to use the plugin for other file types and didn't want it to activate for latex files. I agree that it's unnecessary for your use case.

EDIT: My apologies, what I wrote here was incorrect. It seems that I changed the code a bit a few years ago and accidentally removed this functionality. I've just added a commit that re-adds the code that checks for user dictionaries before defining the default dictionaries. Thanks for your comment!

How would one trigger AssignExpander without creating a synthetic FileType event?

Why don't you just have your config function call AssignExpander() directly instead of calling all FileType autocommands a second time?

Also, wanted to say I wrote my thesis using your plugin.

I'm happy to hear this 😄 I made this plugin while studying mathematics in graduate school. I graduated a few years ago, but I'm glad to hear that it has been useful for others.