From e239a560f338be31337e7abc3ee42515daf23f5e Mon Sep 17 00:00:00 2001 From: Lopy <70210066+lopi-py@users.noreply.github.com> Date: Tue, 27 Aug 2024 17:42:20 -0500 Subject: [PATCH] feat: allow to be lazy loaded on InsertEnter (#212) --- lua/nvim-ts-autotag/config/plugin.lua | 7 +++++++ lua/nvim-ts-autotag/internal.lua | 3 +++ 2 files changed, 10 insertions(+) diff --git a/lua/nvim-ts-autotag/config/plugin.lua b/lua/nvim-ts-autotag/config/plugin.lua index 2cb3690..09d2226 100644 --- a/lua/nvim-ts-autotag/config/plugin.lua +++ b/lua/nvim-ts-autotag/config/plugin.lua @@ -187,6 +187,13 @@ function Setup.setup(opts) TagConfigs:add_alias(new_ft, existing_ft) end local augroup = vim.api.nvim_create_augroup("nvim_ts_xmltag", { clear = true }) + vim.api.nvim_create_autocmd("InsertEnter", { + group = augroup, + once = true, + callback = function(args) + require("nvim-ts-autotag.internal").attach(args.buf) + end, + }) vim.api.nvim_create_autocmd("Filetype", { group = augroup, callback = function(args) diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 98ce103..b816b93 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -445,6 +445,9 @@ end M.attach = function(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() + if buffer_tag[bufnr] then + return + end ---@diagnostic disable-next-line: invisible if not Setup.did_setup() then local _, ts_configs = pcall(require, "nvim-treesitter.configs")