commit b56a1774eb7d7ba6abd1bc2935af37ffb1075932
parent 70967d9edfc356a3cbc080e2ab0a1b13881fe041
Author: Tomas Nemec <nemi@skaut.cz>
Date: Wed, 27 Jul 2022 06:28:32 +0200
update
Diffstat:
7 files changed, 125 insertions(+), 24 deletions(-)
diff --git a/after/plugin/leap.lua b/after/plugin/leap.lua
@@ -1,11 +1,45 @@
if not pcall(require, 'leap') then return end
-require('leap').set_default_keymaps()
+local leap = require('leap')
+leap.setup({ case_sensitive = false, highlight_unlabeled = true, max_aot_targets = nil })
+
+local default_highlights = function()
+ require('tms.colors').update(function(t)
+ t.Group.link('LeapBackdrop', t.groups.Comment)
+ t.Group.new('LeapMatch', t.colors.green, nil)
+ t.Group.new('LeapLabelPrimary', t.colors.yellow, nil, t.styles.underline)
+ t.Group.new('LeapLabelSecondary', t.colors.red, nil, t.styles.underline)
+ end)
+end
+
+local ast_highlights = function()
+ require('tms.colors').update(function(t)
+ t.Group.link('LeapBackdrop', t.groups.Comment)
+ t.Group.new('LeapMatch', t.colors.green, nil)
+ t.Group.new('LeapLabelPrimary', t.colors.yellow, nil, t.styles.reverse)
+ t.Group.new('LeapLabelSecondary', t.colors.red, nil, t.styles.reverse)
+ end)
+end
+
+default_highlights()
+leap.set_default_keymaps()
vim.keymap.set('n', 'gw', '<Plug>(leap-cross-window)')
-require('tms.colors').update(function(t)
- t.Group.link('LeapBackdrop', t.groups.Comment)
- t.Group.new('LeapMatch', t.groups.Normal, nil, t.styles.underline)
- t.Group.new('LeapLabelPrimary', t.groups.Normal, t.groups.Normal, t.styles.reverse)
- t.Group.link('LeapLabelSecondary', t.groups.Comment)
-end)
+if pcall(require, 'tms.p.leap.ast') then
+ vim.keymap.set({ 'n', 'x', 'o' }, 'gp', function() require('tms.p.leap.ast').parent() end,
+ { desc = 'Leap AST Parent' })
+
+ local leap_ast_group = vim.api.nvim_create_augroup('leap-ast', { clear = true })
+ vim.api.nvim_create_autocmd('User', {
+ group = leap_ast_group,
+ pattern = 'LeapEnter',
+ callback = function() if require('leap').state.args.ast then ast_highlights() end end,
+ desc = 'Default -> Ast highlights',
+ })
+ vim.api.nvim_create_autocmd('User', {
+ group = leap_ast_group,
+ pattern = 'LeapLeave',
+ callback = function() if require('leap').state.args.ast then default_highlights() end end,
+ desc = 'AST -> Default highlights',
+ })
+end
diff --git a/after/plugin/mason.lua b/after/plugin/mason.lua
@@ -0,0 +1,3 @@
+if not pcall(require, 'mason') then return end
+
+require('mason').setup()
diff --git a/after/plugin/nvim-surround.lua b/after/plugin/nvim-surround.lua
@@ -0,0 +1,8 @@
+if not pcall(require, 'nvim-surround') then return end
+
+require('nvim-surround').setup()
+
+vim.keymap.set('o', 'ir', 'i[')
+vim.keymap.set('o', 'ar', 'a[')
+vim.keymap.set('o', 'ia', 'i<')
+vim.keymap.set('o', 'aa', 'a<')
diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua
@@ -32,14 +32,14 @@ require'nvim-treesitter.configs'.setup {
indent = { enable = true },
- refactor = { highlight_definitions = { enable = true, clear_on_cursor_move = false } },
+ refactor = { highlight_definitions = { enable = false, clear_on_cursor_move = false } },
textobjects = {
enable = true,
select = {
enable = true,
- lookahead = true,
- lookbehind = true,
+ lookahead = false,
+ lookbehind = false,
keymaps = {
['ia'] = '@parameter.inner',
['aa'] = '@parameter.outer',
diff --git a/lua/tms/p/leap/ast.lua b/lua/tms/p/leap/ast.lua
@@ -0,0 +1,56 @@
+local api = vim.api
+-- Note: The functions used here will be upstreamed eventually.
+local ts_utils = require('nvim-treesitter.ts_utils')
+local M = {}
+
+local get_nodes = function()
+ local wininfo = vim.fn.getwininfo(api.nvim_get_current_win())[1]
+ -- Get current TS node.
+ local cur_node = ts_utils.get_node_at_cursor(0)
+ if not cur_node then return end
+ -- Get parent nodes recursively.
+ local nodes = { cur_node }
+ local parent = cur_node:parent()
+ while parent do
+ table.insert(nodes, parent)
+ parent = parent:parent()
+ end
+ -- Create Leap targets from TS nodes.
+ local targets = {}
+ for _, node in ipairs(nodes) do
+ local startline, startcol, _, _ = node:range() -- (0,0)
+ if startline + 1 >= wininfo.topline then
+ local target = { node = node, pos = { startline + 1, startcol + 1 } }
+ table.insert(targets, target)
+ end
+ end
+ if #targets >= 1 then return targets end
+end
+
+local select_range = function(target)
+ local mode = api.nvim_get_mode().mode
+ if not mode:match('n?o') then
+ -- Force going back to Normal (implies mode = v | V | ).
+ vim.cmd('normal! ' .. mode)
+ end
+ local vmode = 'charwise'
+ if mode:match('V') then
+ vmode = 'linewise'
+ elseif mode:match('') then
+ vmode = 'blockwise'
+ end
+ ts_utils.update_selection(0, target.node, vmode)
+end
+
+local jump = function(target)
+ local startline, startcol, _, _ = target.node:range() -- (0,0)
+ api.nvim_win_set_cursor(0, { startline + 1, startcol }) -- (1,0)
+end
+
+M.parent = function()
+ local targets = get_nodes()
+ local action = api.nvim_get_mode().mode == 'n' and jump or select_range
+ require('leap').leap { ast = true, targets = targets, action = action, backward = true }
+end
+
+return M
diff --git a/lua/tms/plugins.lua b/lua/tms/plugins.lua
@@ -25,18 +25,18 @@ return packer.startup({
-- editor
use 'tpope/vim-repeat'
- use 'tpope/vim-surround'
+ use 'kylechui/nvim-surround'
use 'chaoren/vim-wordmotion' -- word counts with _,.,-,...
use 'romgrk/equal.operator' -- equal text object `lefthand = righthand`
use 'godlygeek/tabular' -- align
use 'luukvbaal/stabilize.nvim'
- use 'windwp/nvim-autopairs'
+ -- use 'windwp/nvim-autopairs'
use 'numToStr/Comment.nvim'
use 'mbbill/undotree'
use 'camspiers/animate.vim'
use 'norcalli/nvim-colorizer.lua'
use 'rainbowhxch/beacon.nvim'
- use 'Yggdroot/hiPairs'
+ -- use 'Yggdroot/hiPairs'
use 'jandamm/cryoline.nvim'
use 'karb94/neoscroll.nvim'
use 'windwp/nvim-spectre'
@@ -108,7 +108,7 @@ return packer.startup({
-- lsp
use 'neovim/nvim-lspconfig'
- use 'williamboman/nvim-lsp-installer'
+ use 'williamboman/mason.nvim'
use 'b0o/schemastore.nvim'
use 'folke/lua-dev.nvim'
use { 'jose-elias-alvarez/null-ls.nvim', requires = { 'nvim-lua/plenary.nvim' } }
diff --git a/plugin/terminal.lua b/plugin/terminal.lua
@@ -1,18 +1,18 @@
local terminal = require('tms.p.terminal')
-vim.keymap.set('n', '<leader>tl', function() terminal.interactive() end)
-vim.keymap.set('n', '<leader>tL', function() terminal.catchup() end)
-vim.keymap.set('n', '<leader>to', function() terminal.toggle() end)
-vim.keymap.set('n', '<leader>tj', ':TerminalRun<space>')
+vim.keymap.set('n', '<leader>tl', function() terminal.interactive() end, { desc = 'Terminal Interactive' })
+vim.keymap.set('n', '<leader>tL', function() terminal.catchup() end, { desc = 'Terminal Catchup' })
+vim.keymap.set('n', '<leader>to', function() terminal.toggle() end, { desc = 'Terminal Toggle' })
+vim.keymap.set('n', '<leader>tj', ':TerminalRun<space>', { desc = 'Terminal Set' })
+vim.keymap.set('n', '<leader>tJ', ':TerminalRun<space><Up>', { desc = 'Terminal Edit Last' })
vim.keymap.set('n', '<leader>tk', function()
local ok = terminal.rerun()
if not ok then vim.api.nvim_feedkeys(':TerminalRun ', 'n', nil) end
-end)
-vim.keymap.set('n', '<leader>th', function() terminal.exit() end)
-vim.keymap.set('t', '<leader>tn', '<C-\\><C-n>')
-vim.keymap.set('t', '<leader>tl', function() terminal.interactive() end)
-vim.keymap.set('t', '<leader>to', function() terminal.toggle() end)
-vim.keymap.set('t', '<leader>th', function() terminal.exit() end)
+end, { desc = 'Terminal Run' })
+vim.keymap.set('n', '<leader>th', function() terminal.exit() end, { desc = 'Terminal Exit' })
+vim.keymap.set('t', '<leader>tl', function() terminal.interactive() end, { desc = 'Terminal Interactive' })
+vim.keymap.set('t', '<leader>to', function() terminal.toggle() end, { desc = 'Terminal Toggle' })
+vim.keymap.set('t', '<leader>th', function() terminal.exit() end, { desc = 'Terminal Exit' })
local group = vim.api.nvim_create_augroup('user-terminal', { clear = true })
vim.api.nvim_create_autocmd('BufEnter', {