summaryrefslogtreecommitdiff
path: root/dot_config/nvim/lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dot_config/nvim/lua/bindings.lua25
-rw-r--r--dot_config/nvim/lua/blackhole.lua6
-rw-r--r--dot_config/nvim/lua/ipacker.lua24
-rw-r--r--dot_config/nvim/lua/plugins.lua89
-rw-r--r--dot_config/nvim/lua/plugins/conjure.lua17
-rw-r--r--dot_config/nvim/lua/plugins/leap.lua13
-rw-r--r--dot_config/nvim/lua/plugins/lualine.lua11
-rw-r--r--dot_config/nvim/lua/plugins/mini.lua1
-rw-r--r--dot_config/nvim/lua/plugins/nvim-lspconfig.lua71
-rw-r--r--dot_config/nvim/lua/plugins/nvim-tree.lua45
-rw-r--r--dot_config/nvim/lua/plugins/readline.lua10
-rw-r--r--dot_config/nvim/lua/plugins/telescope.lua22
-rw-r--r--dot_config/nvim/lua/transformer.lua80
-rw-r--r--dot_config/nvim/lua/util.lua10
14 files changed, 424 insertions, 0 deletions
diff --git a/dot_config/nvim/lua/bindings.lua b/dot_config/nvim/lua/bindings.lua
new file mode 100644
index 0000000..eb579f9
--- /dev/null
+++ b/dot_config/nvim/lua/bindings.lua
@@ -0,0 +1,25 @@
+local util = require 'util'
+
+local env = vim.env
+
+-- TODO: write a wrapper for both
+if not util.hp 'which-key.nvim' then
+ -- minimal bindings for a no-plugin environment
+ local km = vim.keymap.set
+ km('n', '<leader>sv', function() dofile(env.MYVIMRC) end, { desc = 'source vimrc'})
+ km('n', '<leader>s%', '<cmd>source %<cr>', { desc = 'source current file'})
+else
+ -- general bindings that aren't specific to a plugin
+ require 'which-key'.register {
+ ['<leader>s'] = {
+ name = '+source',
+ v = { function() dofile(env.MYVIMRC) end, 'Vimrc' },
+ ['%'] = { '<cmd>source %<cr>', 'Current File' },
+ },
+ -- document missing builtins
+ ['g'] = {
+ t = 'Next tab',
+ T = 'Previous tab',
+ },
+ }
+end
diff --git a/dot_config/nvim/lua/blackhole.lua b/dot_config/nvim/lua/blackhole.lua
new file mode 100644
index 0000000..c57c300
--- /dev/null
+++ b/dot_config/nvim/lua/blackhole.lua
@@ -0,0 +1,6 @@
+-- black hole object
+-- you can access and call and set things however you want
+-- it will never do anything
+
+local f = function (self) return self end
+return setmetatable({}, {__call = f, __index = f, __newindex = f})
diff --git a/dot_config/nvim/lua/ipacker.lua b/dot_config/nvim/lua/ipacker.lua
new file mode 100644
index 0000000..389e168
--- /dev/null
+++ b/dot_config/nvim/lua/ipacker.lua
@@ -0,0 +1,24 @@
+-- init packer = ipacker
+-- returns packer or blackhole
+-- sets ipacker global to # depending on bootstrap level
+-- ipacker =
+ -- 0 = no packer present
+ -- 1 = bootstrapped just now
+ -- 2 = already present
+local fn = vim.fn
+local ipath = fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
+local repo = 'https://github.com/wbthomason/packer.nvim'
+
+ipacker = 0
+if #fn.findfile('packer.lua', ipath .. '**') == 0 then
+ if fn.executable 'git' == 0 then
+ return require 'blackhole'
+ end
+ fn.system {'git', 'clone', '--depth', '1', repo, ipath}
+ vim.cmd [[packloadall!]]
+ ipacker = 1
+else
+ ipacker = 2
+end
+
+return require 'packer'
diff --git a/dot_config/nvim/lua/plugins.lua b/dot_config/nvim/lua/plugins.lua
new file mode 100644
index 0000000..a99b72a
--- /dev/null
+++ b/dot_config/nvim/lua/plugins.lua
@@ -0,0 +1,89 @@
+local packer = require 'ipacker'
+local compiled = vim.fn.stdpath 'data' .. '/packer_compiled.lua'
+
+local function plugn(plug) -- plug name
+ return plug:gsub([[^.*/([^./]*)%.?.*$]], '%1')
+end
+
+local function plugi(conf) -- plug initialization string
+ -- you can pass it the plugin spec
+ if conf:find '/' then conf = plugn(conf) end
+ return 'plugins.' .. conf
+end
+
+local sust = {}
+colors = {
+ default = 'default', -- in case of no packer
+ scheme = 'tokyonight', -- in case of yes packer
+ lualine = 'tokyonight', -- per plugin stuff from here on
+}
+packer.startup({function(iuse)
+ local tf = require 'transformer'
+ local use = tf(iuse)
+
+ local sus = tf(function(spec)
+ table.insert(sust, plugi(spec[1]))
+ iuse(spec)
+ end)
+ local kbd = sus { requires = {'folke/which-key.nvim'} }
+
+ use 'wbthomason/packer.nvim'
+ use 'Olical/aniseed'
+
+ -- colors
+ use 'folke/tokyonight.nvim'
+
+ -- editor
+ use { run = function()
+ require 'nvim-treesitter.install'.update { with_sync = true }
+ end }
+ { config = function() require 'nvim-treesitter.configs'.setup {
+ ensure_installed = 'all',
+ sync_install = true,
+ } end }
+ 'nvim-treesitter/nvim-treesitter'
+ sus 'neovim/nvim-lspconfig'
+ kbd 'echasnovski/mini.nvim'
+
+ sus 'linty-org/readline.nvim'
+ sus 'nvim-lualine/lualine.nvim'
+ kbd 'kyazdani42/nvim-tree.lua'
+ use 'folke/which-key.nvim'
+
+ -- interactive features
+ use { run = 'make' } 'nvim-telescope/telescope-fzf-native.nvim'
+ kbd { requires = 'nvim-lua/plenary.nvim' } 'nvim-telescope/telescope.nvim'
+
+ kbd 'ggandor/leap.nvim'
+ kbd 'Olical/conjure'
+
+ -- language features
+ use { ft = 'janet' } 'janet-lang/janet.vim'
+ use { ft = {'scm', 'janet' } }
+ 'gpanders/nvim-parinfer'
+end, config = {
+ compile_path = compiled,
+}})
+
+local function configure()
+ vim.cmd(':colo ' .. colors.scheme)
+ for _, v in ipairs(sust) do require(v) end
+ require 'which-key'.setup{}
+ require 'bindings'
+end
+
+if ipacker == 0 then
+ -- no packer
+ vim.cmd(':colo ' .. colors.default)
+elseif ipacker == 1 then
+ -- run sync and wait for it before configuring
+ packer.sync()
+ vim.api.nvim_create_autocmd({'User PackerComplete'}, { callback = function()
+ configure()
+ end })
+else
+ -- run things normally
+ if vim.fn.filereadable(compiled) > 0 then dofile(compiled) end
+ configure()
+end
+
diff --git a/dot_config/nvim/lua/plugins/conjure.lua b/dot_config/nvim/lua/plugins/conjure.lua
new file mode 100644
index 0000000..f74e862
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/conjure.lua
@@ -0,0 +1,17 @@
+local prefix = '<localleader>e'
+vim.g['conjure#mapping#prefix'] = prefix
+vim.g['conjure#extract#tree_sitter#enabled'] = true
+
+-- TODO: only do this in affected buffers
+-- how?
+local wk = require 'which-key'
+wk.register({
+ name = '+conjure',
+ e = {
+ name = '+eval',
+ c = { name = '+comment' },
+ },
+ g = { name = '+get' },
+ l = { name = '+log' },
+ r = { name = '+reset' },
+}, {prefix = prefix})
diff --git a/dot_config/nvim/lua/plugins/leap.lua b/dot_config/nvim/lua/plugins/leap.lua
new file mode 100644
index 0000000..c2a2e70
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/leap.lua
@@ -0,0 +1,13 @@
+local leap = require 'leap'
+leap.set_default_keymaps()
+
+local api = vim.api
+local hl = api.nvim_set_hl
+local auto = api.nvim_create_autocmd
+
+local wk = require 'which-key'
+wk.register {
+ ['g'] = {
+ s = 'Leap across windows',
+ },
+}
diff --git a/dot_config/nvim/lua/plugins/lualine.lua b/dot_config/nvim/lua/plugins/lualine.lua
new file mode 100644
index 0000000..ccac089
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/lualine.lua
@@ -0,0 +1,11 @@
+require 'lualine'.setup {
+ theme = colors.lualine,
+ tabline = {
+ lualine_a = {'buffers'},
+ lualine_b = {},
+ lualine_c = {},
+ lualine_x = {},
+ lualine_y = {},
+ lualine_z = {'tabs'}
+ },
+}
diff --git a/dot_config/nvim/lua/plugins/mini.lua b/dot_config/nvim/lua/plugins/mini.lua
new file mode 100644
index 0000000..ebf75f3
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/mini.lua
@@ -0,0 +1 @@
+require 'mini.comment'.setup{}
diff --git a/dot_config/nvim/lua/plugins/nvim-lspconfig.lua b/dot_config/nvim/lua/plugins/nvim-lspconfig.lua
new file mode 100644
index 0000000..af45a49
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/nvim-lspconfig.lua
@@ -0,0 +1,71 @@
+---@diagnostic disable: undefined-global
+
+local lspc = require 'lspconfig'
+local lspu = require 'lspconfig.util'
+
+local function plist(...)
+ local p = lspu.root_pattern(...)
+ return function(f) return p(f) end
+end
+
+-- mappings
+local wk = require 'which-key'
+---@diagnostic disable-next-line: unused-local
+local on_attach = function(c, b)
+ local lsp = vim.lsp
+ local lbf = lsp.buf
+ vim.api.nvim_buf_set_option(b, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
+ wk.register({
+ name = '+lsp',
+ D = {lbf.declaration, 'goto declaration'},
+ d = {lbf.definition, 'goto definition'},
+ k = {lbf.hover, 'hover'},
+ K = {lbf.signature_help, 'signature help'},
+ i = {lbf.implementation, 'goto implementation'},
+ t = {lbf.type_definition, 'goto type definition'},
+ r = {lbf.rename, 'rename'},
+ c = {lbf.code_action, 'code action'},
+ R = {lbf.references, 'list references'},
+ w = {
+ name = '+workspace',
+ a = {lbf.add_workspace_folder, 'add folder'},
+ r = {lbf.remove_workspace_folder, 'remove folder'},
+ l = {
+ function() print(vim.inspect(lbf.list_workspace_folders())) end,
+ 'list folders'
+ },
+ },
+ }, {
+ prefix = '<localleader><localleader>',
+ buffer = b,
+ })
+ wk.register({
+ ['<leader>F'] = {
+ function() vim.lsp.buf.format {async = true} end,
+ 'run format',
+ },
+ }, { buffer = b })
+end
+
+-- configs
+local common = { on_attach = on_attach }
+local deno = vim.deepcopy(common)
+local tss = vim.deepcopy(common)
+deno.root_dir = plist('deno.json', 'deno.jsonc')
+tss.root_dir = plist('tsconfig.json', 'package.json')
+
+-- servers
+local function enable(name, opts)
+ opts = opts or common
+ local s = lspc[name]
+ local c = opts.cmd or s.document_config.default_config.cmd
+ if vim.fn.executable(c[1]) ~= 0 then
+ s.setup(opts)
+ end
+end
+
+enable('denols', deno)
+enable 'gopls'
+enable 'ltex'
+enable 'sumneko_lua'
+enable('tsserver', tss)
diff --git a/dot_config/nvim/lua/plugins/nvim-tree.lua b/dot_config/nvim/lua/plugins/nvim-tree.lua
new file mode 100644
index 0000000..129721d
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/nvim-tree.lua
@@ -0,0 +1,45 @@
+require 'nvim-tree'.setup {
+ filters = {
+ dotfiles = true,
+ },
+ git = {
+ enable = true,
+ ignore = true,
+ },
+ renderer = {
+ icons = {
+ glyphs = {
+ default = '-',
+ symlink = '→',
+ folder = {
+ arrow_closed = '▶',
+ arrow_open = '▼',
+
+ default = '📁',
+ open = '📂',
+
+ symlink = '📁',
+ symlink_open = '📂',
+
+ empty = '📁',
+ empty_open = '📂',
+ },
+ git = {
+ deleted = '-', -- unused
+ unstaged = '±',
+ untracked = '+',
+ unmerged = 'U',
+ },
+ },
+ },
+ },
+}
+
+local api = require 'nvim-tree.api'
+local wk = require 'which-key'
+local km = vim.keymap.set
+wk.register {
+ ['<leader>'] = {
+ n = { api.tree.toggle, 'nvim-tree' },
+ }
+}
diff --git a/dot_config/nvim/lua/plugins/readline.lua b/dot_config/nvim/lua/plugins/readline.lua
new file mode 100644
index 0000000..66ace95
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/readline.lua
@@ -0,0 +1,10 @@
+local readline = require 'readline'
+vim.keymap.set('!', '<M-f>', readline.forward_word)
+vim.keymap.set('!', '<M-b>', readline.backward_word)
+vim.keymap.set('!', '<C-a>', readline.dwim_beginning_of_line)
+vim.keymap.set('!', '<C-e>', readline.end_of_line)
+vim.keymap.set('!', '<M-d>', readline.kill_word)
+vim.keymap.set('!', '<M-BS>', readline.backward_kill_word)
+vim.keymap.set('!', '<C-w>', readline.unix_word_rubout)
+vim.keymap.set('!', '<C-k>', readline.kill_line)
+vim.keymap.set('!', '<C-u>', readline.dwim_backward_kill_line)
diff --git a/dot_config/nvim/lua/plugins/telescope.lua b/dot_config/nvim/lua/plugins/telescope.lua
new file mode 100644
index 0000000..219e80b
--- /dev/null
+++ b/dot_config/nvim/lua/plugins/telescope.lua
@@ -0,0 +1,22 @@
+local ts = require 'telescope'
+
+ts.setup {
+ -- pickers = {},
+ -- extensions = {},
+}
+
+ts.load_extension 'fzf'
+
+local tb = require 'telescope.builtin'
+local wk = require 'which-key'
+wk.register {
+ ['<leader>f'] = {
+ name = '+find',
+ f = { tb.find_files, 'Find File' },
+ g = { tb.live_grep, 'Live Grep' },
+ b = { tb.buffers, 'Find Buffer' },
+ h = { tb.help_tags, 'Find Help' },
+ c = { tb.commands, 'Find Command' },
+ t = { tb.treesitter, 'Find Treesitter' },
+ }
+}
diff --git a/dot_config/nvim/lua/transformer.lua b/dot_config/nvim/lua/transformer.lua
new file mode 100644
index 0000000..a479826
--- /dev/null
+++ b/dot_config/nvim/lua/transformer.lua
@@ -0,0 +1,80 @@
+--[[
+ Transformer.lua
+ A transforming meta-flow originally built for packer.
+
+ TL;DR you have a function to which you want to eventually pass a table.
+ With this, you can construct the table piece by piece.
+ It will finally call out once you pass () or a string.
+ The string will *prepend* itself to the object.
+
+ Merging rules are a bit complicated:
+ For tables, we merge the ipairs in order (left to right).
+ The final '' is an exception.
+ Then we merge the map-like keys recursively.
+ If the target is a table but the merged key isn't, we append it.
+ Otherwise we always overwrite.
+]]--
+
+---@diagnostic disable-next-line: unused-vararg
+local function tables(...)
+ for i=1,select('#') do
+ if type(select(i)) ~= 'table' then return false end
+ end
+ return true
+end
+
+local function imerge(t1, t2) -- mutates t1
+ for _, v in ipairs(t2) do table.insert(t1, v) end
+end
+
+local bigmerge -- forward declaration
+
+local function kmerge(t1, t2) -- mutates t2
+ for k, v in pairs(t2) do
+ if type(k) == 'number' and k >= 1 and k <= #t1 then
+ -- skip, we did this in imerge
+ else
+ if t1[k] and type(t1[k]) == 'table' then
+ if type(v) == 'table' then
+ t1[k] = bigmerge(t1[k], v)
+ else
+ table.insert(t1[k], v)
+ end
+ else
+ t1[k] = v
+ end
+ end
+ end
+end
+
+bigmerge = function(t1, t2)
+ assert(tables(t1, t2))
+ local out = {}
+ imerge(out, t1)
+ imerge(out, t2)
+ kmerge(out, t1)
+ kmerge(out, t2)
+ return out
+end
+
+local function tgen(use) return function (self, obj)
+ if obj == nil then return use(self) end
+
+ if type(obj) == 'string' then
+ local out = { obj }
+ imerge(out, self)
+ kmerge(out, self)
+ return setmetatable(out, getmetatable(self))()
+ elseif type(obj) == 'table' then
+ local out = bigmerge(self, obj)
+ return setmetatable(out, getmetatable(self))
+
+ else
+ error 'Invalid argument.'
+ end
+
+end end
+
+return function(use)
+ return setmetatable({}, { __call = tgen(use) })
+end
diff --git a/dot_config/nvim/lua/util.lua b/dot_config/nvim/lua/util.lua
new file mode 100644
index 0000000..aa114d8
--- /dev/null
+++ b/dot_config/nvim/lua/util.lua
@@ -0,0 +1,10 @@
+-- hasplug
+local function hp(plug)
+ return packer_plugins and
+ packer_plugins[plug] and
+ packer_plugins[plug].loaded
+end
+
+return {
+ hp = hp,
+}