From 8e9ef610870744783eba62f3f061fd7a61c591d8 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sun, 23 Nov 2014 17:39:51 +0100 Subject: [PATCH] Refactoring: make "dir" list always relative --- autoload/startify.vim | 29 ++++++++++++++--------------- doc/startify.txt | 3 ++- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/autoload/startify.vim b/autoload/startify.vim index 04801bb..503b047 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -14,7 +14,7 @@ let g:autoloaded_startify = 1 let s:numfiles = get(g:, 'startify_files_number', 10) let s:show_special = get(g:, 'startify_enable_special', 1) let s:delete_buffers = get(g:, 'startify_session_delete_buffers') -let s:relative_path = get(g:, 'startify_relative_path') +let s:relative_path = get(g:, 'startify_relative_path') ? ':.' : ':p:~' let s:session_dir = resolve(expand(get(g:, 'startify_session_dir', \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session'))) @@ -370,17 +370,16 @@ endfunction " Function: s:display_by_path {{{1 -function! s:display_by_path(prefix) abort - let files = s:filter_oldfiles(a:prefix) - - if !empty(files) +function! s:display_by_path(path_prefix, path_format) abort + let oldfiles = s:filter_oldfiles(a:path_prefix, a:path_format) + if !empty(oldfiles) if exists('s:last_message') call s:print_section_header() endif - for [abs_path, display_path] in files + for [absolute_path, entry_path] in oldfiles let index = s:get_index_as_string(s:entry_number) - call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . display_path) - execute 'nnoremap ' index ':edit' escape(abs_path, ' ') ' call check_user_options()' + call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . entry_path) + execute 'nnoremap ' index ':edit' escape(absolute_path, ' ') ' call check_user_options()' let s:entry_number += 1 endfor call append('$', '') @@ -388,10 +387,10 @@ function! s:display_by_path(prefix) abort endfunction " Function: s:filter_oldfiles {{{1 -function! s:filter_oldfiles(path_prefix) abort - let counter = s:numfiles - let entries = {} - let oldfiles = [] +function! s:filter_oldfiles(path_prefix, path_format) abort + let counter = s:numfiles + let entries = {} + let oldfiles = [] for fname in copy(v:oldfiles) if counter <= 0 @@ -412,7 +411,7 @@ function! s:filter_oldfiles(path_prefix) abort continue endif - let entry_path = fnamemodify(absolute_path, s:relative_path ? ':.' : ':p:~') + let entry_path = fnamemodify(absolute_path, a:path_format) let entries[absolute_path] = 1 let counter -= 1 let oldfiles += [[absolute_path, entry_path]] @@ -424,12 +423,12 @@ endfun " Function: s:show_dir {{{1 function! s:show_dir() abort " let cwd = escape(getcwd(), '\') - return s:display_by_path(getcwd()) + return s:display_by_path(getcwd(), ':.') endfunction " Function: s:show_files {{{1 function! s:show_files() abort - return s:display_by_path('') + return s:display_by_path('', s:relative_path) endfunction " Function: s:show_sessions {{{1 diff --git a/doc/startify.txt b/doc/startify.txt index 8122bf8..1a65d37 100644 --- a/doc/startify.txt +++ b/doc/startify.txt @@ -402,7 +402,8 @@ Don't run Startify at Vim startup. You can still call it anytime via let g:startify_relative_path = 0 < Show filenames relative to the current working directory instead of as -absolute paths. +absolute paths. This only applies to the "files" list, since the "dir" list is +relative by nature. ============================================================================== AUTOCMD *startify-autocmd*