From 7d462d029445be03d15db0821b9f1a53ef778792 Mon Sep 17 00:00:00 2001 From: aprzn Date: Wed, 13 Dec 2023 19:00:13 -0500 Subject: [PATCH] uiua pad and link (plus some other stuff) --- configs/nvim/init.lua | 10 +- configs/nvim/lua/autocmds.lua | 102 ++++++++-------- configs/nvim/lua/bindings.lua | 149 +++++++++++------------ configs/nvim/lua/nvcfg.lua | 151 ++++++++++++++++++------ configs/nvim/lua/packages.lua | 99 ++++++++-------- configs/nvim/plugin/packer_compiled.lua | 5 - 6 files changed, 298 insertions(+), 218 deletions(-) diff --git a/configs/nvim/init.lua b/configs/nvim/init.lua index 95a5634..c4ff48d 100644 --- a/configs/nvim/init.lua +++ b/configs/nvim/init.lua @@ -1,5 +1,5 @@ -require('packages') -require('bindings') -require('autocmds') -require('nvcfg') -require('local') +require('packages')() +require('bindings')() +require('autocmds')() +require('nvcfg')() +require('local')() diff --git a/configs/nvim/lua/autocmds.lua b/configs/nvim/lua/autocmds.lua index 9cd43f3..00664c0 100644 --- a/configs/nvim/lua/autocmds.lua +++ b/configs/nvim/lua/autocmds.lua @@ -1,57 +1,57 @@ --- detect filetype -vim.filetype.add({extension = {ua = "uiua" }}) +return function() + -- detect filetype + vim.filetype.add({extension = {ua = "uiua" }}) -vim.api.nvim_create_augroup("aprzn", {clear = true}) -vim.api.nvim_create_autocmd("BufWritePost", { - group = "aprzn", - pattern = {"*/.config/nvim/*.lua", "*/.config/nvim/lua/*.lua"}, - command = "source $MYVIMRC" -}) -- reload config file on save + vim.api.nvim_create_augroup("aprzn", {clear = true}) + vim.api.nvim_create_autocmd("BufWritePost", { + group = "aprzn", + pattern = {"*/nvim/*.lua", "*/nvim/lua/*.lua"}, + command = "source $MYVIMRC" + }) -- reload config file on save --- vim.api.nvim_create_autocmd("VimEnter", { --- group = "aprzn", --- pattern = {"*"}, --- command = "NERDTree" --- }) -- open nerdtree on start + -- vim.api.nvim_create_autocmd("VimEnter", { + -- group = "aprzn", + -- pattern = {"*"}, + -- command = "NERDTree" + -- }) -- open nerdtree on start -vim.api.nvim_create_autocmd("CursorHold", { - group = "aprzn", - pattern = {"*"}, - command = "call CocActionAsync('highlight')" -}) -- highlight matching tokens when not moving cursor + vim.api.nvim_create_autocmd("CursorHold", { + group = "aprzn", + pattern = {"*"}, + command = "call CocActionAsync('highlight')" + }) -- highlight matching tokens when not moving cursor -vim.api.nvim_create_autocmd("ColorScheme", { - group = "aprzn", - pattern = {"*"}, - callback = function(ev) - local file = io.open(vim.fn.stdpath('config') .. "/colorscheme", "w") - local cs = ev.match - file:write(cs) - file:close() - end -}) -- save colorscheme + vim.api.nvim_create_autocmd("ColorScheme", { + group = "aprzn", + pattern = {"*"}, + callback = function(ev) + local file = io.open(vim.fn.stdpath('config') .. "/colorscheme", "w") + local cs = ev.match + file:write(cs) + file:close() + end + }) -- save colorscheme -vim.api.nvim_create_autocmd("BufWritePost", { - group = "aprzn", - pattern = "*.ua", - callback = function(ev) - vim.cmd("silent !uiua fmt " .. vim.fn.expand("")) - end, -}) -- format uiua on save + vim.api.nvim_create_autocmd("BufWritePost", { + group = "aprzn", + pattern = "*.ua", + callback = function(ev) + vim.cmd("silent !uiua fmt " .. vim.fn.expand("")) + end, + }) -- format uiua on save -vim.api.nvim_create_autocmd("FileType", { - group = "aprzn", - pattern = "*", - callback = function(ev) - if vim.g.neovide then - if ev.match == "uiua" then - vim.o.guifont = "Uiua386:h14" - vim.opt_local.commentstring = "# %s" - else - vim.o.guifont = "FiraCode Nerd Font:h14" - end - end - end, -}) - -return false + vim.api.nvim_create_autocmd("FileType", { + group = "aprzn", + pattern = "*", + callback = function(ev) + if vim.g.neovide then + if ev.match == "uiua" then -- use uiua386 when editing uiua + vim.o.guifont = "Uiua386:h14" + vim.opt_local.commentstring = "# %s" + else + vim.o.guifont = "FiraCode Nerd Font:h14" + end + end + end, + }) +end diff --git a/configs/nvim/lua/bindings.lua b/configs/nvim/lua/bindings.lua index 3b5a762..146df1a 100644 --- a/configs/nvim/lua/bindings.lua +++ b/configs/nvim/lua/bindings.lua @@ -1,81 +1,82 @@ -local map = vim.api.nvim_set_keymap -local opts = { noremap = true, silent = true } -vim.g.mapleader = ' ' -map('n', '', '"zdd"zp', opts) -- Move line down -map('n', '', '"zdd"zkP', opts) -- Move line up -map('i', '', '', opts) -- return to normalcy -map('n', '', ':q', opts) -- c-d to close file -map('i', '', 'coc#pum#visible() ? coc#pum#next(1) : "\\"', - {noremap = true, silent = true, expr = true}) -- next item in coc list -map('i', '', 'coc#pum#visible() ? coc#pum#prev(1) : "\\"', - {noremap = true, silent = true, expr = true}) -- prev item in coc list -map('n', '', '(coc-rename)', opts) -- rename -map('n', '', 'TagbarToggle', opts) -- show ctags -vim.keymap.set('n', 'zR', require('ufo').openAllFolds) -- ufo -vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) -- ufo -vim.keymap.set('t', '', '') -- close term -vim.keymap.set('n', '', function() - vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 0.9 -end) -vim.keymap.set('n', '', function() - vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 1.1 -end) +return function() + local map = vim.api.nvim_set_keymap + local opts = { noremap = true, silent = true } + vim.g.mapleader = ' ' + map('n', '', '"zdd"zp', opts) -- Move line down + map('n', '', '"zdd"zkP', opts) -- Move line up + map('i', '', '', opts) -- return to normalcy + map('n', '', ':q', opts) -- c-d to close file + map('i', '', 'coc#pum#visible() ? coc#pum#next(1) : "\\"', + {noremap = true, silent = true, expr = true}) -- next item in coc list + map('i', '', 'coc#pum#visible() ? coc#pum#prev(1) : "\\"', + {noremap = true, silent = true, expr = true}) -- prev item in coc list + map('n', '', '(coc-rename)', opts) -- rename + map('n', '', 'TagbarToggle', opts) -- show ctags + vim.keymap.set('n', 'zR', require('ufo').openAllFolds) -- ufo + vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) -- ufo + vim.keymap.set('t', '', '') -- close term + vim.keymap.set('n', '', function() + vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 0.9 + end) + vim.keymap.set('n', '', function() + vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 1.1 + end) -vim.g.tagbar_map_showproto = '' -- remove tagbar space bar conflict + vim.g.tagbar_map_showproto = '' -- remove tagbar space bar conflict --- whichkey -local wk = require('whichkey_setup') -wk.config{ - hide_statusline = true, - default_keymap_settings = { - silent=true, - noremap=true, - }, - default_mode='n' -} + -- whichkey + local wk = require('whichkey_setup') + wk.config{ + hide_statusline = true, + default_keymap_settings = { + silent=true, + noremap=true, + }, + default_mode='n' + } -wk.register_keymap('leader', { - s = { - name = '+jump', - d = {'(coc-definition)', 'definition'}, - r = {'(coc-references)', 'references'}, - t = {'(coc-type-definition)', 'type definition'}, - s = {'BLines', 'fzf current buffer'}, - S = {'Lines', 'fzf all buffers'}, - }, - nt = {'NERDTreeToggle', 'nerdtree'}, -- originally nt - rc = {'tabedit $MYVIMRCNERDTree ~/.config/nvim/', 'nvim config'}, -- originally rc - c = { - name = '+appearance', - d = {'set background=dark', 'dark'}, - l = {'set background=light', 'light'}, - }, - e = {'CocDiagnostics', 'errors'}, - h = {'call CocActionAsync("doHover")', 'hover'}, - q = { - name = "+modify", - q = {'(coc-fix-current)', 'quick fix'}, - c = {'(coc-codeaction-selected)', 'code actions'}, - }, - l = { - name = '+latex', - c = {'VimtexCompile', 'toggle compile'}, - }, - b = { - name = '+buffer', - m = {'h', 'left'}, - n = {'j', 'down'}, - e = {'k', 'up'}, - i = {'l', 'right'}, - M = {'H', 'move left'}, - N = {'J', 'move down'}, - E = {'K', 'move up'}, - I = {'L', 'move right'}, + wk.register_keymap('leader', { + s = { + name = '+jump', + d = {'(coc-definition)', 'definition'}, + r = {'(coc-references)', 'references'}, + t = {'(coc-type-definition)', 'type definition'}, + s = {'BLines', 'fzf current buffer'}, + S = {'Lines', 'fzf all buffers'}, + }, + nt = {'NERDTreeToggle', 'nerdtree'}, -- originally nt + rc = {'tabedit $MYVIMRCNERDTree ~/.config/nvim/', 'nvim config'}, -- originally rc + c = { + name = '+appearance', + d = {'set background=dark', 'dark'}, + l = {'set background=light', 'light'}, + }, + e = {'CocDiagnostics', 'errors'}, + h = {'call CocActionAsync("doHover")', 'hover'}, + q = { + name = "+modify", + q = {'(coc-fix-current)', 'quick fix'}, + c = {'(coc-codeaction-selected)', 'code actions'}, + }, + l = { + name = '+latex', + c = {'VimtexCompile', 'toggle compile'}, + }, + b = { + name = '+buffer', + m = {'h', 'left'}, + n = {'j', 'down'}, + e = {'k', 'up'}, + i = {'l', 'right'}, + M = {'H', 'move left'}, + N = {'J', 'move down'}, + E = {'K', 'move up'}, + I = {'L', 'move right'}, - t = {'Telescope buffers', 'goto fuzzy'}, - }, -}) + t = {'Telescope buffers', 'goto fuzzy'}, + }, + }) -return false +end diff --git a/configs/nvim/lua/nvcfg.lua b/configs/nvim/lua/nvcfg.lua index faf5613..4426497 100644 --- a/configs/nvim/lua/nvcfg.lua +++ b/configs/nvim/lua/nvcfg.lua @@ -1,34 +1,117 @@ -vim.opt.expandtab = true -- tabs to spaces -vim.opt.shiftwidth = 2 -- 4 spaces for < and > TODO: change back to 4 -vim.opt.softtabstop = 2 -- 4 spaces in a tab TODO: change back to 4 -vim.opt.number = true -- Show line numbers -vim.opt.relativenumber = true -- Show other line numbers as relative -vim.opt.smartindent = true -- Smart indent -vim.g.airline_powerline_fonts = 1 -- nice icons for airline -vim.g.wrap = false -- don't wrap lines -vim.g.termguicolors = true -- better colors -vim.g.gruvbox_italic = 1 -- gruvbox can use italic font -vim.g.material_style = 'oceanic' -- material theme -vim.g.bf_array_mode = 2 -- cyclic brainfuck memory -vim.g.bf_value_mode = 2 -- cyclic brainfuck values - --- load colorscheme -local file = io.open(vim.fn.stdpath('config') .. "/colorscheme", "r") -local cs = file:read("l") -file:close() -vim.cmd("colorscheme " .. cs) - --- ufo -vim.o.foldcolumn = '1' -vim.o.foldlevel = 99 -vim.o.foldlevelstart = 99 -vim.o.foldenable = true -require('ufo').setup() - --- vimtex -vim.g.vimtex_view_general_viewer = 'evince' - --- autoclose -require('autoclose').setup({}) - -return false +-- base64 encode and decode from http://lua-users.org/wiki/BaseSixtyFour +local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_' +-- encoding +function enc(data) + return ((data:gsub('.', function(x) + local r,b='',x:byte() + for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end + return r; + end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) + if (#x < 6) then return '' end + local c=0 + for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end + return b:sub(c+1,c+1) + end)..({ '', '==', '=' })[#data%3+1]) +end + +-- decoding +function dec(data) + data = string.gsub(data, '[^'..b..'=]', '') + return (data:gsub('.', function(x) + if (x == '=') then return '' end + local r,f='',(b:find(x)-1) + for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end + return r; + end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) + if (#x ~= 8) then return '' end + local c=0 + for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end + return string.char(c) + end)) +end + +return function() + vim.opt.expandtab = true -- tabs to spaces + vim.opt.shiftwidth = 2 -- 4 spaces for < and > TODO: change back to 4 + vim.opt.softtabstop = 2 -- 4 spaces in a tab TODO: change back to 4 + vim.opt.number = true -- Show line numbers + vim.opt.relativenumber = true -- Show other line numbers as relative + vim.opt.smartindent = true -- Smart indent + vim.g.airline_powerline_fonts = 1 -- nice icons for airline + vim.g.wrap = false -- don't wrap lines + vim.g.termguicolors = true -- better colors + vim.g.gruvbox_italic = 1 -- gruvbox can use italic font + vim.g.material_style = 'oceanic' -- material theme + vim.g.bf_array_mode = 2 -- cyclic brainfuck memory + vim.g.bf_value_mode = 2 -- cyclic brainfuck values + + -- load colorscheme + local file = io.open(vim.fn.stdpath('config') .. "/colorscheme", "r") + local cs = file:read("l") + file:close() + vim.cmd("colorscheme " .. cs) + + -- ufo + vim.o.foldcolumn = '1' + vim.o.foldlevel = 99 + vim.o.foldlevelstart = 99 + vim.o.foldenable = true + require('ufo').setup() + + -- vimtex + vim.g.vimtex_view_general_viewer = 'evince' + + -- -- autoclose + -- require('autoclose').setup({}) + + -- uiua pad + vim.api.nvim_create_user_command('UiuaPad', function(opts) + math.randomseed(os.time()) + + -- pad file + if vim.g.pad_file == nil then + vim.g.pad_file = vim.fn.stdpath('cache') .. '/pad_' .. math.random(100, 999) .. '.ua' + io.open(vim.g.pad_file, 'w'):close() + end + local pad_file = vim.g.pad_file + + -- open relevant buffers + vim.cmd.edit(pad_file) + vim.cmd.vsplit() + local pad_buf = vim.fn.bufnr('%') + local pad_win = vim.fn.win_getid(); + vim.cmd.wincmd('l') + vim.cmd.term('cd ' .. vim.fn.stdpath('cache') .. '; uiua watch --clear ' .. pad_file) + local term_buf = vim.fn.bufnr('%') + local term_win = vim.fn.win_getid(); + vim.cmd.wincmd('h') + + -- close either one when the other closes + vim.api.nvim_create_augroup("uiuapad", {clear = true}) + vim.api.nvim_create_autocmd("WinClosed", { + group = "uiuapad", + pattern = {tostring(pad_win), tostring(term_win)}, --pad_file, --{"*" .. pad_file, pad_file}, + callback = function(ev) + -- print(pad_buf) + -- print(term_buf) + -- print(vim.fn.bufexists( pad_buf )) + -- print(vim.fn.bufexists( term_buf )) + -- if vim.fn.bufexists(pad_buf) then vim.cmd("bdelete! " .. pad_buf) end + if vim.fn.bufexists(pad_buf) then vim.cmd("bdelete! " .. pad_buf) end + if vim.fn.bufexists(term_buf) then vim.cmd("bdelete! " .. term_buf) end + end, + }) + + end, {}) + + -- generate uiua pad link + vim.api.nvim_create_user_command('UiuaLink', function(opts) + local uiua_version_raw = vim.fn.system({"uiua", "--version"}) + print(uiua_version_raw) + local uiua_version = uiua_version_raw:sub(6, -2):gsub('%p', '_') + local buf_text = vim.fn.join(vim.fn.getline(0, '$'), '\n') + local url = "https://uiua.org/pad?src=" .. uiua_version .. "__" .. enc(buf_text) + print(url) + vim.fn.setreg('+', url) + end, {}) +end diff --git a/configs/nvim/lua/packages.lua b/configs/nvim/lua/packages.lua index 6ed8cde..ab14dfe 100644 --- a/configs/nvim/lua/packages.lua +++ b/configs/nvim/lua/packages.lua @@ -1,54 +1,55 @@ -vim.opt.termguicolors = true -require('packer').startup(function(use) - use 'wbthomason/packer.nvim' -- Ensure that Packer stays updated +return function() + vim.opt.termguicolors = true + require('packer').startup(function(use) + use 'wbthomason/packer.nvim' -- Ensure that Packer stays updated - -- Color Schemes - use { 'dracula/vim', as = 'dracula' } - use 'arcticicestudio/nord-vim' - use 'joshdick/onedark.vim' - use 'morhetz/gruvbox' - use 'sainnhe/everforest' - use 'sainnhe/edge' - use 'edeneast/nightfox.nvim' - use 'catppuccin/vim' - use 'drewtempelmeyer/palenight.vim' - use 'ghifarit53/tokyonight-vim' - use 'hzchirs/vim-material' + -- Color Schemes + use { 'dracula/vim', as = 'dracula' } + use 'arcticicestudio/nord-vim' + use 'joshdick/onedark.vim' + use 'morhetz/gruvbox' + use 'sainnhe/everforest' + use 'sainnhe/edge' + use 'edeneast/nightfox.nvim' + use 'catppuccin/vim' + use 'drewtempelmeyer/palenight.vim' + use 'ghifarit53/tokyonight-vim' + use 'hzchirs/vim-material' - -- Language Support - use { 'neoclide/coc.nvim', branch = 'release' } -- LSPs - use 'preservim/tagbar' -- Ctags - use 'lervag/vimtex' -- LaTeX - use 'sirtaj/vim-openscad' -- OpenSCAD syntax highlighting, etc. - use 'meatballs/vim-xonsh' -- xsh syntax highlighting - use 'vlelo/arduino-helper.nvim' -- Arduino - use 'habamax/vim-godot' -- GDScript - use 'fruit-in/brainfuck-vim' -- brainfuck - use 'mattn/emmet-vim' -- html emmets - use { - 'ModProg/cargo.nvim', - run = 'makers release', - config = function() - require"cargo".setup() - end - } + -- Language Support + use { 'neoclide/coc.nvim', branch = 'release' } -- LSPs + use 'preservim/tagbar' -- Ctags + use 'lervag/vimtex' -- LaTeX + use 'sirtaj/vim-openscad' -- OpenSCAD syntax highlighting, etc. + use 'meatballs/vim-xonsh' -- xsh syntax highlighting + use 'vlelo/arduino-helper.nvim' -- Arduino + use 'habamax/vim-godot' -- GDScript + use 'fruit-in/brainfuck-vim' -- brainfuck + use 'mattn/emmet-vim' -- html emmets + use { + 'ModProg/cargo.nvim', + run = 'makers release', + config = function() + require"cargo".setup() + end + } - use { - 'nvim-telescope/telescope.nvim', tag = '0.1.1', - requires = {{'nvim-lua/plenary.nvim'}} - } - use {'AckslD/nvim-whichkey-setup.lua', requires={ 'liuchengxu/vim-which-key' }} -- keybind helper popup - use 'junegunn/fzf.vim' -- fuzzy finder - use 'tpope/vim-commentary' -- Comment things - use 'preservim/nerdtree' -- NERDTree: File Viewer - use 'vim-airline/vim-airline' -- status bar - use 'm4xshen/autoclose.nvim' -- autoclosing brackets, not sure if I'll keep it - use 'tpope/vim-surround' -- surround text with brackets - use {'kevinhwang91/nvim-ufo', requires = 'kevinhwang91/promise-async'} -- better folding - use 'tpope/vim-fugitive' -- git - use 'junegunn/goyo.vim' -- focus mode + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.1', + requires = {{'nvim-lua/plenary.nvim'}} + } + use {'AckslD/nvim-whichkey-setup.lua', requires={ 'liuchengxu/vim-which-key' }} -- keybind helper popup + use 'junegunn/fzf.vim' -- fuzzy finder + use 'tpope/vim-commentary' -- Comment things + use 'preservim/nerdtree' -- NERDTree: File Viewer + use 'vim-airline/vim-airline' -- status bar + -- use 'm4xshen/autoclose.nvim' -- autoclosing brackets, not sure if I'll keep it + use 'tpope/vim-surround' -- surround text with brackets + use {'kevinhwang91/nvim-ufo', requires = 'kevinhwang91/promise-async'} -- better folding + use 'tpope/vim-fugitive' -- git + use 'junegunn/goyo.vim' -- focus mode - use 'ryanoasis/vim-devicons' -- icons for NERDTree (must be loaded last) -end) + use 'ryanoasis/vim-devicons' -- icons for NERDTree (must be loaded last) + end) -return false +end diff --git a/configs/nvim/plugin/packer_compiled.lua b/configs/nvim/plugin/packer_compiled.lua index a24a899..3ec40a0 100644 --- a/configs/nvim/plugin/packer_compiled.lua +++ b/configs/nvim/plugin/packer_compiled.lua @@ -79,11 +79,6 @@ _G.packer_plugins = { path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/arduino-helper.nvim", url = "https://github.com/vlelo/arduino-helper.nvim" }, - ["autoclose.nvim"] = { - loaded = true, - path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/autoclose.nvim", - url = "https://github.com/m4xshen/autoclose.nvim" - }, ["brainfuck-vim"] = { loaded = true, path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/brainfuck-vim",