mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
autopairs + cleanup
This commit is contained in:
parent
4b7636090f
commit
d01db43a23
15 changed files with 176 additions and 204 deletions
|
|
@ -1,38 +0,0 @@
|
|||
-- ripped from lazyvim
|
||||
return function(opts)
|
||||
local pairs = require('mini.pairs')
|
||||
pairs.setup(opts)
|
||||
local open = pairs.open
|
||||
pairs.open = function(pair, neigh_pattern)
|
||||
if vim.fn.getcmdline() ~= '' then
|
||||
return open(pair, neigh_pattern)
|
||||
end
|
||||
local o, c = pair:sub(1, 1), pair:sub(2, 2)
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local next = line:sub(cursor[2] + 1, cursor[2] + 1)
|
||||
local before = line:sub(1, cursor[2])
|
||||
if opts.markdown and o == '`' and vim.bo.filetype == 'markdown' and before:match('^%s*``') then
|
||||
return '`\n```' .. vim.api.nvim_replace_termcodes('<up>', true, true, true)
|
||||
end
|
||||
if opts.skip_next and next ~= '' and next:match(opts.skip_next) then
|
||||
return o
|
||||
end
|
||||
if opts.skip_ts and #opts.skip_ts > 0 then
|
||||
local ok, captures = pcall(vim.treesitter.get_captures_at_pos, 0, cursor[1] - 1, math.max(cursor[2] - 1, 0))
|
||||
for _, capture in ipairs(ok and captures or {}) do
|
||||
if vim.tbl_contains(opts.skip_ts, capture.capture) then
|
||||
return o
|
||||
end
|
||||
end
|
||||
end
|
||||
if opts.skip_unbalanced and next == c and c ~= o then
|
||||
local _, count_open = line:gsub(vim.pesc(pair:sub(1, 1)), '')
|
||||
local _, count_close = line:gsub(vim.pesc(pair:sub(2, 2)), '')
|
||||
if count_close > count_open then
|
||||
return o
|
||||
end
|
||||
end
|
||||
return open(pair, neigh_pattern)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,15 @@
|
|||
local M = {}
|
||||
local sessions = require('mini.sessions')
|
||||
|
||||
M.setup = function()
|
||||
local id = M.get_id()
|
||||
if M.check_exists(id) then
|
||||
vim.notify('Existing session for ' .. id)
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<leader>fs', function()
|
||||
require('plugins.lib.session_jj').load()
|
||||
end, { noremap = true, desc = 'mini session select' })
|
||||
end
|
||||
|
||||
M.get_id = function()
|
||||
local jj_root = vim.system({ 'jj', 'workspace', 'root' }):wait()
|
||||
|
|
@ -27,7 +37,7 @@ M.get_id = function()
|
|||
end
|
||||
|
||||
M.check_exists = function(id)
|
||||
for name, _ in pairs(sessions.detected) do
|
||||
for name, _ in pairs(MiniSessions.detected) do
|
||||
if name == id then
|
||||
return true
|
||||
end
|
||||
|
|
@ -48,13 +58,14 @@ M.load = function()
|
|||
}, { prompt = 'Session found at ' .. id .. ', load it?' }, function(c)
|
||||
if c == 'Yes' then
|
||||
-- load session (buffers, etc) as well as shada (marks)
|
||||
sessions.read(id)
|
||||
MiniSessions.read(id)
|
||||
vim.notify('loaded jj session: ' .. id)
|
||||
end
|
||||
end)
|
||||
else
|
||||
sessions.write(id)
|
||||
MiniSessions.write(id)
|
||||
end
|
||||
end
|
||||
|
||||
_G.M = M
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue