diff --git a/lua/Trans/database.lua b/lua/Trans/database.lua deleted file mode 100644 index a5b77c0..0000000 --- a/lua/Trans/database.lua +++ /dev/null @@ -1,6 +0,0 @@ -local M = {} - -function M.query(arg) -end - -return M diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index 6a1a55f..909bd06 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -1,17 +1,15 @@ local M = {} - M.conf = require("Trans.conf") function M.setup(conf) conf = conf or {} - if conf.display then - conf.display = vim.tbl_extend('force', M.conf.display, conf.display) + for k, v in pairs(conf) do + if type(v) == 'table' then + M.conf[k] = vim.tbl_extend('force', M.conf[k], v) + else + M.conf[k] = v + end end - - if conf.icon then - conf.icon = vim.tbl_extend('force', M.conf.icon, conf.icon) - end - M.conf = vim.tbl_extend('force', M.conf, conf) require("Trans.setup") end diff --git a/lua/Trans/setup.lua b/lua/Trans/setup.lua index e0325b0..18d4e16 100644 --- a/lua/Trans/setup.lua +++ b/lua/Trans/setup.lua @@ -1,14 +1,17 @@ local db = require("Trans").db --- local conf = require("Trans").conf -vim.api.nvim_create_user_command('TranslateCursorWord', require("Trans.display").query_cursor, {}) -vim.api.nvim_create_user_command('TranslateSelectWord', require("Trans.display").query_select, {}) -vim.api.nvim_create_user_command('TranslateInputWord', require("Trans.display").query_input, {}) +vim.api.nvim_create_user_command('TranslateCursorWord', require("Trans.display").query_cursor, { + desc = '翻译光标下的单词', +}) +vim.api.nvim_create_user_command('TranslateSelectWord', require("Trans.display").query_select, { + desc = '翻译选中的单词', +}) +vim.api.nvim_create_user_command('TranslateInputWord', require("Trans.display").query_input, { + desc = '翻译输入的单词', +}) - -local group = vim.api.nvim_create_augroup("Trans", { clear = true }) -vim.api.nvim_create_autocmd('VimLeave', { - group = group, +vim.api.nvim_create_autocmd('VimLeavePre', { + group = vim.api.nvim_create_augroup("Trans", { clear = true }), pattern = '*', callback = function() if db:isopen() then @@ -17,9 +20,6 @@ vim.api.nvim_create_autocmd('VimLeave', { end, }) --- vim.keymap.set('n', 'mm', 'TranslateCurosorWord') --- vim.keymap.set('v', 'mm', 'TranslateSelectWord') - local highlights = require("Trans").conf.highlight for highlight, opt in pairs(highlights) do vim.nvim_set_hl(0, highlight, opt)