Trans.nvim/lua/Trans/setup.lua

35 lines
1020 B
Lua
Raw Normal View History

local db = require("Trans").db
-- local conf = require("Trans").conf
2022-12-20 10:22:28 +08:00
vim.api.nvim_create_user_command('TranslateCurosorWord', require("Trans.display").query_cursor, {})
2022-12-21 16:18:36 +08:00
vim.api.nvim_create_user_command('TranslateSelectWord', require("Trans.display").query_select, {})
2022-12-20 10:22:28 +08:00
local group = vim.api.nvim_create_augroup("Trans", { clear = true })
vim.api.nvim_create_autocmd('VimLeave', {
group = group,
pattern = '*',
callback = function()
if db:isopen() then
db:close()
end
end,
})
2022-12-21 11:41:21 +08:00
2022-12-19 22:23:12 +08:00
-- TODO: set command to close preview window automatically
2022-12-20 10:22:28 +08:00
local auto_close = require("Trans.conf").auto_close
if auto_close then
vim.api.nvim_create_autocmd(
2022-12-21 16:18:36 +08:00
{ 'InsertEnter', 'CursorMoved', 'BufLeave', }, {
2022-12-20 10:22:28 +08:00
group = group,
pattern = '*',
callback = require('Trans.display').close_win
})
end
2022-12-21 11:41:21 +08:00
2022-12-21 16:18:36 +08:00
2022-12-21 16:59:26 +08:00
-- vim.keymap.set('n', 'mm', '<cmd>TranslateCurosorWord<cr>')
-- vim.keymap.set('v', 'mm', '<Esc><cmd>TranslateSelectWord<cr>')
2022-12-21 11:41:21 +08:00
require("Trans.highlight").set_hl()