1

Refresh generated neovim config

This commit is contained in:
2024-08-15 13:01:03 +02:00
parent 64b51cf53a
commit f5af8e2b28
1836 changed files with 38979 additions and 31094 deletions

View File

@ -80,7 +80,7 @@ EOF
If you wish to use session _autoloading_ alongside a dashboard plugin, it is recommended that you give this plugin a greater loading priority. With **Packer** the `after` config option can be used and in **Lazy.nvim**, the `priority` property.
### Telescope extension
**Telescope extension**
Ensure that the telescope extension is loaded with:
@ -105,7 +105,7 @@ require('telescope').setup({
## :rocket: Usage
### Commands
**Commands**
The plugin comes with a number of commands:
@ -118,7 +118,7 @@ The plugin comes with a number of commands:
- `:SessionLoadFromFile` - Load a session from a given path
- `:SessionDelete` - Delete the current session
### Telescope extension
**Telescope extension**
<!-- panvimdoc-ignore-start -->
@ -135,7 +135,7 @@ The Telescope extension may be opened via `:Telescope persisted`. The available
- `<C-c>` - Copy the session file
- `<C-d>` - Delete the session file
### Global variables
**Global variables**
The plugin sets a number of global variables throughout its lifecycle:
@ -145,12 +145,13 @@ The plugin sets a number of global variables throughout its lifecycle:
## :wrench: Configuration
### Defaults
**Defaults**
The plugin comes with the following defaults:
```lua
require("persisted").setup({
log_level = "ERROR", -- One of "TRACE", "DEBUG", "ERROR"
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 a git enabled repository
@ -179,14 +180,14 @@ require("persisted").setup({
})
```
### What is saved in the session?
**What is saved in the session?**
As the plugin uses Vim's `:mksession` command then you may change the `vim.o.sessionoptions` value to determine what to write into the session. Please see `:h sessionoptions` for more information.
> [!NOTE]
> The author uses: `vim.o.sessionoptions = "buffers,curdir,folds,tabpages,winpos,winsize"`
### Session save location
**Session save location**
The location of the session files may be changed by altering the `save_dir` configuration option. For example:
@ -199,7 +200,7 @@ require("persisted").setup({
> [!NOTE]
> The plugin may be unable to find existing sessions if the `save_dir` value is changed
### Git branching
**Git branching**
One of the plugin's core features is the ability to have multiple session files for a given project, by using git branches. To enable git branching:
@ -209,7 +210,7 @@ require("persisted").setup({
})
```
### Autosaving
**Autosaving**
By default, the plugin will automatically save a Neovim session to disk when the `VimLeavePre` event is triggered. Autosaving can be turned off by:
@ -240,7 +241,7 @@ Of course, if you wish to manually save the session when autosaving is disabled,
> [!NOTE]
> If `autosave = false` then the `should_autosave` callback will not be executed.
### Autoloading
**Autoloading**
The plugin can be enabled to automatically load sessions when Neovim is started. Whilst off by default, this can be turned on by:
@ -266,7 +267,7 @@ Autoloading can be further controlled for certain directories by specifying `all
> [!NOTE]
> Autoloading will not occur if the plugin is lazy loaded or a user opens Neovim with arguments other than a single directory argument. For example: `nvim some_file.rb` will not result in autoloading but `nvim some/existing/path` or `nvim .` will.
### Following current working directory
**Following current working directory**
There may be a need to change the working directory to quickly access files in other directories without changing the current session's name on save. This behavior can be configured with `follow_cwd = false`.
@ -281,7 +282,7 @@ require("persisted").setup({
> [!NOTE]
> If `follow_cwd = false` the session name is stored upon loading under the global variable `vim.g.persisting_session`. This variable can be manually adjusted if changes to the session name are needed. Alternatively, if `follow_cwd = true` then `vim.g.persisting_session = nil`.
### Allowed directories
**Allowed directories**
You may specify a table of directories for which the plugin will autosave and/or autoload from. For example:
@ -299,7 +300,7 @@ Specifying `~/Code` will autosave and autoload from that directory as well as al
> [!NOTE]
> If `allowed_dirs` is left at its default value and `autosave` and/or `autoload` are set to `true`, then the plugin will autoload/autosave from _any_ directory
### Ignored directories
**Ignored directories**
You may specify a table of directories for which the plugin will **never** autosave and autoload from. For example:
@ -329,7 +330,7 @@ require("persisted").setup({
In this setup, `~/.config` and `~/.local/nvim` are still going to behave in their default setting (ignoring all listed directory and its children), however `/` and `/tmp` will only ignore those directories exactly.
### Ignored branches
**Ignored branches**
You may specify a table of patterns that match against branches for which the plugin will **never** autosave and autoload from:
@ -342,7 +343,7 @@ require("persisted").setup({
})
```
### Events / Callbacks
**Events / Callbacks**
The plugin fires events at various points during its lifecycle:
@ -359,8 +360,6 @@ The plugin fires events at various points during its lifecycle:
These events can be consumed anywhere within your configuration by utilising the `vim.api.nvim_create_autocmd` function.
#### Example use case
A commonly requested example is to use the Telescope extension to load a session, saving the current session before clearing all of the open buffers:
```lua
@ -379,7 +378,7 @@ vim.api.nvim_create_autocmd({ "User" }, {
})
```
#### Using callback data
**Using callback data**
When certain events are fired, session data is made available for the user to consume, for example:

View File

@ -76,8 +76,7 @@ recommended that you give this plugin a greater loading priority. With
**Packer** the `after` config option can be used and in **Lazy.nvim**, the
`priority` property.
TELESCOPE EXTENSION ~
**Telescope extension**
Ensure that the telescope extension is loaded with:
@ -103,8 +102,7 @@ The layout can then be customised from within Telescope:
USAGE *persisted.nvim-usage*
COMMANDS ~
**Commands**
The plugin comes with a number of commands:
@ -118,8 +116,7 @@ The plugin comes with a number of commands:
- `:SessionLoadFromFile` - Load a session from a given path
- `:SessionDelete` - Delete the current session
TELESCOPE EXTENSION ~
**Telescope extension**
The Telescope extension may be opened via `:Telescope persisted`. The available
actions are:
@ -130,8 +127,7 @@ actions are:
- `<C-c>` - Copy the session file
- `<C-d>` - Delete the session file
GLOBAL VARIABLES ~
**Global variables**
The plugin sets a number of global variables throughout its lifecycle:
@ -143,13 +139,13 @@ The plugin sets a number of global variables throughout its lifecycle:
CONFIGURATION *persisted.nvim-configuration*
DEFAULTS ~
**Defaults**
The plugin comes with the following defaults:
>lua
require("persisted").setup({
log_level = "ERROR", -- One of "TRACE", "DEBUG", "ERROR"
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 a git enabled repository
@ -170,16 +166,15 @@ The plugin comes with the following defaults:
delete_session = "<c-d>",
},
icons = { -- icons displayed in the picker, set to nil to disable entirely
branch = " ",
dir = " ",
selected = " ",
branch = " ",
dir = " ",
selected = " ",
},
},
})
<
WHAT IS SAVED IN THE SESSION? ~
**What is saved in the session?**
As the plugin uses Vims `:mksession` command then you may change the
`vim.o.sessionoptions` value to determine what to write into the session.
@ -188,8 +183,7 @@ Please see `:h sessionoptions` for more information.
[!NOTE] The author uses: `vim.o.sessionoptions =
"buffers,curdir,folds,tabpages,winpos,winsize"`
SESSION SAVE LOCATION ~
**Session save location**
The location of the session files may be changed by altering the `save_dir`
configuration option. For example:
@ -203,8 +197,7 @@ configuration option. For example:
[!NOTE] The plugin may be unable to find existing sessions if the `save_dir`
value is changed
GIT BRANCHING ~
**Git branching**
One of the plugins core features is the ability to have multiple session
files for a given project, by using git branches. To enable git branching:
@ -215,8 +208,7 @@ files for a given project, by using git branches. To enable git branching:
})
<
AUTOSAVING ~
**Autosaving**
By default, the plugin will automatically save a Neovim session to disk when
the `VimLeavePre` event is triggered. Autosaving can be turned off by:
@ -252,8 +244,7 @@ disabled, the `:SessionSave` command can be used.
[!NOTE] If `autosave = false` then the `should_autosave` callback will not be
executed.
AUTOLOADING ~
**Autoloading**
The plugin can be enabled to automatically load sessions when Neovim is
started. Whilst off by default, this can be turned on by:
@ -284,8 +275,7 @@ Autoloading can be further controlled for certain directories by specifying
Neovim with arguments other than a single directory argument. For example:
`nvim some_file.rb` will not result in autoloading but `nvim
some/existing/path` or `nvim .` will.
FOLLOWING CURRENT WORKING DIRECTORY ~
**Following current working directory**
There may be a need to change the working directory to quickly access files in
other directories without changing the current sessions name on save. This
@ -304,8 +294,7 @@ By default, the session name will match the current working directory:
the global variable `vim.g.persisting_session`. This variable can be manually
adjusted if changes to the session name are needed. Alternatively, if
`follow_cwd = true` then `vim.g.persisting_session = nil`.
ALLOWED DIRECTORIES ~
**Allowed directories**
You may specify a table of directories for which the plugin will autosave
and/or autoload from. For example:
@ -326,8 +315,7 @@ all its sub-directories.
[!NOTE] If `allowed_dirs` is left at its default value and `autosave` and/or
`autoload` are set to `true`, then the plugin will autoload/autosave from _any_
directory
IGNORED DIRECTORIES ~
**Ignored directories**
You may specify a table of directories for which the plugin will **never**
autosave and autoload from. For example:
@ -363,8 +351,7 @@ In this setup, `~/.config` and `~/.local/nvim` are still going to behave in
their default setting (ignoring all listed directory and its children), however
`/` and `/tmp` will only ignore those directories exactly.
IGNORED BRANCHES ~
**Ignored branches**
You may specify a table of patterns that match against branches for which the
plugin will **never** autosave and autoload from:
@ -378,8 +365,7 @@ plugin will **never** autosave and autoload from:
})
<
EVENTS / CALLBACKS ~
**Events / Callbacks**
The plugin fires events at various points during its lifecycle:
@ -398,9 +384,6 @@ The plugin fires events at various points during its lifecycle:
These events can be consumed anywhere within your configuration by utilising
the `vim.api.nvim_create_autocmd` function.
EXAMPLE USE CASE
A commonly requested example is to use the Telescope extension to load a
session, saving the current session before clearing all of the open buffers:
@ -420,8 +403,7 @@ session, saving the current session before clearing all of the open buffers:
})
<
USING CALLBACK DATA
**Using callback data**
When certain events are fired, session data is made available for the user to
consume, for example:

View File

@ -1,6 +1,7 @@
local M = {}
local defaults = {
log_level = "ERROR", -- One of "TRACE", "DEBUG", "ERROR"
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

View File

@ -1,5 +1,6 @@
local utils = require("persisted.utils")
local config = require("persisted.config")
local log = require("persisted.log")
local utils = require("persisted.utils")
local M = {}
@ -80,12 +81,12 @@ local function ignore_dir(dir)
end
---Is the current branch ignored for auto-saving and loading?
---@param dir string Branch to be used for the session
---@param branch? string Branch to be used for the session
---@return boolean
local function ignore_branch(branch)
local ignored_branches = config.options.ignored_branches
if ignored_branches == nil then
if not branch or ignored_branches == nil then
return false
end
@ -143,14 +144,8 @@ function M.get_branch(dir)
if vim.fn.filereadable(branch_session) ~= 0 then
return branch
else
vim.notify(
string.format("[Persisted.nvim]: Trying to load a session for branch %s", config.options.default_branch),
vim.log.levels.INFO
)
vim.notify(
string.format("[Persisted.nvim]: Could not load a session for branch %s.", git_branch[1]),
vim.log.levels.WARN
)
log:debug("Trying to load a session for branch: %s", config.options.default_branch)
log:error("Could not load a session for branch: %s", git_branch[1])
vim.g.persisted_branch_session = branch_session
return config.options.branch_separator .. config.options.default_branch
end
@ -183,6 +178,21 @@ end
---@return nil
function M.setup(opts)
config.setup(opts)
log.set_root(log.new({
handlers = {
{
type = "echo",
level = vim.log.levels.WARN,
},
{
type = "file",
filename = "persisted.log",
level = vim.log.levels[config.options.log_level],
},
},
}))
local dir = session_dir()
local branch = get_branchname()
@ -192,6 +202,7 @@ function M.setup(opts)
and not ignore_branch(branch)
and args_check()
then
log:trace("Starting session")
M.start()
end
end
@ -210,19 +221,24 @@ function M.load(opt, dir)
session = opt.session
local session_data = utils.make_session_data(session)
branch = session_data and session_data.branch or ""
log:trace("Session branch %s", branch)
log:trace("Session data %s", session_data)
if not branch then
vim.notify(string.format("[Persisted.nvim]: Invalid session file %s", session), vim.log.levels.WARN)
end
else
branch = get_branchname()
session = opt.last and get_last() or get_current(dir)
log:trace("Session branch: %s", branch)
end
if session then
if vim.fn.filereadable(session) ~= 0 then
vim.g.persisting_session = not config.options.follow_cwd and session or nil
log:trace("Session load: %s", session)
utils.load_session(session, config.options.silent)
elseif type(config.options.on_autoload_no_session) == "function" then
log:trace("No session to load")
config.options.on_autoload_no_session()
end
end
@ -241,6 +257,7 @@ function M.autoload()
if config.options.autoload and args_check() then
if allow_dir(dir) and not ignore_dir(dir) and not ignore_branch(branch) then
log:trace("Autoloading from %s", dir)
M.load({}, dir)
end
end
@ -268,6 +285,7 @@ local function write(session)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePre" })
vim.cmd("mks! " .. e(session))
vim.g.persisting = true
log:trace("Session saved")
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePost" })
end
@ -317,6 +335,7 @@ function M.delete(dir)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedDeletePre", data = session_data })
vim.schedule(function()
log:trace("Deleting session %s", session)
M.stop()
vim.fn.system("rm " .. e(session))
end)
@ -334,13 +353,16 @@ function M.toggle(dir)
dir = dir or session_dir()
if vim.g.persisting == nil then
log:trace("Toggling load")
return M.load({}, dir)
end
if vim.g.persisting then
log:trace("Toggling stop")
return M.stop()
end
log:trace("Toggling start")
return M.start()
end