dhruvasagar / vim-prosession

Handle vim sessions like a pro
254 stars 22 forks source link

Any best practices about integration with vim-projectionist? #102

Closed jiz4oh closed 7 months ago

jiz4oh commented 1 year ago

Hi there, is anyone used this plugin with vim-projectionist? I think it's a good use case that let projectionist determine which dir is a project and prosession it. But I have met some troubles.

function! s:switch_project(path) abort
  if empty(a:path)
    return
  endif

  exec 'Prosession ' a:path
endfunction

augroup prosession_init
  autocmd!

  autocmd User ProjectionistActivate call s:switch_project(projectionist#path())
augroup END

There is my vimrc. So is there any best practices to share to others and me?

dhruvasagar commented 1 year ago

@jiz4oh I don't quite use vim-projectionist actively so there aren't any use cases I have in mind. If you think there's some things you'd like to share, perhaps we can add that in the README ?

jiz4oh commented 1 year ago

Hi @dhruvasagar, vim-prosession is designed for

to maintain one session per project (directory) and switch between them when we need to switch context, automatically loading along with it the various files, settings etc ensuring compete isolation between projects.

but vim-prosession only can auto switch between git projects and require additional plugin vim-fugitive. I must handle session myself after I changed to another project which is not controlled by git.

vim-projectionist provide a way to define is this one a project, so I think it would be very nice if I can auto switch session after I changed to a dir which is detected by vim-projectionist as project

dhruvasagar commented 1 year ago

@jiz4oh Well vim-prosession provides a direct way to switch to a project using the :Prosession /path/to/project command, and when you do so, it handles the sessions for you like you'd expect. There's no additional manual work required and vim-prosession does not require git in any way for that workflow. Additionally vim-prosession also provides nice completion for existing projects / paths for the :Prosession

If you don't want to use the :Prosession command provided by vim-prosession to switch to projects, I suppose there may be something you can include in projectionist configuration to do that, but I don't see how vim-prosession can do something here.

dhruvasagar commented 1 year ago

@jiz4oh Do you believe vim-prosession should do something in this regard or can I close this issue ?

jiz4oh commented 1 year ago

Hi @dhruvasagar, I have a problem make me do not work properly with vim-prosession, and you can repeat that by following codes

~/testvimrc.vim:

set nocompatible
call plug#begin('~/.vim/bundle')

Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-obsession'
Plug 'dhruvasagar/vim-prosession'
let g:projectionist_heuristics = {
      \ ".git/": {
      \ }
      \}

augroup test
  autocmd!

  autocmd User ProjectionistActivate execute 'Prosession ' . projectionist#path()
augroup END

call plug#end()

start vim by vim -u ~/testvimrc.vim.

when I enter any files which under git project, i face a empty buffer with no content.

after read the code, i believe it's caused by this line. could you please help to review this issue?

dhruvasagar commented 1 year ago

The line of code you linked to deletes all files, but then later loads the files corresponding to the session of the project and loads them. If there were no files in that session / there wasn't a session to begin with it will be blank. But when you open files, then finally close vim and start in that project again, you should see the files that you had previously opened in that session.

jiz4oh commented 1 year ago

ProjectionistActivate event is trigger on each buffer under git project image

If there were no files in that session / there wasn't a session to begin with it will be blank

after I first enter a file autocmd User ProjectionistActivate execute 'Prosession ' . projectionist#path() is triggered and there were no files in that session, all current buffers are wiped. autocmd User ProjectionistActivate execute 'Prosession ' . projectionist#path() is triggered again while I jump to other files under the same project, and there still has no files in that session.

But when you open files, then finally close vim and start in that project again, you should see the files that you had previously opened in that session.

so no files were saved in that session even if I restart vim. I always find a empty buffer whatever files I jumped to

dhruvasagar commented 1 year ago

I will need to investigate this, thanks for bringing this to my notice.

dhruvasagar commented 1 year ago

@jiz4oh How are you launching vim / neovim ? It looks like ProjectistActivate triggers multiple times as you open files and that will surely not work with vim-prosession. You should just not use that autocmd. But I am still struggling to fully understand your workflow and expectations.

jiz4oh commented 1 year ago

Hi @dhruvasagar, sorry for my bad English, I try to describe more clearly. it's regardless of how I launch vim, vim-projectionst will trigger a detect that determine the directory of the buffer whether it is a project on each buffers and ProjectionistActivate event is fired if the buffer is considered as a part of a project, so some buffers maybe re-trigger ProjectionistActivate event.

dhruvasagar commented 1 year ago

@jiz4oh Ok, thanks for clarifying. I believe this following snippet should do the job as you want :

augroup Prosessionist
  au!

  autocmd User ProjectionistActivate if empty(v:this_session) | execute 'Prosession' projectionist#path() | endif
augroup END

The additional guard if empty(v:this_session) I added will ensure Prosession command is only executed if a session has not loaded yet.

dhruvasagar commented 1 year ago

@jiz4oh Let me know if that helps.