From 29ae2d441a7834ab80e936e146ff3f64e207d1ba Mon Sep 17 00:00:00 2001 From: punkfairie Date: Fri, 22 Nov 2024 15:00:17 -0800 Subject: [PATCH] wip --- config/default.nix | 6 ++--- config/options.nix | 15 +++++++----- config/plugins/base/default.nix | 6 +++++ config/plugins/base/snacks.nix | 41 +++++++++++++++++++++++++++++++++ config/plugins/default.nix | 6 +++++ config/util/default.nix | 8 +++++++ config/util/ui.lua | 27 ++++++++++++++++++++++ 7 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 config/plugins/base/default.nix create mode 100644 config/plugins/base/snacks.nix create mode 100644 config/plugins/default.nix create mode 100644 config/util/default.nix create mode 100644 config/util/ui.lua diff --git a/config/default.nix b/config/default.nix index dce3ecb..00d9a63 100644 --- a/config/default.nix +++ b/config/default.nix @@ -2,7 +2,7 @@ ... }: { - imports = [ - ./options.nix - ]; + imports = with builtins; + map (fn: ./${fn}) + (filter (fn: fn != "default.nix") (attrNames (readDir ./.))); } diff --git a/config/options.nix b/config/options.nix index 04d4f01..978c0c1 100644 --- a/config/options.nix +++ b/config/options.nix @@ -1,4 +1,4 @@ -{ ... }: +{ config, ... }: { globals = { mapleader = " "; @@ -67,7 +67,12 @@ }; foldlevel = 99; - formatexpr = "v:lua.require'lazyvim.util'.format.formatexpr()"; + + formatexpr = + if config.plugins.conform.enable + then "v:lua.require'conform'.formatexpr()" + else "vim.lsp.formatexpr({ timeout_ms = 3000 })"; + formatoptions = "jcroqlnt"; grepformat = "%f:%l:%c:%m"; grepprg = "rg --vimgrep"; @@ -150,8 +155,6 @@ # Put new windows right of current splitright = true; - statuscolumn = "%!v:lua.require'snacks.statuscolumn'.get()"; - # Number of spaces tabs count for tabstop = 2; @@ -189,12 +192,12 @@ if vim.fn.has("nvim-0.10") == 1 then vim.opt.smoothscroll = true - vim.opt.foldexpr = "v:lua.require'lazyvim.util'.ui.foldexpr()" + vim.opt.foldexpr = "v:lua.require'lixyvim.util'.ui.foldexpr()" vim.opt.foldmethod = "expr" vim.opt.foldtext = "" else vim.opt.foldmethod = "indent" - vim.opt.foldtext = "v:lua.require'lazyvim.util'.ui.foldtext()" + vim.opt.foldtext = "v:lua.require'lixyvim.util'.ui.foldtext()" end ''; } diff --git a/config/plugins/base/default.nix b/config/plugins/base/default.nix new file mode 100644 index 0000000..0cb9ea3 --- /dev/null +++ b/config/plugins/base/default.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + imports = with builtins; + map (fn: ./${fn}) + (filter (fn: fn != "default.nix") (attrNames (readDir ./.))); +} diff --git a/config/plugins/base/snacks.nix b/config/plugins/base/snacks.nix new file mode 100644 index 0000000..e2df5d2 --- /dev/null +++ b/config/plugins/base/snacks.nix @@ -0,0 +1,41 @@ +{ ... }: +{ + plugins.snacks = { + enable = true; + + settings = { + bigfile.enabled = true; + notifier.enabled = true; + quickfile.enabled = true; + statuscolumn.enabled = false; + + terminal.win.keys = let + mkKey = k: d: { + __unkeyed.1 = ""; + __unkeyed.2 = helpers.mkRaw #lua + '' + function(self) + return self:is_floating() and "" or vim.schedule(function() + vim.cmd.wincmd(${k}) + end) + end + ''; + desc = "Go to ${d} Window"; + expr = true; + mode = "t"; + }; + in { + nav_h = mkKey "h" "Left"; + nav_j = mkKey "j" "Lower"; + nav_k = mkKey "k" "Upper"; + nav_l = mkKey "l" "Right"; + }; + + toggle.map = ""; + words.enabled = true; + }; + + opts = { + statuscolumn = "%!v:lua.require'snacks.statuscolumn'.get()"; + }; +} diff --git a/config/plugins/default.nix b/config/plugins/default.nix new file mode 100644 index 0000000..0cb9ea3 --- /dev/null +++ b/config/plugins/default.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + imports = with builtins; + map (fn: ./${fn}) + (filter (fn: fn != "default.nix") (attrNames (readDir ./.))); +} diff --git a/config/util/default.nix b/config/util/default.nix new file mode 100644 index 0000000..c8a244c --- /dev/null +++ b/config/util/default.nix @@ -0,0 +1,8 @@ +{ + ... +}: +{ + extraFiles = { + "util/ui.lua".source = ./ui.lua; + }; +} diff --git a/config/util/ui.lua b/config/util/ui.lua new file mode 100644 index 0000000..572a385 --- /dev/null +++ b/config/util/ui.lua @@ -0,0 +1,27 @@ +--@class util.ui +local M = {} + +-- foldtext for Neovim < 0.10.0 +function M.foldtext() + return vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1] +end + +-- optimized treesitter foldexpr for Neovim >= 0.10.0 +function M.foldexpr() + local buf = vim.api.nvim_get_current_buf() + if vim.b[buf].ts_folds == nil then + -- as long as we don't have a filetype, don't bother + -- checking if treesitter is available (it won't) + if vim.bo[buf].filetype == "" then + return "0" + end + if vim.bo[buf].filetype:find("dashboard") then + vim.b[buf].ts_folds = false + else + vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf) + end + end + return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or "0" +end + +return M