* Update logic for autoload or starting sessions.
The logic to prevent autoloading/starting sessions when any arguments
are supplied to neovim is to prevent session management from kicking in
when editing a single file.
This updates the logic to allow a single argument passed to neovim as
long as the argument is an existing directory. When neovim is launched
in this way it behaves the same as opening neovim with no arguments but
has changed the working directory.
This results in consistent behavior of the autoloading/starting of
sessions when passing a directory argument to start neovim.
See: https://github.com/olimorris/persisted.nvim/discussions/93
* Fix comment, make comparisons more direct
* Update functions to be directory-aware
The main functionality in `init.lua` assumes using current working
directory in most cases. This refactors these functions to allow passing
in a directory instead.
The default behavior is to now use the current directory unless neovim
was started with a single directory argument, using that instead.
This also special-cases `.` as `vim.fn.expand()` does not resolve that
to the current working directory.
* fix: unnecessary shell commands when autosave off
Problem: Shell programs aren't able to detect nvim exit.
Solution: Avoid running shell-commands unnecessarily on exit.
Programs that spawn nvim in-order to edit a file are unable to detect
nvim exit cleanly because of a race-condition that happens in
`VimLeavePre` and `get_current()` which runs shell commands during exit
even when `autosave` is off.
For example, using nvim nightly, run persisted.nvim with:
```lua
opts.should_autosave = function()
-- Do not autosave if git commit/rebase session.
return vim.env.GIT_EXEC_PATH == nil
end
```
And run `EDITOR=nvim git commit` from shell; git will fail waiting for
nvim to exit cleanly.
* fix: global variable in lowercase initial
When nvim is used as a man pager with `export MANPAGER='nvim +Man! '`, with autoload set to true, persisted.nvim still autoloads the current directory which is not desirable
- Use telescope builtin resolver to calculate width.
- The branch is missing. Fixed.
- If session file stores without git branch, `session.branch` should be nil. And do not show branch in list.
- `make test` will fail because plenary.nvim is old.
close#34
* Add follow_cwd option to allow fixing session name on load
* Update readme to reflect new follow_cwd command and explain use
* Add tests for follow_cwd
* Update README.md
* Adjust wording in README for follow_cwd to clarify use case
Co-authored-by: Oli M <olimorris@users.noreply.github.com>
For users who not use git branching (majority) this is redundant. For users who have lots of '_' in their file path, this becomes messy. Cleaner to just remove it as the user can determine the branch from the filename anyway
A big shoutout to @simonmclean for this pull request. Previously we autoloaded a session file as soon as Neovim opened. The problem with this is that key plugins like LSP and Treesitter may not have been initialised. This would lead to syntax highlighting issues or LSPs not attaching to buffers in the session. Pushing this to Neovim's event loop via vim.schedule allows us to sensibly load the session after these key plugins. Fixing the tests was a little cumbersome as we needed to use plenary's async library but once figured out, we have some lovely robust async tests
I'm experiencing a bug whereby if I enable autoloading, I don't get any syntax highlighting on startup (until I trigger it with `:e` for example). I had the same issue with `persistence.nvim` (I made an auto command to get the same functionality). For both plugins, wrapping the call to `load` in `vim.schedule` solved the problem.
I don't really know enough about the inner workings of Neovim to explain this though.
This addresses #1 and allows the user to specify directories which the plugin will automatically save or load from. Alternatively, specify directories for which this behaviour will be ignored