diff --git a/lua/base16.lua b/lua/base16.lua index 5241351..f352bae 100644 --- a/lua/base16.lua +++ b/lua/base16.lua @@ -1,5 +1,3 @@ -local nvim = require 'nvim' - local function highlight(group, guifg, guibg, attr, guisp) local parts = {group} if guifg then table.insert(parts, "guifg=#"..guifg) end @@ -17,29 +15,29 @@ end local function apply_base16_theme(theme) -- Neovim terminal colours - if nvim.fn.has("nvim") then - nvim.g.terminal_color_0 = "#"..theme.base00 - nvim.g.terminal_color_1 = "#"..theme.base08 - nvim.g.terminal_color_2 = "#"..theme.base0B - nvim.g.terminal_color_3 = "#"..theme.base0A - nvim.g.terminal_color_4 = "#"..theme.base0D - nvim.g.terminal_color_5 = "#"..theme.base0E - nvim.g.terminal_color_6 = "#"..theme.base0C - nvim.g.terminal_color_7 = "#"..theme.base05 - nvim.g.terminal_color_8 = "#"..theme.base03 - nvim.g.terminal_color_9 = "#"..theme.base08 - nvim.g.terminal_color_10 = "#"..theme.base0B - nvim.g.terminal_color_11 = "#"..theme.base0A - nvim.g.terminal_color_12 = "#"..theme.base0D - nvim.g.terminal_color_13 = "#"..theme.base0E - nvim.g.terminal_color_14 = "#"..theme.base0C - nvim.g.terminal_color_15 = "#"..theme.base07 - if nvim.o.background == "light" then - nvim.g.terminal_color_background = "#"..theme.base05 - nvim.g.terminal_color_foreground = "#"..theme.base0B + if vim.fn.has("nvim") then + vim.g.terminal_color_0 = "#"..theme.base00 + vim.g.terminal_color_1 = "#"..theme.base08 + vim.g.terminal_color_2 = "#"..theme.base0B + vim.g.terminal_color_3 = "#"..theme.base0A + vim.g.terminal_color_4 = "#"..theme.base0D + vim.g.terminal_color_5 = "#"..theme.base0E + vim.g.terminal_color_6 = "#"..theme.base0C + vim.g.terminal_color_7 = "#"..theme.base05 + vim.g.terminal_color_8 = "#"..theme.base03 + vim.g.terminal_color_9 = "#"..theme.base08 + vim.g.terminal_color_10 = "#"..theme.base0B + vim.g.terminal_color_11 = "#"..theme.base0A + vim.g.terminal_color_12 = "#"..theme.base0D + vim.g.terminal_color_13 = "#"..theme.base0E + vim.g.terminal_color_14 = "#"..theme.base0C + vim.g.terminal_color_15 = "#"..theme.base07 + if vim.o.background == "light" then + vim.g.terminal_color_background = "#"..theme.base05 + vim.g.terminal_color_foreground = "#"..theme.base0B else - nvim.g.terminal_color_background = "#"..theme.base00 - nvim.g.terminal_color_foreground = "#"..theme.base0E + vim.g.terminal_color_background = "#"..theme.base00 + vim.g.terminal_color_foreground = "#"..theme.base0E end end diff --git a/lua/nvim.lua b/lua/nvim.lua deleted file mode 100644 index 5dd7fbf..0000000 --- a/lua/nvim.lua +++ /dev/null @@ -1,189 +0,0 @@ --- Equivalent to `echo vim.inspect(...)` -local function nvim_print(...) - if select("#", ...) == 1 then - vim.api.nvim_out_write(vim.inspect((...))) - else - vim.api.nvim_out_write(vim.inspect {...}) - end - vim.api.nvim_out_write("\n") -end - ---- Equivalent to `echo` EX command -local function nvim_echo(...) - for i = 1, select("#", ...) do - local part = select(i, ...) - vim.api.nvim_out_write(tostring(part)) - -- vim.api.nvim_out_write("\n") - vim.api.nvim_out_write(" ") - end - vim.api.nvim_out_write("\n") -end - -local window_options = { - arab = true; arabic = true; breakindent = true; breakindentopt = true; - bri = true; briopt = true; cc = true; cocu = true; - cole = true; colorcolumn = true; concealcursor = true; conceallevel = true; - crb = true; cuc = true; cul = true; cursorbind = true; - cursorcolumn = true; cursorline = true; diff = true; fcs = true; - fdc = true; fde = true; fdi = true; fdl = true; - fdm = true; fdn = true; fdt = true; fen = true; - fillchars = true; fml = true; fmr = true; foldcolumn = true; - foldenable = true; foldexpr = true; foldignore = true; foldlevel = true; - foldmarker = true; foldmethod = true; foldminlines = true; foldnestmax = true; - foldtext = true; lbr = true; lcs = true; linebreak = true; - list = true; listchars = true; nu = true; number = true; - numberwidth = true; nuw = true; previewwindow = true; pvw = true; - relativenumber = true; rightleft = true; rightleftcmd = true; rl = true; - rlc = true; rnu = true; scb = true; scl = true; - scr = true; scroll = true; scrollbind = true; signcolumn = true; - spell = true; statusline = true; stl = true; wfh = true; - wfw = true; winbl = true; winblend = true; winfixheight = true; - winfixwidth = true; winhighlight = true; winhl = true; wrap = true; -} - --- `nvim.$method(...)` redirects to `nvim.api.nvim_$method(...)` --- `nvim.fn.$method(...)` redirects to `vim.api.nvim_call_function($method, {...})` --- TODO `nvim.ex.$command(...)` is approximately `:$command {...}.join(" ")` --- `nvim.print(...)` is approximately `echo vim.inspect(...)` --- `nvim.echo(...)` is approximately `echo table.concat({...}, '\n')` --- Both methods cache the inital lookup in the metatable, but there is a small overhead regardless. -return setmetatable({ - print = nvim_print; - echo = nvim_echo; - fn = setmetatable({}, { - __index = function(self, k) - local mt = getmetatable(self) - local x = mt[k] - if x ~= nil then - return x - end - local f = function(...) return vim.api.nvim_call_function(k, {...}) end - mt[k] = f - return f - end - }); - buf = setmetatable({ - }, { - __index = function(self, k) - local mt = getmetatable(self) - local x = mt[k] - if x ~= nil then return x end - local f - if k == 'line' then - f = function() - local pos = vim.api.nvim_win_get_cursor(0) - return vim.api.nvim_buf_get_lines(0, pos[1]-1, pos[1], 'line')[1] - end - elseif k == 'nr' then - f = vim.api.nvim_get_current_buf - end - mt[k] = f - return f - end - }); - ex = setmetatable({}, { - __index = function(self, k) - local mt = getmetatable(self) - local x = mt[k] - if x ~= nil then - return x - end - local command = k:gsub("_$", "!") - local f = function(...) - return vim.api.nvim_command(table.concat(vim.tbl_flatten {command, ...}, " ")) - end - mt[k] = f - return f - end - }); - g = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_get_var(k) - end; - __newindex = function(_, k, v) - if v == nil then - return vim.api.nvim_del_var(k) - else - return vim.api.nvim_set_var(k, v) - end - end; - }); - v = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_get_vvar(k) - end; - __newindex = function(_, k, v) - return vim.api.nvim_set_vvar(k, v) - end - }); - b = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_buf_get_var(0, k) - end; - __newindex = function(_, k, v) - if v == nil then - return vim.api.nvim_buf_del_var(0, k) - else - return vim.api.nvim_buf_set_var(0, k, v) - end - end - }); - w = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_win_get_var(0, k) - end; - __newindex = function(_, k, v) - if v == nil then - return vim.api.nvim_win_del_var(0, k) - else - return vim.api.nvim_win_set_var(0, k, v) - end - end - }); - o = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_get_option(k) - end; - __newindex = function(_, k, v) - return vim.api.nvim_set_option(k, v) - end - }); - -- TODO add warning if you try to use a window option here? - bo = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_buf_get_option(0, k) - end; - __newindex = function(_, k, v) - return vim.api.nvim_buf_set_option(0, k, v) - end - }); - wo = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_win_get_option(0, k) - end; - __newindex = function(_, k, v) - -- passing v == nil will clear the value, just like above. - return vim.api.nvim_win_set_option(0, k, v) - end - }); - env = setmetatable({}, { - __index = function(_, k) - return vim.api.nvim_call_function('getenv', {k}) - end; - __newindex = function(_, k, v) - return vim.api.nvim_call_function('setenv', {k, v}) - end - }); -}, { - __index = function(self, k) - local mt = getmetatable(self) - local x = mt[k] - if x ~= nil then - return x - end - local f = vim.api['nvim_'..k] - mt[k] = f - return f - end -}) -