Refactoring: l:cnt -> s:entry_number
This commit is contained in:
parent
1b6b53f2f9
commit
3151fdf4b1
|
@ -75,12 +75,11 @@ function! startify#insane_in_the_membrane() abort
|
||||||
call append('$', [' [e] <empty buffer>', ''])
|
call append('$', [' [e] <empty buffer>', ''])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cnt = 0
|
let s:entry_number = 0
|
||||||
|
|
||||||
if filereadable('Session.vim')
|
if filereadable('Session.vim')
|
||||||
call append('$', [' [0] '. getcwd() . s:sep .'Session.vim', ''])
|
call append('$', [' [0] '. getcwd() . s:sep .'Session.vim', ''])
|
||||||
execute 'nnoremap <buffer> 0 :call startify#session_delete_buffers() <bar> source Session.vim<cr>'
|
execute 'nnoremap <buffer> 0 :call startify#session_delete_buffers() <bar> source Session.vim<cr>'
|
||||||
let cnt = 1
|
let s:entry_number = 1
|
||||||
let l:show_session = 1
|
let l:show_session = 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ function! startify#insane_in_the_membrane() abort
|
||||||
|
|
||||||
for item in s:lists
|
for item in s:lists
|
||||||
if type(item) == 1
|
if type(item) == 1
|
||||||
let cnt = s:show_{item}(cnt)
|
call s:show_{item}()
|
||||||
else
|
else
|
||||||
let s:last_message = item
|
let s:last_message = item
|
||||||
endif
|
endif
|
||||||
|
@ -370,123 +369,109 @@ function! startify#open_buffers() abort
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" Function: s:_get_filtered_oldfiles {{{1
|
" Function: s:display_by_path {{{1
|
||||||
function! s:_get_filtered_oldfiles(num, prefix)
|
function! s:display_by_path(prefix) abort
|
||||||
let num = a:num
|
let files = s:filter_oldfiles(a:prefix)
|
||||||
let filter_prefix = len(a:prefix) > 0
|
|
||||||
let entries = {}
|
|
||||||
let files = []
|
|
||||||
|
|
||||||
for fname in copy(v:oldfiles)
|
|
||||||
if num <= 0
|
|
||||||
break
|
|
||||||
endif
|
|
||||||
|
|
||||||
let abs_path = glob(fnameescape(fnamemodify(resolve(fname), ":p")))
|
|
||||||
|
|
||||||
" filter duplicates, bookmarks and entries from the skiplist
|
|
||||||
if has_key(entries, abs_path)
|
|
||||||
\ || !filereadable(abs_path)
|
|
||||||
\ || s:is_in_skiplist(abs_path)
|
|
||||||
\ || (exists('g:startify_bookmarks') && s:is_bookmark(abs_path))
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
|
|
||||||
if filter_prefix && match(abs_path, a:prefix) != 0
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
|
|
||||||
let display_path = fnamemodify(abs_path, s:relative_path ? ':.' : ':p:~')
|
|
||||||
let entries[abs_path] = 1
|
|
||||||
|
|
||||||
let files += [[abs_path, display_path]]
|
|
||||||
|
|
||||||
let num -= 1
|
|
||||||
endfor
|
|
||||||
return files
|
|
||||||
endfun
|
|
||||||
|
|
||||||
" Function: s:_show_filtered_oldfiles {{{1
|
|
||||||
function! s:_show_filtered_oldfiles(cnt, prefix) abort
|
|
||||||
let cnt = a:cnt
|
|
||||||
let files = s:_get_filtered_oldfiles(s:numfiles, a:prefix)
|
|
||||||
|
|
||||||
if !empty(files)
|
if !empty(files)
|
||||||
if exists('s:last_message')
|
if exists('s:last_message')
|
||||||
call s:print_section_header()
|
call s:print_section_header()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for [abs_path, display_path] in files
|
for [abs_path, display_path] in files
|
||||||
let index = s:get_index_as_string(cnt)
|
let index = s:get_index_as_string(s:entry_number)
|
||||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . display_path)
|
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . display_path)
|
||||||
execute 'nnoremap <buffer><silent>' index ':edit' escape(abs_path, ' ') '<bar> call <sid>check_user_options()<cr>'
|
execute 'nnoremap <buffer><silent>' index ':edit' escape(abs_path, ' ') '<bar> call <sid>check_user_options()<cr>'
|
||||||
let cnt += 1
|
let s:entry_number += 1
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call append('$', '')
|
call append('$', '')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return cnt
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function: s:filter_oldfiles {{{1
|
||||||
|
function! s:filter_oldfiles(path_prefix) abort
|
||||||
|
let counter = s:numfiles
|
||||||
|
let entries = {}
|
||||||
|
let oldfiles = []
|
||||||
|
|
||||||
|
for fname in copy(v:oldfiles)
|
||||||
|
if counter <= 0
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
|
||||||
|
let absolute_path = glob(fnameescape(fnamemodify(resolve(fname), ":p")))
|
||||||
|
|
||||||
|
" filter duplicates, bookmarks and entries from the skiplist
|
||||||
|
if has_key(entries, absolute_path)
|
||||||
|
\ || !filereadable(absolute_path)
|
||||||
|
\ || s:is_in_skiplist(absolute_path)
|
||||||
|
\ || (exists('g:startify_bookmarks') && s:is_bookmark(absolute_path))
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
if match(absolute_path, a:path_prefix)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
let entry_path = fnamemodify(absolute_path, s:relative_path ? ':.' : ':p:~')
|
||||||
|
let entries[absolute_path] = 1
|
||||||
|
let counter -= 1
|
||||||
|
let oldfiles += [[absolute_path, entry_path]]
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return oldfiles
|
||||||
|
endfun
|
||||||
|
|
||||||
" Function: s:show_dir {{{1
|
" Function: s:show_dir {{{1
|
||||||
function! s:show_dir(cnt) abort
|
function! s:show_dir() abort
|
||||||
let cwd = escape(getcwd(), '\')
|
" let cwd = escape(getcwd(), '\')
|
||||||
return s:_show_filtered_oldfiles(a:cnt, cwd)
|
return s:display_by_path(getcwd())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:show_files {{{1
|
" Function: s:show_files {{{1
|
||||||
function! s:show_files(cnt) abort
|
function! s:show_files() abort
|
||||||
return s:_show_filtered_oldfiles(a:cnt, '')
|
return s:display_by_path('')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:show_sessions {{{1
|
" Function: s:show_sessions {{{1
|
||||||
function! s:show_sessions(cnt) abort
|
function! s:show_sessions() abort
|
||||||
let sfiles = split(globpath(s:session_dir, '*'), '\n')
|
let sfiles = split(globpath(s:session_dir, '*'), '\n')
|
||||||
if empty(sfiles)
|
if empty(sfiles)
|
||||||
if exists('s:last_message')
|
if exists('s:last_message')
|
||||||
unlet s:last_message
|
unlet s:last_message
|
||||||
endif
|
endif
|
||||||
return a:cnt
|
|
||||||
endif
|
endif
|
||||||
if exists('s:last_message')
|
if exists('s:last_message')
|
||||||
call s:print_section_header()
|
call s:print_section_header()
|
||||||
endif
|
endif
|
||||||
let cnt = a:cnt
|
|
||||||
for i in range(len(sfiles))
|
for i in range(len(sfiles))
|
||||||
let index = s:get_index_as_string(cnt)
|
let index = s:get_index_as_string(s:entry_number)
|
||||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fnamemodify(sfiles[i], ':t'))
|
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fnamemodify(sfiles[i], ':t'))
|
||||||
execute 'nnoremap <buffer><silent>' index ':SLoad' fnamemodify(sfiles[i], ':t') '<cr>'
|
execute 'nnoremap <buffer><silent>' index ':SLoad' fnamemodify(sfiles[i], ':t') '<cr>'
|
||||||
let cnt += 1
|
let s:entry_number += 1
|
||||||
endfor
|
endfor
|
||||||
call append('$', '')
|
call append('$', '')
|
||||||
return cnt
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:show_bookmarks {{{1
|
" Function: s:show_bookmarks {{{1
|
||||||
function! s:show_bookmarks(cnt) abort
|
function! s:show_bookmarks() abort
|
||||||
if !exists('g:startify_bookmarks')
|
if !exists('g:startify_bookmarks')
|
||||||
return a:cnt
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists('s:last_message')
|
if exists('s:last_message')
|
||||||
call s:print_section_header()
|
call s:print_section_header()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cnt = a:cnt
|
|
||||||
|
|
||||||
for fname in g:startify_bookmarks
|
for fname in g:startify_bookmarks
|
||||||
let index = s:get_index_as_string(cnt)
|
let index = s:get_index_as_string()
|
||||||
|
|
||||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
|
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
|
||||||
execute 'nnoremap <buffer><silent>' index ':edit' fnameescape(fname) '<bar> call <sid>check_user_options()<cr>'
|
execute 'nnoremap <buffer><silent>' index ':edit' fnameescape(fname) '<bar> call <sid>check_user_options()<cr>'
|
||||||
|
|
||||||
let cnt += 1
|
let s:entry_number += 1
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call append('$', '')
|
call append('$', '')
|
||||||
|
|
||||||
return cnt
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:is_in_skiplist {{{1
|
" Function: s:is_in_skiplist {{{1
|
||||||
|
|
Loading…
Reference in a new issue