From ac6b04884965460d5db2f1b1d00483a0adde9fd0 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 19 Jan 2025 17:26:30 -0800 Subject: [PATCH] Add object keys --- lua/argonaut/options.lua | 26 +++++++++++++++++++++----- plugin/argonaut.lua | 16 +++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lua/argonaut/options.lua b/lua/argonaut/options.lua index 1c06b17..d3887fe 100644 --- a/lua/argonaut/options.lua +++ b/lua/argonaut/options.lua @@ -1,11 +1,11 @@ local options_current = { - auto_reload = false, brace_last_indent = false, brace_last_wrap = true, brace_pad = false, comma_last = {['{'] = true}, comma_prefix = false, comma_prefix_indent = false, + object_char = 'a', by_filetype = { go = {comma_last = true}, }, @@ -34,10 +34,6 @@ local function query_with_pairing(value, pairing) return value end -local function setup(options) - merge_table(options_current, options) -end - local function query(name, pairing) local options_current_by_filetype = options_current.by_filetype[vim.bo.filetype] if options_current_by_filetype then @@ -50,6 +46,26 @@ local function query(name, pairing) return query_with_pairing(options_current[name], pairing) end +local function setup(options) + merge_table(options_current, options) + + local object_char = query('object_char') + for _, mode in ipairs({'x', 'o'}) do + vim.api.nvim_set_keymap( + mode, + 'i' .. object_char, + ':ArgonautInnerObject', + {noremap = true, silent = true} + ) + vim.api.nvim_set_keymap( + mode, + 'a' .. object_char, + ':ArgonautOuterObject', + {noremap = true, silent = true} + ) + end +end + return { setup = setup, query = query, diff --git a/plugin/argonaut.lua b/plugin/argonaut.lua index e1d1be2..ca1e525 100644 --- a/plugin/argonaut.lua +++ b/plugin/argonaut.lua @@ -11,13 +11,11 @@ if not vim.g.argonaut_loaded then require('argonaut').inspect() end - local function argonaut_object_inner() - argonaut_reload() + local function argonaut_inner_object() require('argonaut').object(true) end - local function argonaut_object_outer() - argonaut_reload() + local function argonaut_outer_object() require('argonaut').object(false) end @@ -29,12 +27,12 @@ if not vim.g.argonaut_loaded then require('argonaut').reflow(true) end - vim.api.nvim_create_user_command('ArgonautInspect', argonaut_inspect, {}) - vim.api.nvim_create_user_command('ArgonautObjectInner', argonaut_object_inner, {}) - vim.api.nvim_create_user_command('ArgonautObjectOuter', argonaut_object_outer, {}) - vim.api.nvim_create_user_command('ArgonautReflow', argonaut_reflow, {}) - vim.api.nvim_create_user_command('ArgonautReload', argonaut_reload, {}) vim.api.nvim_create_user_command('ArgonautToggle', argonaut_toggle, {}) + vim.api.nvim_create_user_command('ArgonautInnerObject', argonaut_inner_object, {}) + vim.api.nvim_create_user_command('ArgonautOuterObject', argonaut_outer_object, {}) + vim.api.nvim_create_user_command('ArgonautReflow', argonaut_reflow, {}) + vim.api.nvim_create_user_command('ArgonautInspect', argonaut_inspect, {}) + vim.api.nvim_create_user_command('ArgonautReload', argonaut_reload, {}) vim.g.argonaut_loaded = true end