Skip to content

Commit

Permalink
Add persisted.nvim plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticalDevil committed Oct 16, 2023
1 parent f03a600 commit 5551533
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
53 changes: 53 additions & 0 deletions lua/configs/plugin/persisted.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local status, persisted = pcall(require, "persisted")
if not status then
vim.notify("persistence.nvim not found", "error")
return
end

local ignore_filetype = {
"alpha",
"aerial",
"neo-tree",
"nerdtree",
"NvimTree",
"dashboard",
"Trouble",
"DiffViewFiles",
"dapui_stacks",
"dapui_scopes",
"dapui_watches",
"dapui_breakpoints",
"dapui_console",
"dap-repl",
}

persisted.setup({
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
silent = false, -- silent nvim message when sourcing session file
use_git_branch = false, -- create session files based on the branch of the git enabled repository
autosave = true, -- automatically save session files when exiting Neovim
should_autosave = function()
-- do not autosave if the alpha dashboard is the current filetype
if ignore_filetype[vim.bo.filetype] then
return false
end
return true
end, -- function to determine if a session should be autosaved
autoload = false, -- automatically load the session for the cwd on Neovim startup
on_autoload_no_session = nil, -- function to run when `autoload = true` but there is no session to load
follow_cwd = true, -- change session file name to match current working directory if it changes
allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading
telescope = { -- options for the telescope extension
reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted
},
})

-- restore the session for the current directory
vim.api.nvim_set_keymap("n", "<leader>ps", [[<cmd>lua require("persisted").load()<cr>]], {})

-- restore the last session
vim.api.nvim_set_keymap("n", "<leader>pl", [[<cmd>lua require("persisted").load({ last = true })<cr>]], {})

-- stop Persistence => session won't be saved on exit
vim.api.nvim_set_keymap("n", "<leader>pd", [[<cmd>lua require("persisted").stop()<cr>]], {})
19 changes: 17 additions & 2 deletions lua/configs/plugin/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ local utils = require("utils")
local trouble = require("trouble.providers.telescope")
local builtin = require("telescope.builtin")

local extensions_list =
{ "env", "ui-select", "noice", "neoclip", "aerial", "fzf", "file_browser", "project", "scope", "agrolens" }
local extensions_list = {
"env",
"ui-select",
"noice",
"neoclip",
"aerial",
"fzf",
"file_browser",
"project",
"scope",
"agrolens",
"persisted",
}

for _, value in pairs(extensions_list) do
telescope.load_extension(value)
Expand Down Expand Up @@ -91,6 +102,9 @@ local opts = {
disable_indentation = false,
aliases = {},
},
persisted = {
layout_config = { width = 0.55, height = 0.55 },
},
},
}

Expand All @@ -103,3 +117,4 @@ utils.keymap("n", "<space>fb", "<CMD>Telescope file_browser<CR>")
utils.keymap("n", "<space>no", "<CMD>Telescope noice<CR>")
utils.keymap("n", "<space>cl", "<CMD>Telescope neoclip<CR>")
utils.keymap("n", "<space>pj", "<CMD>Telescope project<CR>")
utils.keymap("n", "<space>ps", "<CMD>Telescope persisted<CR>")
2 changes: 1 addition & 1 deletion lua/configs/plugin/yanky.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local opts = {
},
}

vim.keymap.set("n", "<leader>p", function()
vim.keymap.set("n", "<leader>yp", function()
require("telescope").extensions.yank_history.yank_history({})
end, { desc = "Open Yank History" })
vim.keymap.set({ "n", "x" }, "y", "<Plug>(YankyYank)", { desc = "Yank text" })
Expand Down
9 changes: 9 additions & 0 deletions lua/plugins/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ return {
cmd = "ParinferOn",
build = "cargo build --release",
},
-- persisted.nvim
-- Simple session management for Neovim, autoloading and Telescope support(forked folke/persistence.nvim)
{
"olimorris/persisted.nvim",
event = "BufReadPre", -- this will only start session saving when an actual file was opened
config = function()
require("configs.plugin.persisted")
end,
},
-- plenary.nvim
-- plenary: full; complete; entire; absolute; unqualified.
-- All the lua functions I don't want to write twice.
Expand Down

0 comments on commit 5551533

Please sign in to comment.