Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit c26b473

Browse files
Include variable to define what files to autosave and hide errors with mksession (#46)
* include global variable to set a list of files to autosave * include list of files to autosave also to workspace to avoid errors * remove autosave in load workspace, since It dont works * create session in vimleave pre instead of vimleave to avoid errors * mksession silent to avoid print errors * fix silent error * only create workspace if git repo * fix bug * dont send workspace created when not created * echo if git repo or not * variable for set workspace only for git repositorys Co-authored-by: jordisantamaria <santamaria.jordi@nicosys.jp>
1 parent 5c0025f commit c26b473

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

plugin/workspace.vim

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ let g:workspace_autocreate = get(g:, 'workspace_autocreate', 0)
1717
let g:workspace_nocompatible = get(g:, 'workspace_nocompatible', 1)
1818
let g:workspace_session_directory = get(g:, 'workspace_session_directory', '')
1919
let g:workspace_create_new_tabs = get(g:, 'workspace_create_new_tabs', 1)
20+
let g:workspace_autosave_files = get(g:, 'workspace_autosave_files', [])
21+
let g:workspace_only_git_dir = get(g:, 'workspace_only_git_dir', 0)
2022

2123
function! s:IsSessionDirectoryUsed()
2224
return !empty(g:workspace_session_directory)
@@ -52,15 +54,24 @@ function! s:MakeWorkspace(workspace_save_session)
5254
if a:workspace_save_session == 1 || get(s:, 'workspace_save_session', 0) == 1
5355
let s:workspace_save_session = 1
5456
if s:IsSessionDirectoryUsed()
55-
execute printf('mksession! %s', escape(s:GetSessionDirectoryPath(), '%'))
57+
silent! execute printf('mksession! %s', escape(s:GetSessionDirectoryPath(), '%'))
5658
elseif s:IsAbsolutePath(g:workspace_session_name)
57-
execute printf('mksession! %s', g:workspace_session_name)
59+
silent! execute printf('mksession! %s', g:workspace_session_name)
5860
else
59-
execute printf('mksession! %s/%s', getcwd(), g:workspace_session_name)
61+
silent! execute printf('mksession! %s/%s', getcwd(), g:workspace_session_name)
6062
endif
6163
endif
6264
endfunction
6365

66+
function! s:IsGitDir()
67+
silent! !git rev-parse --is-inside-work-tree
68+
if v:shell_error == 0
69+
return 1
70+
else
71+
return 0
72+
endif
73+
endfunction
74+
6475
function! s:FindOrNew(filename)
6576
let l:fnr = bufnr(a:filename)
6677
for tabnr in range(1, tabpagenr("$"))
@@ -107,6 +118,9 @@ function! s:RemoveWorkspace()
107118
endfunction
108119

109120
function! s:ToggleWorkspace()
121+
if g:workspace_only_git_dir == 1 && s:IsGitDir() == 0
122+
return
123+
endif
110124
if s:WorkspaceExists()
111125
call s:RemoveWorkspace()
112126
execute printf('silent !rm -rf %s', g:workspace_undodir)
@@ -160,6 +174,11 @@ function! s:UntrailTabs()
160174
endfunction
161175

162176
function! s:Autosave(timed)
177+
" If autosave files list is not empty and file is not in list, don't autosave
178+
if len(g:workspace_autosave_files) > 0 && index(g:workspace_autosave_files, &filetype) == -1
179+
return
180+
endif
181+
163182
if index(g:workspace_autosave_ignore, &filetype) != -1 || &readonly || mode() == 'c' || pumvisible()
164183
return
165184
endif
@@ -266,5 +285,3 @@ augroup END
266285
command! ToggleAutosave call s:ToggleAutosave()
267286
command! ToggleWorkspace call s:ToggleWorkspace()
268287
command! CloseHiddenBuffers call s:CloseHiddenBuffers()
269-
270-
" vim: ts=2 sw=2 et

0 commit comments

Comments
 (0)