|
|
|
@ -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.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
|
|
|
|
@ -28,7 +61,57 @@ require('ufo').setup()
|
|
|
|
|
-- vimtex
|
|
|
|
|
vim.g.vimtex_view_general_viewer = 'evince'
|
|
|
|
|
|
|
|
|
|
-- autoclose
|
|
|
|
|
require('autoclose').setup({})
|
|
|
|
|
-- -- 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, {})
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|