From 14c3d3822a4e22d7507f7f77ef1388a070f0897e Mon Sep 17 00:00:00 2001 From: Larry Botha Date: Sat, 6 Jan 2024 16:22:36 +0200 Subject: [PATCH] refactor(ui.lua): only notify the user for conceallevel in markdown files once --- lua/obsidian/ui.lua | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lua/obsidian/ui.lua b/lua/obsidian/ui.lua index 16a632aa6..5a69d3e4c 100644 --- a/lua/obsidian/ui.lua +++ b/lua/obsidian/ui.lua @@ -567,20 +567,30 @@ M.setup = function(ui_opts) return end - local conceallevel = vim.opt_local.conceallevel:get() - if conceallevel < 1 or conceallevel > 2 then - log.warn( - "Obsidian additional syntax features require 'conceallevel' to be set to 1 or 2, " - .. "but you have 'conceallevel' set to '%s'.\n" - .. "See https://github.com/epwalsh/obsidian.nvim/issues/286 for more details.", - conceallevel - ) - end - local group = vim.api.nvim_create_augroup("obsidian_ui", { clear = true }) install_hl_groups(ui_opts) + vim.api.nvim_create_autocmd({ "BufEnter" }, { + group = group, + pattern = "*.md", + callback = function() + local conceallevel = vim.opt_local.conceallevel:get() + + if conceallevel < 1 or conceallevel > 2 then + log.warn( + "Obsidian additional syntax features require 'conceallevel' to be set to 1 or 2, " + .. "but you have 'conceallevel' set to '%s'.\n" + .. "See https://github.com/epwalsh/obsidian.nvim/issues/286 for more details.", + conceallevel + ) + end + + -- delete the autocommand + return true + end, + }) + vim.api.nvim_create_autocmd({ "BufEnter" }, { group = group, pattern = "*.md",