commit 49d7eadec9ffe685a726245736abade12650a980
parent cb3a570f421dca3d2525c689898ce50b8f9660be
Author: Tomas Nemec <nemi@skaut.cz>
Date: Tue, 8 Mar 2022 08:02:54 +0100
update
Diffstat:
8 files changed, 59 insertions(+), 217 deletions(-)
diff --git a/lua/tms/colors/gruvbox.lua b/lua/tms/colors/gruvbox.lua
@@ -1,128 +0,0 @@
--- map <buffer> ,c <cmd>execute 'lua ' . getline('.')<cr>
-local M = {}
-
-M.setup = function()
- local Color, c, Group, g, _ = require('colorbuddy').setup()
-
- if vim.opt.background:get() == 'dark' then
- -- gruvbox
- Color.new('gwhite', '#f2e5bc')
- Color.new('gred', '#fb4934')
- Color.new('gpurple', '#d3869b')
- Color.new('ggreen', '#b8bb26')
- Color.new('gyellow', '#fabd2f')
- Color.new('gblue', '#83a598')
- Color.new('gaqua', '#8ec07c')
- Color.new('gorange', '#fe8019')
- Color.new('ggray', '#928374')
- Color.new('gbgh', '#1d2021')
- Color.new('gbg0', '#282828')
- Color.new('gbg1', '#3c3836')
- Color.new('gbg2', '#504945')
- Color.new('gbg3', '#665c54')
- Color.new('gbg4', '#7c6f64')
- -- general
- Group.new('Normal', c.gwhite, c.gbgh)
- Group.new('SignColumn', nil, c.gbgh:dark(0.01))
- Group.new('NormalFloat', nil, c.gbgh)
- Group.new('Search', c.gwhite:light(), c.gbg0)
- Group.new('CursorLine', nil, g.Normal.bg:light(0.02))
- Group.new('Visual', nil, c.gbg1)
- Group.new('FloatBorder', nil, c.gbgh)
- Group.new('Folded', c.gbgh:light(0.20), g.Normal.bg:light(0.02))
- Group.new('FoldColumn', g.SignColumn, g.SignColumn)
-
- -- syntax
- Group.new('Operator', nil, nil)
-
- -- GitSigns
- Group.new('GitSignsAdd', c.ggreen, g.SignColumn.bg)
- Group.new('GitSignsChange', c.gorange, g.SignColumn.bg)
- Group.new('GitSignsDelete', c.gred, g.SignColumn.bg)
-
- -- Lsp
- Group.new('DiagnosticsSignError', c.red:saturate(-0.5), g.SignColumn)
- Group.new('DiagnosticsSignWarning', c.orange:saturate(-0.5), g.SignColumn)
- Group.new('DiagnosticsSignInformation', c.gbg1, g.SignColumn)
- Group.new('DiagnosticsSignHint', c.gbg1, g.SignColumn)
-
- -- TreeSitter
- Group.new('TSDefinitionUsage', nil, c.gbg0)
- Group.new('TSDefinition', nil, c.gbg0)
-
- -- Telescope
- Group.new('TelescopeMatching', c.gwhite:light(), nil)
- Group.new('TelescopeSelection', nil, g.CursorLine)
-
- -- Indent blankline
- Group.new('IndentBlanklineChar', c.gbgh:light(0.05), nil)
- Group.new('IndentBlanklineSpaceChar', c.gbgh:light(0.05), nil)
- Group.new('IndentBlanklineSpaceCharBlankline', c.gbgh:light(0.05), nil)
-
- -- HiPairs
- Group.new('hiPairs_matchPair', c.gyellow, c.gbgh)
- Group.new('hiPairs_unmatchPair', nil, c.gred)
- else
- -- gruvbox
- Color.new('gwhite', '#282828')
- Color.new('gred', '#cc241d')
- Color.new('gpurple', '#8f3f71')
- Color.new('ggreen', '#98971e')
- Color.new('gyellow', '#d79921')
- Color.new('gblue', '#458588')
- Color.new('gaqua', '#689d6a')
- Color.new('gorange', '#d65d0e')
- Color.new('ggray', '#928374')
- Color.new('gbgh', '#f9f5d7')
- Color.new('gbg0', '#fbf1c7')
- Color.new('gbg1', '#ebdbb2')
- Color.new('gbg2', '#d5c4a1')
- Color.new('gbg3', '#bdae93')
- Color.new('gbg4', '#a89984')
-
- -- general
- -- Group.new('Normal', nil, nil)
- Group.new('SignColumn', nil, c.gbg1)
- Group.new('NormalFloat', nil, c.gbg0)
- -- Group.new('FloatBorder', nil, g.NormalFloat.bg)
- -- Group.new('Search', c.gwhite:light(), c.gbg0)
- Group.new('CursorLine', nil, c.gbg1)
- Group.new('Cursor', nil, c.gbg4)
- Group.new('Visual', nil, c.gbg1:dark(0.05))
- -- Group.new('Folded', c.gbgh:light(0.20), g.Normal.bg:light(0.02))
- -- Group.new('FoldColumn', g.SignColumn, g.SignColumn)
-
- -- syntax
- Group.new('Operator', nil, nil)
-
- -- GitSigns
- Group.new('GitSignsAdd', nil, c.ggreen)
- Group.new('GitSignsChange', nil, c.gorange)
- Group.new('GitSignsDelete', nil, c.gred)
-
- -- Lsp
- Group.new('DiagnosticsSignError', c.red:saturate(-0.5), g.SignColumn)
- Group.new('DiagnosticsSignWarning', c.orange:saturate(-0.5), g.SignColumn)
- Group.new('DiagnosticsSignInformation', c.gbg1, g.SignColumn)
- Group.new('DiagnosticsSignHint', c.gbg1, g.SignColumn)
-
- -- TreeSitter
- Group.new('TSDefinitionUsage', nil, c.gbg0)
- Group.new('TSDefinition', nil, c.gbg0)
-
- -- Telescope
- Group.new('TelescopeMatching', c.gwhite:light(), nil)
- -- Group.new('TelescopeSelection', nil, g.CursorLine)
-
- -- Indent blankline
- Group.new('IndentBlanklineChar', c.gbgh:light(0.05), nil)
- Group.new('IndentBlanklineSpaceChar', c.gbgh:light(0.05), nil)
- Group.new('IndentBlanklineSpaceCharBlankline', c.gbgh:light(0.05), nil)
-
- -- HiPairs
- Group.new('hiPairs_matchPair', nil, c.gbg2)
- Group.new('hiPairs_unmatchPair', c.gbg1, c.gred)
- end
-end
-
-return M
diff --git a/lua/tms/colors/solarized.lua b/lua/tms/colors/solarized.lua
@@ -1,74 +0,0 @@
--- Color, c, Group, g, s = require('colorbuddy').setup()
--- map <buffer> ,c <cmd>execute 'lua ' . getline('.')<cr>
-local M = {}
-
-local get_color = function(name, part) return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(name)), part) end
-
-M.setup = function()
- local Color, c, Group, g, styles = require('colorbuddy').setup()
- Color.new('normal_bg', get_color('Normal', 'bg'))
- Color.new('normal_fg', get_color('Normal', 'fg'))
- Color.new('linenr_bg', get_color('LineNr', 'bg'))
- Color.new('linenr_fg', get_color('LineNr', 'fg'))
- Color.new('cursorline_bg', get_color('CursorLine', 'bg'))
- Color.new('cursorline_fg', get_color('CursorLine', 'fg'))
- Color.new('red', '#dc322f')
- Color.new('black', '#000000')
- Color.new('green', '#859900')
- Color.new('yellow', '#b58900')
- Color.new('blue', '#268bd2')
- Color.new('magenta', '#d33682')
- Color.new('cyan', '#2aa198')
- Color.new('orange', '#cb4b16')
- Color.new('violet', '#6c71c4')
-
- -- general
- Group.new('SignColumn', c.none, c.none)
- Group.new('NormalFloat', c.none, c.normal_bg)
- Group.new('LineNr', c.normal_fg:dark(0.2), c.none)
-
- -- Lsp
- Group.new('DiagnosticsSignError', c.red, g.SignColumn.bg)
- Group.new('DiagnosticsSignWarning', c.orange, g.SignColumn.bg)
- Group.new('DiagnosticsSignInformation', c.linenr_fg, g.SignColumn.bg)
- Group.new('DiagnosticsSignHint', c.linenr_fg, g.SignColumn.bg)
- -- Telescope
- Group.new('TelescopeSelection', c.none, c.cursorline_bg)
- -- Zen
- Group.new('ZenBg', c.none, c.normal_bg:dark(0.05))
- -- Notify
- Group.new('NotifyINFOIcon', c.green, c.none)
- Group.new('NotifyINFOTitle', c.green, c.none)
-
- -- background specific
- if vim.opt.background:get() == 'dark' then
- -- GitSigns
- Group.new('GitSignsAdd', c.green, g.SignColumn.bg)
- Group.new('GitSignsChange', c.orange, g.SignColumn.bg)
- Group.new('GitSignsDelete', c.red, g.SignColumn.bg)
- -- Treesitter
- Group.new('TSDefinitionUsage', c.none, c.cursorline_bg)
- Group.new('TSDefinition', c.white, c.cursorline_bg)
-
- -- HiPairs
- Group.new('hiPairs_matchPair', c.white, c.none)
- Group.new('hiPairs_unmatchPair', c.white, c.red)
- -- Beacon
- Group.new('Beacon', nil, c.white)
- else
- -- GitSigns
- Group.new('GitSignsAdd', c.green, c.green)
- Group.new('GitSignsChange', c.orange, c.orange)
- Group.new('GitSignsDelete', c.red, c.red)
- -- Treesitter
- Group.new('TSDefinitionUsage', c.none, c.cursorline_bg)
- Group.new('TSDefinition', c.black, c.cursorline_bg)
- -- HiPairs
- Group.new('hiPairs_matchPair', c.black, c.none)
- Group.new('hiPairs_unmatchPair', c.white, c.red)
- -- Beacon
- Group.new('Beacon', nil, c.black)
- end
-end
-
-return M
diff --git a/lua/tms/p/hexen.lua b/lua/tms/p/hexen.lua
@@ -25,7 +25,8 @@ end
local function byteFromHex(h) return tonumber(h, 16) end
local function lineFromHex(line)
- return string.gsub(line, "\\u(%x+)", function(hex) return utf8.char(byteFromHex(hex)) end)
+ local sub = string.gsub(line, "\\u(%x+)", function(hex) return utf8.char(byteFromHex(hex)) end)
+ return sub
end
-- --
@@ -37,6 +38,10 @@ local function translate(filterFn)
local end_range = {_e[2], _e[3]}
local lines = api.nvim_buf_get_lines(0, start_range[1] - 1, end_range[1], true)
+ if #lines == 0 then
+ print('No lines selected')
+ return
+ end
local end_col = #lines[#lines]
end_range[2] = math.min(end_col, end_range[2] + 1)
lines[#lines] = string.sub(lines[#lines], 1, end_range[2])
@@ -52,8 +57,6 @@ end
-- API
--- todo wierd ERROR
--- E5108: Error executing lua /home/tms/.config/nvim/lua/tms/p/hexen.lua:47: bad argument #2 to 'insert' (number expected, got string)
function M.decode() translate(lineFromHex) end
function M.encode() translate(lineToHex) end
diff --git a/lua/tms/p/trans.lua b/lua/tms/p/trans.lua
@@ -0,0 +1,42 @@
+local api = vim.api
+
+local M = {}
+
+local function translateText(line, from, to)
+ local text = table.concat(line, '')
+ return vim.fn.system(string.format('trans %s:%s --brief --no-autocorrect "%s"', from or '', to or '', text))
+end
+
+local function getLines()
+ local open = api.nvim_buf_get_mark(0, '<')
+ local close = api.nvim_buf_get_mark(0, '>')
+
+ -- get text from visual
+ local lines = api.nvim_buf_get_lines(0, open[1] - 1, close[1], true)
+ local endColumn = #lines[1]
+ close[2] = math.min(close[2] + 1, endColumn)
+ if #lines > 1 then
+ print('translation on multiple lines not implemented')
+ return nil
+ else
+ lines[1] = string.sub(lines[1], open[2] + 1, close[2])
+ end
+ return lines
+end
+
+local function replace(text)
+ text = text:gsub('\n', '')
+ vim.fn.setreg('t', text)
+ vim.cmd [[norm gv"tp]]
+end
+
+function M.translate(to, from)
+ local lines = getLines()
+ if not lines then
+ return
+ end
+ local trans = translateText(lines, from, to)
+ replace(trans)
+end
+
+return M
diff --git a/lua/tms/plugins.lua b/lua/tms/plugins.lua
@@ -3,6 +3,9 @@ local packer = require('packer')
return packer.startup({
function()
local use = packer.use
+
+ packer.use_rocks('luautf8')
+
use {'wbthomason/packer.nvim', opt = true}
-- meta
@@ -332,12 +335,7 @@ return packer.startup({
'stevearc/dressing.nvim',
config = function()
require('dressing').setup({
- select = {
- backend = {'telescope', 'builtin', 'nui'},
- telescope = {
- theme = 'dropdown',
- },
- },
+ select = {backend = {'telescope', 'builtin', 'nui'}, telescope = {theme = 'dropdown'}},
})
end,
}
diff --git a/plugin/terminal.lua b/plugin/terminal.lua
@@ -14,14 +14,14 @@ vim.keymap.set('t', '<leader>tl', function() terminal.interactive() end, {norema
vim.keymap.set('t', '<leader>to', function() terminal.toggle() end, {noremap = true})
vim.keymap.set('t', '<leader>th', function() terminal.exit() end, {noremap = true})
-vim.api.nvim_create_augroup('user-terminal', {clear = true})
+local group = vim.api.nvim_create_augroup('user-terminal', {clear = true})
vim.api.nvim_create_autocmd('BufEnter', {
- group = 'user-terminal',
+ group = group,
pattern = 'terminal',
command = 'let g:SexyScroller_ScrollTime=0|let g:SexyScroller_CursorTime=0',
})
vim.api.nvim_create_autocmd('BufLeave', {
- group = 'user-terminal',
+ group = group,
pattern = 'terminal',
command = 'let g:SexyScroller_ScrollTime=10|let g:SexyScroller_CursorTime=5',
})
diff --git a/plugin/trans.lua b/plugin/trans.lua
@@ -0,0 +1,2 @@
+vim.keymap.set('x', 'mtt', function() require('trans').translate() end)
+vim.keymap.set('x', 'mtc', function() require('trans').translate('cs') end)
diff --git a/plugin/ws.lua b/plugin/ws.lua
@@ -2,9 +2,8 @@ local ws = require('tms.ws')
for name, setup in pairs(ws) do
if setup.path then
- local gname = 'user-project-' .. name
- vim.api.nvim_create_augroup(gname, {clear = true})
- vim.api.nvim_create_autocmd('VimEnter', {group = gname, pattern = setup.path, callback = setup.config})
+ local group = vim.api.nvim_create_augroup('user-project-' .. name, {clear = true})
+ vim.api.nvim_create_autocmd('VimEnter', {group = group, pattern = setup.path, callback = setup.config})
end
-- if setup.buffer then au.addListener('user-project-buffer-' .. name, {'BufEnter ' .. setup.buffer}, setup.config) end
-- if setup.filetypes then