From 26e2bee4e02c51a8860a320adbfcb6080c71171e Mon Sep 17 00:00:00 2001
From: Matei Adriel <rafaeladriel11@gmail.com>
Date: Fri, 31 Mar 2023 18:54:44 +0200
Subject: [PATCH] Jupytext and harpoon setup!

---
 dotfiles/neovim/lazy-lock.json              |  2 +
 dotfiles/neovim/lua/my/options.lua          |  2 +
 dotfiles/neovim/lua/my/plugins/harpoon.lua  | 30 ++++++++++++++
 dotfiles/neovim/lua/my/plugins/init.lua     | 42 ++++----------------
 dotfiles/neovim/lua/my/plugins/jupytext.lua | 43 +++++++++++++++++++++
 dotfiles/neovim/lua/my/plugins/lualine.lua  |  3 ++
 6 files changed, 88 insertions(+), 34 deletions(-)
 create mode 100644 dotfiles/neovim/lua/my/plugins/harpoon.lua
 create mode 100644 dotfiles/neovim/lua/my/plugins/jupytext.lua

diff --git a/dotfiles/neovim/lazy-lock.json b/dotfiles/neovim/lazy-lock.json
index a308e68..b4e5e5c 100644
--- a/dotfiles/neovim/lazy-lock.json
+++ b/dotfiles/neovim/lazy-lock.json
@@ -17,6 +17,7 @@
   "firenvim": { "branch": "master", "commit": "12003d9727bc5074ccb405b3d80e691c72d4859b" },
   "gitlinker.nvim": { "branch": "master", "commit": "cc59f732f3d043b626c8702cb725c82e54d35c25" },
   "glow.nvim": { "branch": "main", "commit": "5a8ccfb1876b1b2e29ea32c63221be6df45870d1" },
+  "harpoon": { "branch": "master", "commit": "f7040fd0c44e7a4010369136547de5604b9c22a1" },
   "hydra.nvim": { "branch": "master", "commit": "3ced42c0b6a6c85583ff0f221635a7f4c1ab0dd0" },
   "idris2-nvim": { "branch": "main", "commit": "dd850c1c67bcacd2395121b0898374fe9cdd228f" },
   "inc-rename.nvim": { "branch": "main", "commit": "21c23c379342a731a0c90f226601ec0434627b26" },
@@ -57,6 +58,7 @@
   "telescope-file-browser.nvim": { "branch": "master", "commit": "94fe37a1ea217dd2f90d91222bc1531521146ac3" },
   "telescope-fzf-native.nvim": { "branch": "main", "commit": "580b6c48651cabb63455e97d7e131ed557b8c7e2" },
   "telescope.nvim": { "branch": "master", "commit": "e960efa60e97df58e089b00270f09d60f27202c8" },
+  "undotree": { "branch": "master", "commit": "485f01efde4e22cb1ce547b9e8c9238f36566f21" },
   "venn.nvim": { "branch": "main", "commit": "c114563960b8fb1197695d42798d1f3e7190b798" },
   "vim-abolish": { "branch": "master", "commit": "880a562ff9176773897930b5a26a496f68e5a985" },
   "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" },
diff --git a/dotfiles/neovim/lua/my/options.lua b/dotfiles/neovim/lua/my/options.lua
index bb121f3..3e7c767 100644
--- a/dotfiles/neovim/lua/my/options.lua
+++ b/dotfiles/neovim/lua/my/options.lua
@@ -35,6 +35,8 @@ function M.setup()
   vim.opt.wildmode = { "list", "longest" } -- Command-line completion mode
   vim.opt.completeopt = { "menu", "menuone", "noselect" }
 
+  vim.opt.undofile = true -- persist undos!!
+
   -- Set leader
   vim.g.mapleader = " "
 
