diff --git a/README.md b/README.md index bbb7641..e81d29f 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,33 @@ require("grapple").setup({ -- footer = "", -- disable footer footer_pos = "center", }, + + --Override tag mappings + tag_mappings = { + select_split = "", + select_vsplit = "|", + quickfix = "", + go_to_scopes = "-", + }, + --Override scope mappings + scope_mappings = { + change = "", + go_to_loaded = "-", + }, + --Override loaded (containers) mappings + loaded_mappings = { + unload = "x", + reset = "X", + go_to_scopes = "-", + }, + + --Override default general mappings + mappings = { + toggle_hidden = "g.", + select = "", + rename = "R", + help = "?", + }, }) ``` diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index 69c2de3..57f93be 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -186,20 +186,22 @@ local DEFAULT_SETTINGS = { local TagActions = require("grapple.tag_actions") local app = Grapple.app() + local mappings = vim.tbl_deep_extend("force", app.settings.mappings, app.settings.tag_mappings) + -- Select - window:map("n", "", function() + window:map("n", mappings.select, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1] }) end, { desc = "Select" }) -- Select (horizontal split) - window:map("n", "", function() + window:map("n", mappings.select_split, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.split }) end, { desc = "Select (split)" }) -- Select (vertical split) - window:map("n", "|", function() + window:map("n", mappings.select_vsplit, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.vsplit }) end, { desc = "Select (vsplit)" }) @@ -212,24 +214,24 @@ local DEFAULT_SETTINGS = { end -- Quickfix list - window:map("n", "", function() + window:map("n", mappings.quickfix, function() window:perform_close(TagActions.quickfix) end, { desc = "Quickfix" }) -- Go "up" to scopes - window:map("n", "-", function() + window:map("n", mappings.go_to_scopes, function() window:perform_close(TagActions.open_scopes) end, { desc = "Go to scopes" }) -- Rename - window:map("n", "R", function() + window:map("n", mappings.rename, function() local entry = window:current_entry() local path = entry.data.path window:perform_retain(TagActions.rename, { path = path }) end, { desc = "Rename" }) -- Help - window:map("n", "?", function() + window:map("n", mappings.help, function() local WindowActions = require("grapple.window_actions") window:perform_retain(WindowActions.help) end, { desc = "Help" }) @@ -249,8 +251,10 @@ local DEFAULT_SETTINGS = { local ScopeActions = require("grapple.scope_actions") local app = Grapple.app() + local mappings = vim.tbl_deep_extend("force", app.settings.mappings, app.settings.scope_mappings) + -- Select - window:map("n", "", function() + window:map("n", mappings.select, function() local entry = window:current_entry() local name = entry.data.name window:perform_close(ScopeActions.open_tags, { name = name }) @@ -271,24 +275,24 @@ local DEFAULT_SETTINGS = { end -- Change - window:map("n", "", function() + window:map("n", mappings.change, function() local entry = window:current_entry() local name = entry.data.name window:perform_close(ScopeActions.change, { name = name }) end, { desc = "Change scope" }) -- Navigate "up" to loaded scopes - window:map("n", "-", function() + window:map("n", mappings.go_to_loaded, function() window:perform_close(ScopeActions.open_loaded) end, { desc = "Go to loaded scopes" }) -- Toggle - window:map("n", "g.", function() + window:map("n", mappings.toggle_hidden, function() window:perform_retain(ScopeActions.toggle_all) end, { desc = "Toggle show hidden" }) -- Help - window:map("n", "?", function() + window:map("n", mappings.help, function() local WindowActions = require("grapple.window_actions") window:perform_retain(WindowActions.help) end, { desc = "Help" }) @@ -308,8 +312,10 @@ local DEFAULT_SETTINGS = { local ContainerActions = require("grapple.container_actions") local app = Grapple.app() + local mappings = vim.tbl_deep_extend("force", app.settings.mappings, app.settings.loaded_mappings) + -- Select - window:map("n", "", function() + window:map("n", mappings.select, function() local entry = window:current_entry() local id = entry.data.id window:perform_close(ContainerActions.select, { id = id }) @@ -330,31 +336,31 @@ local DEFAULT_SETTINGS = { end -- Unload - window:map("n", "x", function() + window:map("n", mappings.unload, function() local entry = window:current_entry() local id = entry.data.id window:perform_retain(ContainerActions.unload, { id = id }) end, { desc = "Unload scope" }) -- Reset - window:map("n", "X", function() + window:map("n", mappings.reset, function() local entry = window:current_entry() local id = entry.data.id window:perform_retain(ContainerActions.reset, { id = id }) end, { desc = "Reset scope" }) -- Navigate "up" to scopes - window:map("n", "-", function() + window:map("n", mappings.go_to_scopes, function() window:perform_close(ContainerActions.open_scopes) end, { desc = "Go to scopes" }) -- Toggle - window:map("n", "g.", function() + window:map("n", mappings.toggle_hidden, function() window:perform_retain(ContainerActions.toggle_all) end, { desc = "Toggle show unloaded" }) -- Help - window:map("n", "?", function() + window:map("n", mappings.help, function() local WindowActions = require("grapple.window_actions") window:perform_retain(WindowActions.help) end, { desc = "Help" }) @@ -432,6 +438,33 @@ local DEFAULT_SETTINGS = { footer_pos = "center", }, + --Override tag mappings + tag_mappings = { + select_split = "", + select_vsplit = "|", + quickfix = "", + go_to_scopes = "-", + }, + --Override scope mappings + scope_mappings = { + change = "", + go_to_loaded = "-", + }, + --Override loaded (containers) mappings + loaded_mappings = { + unload = "x", + reset = "X", + go_to_scopes = "-", + }, + + --Override default general mappings + mappings = { + toggle_hidden = "g.", + select = "", + rename = "R", + help = "?", + }, + ---Values for which a buffer should be excluded from being tagged exclusions = { buftype = { diff --git a/lua/grapple/window.lua b/lua/grapple/window.lua index d017cab..04de9d4 100644 --- a/lua/grapple/window.lua +++ b/lua/grapple/window.lua @@ -44,6 +44,8 @@ function Window:window_options() ---@diagnostic disable-next-line: assign-type-mismatch local opts = vim.tbl_deep_extend("keep", self.win_opts, {}) + local app = require("grapple").app() + -- Window title if self:has_content() and self.content:title() then opts.title = self.content:title() @@ -58,7 +60,7 @@ function Window:window_options() end if not opts.footer then - opts.footer = "Press '?' to toggle Help" + opts.footer = string.format("Press '%s' to toggle Help", app.settings.mappings.help) end -- Remove custom fields