Răsfoiți Sursa

refactor load/save_session()

Marco Hinz 12 ani în urmă
părinte
comite
a8d388f956
1 a modificat fișierele cu 13 adăugiri și 13 ștergeri
  1. 13 13
      autoload/startify.vim

+ 13 - 13
autoload/startify.vim

@@ -8,26 +8,26 @@ if exists('g:autoloaded_startify') || &cp
 endif
 let g:autoloaded_startify = 1
 
-function! startify#save_session() abort
-  let spath = g:startify_session_dir .'/'. input('Save under this session name: ') | redraw
-  if filereadable(spath)
-    echo 'Session already exists. Overwrite?  [y/n]' | redraw
-    if nr2char(getchar()) == 'y'
-      execute 'mksession! '. spath | echo 'Session saved under: '. spath
-    else
-      echo 'Did NOT save the session!'
-    endif
-  else
+function! startify#save_session(...) abort
+  let spath = g:startify_session_dir .'/'. (exists('a:1') ? a:1 : input('Save under this session name: ')) | redraw
+  if !filereadable(spath)
     execute 'mksession '. spath | echo 'Session saved under: '. spath
+    return
+  endif
+  echo 'Session already exists. Overwrite?  [y/n]' | redraw
+  if nr2char(getchar()) == 'y'
+    execute 'mksession! '. spath | echo 'Session saved under: '. spath
+  else
+    echo 'Did NOT save the session!'
   endif
 endfunction
 
-function! startify#load_session() abort
-  let spath = g:startify_session_dir .'/'. input('Load this session: ') | redraw
+function! startify#load_session(...) abort
+  let spath = g:startify_session_dir .'/'. (exists('a:1') ? a:1 : input('Load this session: ')) | redraw
   if filereadable(spath)
     execute 'source '. spath
   else
-    echo 'No such file!'
+    echo 'No such file: '. spath
   endif
 endfunction