uiua pad and link (plus some other stuff)

main
aprzn 1 year ago
parent a9d3bceb9f
commit 7d462d0294

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

@ -1,26 +1,27 @@
-- 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", {
vim.api.nvim_create_augroup("aprzn", {clear = true})
vim.api.nvim_create_autocmd("BufWritePost", {
group = "aprzn",
pattern = {"*/.config/nvim/*.lua", "*/.config/nvim/lua/*.lua"},
pattern = {"*/nvim/*.lua", "*/nvim/lua/*.lua"},
command = "source $MYVIMRC"
}) -- reload config file on save
}) -- 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", {
vim.api.nvim_create_autocmd("CursorHold", {
group = "aprzn",
pattern = {"*"},
command = "call CocActionAsync('highlight')"
}) -- highlight matching tokens when not moving cursor
}) -- highlight matching tokens when not moving cursor
vim.api.nvim_create_autocmd("ColorScheme", {
vim.api.nvim_create_autocmd("ColorScheme", {
group = "aprzn",
pattern = {"*"},
callback = function(ev)
@ -29,22 +30,22 @@ vim.api.nvim_create_autocmd("ColorScheme", {
file:write(cs)
file:close()
end
}) -- save colorscheme
}) -- save colorscheme
vim.api.nvim_create_autocmd("BufWritePost", {
vim.api.nvim_create_autocmd("BufWritePost", {
group = "aprzn",
pattern = "*.ua",
callback = function(ev)
vim.cmd("silent !uiua fmt " .. vim.fn.expand("<amatch>"))
end,
}) -- format uiua on save
}) -- format uiua on save
vim.api.nvim_create_autocmd("FileType", {
vim.api.nvim_create_autocmd("FileType", {
group = "aprzn",
pattern = "*",
callback = function(ev)
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.opt_local.commentstring = "# %s"
else
@ -52,6 +53,5 @@ vim.api.nvim_create_autocmd("FileType", {
end
end
end,
})
return false
})
end

@ -1,42 +1,43 @@
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
vim.g.mapleader = ' '
map('n', '<m-n>', '"zdd"zp', opts) -- Move line down
map('n', '<m-e>', '"zdd"zkP', opts) -- Move line up
map('i', '<c-t>', '<esc>', opts) -- return to normalcy
map('n', '<c-d>', ':q<cr>', opts) -- c-d to close file
map('i', '<tab>', 'coc#pum#visible() ? coc#pum#next(1) : "\\<Tab>"',
return function()
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
vim.g.mapleader = ' '
map('n', '<m-n>', '"zdd"zp', opts) -- Move line down
map('n', '<m-e>', '"zdd"zkP', opts) -- Move line up
map('i', '<c-t>', '<esc>', opts) -- return to normalcy
map('n', '<c-d>', ':q<cr>', opts) -- c-d to close file
map('i', '<tab>', 'coc#pum#visible() ? coc#pum#next(1) : "\\<Tab>"',
{noremap = true, silent = true, expr = true}) -- next item in coc list
map('i', '<s-tab>', 'coc#pum#visible() ? coc#pum#prev(1) : "\\<C-h>"',
map('i', '<s-tab>', 'coc#pum#visible() ? coc#pum#prev(1) : "\\<C-h>"',
{noremap = true, silent = true, expr = true}) -- prev item in coc list
map('n', '<F2>', '<Plug>(coc-rename)', opts) -- rename
map('n', '<F8>', '<Cmd>TagbarToggle<cr>', 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', '<c-d><c-d>', '<c-\\><c-n>') -- close term
vim.keymap.set('n', '<c-->', function()
map('n', '<F2>', '<Plug>(coc-rename)', opts) -- rename
map('n', '<F8>', '<Cmd>TagbarToggle<cr>', 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', '<c-t>', '<c-\\><c-n>') -- close term
vim.keymap.set('n', '<c-->', function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 0.9
end)
vim.keymap.set('n', '<c-=>', function()
end)
vim.keymap.set('n', '<c-=>', function()
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * 1.1
end)
end)
vim.g.tagbar_map_showproto = '<C-Space>' -- remove tagbar space bar conflict
vim.g.tagbar_map_showproto = '<C-Space>' -- remove tagbar space bar conflict
-- whichkey
local wk = require('whichkey_setup')
wk.config{
-- 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', {
wk.register_keymap('leader', {
s = {
name = '+jump',
d = {'<Plug>(coc-definition)', 'definition'},
@ -76,6 +77,6 @@ wk.register_keymap('leader', {
t = {'<cmd>Telescope buffers<cr>', 'goto fuzzy'},
},
})
})
return false
end

@ -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

@ -1,5 +1,6 @@
vim.opt.termguicolors = true
require('packer').startup(function(use)
return function()
vim.opt.termguicolors = true
require('packer').startup(function(use)
use 'wbthomason/packer.nvim' -- Ensure that Packer stays updated
-- Color Schemes
@ -42,13 +43,13 @@ require('packer').startup(function(use)
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 '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)
end)
return false
end

@ -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",

Loading…
Cancel
Save