From 48eb0d8d60ed4f6909c2b3d0d773bc7304ffdccc Mon Sep 17 00:00:00 2001 From: Tyler White Date: Mon, 29 Jan 2024 16:53:18 +0800 Subject: [PATCH] Switched to lazy vim as packer stopped working. Will need to clear the .local/shared/nvim/site directory to stop using the packer packages. I guess I made a build and run? that's neat. --- .gitignore | 1 + init.lua | 23 +++++++++++++++++++++-- lua/buildcmd.lua | 46 +++++++++++++++++++++++++++++++++++++++++++++ lua/keybindings.lua | 1 + lua/packer_init.lua | 42 ++++++++++++++++++++--------------------- 5 files changed, 90 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 8fe88e8..ba310e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ [Pp]lugin/ +lazy-lock.json diff --git a/init.lua b/init.lua index b60614f..b381aea 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,25 @@ --- Only required if you have packer configured as `opt` +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) +require("lazy").setup({ + "morhetz/gruvbox", + "neovim/nvim-lspconfig", + { "nvim-telescope/telescope.nvim", dependencies = {"nvim-lua/plenary.nvim"} }, + "windwp/nvim-autopairs", + "sheerun/vim-polyglot", + "habamax/vim-godot", + }) require('statusline') -require('packer_init') +--require('packer_init') require('keybindings') --vim.opt.guicursor = " " diff --git a/lua/buildcmd.lua b/lua/buildcmd.lua index c8349b9..da990dc 100644 --- a/lua/buildcmd.lua +++ b/lua/buildcmd.lua @@ -28,6 +28,25 @@ local function get_build_cmd() return "" end +local function get_buildnrun_cmd() + for path, type in vim.fs.dir(vim.fn.getcwd(), nil) + do + if (path == "build.zig") then + return "zig build run" + end + -- TODO(twig): build and run on other langauges + --if (path == "build.bat" or path == "build.sh") then + -- if (vim.loop.os_uname().sysname == "Windows_NT") then + -- -- TODO(twig): if I move to llvm this should work, right now cl doesn't work because nvim spawns a command prompt that doesn't have vcvars in it (nor does it have my stuff) + -- return "build.bat" + -- else + -- -- TODO(twig): this is untested! + -- return "./build.sh" + -- end + --end + end + return "" +end function save_all_and_build() if job_id then print("Job processing") @@ -53,3 +72,30 @@ function save_all_and_build() job_id = vim.fn.termopen(build_cmd, {on_exit = job_exit}) vim.api.nvim_buf_set_name(job_buffer, '[build]') end + +function save_all_and_buildnrun() +if job_id then + print("Job processing") + return + end + + local opts = {} + vim.api.nvim_exec('wa', opts) + + if not has_buffer() then + job_buffer = vim.api.nvim_create_buf(true, true) + end + local job_window = vim.fn.bufwinnr(job_buffer) + if job_window ~= -1 then + vim.cmd(job_window .. ' wincmd w') + else + vim.cmd('buffer ' .. job_buffer) + end + vim.api.nvim_buf_set_option(job_buffer, 'filetype', 'build') + vim.api.nvim_buf_set_option(job_buffer, 'modified', false) + -- THis looks at files in the cwd and decides if there is something to build (build.zig for zig, build.bat/.sh for c++) + local build_cmd = get_build_cmd() + job_id = vim.fn.termopen(build_cmd, {on_exit = job_exit}) + vim.api.nvim_buf_set_name(job_buffer, '[build]') +end + diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 7659be7..e120648 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -10,6 +10,7 @@ vim.keymap.set('n', 'e', 'Ex', opts) vim.keymap.set('n', 'ff', tbuiltin.find_files, opts) vim.keymap.set('n', 'fb', 'Telescope buffers', opts) vim.keymap.set('n', 'bb', save_all_and_build, opts) +vim.keymap.set('n', 'br', save_all_and_buildnrun, opts) -- TODO: get fancy and read the commentstring and user vim.keymap.set('i', '', '// TODO(twig): ', opts) vim.keymap.set('i', '', '// NOTE(twig): ', opts) diff --git a/lua/packer_init.lua b/lua/packer_init.lua index fdf3312..6fc32fc 100644 --- a/lua/packer_init.lua +++ b/lua/packer_init.lua @@ -1,21 +1,21 @@ -vim.cmd [[packadd packer.nvim]] - -return require('packer').startup(function(use) - -- Packer can manage itself - use 'wbthomason/packer.nvim' - -- themes - --use 'sainnhe/everforest' - --use 'sainnhe/sonokai' - --use { 'tomasr/molokai' } - use 'morhetz/gruvbox' - -- Treesitter - --use { 'nvim-treesitter/nvim-treesitter' } - --use 'nvim-treesitter/nvim-treesitter-context' - --use { 'nvim-treesitter/playground', requires = {{'nvim-treesitter/nvim-treesitter'}} } - -- Utils - use 'neovim/nvim-lspconfig' - use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = {{'nvim-lua/plenary.nvim'}} } - use { 'windwp/nvim-autopairs' } - use 'sheerun/vim-polyglot' - use 'habamax/vim-godot' -end) +--vim.cmd [[packadd packer.nvim]] +-- +--return require('packer').startup(function(use) +-- -- Packer can manage itself +-- use 'wbthomason/packer.nvim' +-- -- themes +-- --use 'sainnhe/everforest' +-- --use 'sainnhe/sonokai' +-- --use { 'tomasr/molokai' } +-- use 'morhetz/gruvbox' +-- -- Treesitter +-- --use { 'nvim-treesitter/nvim-treesitter' } +-- --use 'nvim-treesitter/nvim-treesitter-context' +-- --use { 'nvim-treesitter/playground', requires = {{'nvim-treesitter/nvim-treesitter'}} } +-- -- Utils +-- use 'neovim/nvim-lspconfig' +-- use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = {{'nvim-lua/plenary.nvim'}} } +-- use { 'windwp/nvim-autopairs' } +-- use 'sheerun/vim-polyglot' +-- use 'habamax/vim-godot' +--end)