diff --git a/README.md b/README.md index afa6c669..c585bc9f 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ Navigate your [Kitty](https://sw.kovidgoyal.net/kitty/) scrollback buffer to qui - The command `KittyScrollbackGenerateKittens` no longer accepts the bang `!` modifier - The api `generate_kittens` signature removed the `all` parameter - Removed the undocumented reserved `default` configuration name + - Removed the reserved `global` configuration name diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index f71b23e8..96856499 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -288,6 +288,13 @@ local function load_requires() ksb_backport = require('kitty-scrollback.backport') end +local function config_to_opts(config) + if type(config) == 'function' then + config = config(p.kitty_data) + end + return type(config) == 'table' and config or {} +end + ---Setup and configure kitty-scrollback.nvim ---@param kitty_data_str string M.setup = function(kitty_data_str) @@ -299,14 +306,13 @@ M.setup = function(kitty_data_str) p.kitty_data = vim.fn.json_decode(kitty_data_str) load_requires() -- must be after p.kitty_data initialized - -- if a config named 'global' is found, that will be applied to all configurations regardless of prefix + -- if a config at the first index found, that will be applied to all configurations regardless of prefix -- if a config name is prefixed 'ksb_builtin_', the user's config will be merged with configs/builtin.lua -- if a config does not meet the above criteria, check if a user had defined a configuration with the given config name and use that local config_name = p.kitty_data.kitty_scrollback_config or '' local config_source = require('kitty-scrollback') - local global_fn = config_source.configs['global'] - local global_opts = global_fn and global_fn(p.kitty_data) or {} + local global_opts = config_to_opts(config_source.configs[1]) local user_config = config_source.configs[config_name] if config_name ~= '' and not user_config and not config_name:match('^ksb_builtin_.*') then vim.defer_fn(function() @@ -315,17 +321,10 @@ M.setup = function(kitty_data_str) config_name = 'ksb_builtin_get_text_all' user_config = config_source.configs[config_name] end - if type(user_config) == 'function' then - user_config = user_config(p.kitty_data) - end - local user_opts = type(user_config) == 'table' and user_config or {} + local user_opts = config_to_opts(user_config) local builtin_opts = {} if config_name:match('^ksb_builtin_.*') then - local builtin_config = require('kitty-scrollback.configs.builtin')[config_name] - if type(builtin_config) == 'function' then - builtin_config = builtin_config(p.kitty_data) - end - builtin_opts = type(builtin_config) == 'table' and builtin_config or {} + builtin_opts = config_to_opts(require('kitty-scrollback.configs.builtin')[config_name]) end opts = vim.tbl_deep_extend('force', default_opts, global_opts, builtin_opts, user_opts)