Comments (8)
This is also a problem if I, for example, edit a file by entering its absolute path (without calling chdir). The session will not be loaded when I edit the file from a different directory. This could be fixed by checking all session files if the current file is contained in any of the sessions, loading the first session where the current file is contained. This would also fix my initial problem with having two distinct sessions for different files in the same folder.
from trailblazer.nvim.
Sessions are usually dependent on the current working directory as this is the best solution for most users. Checking all session files for the first occurence of the opened file and loading only those trail marks is not the way to go since you could have multiple sessions with the same file which would introduce inconsistencies in the loading behavior once the order changes.
If your workflow requires a more granular approach to sessions you can simply use the API to create a named session with only the marks you need and load them on demand.
TrailBlazer sessions are stored in this directory:
local session_dir = vim.fn.stdpath("data") .. "/trailblazer/"
You could then create a new session for the currently open file like this:
local file_name = vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0)))
require("trailblazer").save_trailblazer_state_to_file(session_dir .. file_name .. ".tbsv", nil, false)
If you want to auto-save per file sessions on exit you can simply add the the above to a custom auto command that is called on the VimLeavePre
event. You could also implement a solution that would save per file sessions on BufUnload
. This would ensure that all open files have their own session and automatically save the current session state for each individual file, meaning that you would be able to open any of the files that are currently in your session at a later point and all other files would automatically be opend.
You can just as easily load the session for the current file like this:
local file_name = vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0)))
require("trailblazer").load_trailblazer_state_from_file(session_dir .. file_name .. ".tbsv", false)
If you want to auto load sessions like this on startup you can simply call the above after TrailBlazer's setup function or add a custom auto command to the BufFilePost
event. Obviously you would have to disable auto-saving/loading sessions in your custom config.
from trailblazer.nvim.
I would like to use the configured
custom_session_storage_dir = "~/tb_sessions/",
without hardcoding it in my keybinding, would it perhaps be better to separate dir and filename arguments in both signatures, such that I dont have to specify the path but only the name of the file?
from trailblazer.nvim.
This doesn't seem to work:
vim.api.nvim_set_keymap("n", "<Esc>l", ':lua local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0))) require("trailblazer").load_trailblazer_state_from_file(file, false) require("trailblazer").open_trail_mark_list()<CR>:wincmd p<CR>', opts)
vim.api.nvim_set_keymap("n", "<Esc>s", ':lua local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0))) require("trailblazer").save_trailblazer_state_to_file(file, nil, false) print("Saved Session")<CR>', opts)
It creates a file without the .tbsv
file ending which I guess can not be loaded again? There is no error indicating this however.
This works:
vim.api.nvim_set_keymap("n", "<Esc>l", ':lua local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0))) .. ".tbsv" require("trailblazer").load_trailblazer_state_from_file(file, false) require("trailblazer").open_trail_mark_list()<CR>:wincmd p<CR>', opts)
vim.api.nvim_set_keymap("n", "<Esc>s", ':lua local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0))) .. ".tbsv" require("trailblazer").save_trailblazer_state_to_file(file, nil, false) print("Saved Session")<CR>', opts)
I would suggest that the .tbsv
extension is added automatically if not specified and that either the path is split into separate dir and file name arguments, or that relative paths, e.g. just the name, will automatically be adapted to include the configured/default storage dir.
from trailblazer.nvim.
I would like to use the configured
custom_session_storage_dir = "~/tb_sessions/",without hardcoding it in my keybinding, would it perhaps be better to separate dir and filename arguments in both signatures, such that I dont have to specify the path but only the name of the file?
Having two separate arguments would unnecessarily complicate things. You can simpy get the default value from TrailBlazers configuration table like this:
local default_storage_path = require("trailblazer").options.custom_session_storage_dir
This doesn't seem to work:
vim.api.nvim_set_keymap("n", "<Esc>l", ':lua local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0))) require("trailblazer").load_trailblazer_state_from_file(file, false) require("trailblazer").open_trail_mark_list()<CR>:wincmd p<CR>', opts) vim.api.nvim_set_keymap("n", "<Esc>s", ':lua local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0))) require("trailblazer").save_trailblazer_state_to_file(file, nil, false) print("Saved Session")<CR>', opts)It creates a file without the
.tbsv
file ending which I guess can not be loaded again? There is no error indicating this however.
Oh yes, I forgot about that. This is actually the inteded behavior and the reason for this is detailed in the documentation. You will just have to add any file extension to your save path for it to work properly. There is no error message for this as this is not a bug but enables you to dynamically create session directories or save files depending on whether or not you add a file type extension.
from trailblazer.nvim.
If you pass either a directory or file name to :TrailBlazerSaveSession or :TrailBlazerLoadSession, the session will be saved into or loaded from the given directory or file. Note that you have to append any file extension (e.g. ".tbsv") to the file name argument when saving a session. Otherwise TrailBlazer will create a directory with the given name and save the session file named as the hashed path of the current working directory. Passing a directory name to :TrailBlazerLoadSession will cause TrailBlazer to search for a session file which matches the name of the hashed path of the current working directory.
Even after reading it again I have no clue what you want to tell me with this paragraph. I will just use the default_storage_path
in my keybindings.
from trailblazer.nvim.
It's actually quite simple:
:TrailBlazerSaveSession sessions
will create the directory "sessions" in the currentcwd
and save all trail marks to a file in this directory named after the hashed value of the expandedcwd
(i.e./home/<username>/projects/your_project
->5c33a1e23599584ac47ea3914ecec378ca4ab49f3fb9d9a6e54f0491a5dc8620.tbsv
) or create it if it doesn't already exist.:TrailBlazerSaveSession sessions/session_file.tbsv
will save all trail marks to a file namedsession_file.tbsv
in the directory "sessions" or create it if it does not already exist within the currentcwd
.
from trailblazer.nvim.
It's actually quite simple:
:TrailBlazerSaveSession sessions
will create the directory "sessions" in the currentcwd
and save all trail marks to a file in this directory named after the hashed value of the expandedcwd
(i.e./home/<username>/projects/your_project
->5c33a1e23599584ac47ea3914ecec378ca4ab49f3fb9d9a6e54f0491a5dc8620.tbsv
) or create it if it doesn't already exist.:TrailBlazerSaveSession sessions/session_file.tbsv
will save all trail marks to a file namedsession_file.tbsv
in the directory "sessions" or create it if it does not already exist within the currentcwd
.
So why exactly doesn't this work then and why would that be expected behavior?
local file = vim.fn.stdpath("data") .. "/trailblazer/" .. vim.fn.sha256(vim.fn.expand(vim.api.nvim_buf_get_name(0)))
require("trailblazer").save_trailblazer_state_to_file(file, nil, false)
followed by
require("trailblazer").load_trailblazer_state_from_file(file, false)
I just find this super unintuitive.
from trailblazer.nvim.
Related Issues (20)
- bug: prompt on trail mark stack deletion HOT 1
- bug: Deleting the only custom stack makes the default stack inaccessible HOT 1
- bug: Autoload session does not work HOT 3
- feature: Callback functions and events HOT 1
- bug: Autoload errors HOT 2
- bug: Manual session loading errors HOT 2
- feature: Verbose flag for stack change HOT 1
- bug: Stack sorting is inverted after loading session HOT 1
- [Bug] Multiple execution of `TrailBlazerToggleTrailMarkList` leads to a crash HOT 3
- [Bug] Mark navigation really slow when the mark quick-fix list is open HOT 13
- [Bug] Buffers with lowercase and uppercase driver letter cause sorting issue in Windows HOT 1
- [Bug] Drive units of buffer paths are not correctly saved when exporting the `trailblazer` session file in Windows HOT 1
- [Bug] No colors / Colors disappear when switching colorschemes HOT 1
- bug: doesn't respect current active window if screen is split HOT 3
- feature: navigate freely between trails back and forth HOT 2
- bug: seems not work with statuscol.nvim? the symbols not showing. HOT 3
- bug: Changing TrailMarksStack will change the open tranmarklist, but not associated to the correct position when jump HOT 3
- feature: Cycle through marks ? HOT 1
- bug: saving the file sends the trailblazer mark to the bottom of the file? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trailblazer.nvim.