Skip to content
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

Move the selected workspace to the previous/next bookmark #318

Open
swoh816 opened this issue Apr 17, 2024 · 3 comments
Open

Move the selected workspace to the previous/next bookmark #318

swoh816 opened this issue Apr 17, 2024 · 3 comments

Comments

@swoh816
Copy link
Contributor

swoh816 commented Apr 17, 2024

Is your feature request related to a problem? Please describe.
It happens when I open files outside the current bookmark (cwd) but relevant to the current workspace (e.g., when I modify system-level configurations). Later, the current workspace becomes overwhelmed by files outside the current bookmark. In such a scenario, I want to move the workspace to a more relevant bookmark (which isn't implemented in CtrlSpace yet as far as I know).

Describe the solution you'd like
There is a function MoveBufferToTab to move the buffer to another tab. I think it would be helpful to have a version of that for moving workspace across different bookmarks, such as MoveWorkspaceToBookmark (and also, MoveTabToWorkspace).

For consistency with the keymap for MoveBufferToTab, we can map MoveWorkspaceToBookmark and MoveTabToWorkspace to { and } in the Workspace List view and Tab List view respectively. (At the moment, { and } in the Tab List view are mapped to moving a selected tab backwards/forward, but given that the order of workspaces in the Workspace List view nor bookmarks in the Bookmark List view are not controllable, I think it's okay also to leave Tab order not controllable unless it is frequently used functionality by other users.

Describe alternatives you've considered
I tried using ctrlspace#keys#workspace#Append which is mapped to a in the Workspace List view, but it works only within the same bookmark.

Version(s) (please complete the following information):

  • OS: Ubuntu 22.04 LTS
  • Version: LazyVim (nvim 0.9.4)
@Konfekt
Copy link
Collaborator

Konfekt commented Apr 17, 2024

Just two thoughts: This should not be too hard to implement, as it means moving the lines between CS_WORKSPACE_BEGIN: b and CS_WORKSPACE_END: b in ~/a/.git/cs_workspaces to ~/b/.git/cs_workspaces.
Here's an example of such a file:

CS_LAST_WORKSPACE: b
CS_WORKSPACE_BEGIN: a
let SessionLoad = 1
if &cp | set nocp | endif
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
exe "cd " . escape(expand("<sfile>:p:h"), ' ')
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
  let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
  set shortmess=aoOA
else
  set shortmess=aoO
endif
badd +0 README.md
argglobal
%argdel
edit README.md
argglobal
let s:l = 1 - ((0 * winheight(0) + 14) / 29)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 1
normal! 0
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0
  silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
  exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
CS_WORKSPACE_END: a
CS_WORKSPACE_BEGIN: b
let SessionLoad = 1
if &cp | set nocp | endif
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
exe "cd " . escape(expand("<sfile>:p:h"), ' ')
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
  let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
  set shortmess=aoOA
else
  set shortmess=aoO
endif
badd +1 CHANGELOG.md
argglobal
%argdel
edit CHANGELOG.md
argglobal
let s:l = 1 - ((0 * winheight(0) + 14) / 29)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 1
normal! 0
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0
  silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
  exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
CS_WORKSPACE_END: b

and here example code to move these lines

let s:source = '~/a/.git/cs_workspaces'
let s:dest = '~/b/.git/cs_workspaces'
let s:content = readfile(s:source)
let s:start = index(s:content, 'CS_WORKSPACE_BEGIN: b') + 1
let s:end = index(s:content, 'CS_WORKSPACE_END: b') - 1
let s:block = s:content[s:start:s:end]
call writefile(s:block, s:dest, 'a')
let s:content = remove(s:content, s:start - 1, s:end + 1)
let s:content = map(s:content, 'substitute(v:val, "CS_LAST_WORKSPACE: b", "CS_LAST_WORKSPACE: a", "")')
call writefile(s:content, s:source)

let s:new_content = readfile(s:dest)
let s:new_content = map(s:new_content, 'substitute(v:val, "CS_LAST_WORKSPACE: a", "CS_LAST_WORKSPACE: b", "")')
call writefile(s:new_content, s:dest)

As before, pull requests are welcome.

Regarding reordering of tabs, I am using it and don't know of any other way.

@swoh816
Copy link
Contributor Author

swoh816 commented Apr 18, 2024

I get what you mean @Konfekt, thanks so much for your answer. By the way, shouldn't we also consider the change of CWD in case we're moving a workspace from Bookmark A to Bookmark B if those bookmarks have different CWDs? The relative paths to the files in a workspace must change if the workspace moves to a different bookmark because CWD changes for different bookmarks (correct me if your code implements such functionality already, I'm probably just not able to see it for the moment),

@Konfekt
Copy link
Collaborator

Konfekt commented Apr 18, 2024

shouldn't we also consider the change of CWD in case we're moving a workspace from Bookmark A to Bookmark B if those bookmarks have different CWDs

Yes, indeed, the cwd should change where cwd refers to that in Vim? The paths in the workspaces are relative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants