diff --git a/README.md b/README.md index 9056281..b87b3b9 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,19 @@ Plug 'nvim-treesitter/nvim-treesitter' Plug 'cuducos/yaml.nvim' ``` +## Configuration + +### Showing the YAML patch and value in Neovim's winbar + +```lua +vim.api.nvim_create_autocmd({ "FileType" }, { + pattern = { "yaml" }, + callback = function() + vim.opt_local.winbar = [[%{%v:lua.require("yaml_nvim").get_yaml_key_and_value()%}]] + end, +}) +``` + ## Reporting bugs and contributing There is a mini toolchain to help you test the plugin in isolation using a container. It requires: diff --git a/lua/yaml_nvim/init.lua b/lua/yaml_nvim/init.lua index f074a38..ef28a0e 100644 --- a/lua/yaml_nvim/init.lua +++ b/lua/yaml_nvim/init.lua @@ -57,15 +57,18 @@ local yank = function(key, value, register) end M.view = function() - assure_yaml_filetype(function() - local node = document.get_key_relevant_to_cursor() - if node == nil then - return - end + vim.notify(M.get_yaml_key_and_value()) +end - local parsed = pair.parse(node) - vim.notify(parsed.human) - end) +M.get_yaml_key_and_value = function() + local restore_to = set_yaml_as_filetype() + local node = document.get_key_relevant_to_cursor() + if node == nil then + return + end + local parsed = pair.parse(node) + restore_filetype(restore_to) + return parsed.human end M.yank = function(register)