From bf67d70bd7265d075191e7812d8eb42b9791f737 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 22 Jan 2024 20:39:45 +0100 Subject: [PATCH] perf: ignore events when setting buf options during render. Fixes #694 --- lua/noice/util/init.lua | 15 +++++++++++++-- lua/noice/view/init.lua | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lua/noice/util/init.lua b/lua/noice/util/init.lua index e8895589..a1d2cc11 100644 --- a/lua/noice/util/init.lua +++ b/lua/noice/util/init.lua @@ -43,11 +43,22 @@ function M.open(uri) end end +---@param fn fun():any +function M.ignore_events(fn) + local ei = vim.go.eventignore + vim.go.eventignore = "all" + local ret = fn() + vim.go.eventignore = ei + return ret +end + function M.tag(buf, tag) - local ft = vim.api.nvim_buf_get_option(buf, "filetype") + local ft = vim.bo[buf].filetype if ft == "" then - vim.api.nvim_buf_set_option(buf, "filetype", "noice") + M.ignore_events(function() + vim.bo[buf].filetype = "noice" + end) end if Config.options.debug and vim.api.nvim_buf_get_name(buf) == "" then diff --git a/lua/noice/view/init.lua b/lua/noice/view/init.lua index e32bd8b1..00f07fc1 100644 --- a/lua/noice/view/init.lua +++ b/lua/noice/view/init.lua @@ -221,7 +221,9 @@ function View:render(buf, opts) local linenr = opts.offset or 1 if self._opts.buf_options then - require("nui.utils")._.set_buf_options(buf, self._opts.buf_options) + Util.ignore_events(function() + require("nui.utils")._.set_buf_options(buf, self._opts.buf_options) + end) end if self._opts.lang and not vim.b[buf].ts_highlight then