-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] "In project: x" capability #27
Comments
@Gazareth Let me know if this is all you want. |
Ah excellent, thank you. This should do what I need for now. I do still think it might be worth having a more explicit indicator that we are in a project though. If you could visit a project's directory without 'officially' being in a project, you could edit one or two files and avoid overwriting your session, which you might have wanted to return to later, or even immediately afterwards by using the project browser. |
But how do I make, "inside a project", more explicit? I can't think of any setting I can tweak in the default projections config. Apart from writing a status line component, how do you want projections to indicate projects? Overwriting sessions is definitely annoying. Any ideas to make this happen less frequently are welcome. But, since the user sets up all the autocmds, can't think of anything else projections can do. |
I was thinking Then, users could call something like:
To return that path. Looking at the code it seems all the classes are implemented in a static way, which is nice, and I'm hesitant to pollute that with some kind of global state persistence, so if you have any guidance on where the variable could live and where it would be set, I'd be happy to open a PR for this. |
I don't see a strong reason to track this internally. Since it shouldn't be very hard to track this yourself. You can maybe look into a post restore hook that saves the restored project's directory in a global variable. require("projections").setup({
restore_hooks = {
post = function
LAST_PROJECT_DIR = vim.loop.cwd()
end,
},
}) You can then use if LAST_PROJECT_DIR != nil then
local last_project_name = Session.info(LAST_PROJECT_DIR).project.name
end |
A problem like this is partly self-inflicted, I believe. You control exactly when projections switches projects. You control exactly when projections stores a session file, and exactly when it restores an existing session. After all, projections does 0 work by default 😄. So you control what it means to be "officially" in a project. If you find your session files to be overridden often, and by mistake, then you need to figure out which autocmd is doing that. And refine that. Heck, you can just use switcher to switch between projects and remove all autocmds (apart from the VimLeavePre that stores your session). |
Forgive me if I am mistaken but I don't think the restore hook is called
when loading a project for the first time, since there will be no session
yet.
…On Mon, 9 Jan 2023, 12:40 Gnik, ***@***.***> wrote:
If you could visit a project's directory without 'officially' being *in*
a project, you could edit one or two files and avoid overwriting your
session, which you might have wanted to return to later, or even
immediately afterwards by using the project browser.
A problem like this is partly self-inflicted, I believe. You control
*exactly* when projections switches projects. You control exactly when
projections stores a session file, and exactly when it restores an existing
session. After all, projections does 0 work by default 😄. So you control
what it means to be "officially" in a project.
If you find your session files to be overridden often, and by mistake,
then you need to figure out which autocmd is doing that. And refine that.
Heck, you can just use switcher to switch between projects and remove all
autocmds (apart from the VimLeavePre that stores your session).
—
Reply to this email directly, view it on GitHub
<#27 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC24AWYOUUX6P7LD6UYO42TWRQBLJANCNFSM6AAAAAATUYC4MU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes, you are correct. The restore hook will be called only on restoring sessions. If no session is present, then it won't be called. If you want to track (no session) cases as well, you will need to hook into local switcher = require("projections.switcher")
local original_switch_function = switcher.switch
switcher.switch = function(...)
local operation_successful = original_switch_function(...)
if operation_successful then
LAST_PROJECT_DIR = vim.loop.cwd()
end
return operation_successful
end
It is a bit hacky though. I am not 100% opposed to the idea of By hooking into the That being said, if you want to add this, send in a PR, and I will take a look. No pressure though. If you don't have time to implement this, I will take a look when I'm free. I do hope you consider the above snippet though. 😄 |
Is your feature request related to a problem? Please describe.
I'd like to display which project I'm currently in on my statusbar. I think the closest we'd have is to use the session load hooks, but I'm not sure we'd know which project we've just loaded into? And it also wouldn't tell us when we load up a project for the first time.
Describe the solution you'd like
I was thinking a global could be set, i.e. `vim.g.GnikDroy_projections.project = "MyProjectFolderName" each time the switcher is used or a sesion is loaded.
If appropriate, have you considered any alternatives?
We could provide hooks on the switcher as well, for people to pass in callbacks with receive the project name as an argument.
The text was updated successfully, but these errors were encountered: