From 4c3f8c1f37603ad4b53a877ceb87bf39d498597b Mon Sep 17 00:00:00 2001 From: Larry Botha Date: Sun, 7 Jan 2024 03:25:56 +0200 Subject: [PATCH] refactor(ui.lua): only notify the user for conceallevel in markdown files once (#307) --- 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",