nvim: remove some parens

This commit is contained in:
chayleaf 2023-03-19 18:25:24 +07:00
parent e05588fa93
commit 82c96d70cf
2 changed files with 144 additions and 118 deletions

View file

@ -16,13 +16,33 @@
programs.neovim = let programs.neovim = let
notlua = config.notlua; notlua = config.notlua;
notlua-nvim = notlua.neovim { inherit (config.programs.neovim) plugins extraLuaPackages; }; notlua-nvim = notlua.neovim { inherit (config.programs.neovim) plugins extraLuaPackages; };
inherit (notlua.keywords) CALL RAW PROP SET LET DEFUN IF APPLY OR EQ RETURN ELSE IDX MCALL LETREC; inherit (notlua.keywords) CALL PROP SET LET DEFUN IF APPLY OR EQ RETURN ELSE IDX MCALL LETREC;
inherit (notlua.utils) compile; inherit (notlua.utils) compile;
inherit (notlua-nvim.stdlib) vim string require print; inherit (notlua-nvim.stdlib) vim string require print;
inherit (notlua-nvim.keywords) REQ REQ'; inherit (notlua-nvim.keywords) REQ REQ';
in let in let
vimcmd = name: CALL (RAW "vim.cmd.${name}");
vimg = name: PROP vim.g name; vimg = name: PROP vim.g name;
# _ is basically semicolon
_ = { __IS_SEPARATOR = true; };
splitList = sep: list:
let
ivPairs = lib.imap0 (i: x: { inherit i x; }) list;
is' = map ({ i, ... }: i) (builtins.filter ({ x, ... }: sep == x) ivPairs);
is = [ 0 ] ++ (map (x: x + 1) is');
ie = is' ++ [ (builtins.length list) ];
se = lib.zipLists is ie;
in
map ({ fst, snd }: lib.sublist fst (snd - fst) list) se;
# this transforms [ a b _ c _ d _ e f g ] into [ (a b) c d (RETURN (e f g)) ]
L = args:
let
spl = splitList _ args;
body = lib.init spl;
ret = lib.last spl;
in
(map
(list: builtins.foldl' lib.id (builtins.head list) (builtins.tail list))
body) ++ (if ret == [] then [] else [(APPLY RETURN ret)]);
keymapSetSingle = opts@{ keymapSetSingle = opts@{
mode, mode,
lhs, lhs,
@ -62,6 +82,7 @@
which-key = REQ "which-key"; which-key = REQ "which-key";
luasnip = REQ "luasnip"; luasnip = REQ "luasnip";
cmp = REQ "cmp"; cmp = REQ "cmp";
compile' = name: stmts: compile name (L stmts);
in { in {
enable = true; enable = true;
defaultEditor = true; defaultEditor = true;
@ -91,56 +112,60 @@
vimAlias = true; vimAlias = true;
vimdiffAlias = true; vimdiffAlias = true;
extraLuaConfig = (compile "main" [ extraLuaConfig = (compile' "main" [
(SET (vimg "vimsyn_embed") "l") SET (vimg "vimsyn_embed") "l" _
(LET (vim.api.nvim_create_augroup "nvimrc" { clear = true; }) (group: LET (vim.api.nvim_create_augroup "nvimrc" { clear = true; }) (group:
lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) { lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) {
BufReadPre = DEFUN (SET vim.o.foldmethod "syntax"); BufReadPre = DEFUN (SET vim.o.foldmethod "syntax");
BufEnter = { buf, ... }: BufEnter = { buf, ... }:
(LET (vim.filetype.match { inherit buf; }) (filetype: [ (LET (vim.filetype.match { inherit buf; }) (filetype: L [
(IF (APPLY OR (map (EQ filetype) [ "gitcommit" "markdown" ])) (LET vim.o.colorcolumn (old_colorcolumn: [ IF (APPLY OR (map (EQ filetype) [ "gitcommit" "markdown" ])) (
(SET vim.o.colorcolumn "73") LET vim.o.colorcolumn (old_colorcolumn: L [
(vim.api.nvim_create_autocmd "BufLeave" { SET vim.o.colorcolumn "73" _
callback = DEFUN [ vim.api.nvim_create_autocmd "BufLeave" {
(SET vim.o.colorcolumn old_colorcolumn) callback = DEFUN (L [
SET vim.o.colorcolumn old_colorcolumn _
# return true = delete autocommand # return true = delete autocommand
(RETURN true) true
]; ]);
}) } _
]))) ])
(IF (EQ filetype "markdown") (LET vim.o.textwidth (old_textwidth: [ ) _
(SET vim.o.textwidth 72) IF (EQ filetype "markdown") (
(vim.api.nvim_create_autocmd "BufLeave" { LET vim.o.textwidth (old_textwidth: L [
callback = DEFUN [ SET vim.o.textwidth 72 _
(SET vim.o.textwidth old_textwidth) vim.api.nvim_create_autocmd "BufLeave" {
(RETURN true) callback = DEFUN (L [
]; SET vim.o.textwidth old_textwidth _
}) true
]))) ]);
} _
])
) _
])); ]));
BufWinEnter = { buf, ... }: BufWinEnter = { buf, ... }:
(LET (vim.filetype.match { inherit buf; }) (filetype: [ (LET (vim.filetype.match { inherit buf; }) (filetype: L [
(vimcmd "folddoc" "foldopen!") CALL (PROP vim.cmd "folddoc") "foldopen!" _
(IF (EQ filetype "gitcommit") IF (EQ filetype "gitcommit") (
(CALL vim.cmd { CALL vim.cmd {
cmd = "normal"; cmd = "normal";
bang = true; bang = true;
args = [ "gg" ]; args = [ "gg" ];
}) }
ELSE ) ELSE (
(CALL vim.cmd { CALL vim.cmd {
cmd = "normal"; cmd = "normal";
bang = true; bang = true;
args = [ "g`\"" ]; args = [ "g`\"" ];
}) }
) ) _
])); ]));
} }
)) ) _
]); ]);
plugins = let ps = pkgs.vimPlugins; in map (x: if x?config && x?plugin then { type = "lua"; } // x else x) [ plugins = let ps = pkgs.vimPlugins; in map (x: if x?config && x?plugin then { type = "lua"; } // x else x) [
ps.vim-svelte ps.vim-svelte
# TODO remove on next nvim update (0.8.3/0.9) # TODO remove on next nvim update (0.8.3/0.9? whenever they add builtin nix syntax)
ps.vim-nix ps.vim-nix
{ plugin = pkgs.vimUtils.buildVimPluginFrom2Nix { { plugin = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "vscode-nvim"; pname = "vscode-nvim";
@ -152,8 +177,8 @@
sha256 = "sha256-X2IgIjO5NNq7vJdl09hBY1TFqHlsfF1xfllKr4osILI="; sha256 = "sha256-X2IgIjO5NNq7vJdl09hBY1TFqHlsfF1xfllKr4osILI=";
}; };
}; };
config = compile "vscode_nvim" [ config = compile' "vscode_nvim" [
((REQ "vscode").setup { (REQ "vscode").setup {
transparent = true; transparent = true;
color_overrides = { color_overrides = {
vscGray = "#745b5f"; vscGray = "#745b5f";
@ -170,25 +195,25 @@
vscYellow = "#${config.colors.yellow}"; vscYellow = "#${config.colors.yellow}";
vscPink = "#cf83c4"; vscPink = "#cf83c4";
}; };
}) } _
(vim.api.nvim_set_hl 0 "NormalFloat" { vim.api.nvim_set_hl 0 "NormalFloat" {
bg = "NONE"; bg = "NONE";
}) } _
]; } ]; }
{ plugin = ps.nvim-web-devicons; { plugin = ps.nvim-web-devicons;
config = compile "nvim_web_devicons" ((REQ "nvim-web-devicons").setup {}); } config = compile "nvim_web_devicons" ((REQ "nvim-web-devicons").setup {}); }
{ plugin = ps.nvim-tree-lua; { plugin = ps.nvim-tree-lua;
config = compile "nvim_tree_lua" (LET (REQ "nvim-tree") (REQ "nvim-tree.api") (nvim-tree: nvim-tree-api: [ config = compile "nvim_tree_lua" (LET (REQ "nvim-tree") (REQ "nvim-tree.api") (nvim-tree: nvim-tree-api: L [
(SET (vimg "loaded_netrw") 1) SET (vimg "loaded_netrw") 1 _
(SET (vimg "loaded_netrwPlugin") 1) SET (vimg "loaded_netrwPlugin") 1 _
(SET vim.o.termguicolors true) SET vim.o.termguicolors true _
(nvim-tree.setup {}) # :help nvim-tree-setup nvim-tree.setup {} _ # :help nvim-tree-setup
(kmSetNs { kmSetNs {
"<C-N>" = { "<C-N>" = {
rhs = nvim-tree-api.tree.toggle; rhs = nvim-tree-api.tree.toggle;
desc = "Toggle NvimTree"; desc = "Toggle NvimTree";
}; };
}) } _
])); } ])); }
ps.vim-sleuth ps.vim-sleuth
ps.luasnip ps.luasnip
@ -206,7 +231,7 @@
]); ]);
in compile "nvim_cmp" (LET (REQ "cmp") (REQ "lspkind") (cmp: lspkind: in compile "nvim_cmp" (LET (REQ "cmp") (REQ "lspkind") (cmp: lspkind:
# call is required because cmp.setup is a table # call is required because cmp.setup is a table
(CALL cmp.setup { CALL cmp.setup {
snippet = { snippet = {
expand = { body, ... }: luasnip.lsp_expand body {}; expand = { body, ... }: luasnip.lsp_expand body {};
}; };
@ -221,9 +246,9 @@
}; };
}; };
formatting = { formatting = {
format = _: vim_item: let kind = PROP vim_item "kind"; in [ format = arg1: vim_item: let kind = PROP vim_item "kind"; in L [
(SET kind (string.format "%s %s" (IDX lspkind kind) kind)) SET kind (string.format "%s %s" (IDX lspkind kind) kind) _
(RETURN vim_item) vim_item
]; ];
}; };
mapping = { mapping = {
@ -236,61 +261,62 @@
select = false; select = false;
}; };
"<tab>" = CALL cmp.mapping (fallback: "<tab>" = CALL cmp.mapping (fallback:
(IF IF (CALL cmp.visible) (
(CALL cmp.visible) CALL cmp.select_next_item
(CALL cmp.select_next_item) ) (CALL luasnip.expand_or_jumpable) (
(CALL luasnip.expand_or_jumpable) vim.api.nvim_feedkeys
(vim.api.nvim_feedkeys
(vim.api.nvim_replace_termcodes "<Plug>luasnip-expand-or-jump" true true true) (vim.api.nvim_replace_termcodes "<Plug>luasnip-expand-or-jump" true true true)
"" ""
false) false
ELSE ) ELSE (
(CALL fallback))) CALL fallback
[ "i" "s" ]; )
) [ "i" "s" ];
"<S-tab>" = CALL cmp.mapping (fallback: "<S-tab>" = CALL cmp.mapping (fallback:
(IF IF (CALL cmp.visible) (
(CALL cmp.visible) CALL cmp.select_prev_item
(CALL cmp.select_prev_item) ) (luasnip.jumpable (-1)) (
(luasnip.jumpable (-1)) vim.api.nvim_feedkeys
(vim.api.nvim_feedkeys
(vim.api.nvim_replace_termcodes "<Plug>luasnip-jump-prev" true true true) (vim.api.nvim_replace_termcodes "<Plug>luasnip-jump-prev" true true true)
"" ""
false) false
ELSE ) ELSE (
(CALL fallback))) CALL fallback
[ "i" "s" ]; )
) [ "i" "s" ];
}; };
sources = cmp.config.sources [ sources = cmp.config.sources [
{ name = "nvim_lsp"; } { name = "nvim_lsp"; }
{ name = "luasnip"; } { name = "luasnip"; }
]; ];
}) }
)); } )); }
ps.lspkind-nvim ps.lspkind-nvim
ps.cmp_luasnip ps.cmp_luasnip
ps.cmp-nvim-lsp ps.cmp-nvim-lsp
{ plugin = ps.nvim-autopairs; { plugin = ps.nvim-autopairs;
config = compile "nvim_autopairs" (LET (REQ "nvim-autopairs.completion.cmp") (REQ "nvim-autopairs") (cmp-autopairs: nvim-autopairs: [ config = compile "nvim_autopairs" (LET (REQ "nvim-autopairs.completion.cmp") (REQ "nvim-autopairs") (cmp-autopairs: nvim-autopairs: L [
(nvim-autopairs.setup { nvim-autopairs.setup {
disable_filetype = [ "TelescopePrompt" "vim" ]; disable_filetype = [ "TelescopePrompt" "vim" ];
}) } _
(MCALL cmp.event "on" "confirm_done" (cmp-autopairs.on_confirm_done {})) MCALL cmp.event "on" "confirm_done" (cmp-autopairs.on_confirm_done {}) _
])); } ])); }
{ plugin = ps.comment-nvim; { plugin = ps.comment-nvim;
config = compile "comment_nvim" [ config = compile' "comment_nvim" [
((REQ "Comment").setup {}) (REQ "Comment").setup {} _
(kmSetNs { kmSetNs {
"<space>/" = { "<space>/" = {
rhs = PROP (REQ "Comment.api").toggle "linewise.current"; # metatables......
rhs = REQ' (PROP (require "Comment.api") "toggle.linewise.current");
desc = "Comment current line"; desc = "Comment current line";
}; };
}) } _
(kmSetVs { kmSetVs {
"<space>/" = { "<space>/" = {
rhs = "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>"; rhs = "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>";
desc = "Comment selection"; desc = "Comment selection";
}; };
}) } _
]; } ]; }
{ plugin = ps.nvim-lspconfig; { plugin = ps.nvim-lspconfig;
config = compile "nvim_lspconfig" ( config = compile "nvim_lspconfig" (
@ -299,9 +325,9 @@
(REQ "lspconfig.server_configurations.${name}") (REQ "lspconfig.server_configurations.${name}")
# metatables, son! they harden in response to physical trauma # metatables, son! they harden in response to physical trauma
(REQ' (PROP (require "lspconfig") name)); (REQ' (PROP (require "lspconfig") name));
in [ in L [
# See `:help vim.diagnostic.*` for documentation on any of the below functions # See `:help vim.diagnostic.*` for documentation on any of the below functions
(kmSetNs { kmSetNs {
"<space>e" = { "<space>e" = {
rhs = vim.diagnostic.open_float; rhs = vim.diagnostic.open_float;
desc = "Show diagnostics in a floating window."; desc = "Show diagnostics in a floating window.";
@ -318,15 +344,15 @@
rhs = vim.diagnostic.setloclist; rhs = vim.diagnostic.setloclist;
desc = "Add buffer diagnostics to the location list."; desc = "Add buffer diagnostics to the location list.";
}; };
}) } _
(LET LET
# LET on_attach # LET on_attach
(client: bufnr: [ (client: bufnr: L [
# Enable completion triggered by <c-x><c-o> # Enable completion triggered by <c-x><c-o>
(vim.api.nvim_buf_set_option bufnr "omnifunc" "v:lua.vim.lsp.omnifunc") vim.api.nvim_buf_set_option bufnr "omnifunc" "v:lua.vim.lsp.omnifunc" _
# Mappings. # Mappings.
# See `:help vim.lsp.*` for documentation on any of the below functions # See `:help vim.lsp.*` for documentation on any of the below functions
(kmSetNs { kmSetNs {
"gD" = { "gD" = {
rhs = vim.lsp.buf.declaration; rhs = vim.lsp.buf.declaration;
desc = "Jumps to the declaration of the symbol under the cursor."; }; desc = "Jumps to the declaration of the symbol under the cursor."; };
@ -364,9 +390,9 @@
rhs = vim.lsp.buf.references; rhs = vim.lsp.buf.references;
desc = "Lists all the references to the symbol under the cursor in the quickfix window."; }; desc = "Lists all the references to the symbol under the cursor in the quickfix window."; };
"<space>f" = { "<space>f" = {
rhs = (DEFUN (vim.lsp.buf.format {async = true;})); rhs = DEFUN (vim.lsp.buf.format {async = true;});
desc = "Formats a buffer."; }; desc = "Formats a buffer."; };
}) } _
]) ])
# LET rust_settings # LET rust_settings
{ rust-analyzer = { { rust-analyzer = {
@ -381,31 +407,31 @@
((REQ "cmp_nvim_lsp").default_capabilities {}) ((REQ "cmp_nvim_lsp").default_capabilities {})
(CALL vim.lsp.protocol.make_client_capabilities)) (CALL vim.lsp.protocol.make_client_capabilities))
# BEGIN # BEGIN
(on_attach: rust_settings: capabilities: [ (on_attach: rust_settings: capabilities:
(LETREC LETREC
# LETREC on_attach_rust # LETREC on_attach_rust
(on_attach_rust: client: bufnr: [ (on_attach_rust: client: bufnr: L [
(vim.api.nvim_create_user_command "RustAndroid" (opts: [ vim.api.nvim_create_user_command "RustAndroid" (opts: L [
(vim.lsp.set_log_level "debug") vim.lsp.set_log_level "debug" _
((lsp "rust_analyzer").setup { (lsp "rust_analyzer").setup {
on_attach = on_attach_rust; on_attach = on_attach_rust;
inherit capabilities; inherit capabilities;
settings = vim.tbl_deep_extend settings = vim.tbl_deep_extend
"keep" "keep"
config.rustAnalyzerAndroidSettings config.rustAnalyzerAndroidSettings
rust_settings; rust_settings;
}) } _
]) {}) ]) {} _
(CALL on_attach client bufnr) on_attach client bufnr _
]) ])
# BEGIN # BEGIN
(let setupLsp' = { name, settings ? {} }: (lsp name).setup { (let setupLsp' = { name, settings ? {} }: (lsp name).setup {
inherit on_attach capabilities settings; inherit on_attach capabilities settings;
}; };
setupLsp = args: setupLsp' (if builtins.isString args then { name = args; } else args); setupLsp = args: setupLsp' (if builtins.isString args then { name = args; } else args);
in (on_attach_rust: [ in on_attach_rust: L [
# (vim.lsp.set_log_level "debug") # (vim.lsp.set_log_level "debug")
(map setupLsp [ map setupLsp [
# see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md # see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
"bashls" "bashls"
"clangd" "clangd"
@ -421,20 +447,20 @@
"nil_ls" "nil_ls"
"taplo" "taplo"
"marksman" "marksman"
]) ] _
((lsp "rust_analyzer").setup { (lsp "rust_analyzer").setup {
on_attach = on_attach_rust; on_attach = on_attach_rust;
settings = rust_settings; settings = rust_settings;
inherit capabilities; inherit capabilities;
}) } _
]))) # END ]) # END
])) # END ) _ # END
]); } ]); }
{ plugin = ps.which-key-nvim; { plugin = ps.which-key-nvim;
config = compile "which_key_nvim" [ config = compile' "which_key_nvim" [
(SET vim.o.timeout true) SET vim.o.timeout true _
(SET vim.o.timeoutlen 500) SET vim.o.timeoutlen 500 _
(which-key.setup {}) which-key.setup {} _
]; } ]; }
]; ];
}; };

View file

@ -61,11 +61,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1679159882, "lastModified": 1679217283,
"narHash": "sha256-sE3MPfc6nM+8Wha9/nO7esg14HX5FJhyrBoZfS/Fe5I=", "narHash": "sha256-oX6x3LeRH83LWwKGHGeKB+Sf+v43BWBry18/FsAu5+U=",
"owner": "chayleaf", "owner": "chayleaf",
"repo": "notlua", "repo": "notlua",
"rev": "432a968debd969ef84d78d64bc6e0f31cb54a153", "rev": "2088a194da48d4b96807265c8d043a47162da953",
"type": "github" "type": "github"
}, },
"original": { "original": {