diff --git a/dotfiles/neovim/lua/my/plugins/harpoon.lua b/dotfiles/neovim/lua/my/plugins/harpoon.lua
new file mode 100644
index 0000000..c5b8412
--- /dev/null
+++ b/dotfiles/neovim/lua/my/plugins/harpoon.lua
@@ -0,0 +1,30 @@
+local M = {
+  "ThePrimeagen/harpoon",
+}
+
+local function bindHarpoon(key, index)
+  vim.keymap.set("n", "<C-s>" .. key, function()
+    require("harpoon.ui").nav_file(index)
+  end, { desc = "Harpoon file " .. index })
+end
+
+function M.init()
+  vim.keymap.set("n", "<leader>h", function()
+    require("harpoon.mark").add_file()
+  end, { desc = "Add file to [h]arpoon" })
+  vim.keymap.set("n", "<C-a>", function()
+    require("harpoon.ui").toggle_quick_menu()
+  end, { desc = "Toggle harpoon quickmenu" })
+
+  bindHarpoon("q", 1)
+  bindHarpoon("w", 2)
+  bindHarpoon("e", 3)
+  bindHarpoon("r", 4)
+  bindHarpoon("a", 5)
+  bindHarpoon("s", 6)
+  bindHarpoon("d", 7)
+  bindHarpoon("f", 8)
+  bindHarpoon("z", 9)
+end
+
+return M
diff --git a/dotfiles/neovim/lua/my/plugins/init.lua b/dotfiles/neovim/lua/my/plugins/init.lua
index 0891066..089d8ac 100644
--- a/dotfiles/neovim/lua/my/plugins/init.lua
+++ b/dotfiles/neovim/lua/my/plugins/init.lua
@@ -215,41 +215,15 @@ return {
   },
 
   {
-    "goerz/jupytext.vim",
-    lazy = false, -- Otherwise I can't get this to work with nvim *.ipynb
-    cond = env.vscode.not_active(),
-    config = function()
-      -- Use %% as cell delimiter
-      vim.g.jupytext_fmt = "py:percent"
-      -- vim.opt.foldmarker = "%%,%%"
-    end,
+    "mbbill/undotree",
+    cmd = "UndotreeToggle",
     init = function()
-      vim.cmd([[
-        function GetJupytextFold(linenum)
-            if getline(a:linenum) =~ "^#\\s%%"
-                " start fold
-                return ">1"
-            elseif getline(a:linenum + 1) =~ "^#\\s%%"
-                return "<1"
-            else
-                return "-1"
-            endif
-        endfunction
-      ]])
-
-      -- Set the correct foldexpr
-      vim.api.nvim_create_autocmd("BufEnter", {
-        pattern = { "*.ipynb" },
-        group = vim.api.nvim_create_augroup("JupytextFoldExpr", {}),
-        callback = function()
-          vim.cmd([[
-            setlocal foldexpr=GetJupytextFold(v:lnum)
-            setlocal foldmethod=expr
-            " Deletes and pastes all text. Used to refresh folds.
-            :norm ggVGdpggdd
-          ]])
-        end,
-      })
+      vim.keymap.set(
+        "n",
+        "<leader>u",
+        "<cmd>UndotreeToggle<cr>",
+        { desc = "[U]ndo tree" }
+      )
     end,
   },
 }
diff --git a/dotfiles/neovim/lua/my/plugins/jupytext.lua b/dotfiles/neovim/lua/my/plugins/jupytext.lua
new file mode 100644
index 0000000..eba887a
--- /dev/null
+++ b/dotfiles/neovim/lua/my/plugins/jupytext.lua
@@ -0,0 +1,43 @@
+local env = require("my.helpers.env")
+
+local M = {
+  "goerz/jupytext.vim",
+  lazy = false, -- Otherwise I can't get this to work with nvim *.ipynb
+  cond = env.vscode.not_active(),
+}
+
+function M.config()
+  -- Use %% as cell delimiter
+  vim.g.jupytext_fmt = "py:percent"
+end
+
+function M.init()
+  vim.cmd([[
+        function GetJupytextFold(linenum)
+            if getline(a:linenum) =~ "^#\\s%%"
+                " start fold
+                return ">1"
+            elseif getline(a:linenum + 1) =~ "^#\\s%%"
+                return "<1"
+            else
+                return "-1"
+            endif
+        endfunction
+      ]])
+
+  -- Set the correct foldexpr
+  vim.api.nvim_create_autocmd("BufEnter", {
+    pattern = { "*.ipynb" },
+    group = vim.api.nvim_create_augroup("JupytextFoldExpr", {}),
+    callback = function()
+      vim.cmd([[
+            setlocal foldexpr=GetJupytextFold(v:lnum)
+            setlocal foldmethod=expr
+            " Deletes and pastes all text. Used to refresh folds.
+            :norm ggVGdpggdd
+          ]])
+    end,
+  })
+end
+
+return M
diff --git a/dotfiles/neovim/lua/my/plugins/lualine.lua b/dotfiles/neovim/lua/my/plugins/lualine.lua
index 160486d..85f23e6 100644
--- a/dotfiles/neovim/lua/my/plugins/lualine.lua
+++ b/dotfiles/neovim/lua/my/plugins/lualine.lua
@@ -12,6 +12,9 @@ function M.config()
       component_separators = { left = "", right = "" },
       section_separators = { left = "", right = "" },
       theme = "auto",
+      disabled_filetypes = {
+        "undotree"
+      }
     },
     sections = {
       lualine_a = { "branch" },