瀏覽代碼

testing autosave config poetnetially unstable

christianchiarulli 4 年之前
父節點
當前提交
0e2ad0c1fe
共有 4 個文件被更改,包括 66 次插入38 次删除
  1. 33 29
      lua/lv-floatterm/init.lua
  2. 10 2
      lua/lv-utils/init.lua
  3. 13 3
      lua/lv-which-key/init.lua
  4. 10 4
      lua/plugins.lua

+ 33 - 29
lua/lv-floatterm/init.lua

@@ -1,39 +1,43 @@
 local M = {}
 
 M.config = function()
-    require'FTerm'.setup({
-        dimensions  = {
-            height = 0.8,
-            width = 0.8,
-            x = 0.5,
-            y = 0.5
-        },
-        border = 'single' -- or 'double'
-    })
+  local status_ok, fterm = pcall(require, "FTerm")
+  if not status_ok then
+    return
+  end
 
-    -- Create LazyGit Terminal
-    local term = require("FTerm.terminal")
-    local lazy = term:new():setup({
-        cmd = "lazygit",
-        dimensions = {
-            height = 0.9,
-            width = 0.9
-        }
-    })
+  fterm.setup {
+    dimensions = {
+      height = 0.8,
+      width = 0.8,
+      x = 0.5,
+      y = 0.5,
+    },
+    border = "single", -- or 'double'
+  }
 
-    local function is_installed(exe)
-        return vim.fn.executable(exe) == 1
-    end
+  -- Create LazyGit Terminal
+  local term = require "FTerm.terminal"
+  local lazy = term:new():setup {
+    cmd = "lazygit",
+    dimensions = {
+      height = 0.9,
+      width = 0.9,
+    },
+  }
+
+  local function is_installed(exe)
+    return vim.fn.executable(exe) == 1
+  end
 
-     -- Use this to toggle gitui in a floating terminal
-    function _G.__fterm_lazygit()
-        if is_installed("lazygit") ~= true then
-            print("Please install lazygit. Check documentation for more information")
-            return
-        end
-        lazy:toggle()
+  -- Use this to toggle gitui in a floating terminal
+  function _G.__fterm_lazygit()
+    if is_installed "lazygit" ~= true then
+      print "Please install lazygit. Check documentation for more information"
+      return
     end
+    lazy:toggle()
+  end
 end
 
 return M
-

+ 10 - 2
lua/lv-utils/init.lua

@@ -1,5 +1,12 @@
 local lv_utils = {}
 
+function lv_utils.reload_lv_config()
+  vim.cmd "source ~/.config/nvim/lv-config.lua"
+  vim.cmd "source ~/.config/nvim/lua/plugins.lua"
+  vim.cmd ":PackerCompile"
+  vim.cmd ":PackerInstall"
+end
+
 function lv_utils.define_augroups(definitions) -- {{{1
   -- Create autocommand groups based on the passed definitions
   --
@@ -24,7 +31,7 @@ end
 
 lv_utils.define_augroups {
 
-    _user_autocommands = O.user_autocommands,
+  _user_autocommands = O.user_autocommands,
   _general_settings = {
     {
       "TextYankPost",
@@ -46,6 +53,7 @@ lv_utils.define_augroups {
       "*",
       "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
     },
+    { "BufWritePost", "lv-config.lua", "lua require('lv-utils').reload_lv_config()" },
     { "VimLeavePre", "*", "set title set titleold=" },
   },
   -- _solidity = {
@@ -65,7 +73,7 @@ lv_utils.define_augroups {
   },
   _auto_resize = {
     -- will cause split windows to be resized evenly if main window is resized
-    {'VimResized ', '*', 'wincmd ='},
+    { "VimResized ", "*", "wincmd =" },
   },
   -- _mode_switching = {
   --   -- will switch between absolute and relative line numbers depending on mode

+ 13 - 3
lua/lv-which-key/init.lua

@@ -120,7 +120,7 @@ local mappings = {
     name = "Packer",
     c = { "<cmd>PackerCompile<cr>", "Compile" },
     i = { "<cmd>PackerInstall<cr>", "Install" },
-    r = { ":luafile %<cr>", "Reload" },
+    r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" },
     s = { "<cmd>PackerSync<cr>", "Sync" },
     u = { "<cmd>PackerUpdate<cr>", "Update" },
   },
@@ -266,9 +266,19 @@ end
 if O.plugin.floatterm.active then
   vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
   vim.api.nvim_set_keymap("n", "<A-i>", "<CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true })
-  vim.api.nvim_set_keymap("t", "<A-i>", "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true })
+  vim.api.nvim_set_keymap(
+    "t",
+    "<A-i>",
+    "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>",
+    { noremap = true, silent = true }
+  )
   vim.api.nvim_set_keymap("n", "<A-l>", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
-  vim.api.nvim_set_keymap("t", "<A-l>", "<C-\\><C-n><CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
+  vim.api.nvim_set_keymap(
+    "t",
+    "<A-l>",
+    "<C-\\><C-n><CMD>lua _G.__fterm_lazygit()<CR>",
+    { noremap = true, silent = true }
+  )
   mappings["gg"] = "LazyGit"
 end
 if O.plugin.telescope_project.active then

+ 10 - 4
lua/plugins.lua

@@ -202,14 +202,18 @@ return require("packer").startup(function(use)
   use {
     "mfussenegger/nvim-dap",
     config = function()
-      require "dap"
+      local status_ok, dap = pcall(require, "dap")
+      if not status_ok then
+        return
+      end
+      -- require "dap"
       vim.fn.sign_define("DapBreakpoint", {
         text = "",
         texthl = "LspDiagnosticsSignError",
         linehl = "",
         numhl = "",
       })
-      require("dap").defaults.fallback.terminal_win_cmd = "50vsplit new"
+      dap.defaults.fallback.terminal_win_cmd = "50vsplit new"
     end,
     disable = not O.plugin.debug.active,
   }
@@ -219,7 +223,7 @@ return require("packer").startup(function(use)
     "numToStr/FTerm.nvim",
     event = "BufWinEnter",
     config = function()
-        require('lv-floatterm').config()
+      require("lv-floatterm").config()
     end,
     disable = not O.plugin.floatterm.active,
   }
@@ -235,7 +239,9 @@ return require("packer").startup(function(use)
   use {
     "nvim-telescope/telescope-project.nvim",
     event = "BufRead",
-    setup = function () vim.cmd[[packadd telescope.nvim]] end,
+    setup = function()
+      vim.cmd [[packadd telescope.nvim]]
+    end,
     disable = not O.plugin.telescope_project.active,
   }