From 13407572ac200f3d738ed2ea981023ef7df8362b Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Nov 2022 23:38:29 +0100 Subject: [PATCH] feat: add translation snippet --- configs/nvim/lua/configs/autocomplete.lua | 1 + configs/nvim/lua/configs/translate/init.lua | 58 +++++++++++++++++++ .../nvim/lua/configs/translate/languages.lua | 34 +++++++++++ configs/nvim/lua/core/autocommands.lua | 2 +- configs/nvim/lua/core/keymappings.lua | 4 ++ configs/wezterm/wezterm.lua | 5 +- 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 configs/nvim/lua/configs/translate/init.lua create mode 100644 configs/nvim/lua/configs/translate/languages.lua diff --git a/configs/nvim/lua/configs/autocomplete.lua b/configs/nvim/lua/configs/autocomplete.lua index 565da18..d0ffe8d 100644 --- a/configs/nvim/lua/configs/autocomplete.lua +++ b/configs/nvim/lua/configs/autocomplete.lua @@ -58,6 +58,7 @@ cmp.setup({ { name = "nvim_lsp" }, -- { name = "cmp_tabnine", max_item_count = 3 }, { name = "luasnip" }, + { name = "emoji" }, { name = "path" }, { name = "buffer" }, { name = "calc" }, diff --git a/configs/nvim/lua/configs/translate/init.lua b/configs/nvim/lua/configs/translate/init.lua new file mode 100644 index 0000000..bbd7cde --- /dev/null +++ b/configs/nvim/lua/configs/translate/init.lua @@ -0,0 +1,58 @@ +local languages = require "configs.translate.languages"; +local pickers = require 'telescope.pickers' +local finders = require 'telescope.finders' +local actions = require 'telescope.actions' +local action_state = require 'telescope.actions.state' +local conf = require('telescope.config').values + +return function() + + -- This active_buf and active selection because telescope clears everything (i think) + local active_buf = vim.api.nvim_get_current_buf(); + local mode = vim.api.nvim_get_mode().mode; + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), 'x!', true) + local start_mark = vim.api.nvim_buf_get_mark(active_buf, "<") + local end_mark = vim.api.nvim_buf_get_mark(active_buf, ">") + + pickers + .new({}, { + prompt_title = 'Translate', + finder = finders.new_table { + results = languages, + entry_maker = function(entry) + return { + value = entry[2], + ordinal = entry[1] .. " " .. entry[2], + display = entry[3] .. entry[1], + } + end, + }, + sorter = conf.generic_sorter {}, + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + + local selection = action_state.get_selected_entry() + + vim.api.nvim_set_current_buf(active_buf) + + vim.api.nvim_win_set_cursor(0, start_mark); + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(mode, true, false, true), 'x!', true) + vim.api.nvim_win_set_cursor(0, end_mark); + + local timer = vim.loop.new_timer() + timer:start(500, 0, vim.schedule_wrap(function() + if mode == "v" or mode == "V" then + vim.cmd("'<,'>Translate " .. selection.value) + else + vim.cmd("Translate " .. selection.value) + end + end)) + end) + return true + end, + previewer = nil + }) + :find() + +end diff --git a/configs/nvim/lua/configs/translate/languages.lua b/configs/nvim/lua/configs/translate/languages.lua new file mode 100644 index 0000000..76cbf0c --- /dev/null +++ b/configs/nvim/lua/configs/translate/languages.lua @@ -0,0 +1,34 @@ +return { { "Afrikaans", "af", "🇦🇫" }, { "Albanian", "sq", "🇸🇶" }, { "Amharic", "am", "🇦🇲" }, + { "Arabic", "ar", "🇦🇷" }, { "Armenian", "hy", "🇭🇾" }, { "Azerbaijani", "az", "🇦🇿" }, + { "Basque", "eu", "🇪🇺" }, { "Belarusian", "be", "🇧🇪" }, { "Bengali", "bn", "🇧🇳" }, + { "Bosnian", "bs", "🇧🇸" }, { "Bulgarian", "bg", "🇧🇬" }, { "Catalan", "ca", "🇨🇦" }, + { "Cebuano", "ceb", "🇨🇪🇧" }, { "Chinese (Simplified)", "zh-CN", "🇿🇭🇒🇨🇳" }, + { "Chinese (Traditional)", "zh-TW", "🇿🇭🇒🇹🇼" }, { "Corsican", "co", "🇨🇴" }, + { "Croatian", "hr", "🇭🇷" }, { "Czech", "cs", "🇨🇸" }, { "Danish", "da", "🇩🇦" }, { "Dutch", "nl", "🇳🇱" }, + { "English", "en", "🇪🇳" }, { "Esperanto", "eo", "🇪🇴" }, { "Estonian", "et", "🇪🇹" }, + { "Finnish", "fi", "🇫🇮" }, { "French", "fr", "🇫🇷" }, { "Frisian", "fy", "🇫🇾" }, + { "Galician", "gl", "🇬🇱" }, { "Georgian", "ka", "🇰🇦" }, { "German", "de", "🇩🇪" }, + { "Greek", "el", "🇪🇱" }, { "Gujarati", "gu", "🇬🇺" }, { "Haitian Creole", "ht", "🇭🇹" }, + { "Hausa", "ha", "🇭🇦" }, { "Hawaiian", "haw", "🇭🇦🇼" }, { "Hebrew", "iw", "🇮🇼" }, + { "Hindi", "hi", "🇭🇮" }, { "Hmong", "hmn", "🇭🇲🇳" }, { "Hungarian", "hu", "🇭🇺" }, + { "Icelandic", "is", "🇮🇸" }, { "Igbo", "ig", "🇮🇬" }, { "Indonesian", "id", "🇮🇩" }, + { "Irish", "ga", "🇬🇦" }, { "Italian", "it", "🇮🇹" }, { "Japanese", "ja", "🇯🇦" }, + { "Javanese", "jw", "🇯🇼" }, { "Kannada", "kn", "🇰🇳" }, { "Kazakh", "kk", "🇰🇰" }, + { "Khmer", "km", "🇰🇲" }, { "Korean", "ko", "🇰🇴" }, { "Kurdish", "ku", "🇰🇺" }, { "Kyrgyz", "ky", "🇰🇾" }, + { "Lao", "lo", "🇱🇴" }, { "Latin", "la", "🇱🇦" }, { "Latvian", "lv", "🇱🇻" }, { "Lithuanian", "lt", "🇱🇹" }, + { "Luxembourgish", "lb", "🇱🇧" }, { "Macedonian", "mk", "🇲🇰" }, { "Malagasy", "mg", "🇲🇬" }, + { "Malay", "ms", "🇲🇸" }, { "Malayalam", "ml", "🇲🇱" }, { "Maltese", "mt", "🇲🇹" }, + { "Maori", "mi", "🇲🇮" }, { "Marathi", "mr", "🇲🇷" }, { "Mongolian", "mn", "🇲🇳" }, + { "Myanmar (Burmese)", "my", "🇲🇾" }, { "Nepali", "ne", "🇳🇪" }, { "Norwegian", "no", "🇳🇴" }, + { "Nyanja (Chichewa)", "ny", "🇳🇾" }, { "Pashto", "ps", "🇵🇸" }, { "Persian", "fa", "🇫🇦" }, + { "Polish", "pl", "🇵🇱" }, { "Portuguese (Portugal, Brazil)", "pt", "🇵🇹" }, { "Punjabi", "pa", "🇵🇦" }, + { "Romanian", "ro", "🇷🇴" }, { "Russian", "ru", "🇷🇺" }, { "Samoan", "sm", "🇸🇲" }, + { "Scots Gaelic", "gd", "🇬🇩" }, { "Serbian", "sr", "🇸🇷" }, { "Sesotho", "st", "🇸🇹" }, + { "Shona", "sn", "🇸🇳" }, { "Sindhi", "sd", "🇸🇩" }, { "Sinhala (Sinhalese)", "si", "🇸🇮" }, + { "Slovak", "sk", "🇸🇰" }, { "Slovenian", "sl", "🇸🇱" }, { "Somali", "so", "🇸🇴" }, + { "Spanish", "es", "🇪🇸" }, { "Sundanese", "su", "🇸🇺" }, { "Swahili", "sw", "🇸🇼" }, + { "Swedish", "sv", "🇸🇻" }, { "Tagalog (Filipino)", "tl", "🇹🇱" }, { "Tajik", "tg", "🇹🇬" }, + { "Tamil", "ta", "🇹🇦" }, { "Telugu", "te", "🇹🇪" }, { "Thai", "th", "🇹🇭" }, { "Turkish", "tr", "🇹🇷" }, + { "Ukrainian", "uk", "🇺🇰" }, { "Urdu", "ur", "🇺🇷" }, { "Uzbek", "uz", "🇺🇿" }, + { "Vietnamese", "vi", "🇻🇮" }, { "Welsh", "cy", "🇨🇾" }, { "Xhosa", "xh", "🇽🇭" }, + { "Yiddish", "yi", "🇾🇮" }, { "Yoruba", "yo", "🇾🇴" }, { "Zulu", "zu", "🇿🇺" } } diff --git a/configs/nvim/lua/core/autocommands.lua b/configs/nvim/lua/core/autocommands.lua index 696072a..31f437d 100644 --- a/configs/nvim/lua/core/autocommands.lua +++ b/configs/nvim/lua/core/autocommands.lua @@ -8,7 +8,7 @@ vim.api.nvim_create_autocmd({ 'TextYankPost' }, { end, }) -local rememberFoldsGroup = vim.api.nvim_create_augroup('RememberFolds', { clear = true }) +-- local rememberFoldsGroup = vim.api.nvim_create_augroup('RememberFolds', { clear = true }) -- -- vim.api.nvim_create_autocmd({ 'BufWinLeave', 'BufLeave' }, { -- pattern = "*", diff --git a/configs/nvim/lua/core/keymappings.lua b/configs/nvim/lua/core/keymappings.lua index ee33aba..c686288 100644 --- a/configs/nvim/lua/core/keymappings.lua +++ b/configs/nvim/lua/core/keymappings.lua @@ -1,6 +1,7 @@ -- local map = vim.api.nvim_set_keymap local map = vim.keymap.set local g = vim.g +local translate = require("configs.translate") local saga = require("lspsaga") saga.init_lsp_saga() @@ -31,6 +32,9 @@ map({ "n", "v" }, "gr", "Lspsaga lsp_finder", options) map("n", "t", ":TroubleToggle", remap) +map("n", "t", translate, remap) +map("v", "t", translate, remap) + -- DAP Functionality map("n", "b", ":lua require('dap').toggle_breakpoint()", options) diff --git a/configs/wezterm/wezterm.lua b/configs/wezterm/wezterm.lua index f945e56..0a05135 100644 --- a/configs/wezterm/wezterm.lua +++ b/configs/wezterm/wezterm.lua @@ -11,7 +11,10 @@ local function scheme_for_appearance(appearance) end return { - font = wezterm.font("FiraCodeNerdFont"), + font = wezterm.font_with_fallback { + "FiraCodeNerdFont", + "Noto Color Emoji" + }, font_size = 13, -- You can specify some parameters to influence the font selection; -- for example, this selects a Bold, Italic font variant.