Compare commits

...

2 commits

Author SHA1 Message Date
0972e97cfb
feat: add intellitab and chameleon.nvim 2024-10-31 11:04:57 -07:00
a61dc3486f
flake.lock: Update
Flake lock file updates:

• Updated input 'blink-cmp':
    'github:Saghen/blink.cmp/1a55fd1e03193e10cb8bc866cc2bc47c9473061c' (2024-10-27)
  → 'github:Saghen/blink.cmp/88f1c203465fa3d883f2309bc22412c90a9f6a08' (2024-10-31)
• Updated input 'blink-cmp/fenix':
    'github:nix-community/fenix/5fa09829e74070c1e83b2aaa50b71bbc6da3f37c' (2024-10-27)
  → 'github:nix-community/fenix/482b57f3f27a9336e0fbc62fa99ee0f624ccf4d0' (2024-10-28)
• Updated input 'blink-cmp/fenix/rust-analyzer-src':
    'github:rust-lang/rust-analyzer/26d2fbaef2d68a2fccf55d725915188c2634439a' (2024-10-26)
  → 'github:rust-lang/rust-analyzer/3b3a87fe9bd3f2a79942babc1d1e385b6805c384' (2024-10-27)
• Updated input 'nixCats':
    'github:BirdeeHub/nixCats-nvim/765810b6c14fd581f906d1ac9b2514a6047242ff' (2024-10-27)
  → 'github:BirdeeHub/nixCats-nvim/553caacfe4728ea3ca3671b7edeb9f6fb6025dc7' (2024-10-29)
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/86e78d3d2084ff87688da662cf78c2af085d8e73' (2024-10-26)
  → 'github:nixos/nixpkgs/2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53' (2024-10-30)
2024-10-31 10:41:24 -07:00
5 changed files with 204 additions and 28 deletions

View file

@ -9,11 +9,11 @@
]
},
"locked": {
"lastModified": 1730056977,
"narHash": "sha256-uiZX6iUpLAUiDqphhsoj59MK5SlPyWdCsVSCm37uiqs=",
"lastModified": 1730389505,
"narHash": "sha256-gJwIy5cVBS+AzDm/dYQuHjrO6bIVHO8flC+bhBVk2Js=",
"owner": "Saghen",
"repo": "blink.cmp",
"rev": "1a55fd1e03193e10cb8bc866cc2bc47c9473061c",
"rev": "88f1c203465fa3d883f2309bc22412c90a9f6a08",
"type": "github"
},
"original": {
@ -31,11 +31,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1730010749,
"narHash": "sha256-UBckyKItSD0z50+3YQOqfOuyvUI7UjPHiLbOPFUolqo=",
"lastModified": 1730097176,
"narHash": "sha256-ufvRff76Y19mkRsmx+mAnxKE9A9VaNWC2mVY6TwumOw=",
"owner": "nix-community",
"repo": "fenix",
"rev": "5fa09829e74070c1e83b2aaa50b71bbc6da3f37c",
"rev": "482b57f3f27a9336e0fbc62fa99ee0f624ccf4d0",
"type": "github"
},
"original": {
@ -64,11 +64,11 @@
},
"nixCats": {
"locked": {
"lastModified": 1730063105,
"narHash": "sha256-GWC9E6A+BOVgTSfZ2UyiHtU4Y438dYz4GpeW3b0rlU0=",
"lastModified": 1730202844,
"narHash": "sha256-M4IBPRz/oVlgEERPi5s4Oe3MzoZOSjYXVgjCdsk+YSM=",
"owner": "BirdeeHub",
"repo": "nixCats-nvim",
"rev": "765810b6c14fd581f906d1ac9b2514a6047242ff",
"rev": "553caacfe4728ea3ca3671b7edeb9f6fb6025dc7",
"type": "github"
},
"original": {
@ -79,11 +79,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1729980323,
"narHash": "sha256-eWPRZAlhf446bKSmzw6x7RWEE4IuZgAp8NW3eXZwRAY=",
"lastModified": 1730272153,
"narHash": "sha256-B5WRZYsRlJgwVHIV6DvidFN7VX7Fg9uuwkRW9Ha8z+w=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "86e78d3d2084ff87688da662cf78c2af085d8e73",
"rev": "2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53",
"type": "github"
},
"original": {
@ -149,11 +149,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1729923686,
"narHash": "sha256-Tc+5E/UmjpXlYGQQ6X2nGDv6J6VQgZ+pVOJLcNCIVQc=",
"lastModified": 1730028316,
"narHash": "sha256-FsPsSjqnqMHBgDdM24DFLw4YOw0mFKYFJBcLaI6CvI8=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "26d2fbaef2d68a2fccf55d725915188c2634439a",
"rev": "3b3a87fe9bd3f2a79942babc1d1e385b6805c384",
"type": "github"
},
"original": {

View file

@ -27,6 +27,10 @@ vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
vim.opt.scrolloff = 10
if os.getenv("TERM") == "xterm-kitty" then
require("scripts.chameleon").setup()
end
vim.cmd.colorscheme("rose-pine")
require("nvim-treesitter.configs").setup({
@ -69,3 +73,5 @@ vim.api.nvim_create_autocmd("TextYankPost", {
vim.highlight.on_yank({ higroup = "Visual", timeout = 300 })
end,
})
-- vim.keymap.set("i", "<Tab>", require("scripts.intellitab").indent)

View file

@ -6,19 +6,30 @@ return {
-- for keymap, all values may be string | string[]
-- use an empty table to disable a keymap
keymap = {
show = "<C-space>",
hide = "<C-e>",
accept = "<Tab>",
select_prev = { "<Up>", "<C-p>" },
select_next = { "<Down>", "<C-n>" },
["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
["<C-e>"] = { "hide" },
show_documentation = {},
hide_documentation = {},
scroll_documentation_up = "<C-b>",
scroll_documentation_down = "<C-f>",
["<Tab>"] = {
function(cmp)
if cmp.is_in_snippet() then
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>",
snippet_backward = "<S-Tab>",
["<Up>"] = { "select_prev", "fallback" },
["<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 = {
@ -27,8 +38,6 @@ return {
-- proximity bonus boosts the score of items with a value in the buffer
use_proximity = true,
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 = {
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`

91
lua/scripts/chameleon.lua Normal file
View 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

View 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 }