uiua pad and link (plus some other stuff)

main
aprzn 1 year ago
parent a9d3bceb9f
commit 7d462d0294

@ -1,5 +1,5 @@
require('packages') require('packages')()
require('bindings') require('bindings')()
require('autocmds') require('autocmds')()
require('nvcfg') require('nvcfg')()
require('local') require('local')()

@ -1,10 +1,11 @@
return function()
-- detect filetype -- detect filetype
vim.filetype.add({extension = {ua = "uiua" }}) vim.filetype.add({extension = {ua = "uiua" }})
vim.api.nvim_create_augroup("aprzn", {clear = true}) vim.api.nvim_create_augroup("aprzn", {clear = true})
vim.api.nvim_create_autocmd("BufWritePost", { vim.api.nvim_create_autocmd("BufWritePost", {
group = "aprzn", group = "aprzn",
pattern = {"*/.config/nvim/*.lua", "*/.config/nvim/lua/*.lua"}, pattern = {"*/nvim/*.lua", "*/nvim/lua/*.lua"},
command = "source $MYVIMRC" command = "source $MYVIMRC"
}) -- reload config file on save }) -- reload config file on save
@ -44,7 +45,7 @@ vim.api.nvim_create_autocmd("FileType", {
pattern = "*", pattern = "*",
callback = function(ev) callback = function(ev)
if vim.g.neovide then if vim.g.neovide then
if ev.match == "uiua" then if ev.match == "uiua" then -- use uiua386 when editing uiua
vim.o.guifont = "Uiua386:h14" vim.o.guifont = "Uiua386:h14"
vim.opt_local.commentstring = "# %s" vim.opt_local.commentstring = "# %s"
else else
@ -53,5 +54,4 @@ vim.api.nvim_create_autocmd("FileType", {
end end
end, end,
}) })
end
return false

@ -1,3 +1,4 @@
return function()
local map = vim.api.nvim_set_keymap local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
vim.g.mapleader = ' ' vim.g.mapleader = ' '
@ -13,7 +14,7 @@ map('n', '<F2>', '<Plug>(coc-rename)', opts) -- rename
map('n', '<F8>', '<Cmd>TagbarToggle<cr>', opts) -- show ctags map('n', '<F8>', '<Cmd>TagbarToggle<cr>', opts) -- show ctags
vim.keymap.set('n', 'zR', require('ufo').openAllFolds) -- ufo vim.keymap.set('n', 'zR', require('ufo').openAllFolds) -- ufo
vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) -- ufo vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) -- ufo
vim.keymap.set('t', '<c-d><c-d>', '<c-\\><c-n>') -- close term vim.keymap.set('t', '<c-t>', '<c-\\><c-n>') -- close term
vim.keymap.set('n', '<c-->', function() vim.keymap.set('n', '<c-->', function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 0.9 vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 0.9
end) end)
@ -78,4 +79,4 @@ wk.register_keymap('leader', {
}, },
}) })
return false end

@ -1,3 +1,36 @@
-- 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.expandtab = true -- tabs to spaces
vim.opt.shiftwidth = 2 -- 4 spaces for < and > TODO: change back to 4 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.softtabstop = 2 -- 4 spaces in a tab TODO: change back to 4
@ -28,7 +61,57 @@ require('ufo').setup()
-- vimtex -- vimtex
vim.g.vimtex_view_general_viewer = 'evince' vim.g.vimtex_view_general_viewer = 'evince'
-- autoclose -- -- autoclose
require('autoclose').setup({}) -- 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, {})
return false -- 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

@ -1,3 +1,4 @@
return function()
vim.opt.termguicolors = true vim.opt.termguicolors = true
require('packer').startup(function(use) require('packer').startup(function(use)
use 'wbthomason/packer.nvim' -- Ensure that Packer stays updated use 'wbthomason/packer.nvim' -- Ensure that Packer stays updated
@ -42,7 +43,7 @@ require('packer').startup(function(use)
use 'tpope/vim-commentary' -- Comment things use 'tpope/vim-commentary' -- Comment things
use 'preservim/nerdtree' -- NERDTree: File Viewer use 'preservim/nerdtree' -- NERDTree: File Viewer
use 'vim-airline/vim-airline' -- status bar use 'vim-airline/vim-airline' -- status bar
use 'm4xshen/autoclose.nvim' -- autoclosing brackets, not sure if I'll keep it -- use 'm4xshen/autoclose.nvim' -- autoclosing brackets, not sure if I'll keep it
use 'tpope/vim-surround' -- surround text with brackets use 'tpope/vim-surround' -- surround text with brackets
use {'kevinhwang91/nvim-ufo', requires = 'kevinhwang91/promise-async'} -- better folding use {'kevinhwang91/nvim-ufo', requires = 'kevinhwang91/promise-async'} -- better folding
use 'tpope/vim-fugitive' -- git use 'tpope/vim-fugitive' -- git
@ -51,4 +52,4 @@ require('packer').startup(function(use)
use 'ryanoasis/vim-devicons' -- icons for NERDTree (must be loaded last) use 'ryanoasis/vim-devicons' -- icons for NERDTree (must be loaded last)
end) end)
return false end

@ -79,11 +79,6 @@ _G.packer_plugins = {
path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/arduino-helper.nvim", path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/arduino-helper.nvim",
url = "https://github.com/vlelo/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"] = { ["brainfuck-vim"] = {
loaded = true, loaded = true,
path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/brainfuck-vim", path = "/home/aprzn/.local/share/nvim/site/pack/packer/start/brainfuck-vim",

Loading…
Cancel
Save