Просмотр исходного кода

Merge branch 'improve-sessions'

References #32.
Marco Hinz 12 лет назад
Родитель
Сommit
aabdee64b9
2 измененных файлов с 47 добавлено и 21 удалено
  1. 30 21
      autoload/startify.vim
  2. 17 0
      doc/startify.txt

+ 30 - 21
autoload/startify.vim

@@ -12,11 +12,15 @@ let g:autoloaded_startify = 1
 let s:numfiles         = get(g:, 'startify_files_number', 10)
 let s:numfiles         = get(g:, 'startify_files_number', 10)
 let s:show_special     = get(g:, 'startify_enable_special', 1)
 let s:show_special     = get(g:, 'startify_enable_special', 1)
 let s:restore_position = get(g:, 'startify_restore_position')
 let s:restore_position = get(g:, 'startify_restore_position')
-
-let s:session_dir = resolve(expand(get(g:, 'startify_session_dir',
+let s:session_dir      = resolve(expand(get(g:, 'startify_session_dir',
       \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
       \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
 
 
-let s:chdir = (get(g:, 'startify_change_to_dir', 1) ? '<bar> if isdirectory(expand("%")) <bar> lcd % <bar> else <bar> lcd %:h <bar> endif' : '') .'<cr>'
+" Function: #get_separator {{{1
+function! startify#get_separator() abort
+  return !exists('+shellslash') || &shellslash ? '/' : '\'
+endfunction
+
+let s:sep = startify#get_separator()
 
 
 " Function: #insane_in_the_membrane {{{1
 " Function: #insane_in_the_membrane {{{1
 function! startify#insane_in_the_membrane() abort
 function! startify#insane_in_the_membrane() abort
@@ -49,7 +53,7 @@ function! startify#insane_in_the_membrane() abort
   endif
   endif
 
 
   if get(g:, 'startify_session_detection', 1) && filereadable('Session.vim')
   if get(g:, 'startify_session_detection', 1) && filereadable('Session.vim')
-    call append('$', ['   [0]  Session.vim', ''])
+    call append('$', ['   [0]  '. getcwd() . s:sep .'Session.vim', ''])
     execute 'nnoremap <buffer> 0 :source Session.vim<cr>'
     execute 'nnoremap <buffer> 0 :source Session.vim<cr>'
     let cnt = 1
     let cnt = 1
   endif
   endif
@@ -96,7 +100,7 @@ function! startify#session_load(...) abort
     echo 'There are no sessions...'
     echo 'There are no sessions...'
     return
     return
   endif
   endif
-  let spath = s:session_dir . startify#get_separator() . (exists('a:1')
+  let spath = s:session_dir . s:sep . (exists('a:1')
         \ ? a:1
         \ ? a:1
         \ : input('Load this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
         \ : input('Load this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
         \ | redraw
         \ | redraw
@@ -133,7 +137,7 @@ function! startify#session_save(...) abort
       return
       return
     endif
     endif
   endif
   endif
-  let spath = s:session_dir . startify#get_separator() . sname
+  let spath = s:session_dir . s:sep . sname
   if !filereadable(spath)
   if !filereadable(spath)
     execute 'mksession '. fnameescape(spath) | echo 'Session saved under: '. spath
     execute 'mksession '. fnameescape(spath) | echo 'Session saved under: '. spath
     return
     return
@@ -155,7 +159,7 @@ function! startify#session_delete(...) abort
     echo 'There are no sessions...'
     echo 'There are no sessions...'
     return
     return
   endif
   endif
-  let spath = s:session_dir . startify#get_separator() . (exists('a:1')
+  let spath = s:session_dir . s:sep . (exists('a:1')
         \ ? a:1
         \ ? a:1
         \ : input('Delete this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
         \ : input('Delete this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
         \ | redraw
         \ | redraw
@@ -181,11 +185,6 @@ function! startify#session_list_as_string(lead, ...) abort
   return join(map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")'), "\n")
   return join(map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")'), "\n")
 endfunction
 endfunction
 
 
-" Function: #get_separator {{{1
-function! startify#get_separator() abort
-  return !exists('+shellslash') || &shellslash ? '/' : '\'
-endfunction
-
 " Function: s:show_dir {{{1
 " Function: s:show_dir {{{1
 function! s:show_dir(cnt) abort
 function! s:show_dir(cnt) abort
   let cnt   = a:cnt
   let cnt   = a:cnt
@@ -246,7 +245,7 @@ function! s:show_files(cnt) abort
       let index = s:get_index_as_string(cnt)
       let index = s:get_index_as_string(cnt)
 
 
       call append('$', '   ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
       call append('$', '   ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
-      execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) s:chdir
+      execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) '<bar> call <sid>check_user_options()<cr>'
 
 
       let cnt += 1
       let cnt += 1
       let num -= 1
       let num -= 1
@@ -278,7 +277,7 @@ function! s:show_sessions(cnt) abort
     execute 'nnoremap <buffer>' index ':source' fnameescape(sfiles[i]) '<cr>'
     execute 'nnoremap <buffer>' index ':source' fnameescape(sfiles[i]) '<cr>'
   endfor
   endfor
 
 
-  return idx
+  return idx + 1
 endfunction
 endfunction
 
 
 " Function: s:show_bookmarks {{{1
 " Function: s:show_bookmarks {{{1
@@ -287,11 +286,12 @@ function! s:show_bookmarks(cnt) abort
 
 
   if exists('g:startify_bookmarks')
   if exists('g:startify_bookmarks')
     for fname in g:startify_bookmarks
     for fname in g:startify_bookmarks
-      let cnt  += 1
       let index = s:get_index_as_string(cnt)
       let index = s:get_index_as_string(cnt)
 
 
       call append('$', '   ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
       call append('$', '   ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
-      execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) s:chdir
+      execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) '<bar> call <sid>check_user_options()<cr>'
+
+      let cnt += 1
     endfor
     endfor
   endif
   endif
 
 
@@ -377,6 +377,7 @@ function! s:open_buffers(cword) abort
 
 
     for val in values(s:marked)
     for val in values(s:marked)
       let [path, type] = val[1:2]
       let [path, type] = val[1:2]
+
       " open in split
       " open in split
       if type == 'S'
       if type == 'S'
         if line2byte('$') == -1
         if line2byte('$') == -1
@@ -395,7 +396,8 @@ function! s:open_buffers(cword) abort
       else
       else
         execute 'edit' path
         execute 'edit' path
       endif
       endif
-      call s:chdir()
+
+      call s:check_user_options()
     endfor
     endfor
 
 
     " remove markers for next instance of :Startify
     " remove markers for next instance of :Startify
@@ -408,10 +410,17 @@ function! s:open_buffers(cword) abort
   endif
   endif
 endfunction
 endfunction
 
 
-" Function: s:chdir {{{1
-function! s:chdir() abort
-  if get(g:, 'startify_change_to_dir', 1)
-    if isdirectory(expand('%'))
+" Function: s:check_user_options {{{1
+function! s:check_user_options() abort
+  let path    = expand('%')
+  let session = path . s:sep .'Session.vim'
+
+  " autoload session
+  if get(g:, 'startify_session_autoload') && filereadable(session)
+    execute 'source' session
+  " change directory
+  elseif get(g:, 'startify_change_to_dir', 1)
+    if isdirectory(path)
       lcd %
       lcd %
     else
     else
       lcd %:h
       lcd %:h

+ 17 - 0
doc/startify.txt

@@ -142,6 +142,15 @@ The number of files to list.
 When the file Session.vim is found in the current directory, it will be shown at
 When the file Session.vim is found in the current directory, it will be shown at
 the top of all lists as entry [0].
 the top of all lists as entry [0].
 
 
+============-
+
+    let g:startify_session_autoload = 0
+
+If you bookmark a directory that contains a Session.vim and this option is
+enabled, that session will be loaded automatically when you open the
+directory.
+
+Great way to create a portable project folder.
 
 
 ============-
 ============-
 
 
@@ -313,6 +322,14 @@ Put this in your vimrc:
                 \ endif
                 \ endif
 
 
 
 
+The session autoload feature is not working!
+--------------------------------------------
+
+Do you have NERDTree installed by any chance? If so, try this:
+
+    let NERDTreeHijackNetrw = 0
+
+
 I don't want the start screen to use cursorline!
 I don't want the start screen to use cursorline!
 ------------------------------------------------
 ------------------------------------------------