feat: add intellitab and chameleon.nvim
This commit is contained in:
parent
a61dc3486f
commit
0972e97cfb
4 changed files with 189 additions and 13 deletions
6
init.lua
6
init.lua
|
@ -27,6 +27,10 @@ vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
|
||||||
|
|
||||||
vim.opt.scrolloff = 10
|
vim.opt.scrolloff = 10
|
||||||
|
|
||||||
|
if os.getenv("TERM") == "xterm-kitty" then
|
||||||
|
require("scripts.chameleon").setup()
|
||||||
|
end
|
||||||
|
|
||||||
vim.cmd.colorscheme("rose-pine")
|
vim.cmd.colorscheme("rose-pine")
|
||||||
|
|
||||||
require("nvim-treesitter.configs").setup({
|
require("nvim-treesitter.configs").setup({
|
||||||
|
@ -69,3 +73,5 @@ vim.api.nvim_create_autocmd("TextYankPost", {
|
||||||
vim.highlight.on_yank({ higroup = "Visual", timeout = 300 })
|
vim.highlight.on_yank({ higroup = "Visual", timeout = 300 })
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- vim.keymap.set("i", "<Tab>", require("scripts.intellitab").indent)
|
||||||
|
|
|
@ -6,19 +6,30 @@ return {
|
||||||
-- for keymap, all values may be string | string[]
|
-- for keymap, all values may be string | string[]
|
||||||
-- use an empty table to disable a keymap
|
-- use an empty table to disable a keymap
|
||||||
keymap = {
|
keymap = {
|
||||||
show = "<C-space>",
|
["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
|
||||||
hide = "<C-e>",
|
["<C-e>"] = { "hide" },
|
||||||
accept = "<Tab>",
|
|
||||||
select_prev = { "<Up>", "<C-p>" },
|
|
||||||
select_next = { "<Down>", "<C-n>" },
|
|
||||||
|
|
||||||
show_documentation = {},
|
["<Tab>"] = {
|
||||||
hide_documentation = {},
|
function(cmp)
|
||||||
scroll_documentation_up = "<C-b>",
|
if cmp.is_in_snippet() then
|
||||||
scroll_documentation_down = "<C-f>",
|
return cmp.accept()
|
||||||
|
else
|
||||||
|
return cmp.select_and_accept()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
"snippet_forward",
|
||||||
|
require("scripts.intellitab").indent,
|
||||||
|
"fallback",
|
||||||
|
},
|
||||||
|
["<S-Tab>"] = { "snippet_backward", "fallback" },
|
||||||
|
|
||||||
snippet_forward = "<Tab>",
|
["<Up>"] = { "select_prev", "fallback" },
|
||||||
snippet_backward = "<S-Tab>",
|
["<Down>"] = { "select_next", "fallback" },
|
||||||
|
["<C-p>"] = { "select_prev", "fallback" },
|
||||||
|
["<C-n>"] = { "select_next", "fallback" },
|
||||||
|
|
||||||
|
["<C-b>"] = { "scroll_documentation_up", "fallback" },
|
||||||
|
["<C-f>"] = { "scroll_documentation_down", "fallback" },
|
||||||
},
|
},
|
||||||
|
|
||||||
fuzzy = {
|
fuzzy = {
|
||||||
|
@ -27,8 +38,6 @@ return {
|
||||||
-- proximity bonus boosts the score of items with a value in the buffer
|
-- proximity bonus boosts the score of items with a value in the buffer
|
||||||
use_proximity = true,
|
use_proximity = true,
|
||||||
max_items = 200,
|
max_items = 200,
|
||||||
-- controls which sorts to use and in which order, these three are currently the only allowed options
|
|
||||||
sorts = { "label", "kind", "score" },
|
|
||||||
|
|
||||||
prebuiltBinaries = {
|
prebuiltBinaries = {
|
||||||
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
|
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
|
||||||
|
|
91
lua/scripts/chameleon.lua
Normal file
91
lua/scripts/chameleon.lua
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
-- MIT License
|
||||||
|
-- Copyright (c) 2023 Shaun
|
||||||
|
-- <https://github.com/shaun-mathew/Chameleon.nvim>
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
local fn = vim.fn
|
||||||
|
local api = vim.api
|
||||||
|
M.original_color = nil
|
||||||
|
|
||||||
|
local get_kitty_background = function()
|
||||||
|
if M.original_color == nil then
|
||||||
|
fn.jobstart({ "kitty", "@", "get-colors" }, {
|
||||||
|
on_stdout = function(_, d, _)
|
||||||
|
for _, result in ipairs(d) do
|
||||||
|
if string.match(result, "^background") then
|
||||||
|
local color = vim.split(result, "%s+")[2]
|
||||||
|
M.original_color = color
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_stderr = function(_, d, _)
|
||||||
|
if #d > 1 then
|
||||||
|
api.nvim_err_writeln("Chameleon.nvim: Error getting background. Make sure kitty remote control is turned on.")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local change_background = function(color, sync)
|
||||||
|
local arg = 'background="' .. color .. '"'
|
||||||
|
local command = "kitty @ set-colors " .. arg
|
||||||
|
if not sync then
|
||||||
|
fn.jobstart(command, {
|
||||||
|
on_stderr = function(_, d, _)
|
||||||
|
if #d > 1 then
|
||||||
|
api.nvim_err_writeln(
|
||||||
|
"Chameleon.nvim: Error changing background. Make sure kitty remote control is turned on."
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
fn.system(command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local setup_autocmds = function()
|
||||||
|
local autocmd = api.nvim_create_autocmd
|
||||||
|
local autogroup = api.nvim_create_augroup
|
||||||
|
local bg_change = autogroup("BackgroundChange", { clear = true })
|
||||||
|
|
||||||
|
autocmd({ "ColorScheme", "VimResume" }, {
|
||||||
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
local color = string.format("#%06X", vim.api.nvim_get_hl(0, { name = "Normal" }).bg)
|
||||||
|
change_background(color)
|
||||||
|
end,
|
||||||
|
group = bg_change,
|
||||||
|
})
|
||||||
|
|
||||||
|
autocmd("User", {
|
||||||
|
pattern = "NvChadThemeReload",
|
||||||
|
callback = function()
|
||||||
|
local color = string.format("#%06X", vim.api.nvim_get_hl(0, { name = "Normal" }).bg)
|
||||||
|
change_background(color)
|
||||||
|
end,
|
||||||
|
group = bg_change,
|
||||||
|
})
|
||||||
|
|
||||||
|
autocmd({ "VimLeavePre", "VimSuspend" }, {
|
||||||
|
callback = function()
|
||||||
|
if M.original_color ~= nil then
|
||||||
|
change_background(M.original_color, true)
|
||||||
|
-- Looks like it was silently fixed in NVIM 0.10. At least, I can't reproduce it anymore,
|
||||||
|
-- so for now disable it and see if anyone reports it again.
|
||||||
|
-- https://github.com/neovim/neovim/issues/21856
|
||||||
|
-- vim.cmd[[sleep 10m]]
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
group = autogroup("BackgroundRestore", { clear = true }),
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
M.setup = function()
|
||||||
|
get_kitty_background()
|
||||||
|
setup_autocmds()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
70
lua/scripts/intellitab.lua
Normal file
70
lua/scripts/intellitab.lua
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
-- Copyright 2021 Pedro Alves
|
||||||
|
|
||||||
|
local v = vim.api
|
||||||
|
|
||||||
|
local treesitter = require("nvim-treesitter")
|
||||||
|
|
||||||
|
local function get_line_indent(line, sw)
|
||||||
|
local indent = 0
|
||||||
|
|
||||||
|
for c in line:gmatch("%s") do
|
||||||
|
if c == "\t" then
|
||||||
|
indent = indent + sw
|
||||||
|
else
|
||||||
|
indent = indent + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return indent
|
||||||
|
end
|
||||||
|
|
||||||
|
local function indent()
|
||||||
|
local cursor = v.nvim_win_get_cursor(0)
|
||||||
|
local line = v.nvim_buf_get_lines(0, cursor[1] - 1, cursor[1], false)[1]
|
||||||
|
|
||||||
|
local indentexpr = v.nvim_get_option_value("indentexpr", { buf = 0 })
|
||||||
|
local expand = v.nvim_get_option_value("expandtab", { buf = 0 })
|
||||||
|
local shiftwidth = v.nvim_eval("shiftwidth()")
|
||||||
|
local tab_char = v.nvim_replace_termcodes("<Tab>", true, true, true)
|
||||||
|
local indent_goal
|
||||||
|
|
||||||
|
if treesitter ~= nil and treesitter.get_indent ~= nil then
|
||||||
|
indent_goal = treesitter.get_indent(line)
|
||||||
|
end
|
||||||
|
|
||||||
|
if indent_goal == nil or indent_goal < 0 then
|
||||||
|
if indentexpr ~= "" then
|
||||||
|
indent_goal = v.nvim_eval(indentexpr)
|
||||||
|
elseif v.nvim_get_option_value("cindent", { buf = 0 }) then
|
||||||
|
indent_goal = v.nvim_call_function("cindent", { cursor[1] })
|
||||||
|
else
|
||||||
|
indent_goal = v.nvim_call_function("indent", { cursor[1] })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if indent_goal == -1 and cursor[1] ~= 1 then
|
||||||
|
local prev_line = v.nvim_buf_get_lines(0, cursor[1] - 2, cursor[1] - 1, false)[1]
|
||||||
|
indent_goal = get_line_indent(prev_line, shiftwidth)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Reset the cursor, since the functions are free to move it
|
||||||
|
v.nvim_win_set_cursor(0, cursor)
|
||||||
|
|
||||||
|
if cursor[2] == 0 and line == "" and indent_goal ~= nil and indent_goal > 0 then
|
||||||
|
local i = 0
|
||||||
|
while i < indent_goal do
|
||||||
|
if expand then
|
||||||
|
v.nvim_feedkeys(" ", "n", true)
|
||||||
|
i = i + 1
|
||||||
|
else
|
||||||
|
v.nvim_feedkeys(tab_char, "n", true)
|
||||||
|
i = i + shiftwidth
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print(i, indent_goal)
|
||||||
|
else
|
||||||
|
v.nvim_feedkeys(tab_char, "n", true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return { indent = indent }
|
Loading…
Reference in a new issue