From 003602029951f5be33d0a2e2e925c5c6966aa20a Mon Sep 17 00:00:00 2001 From: Patrick Walsh Date: Sat, 8 Jun 2013 11:53:32 -0600 Subject: [PATCH 1/3] Fix extra trailing slash bug On mac, the resolve() function was adding a trailing slash. Reorder the substitutions to fix. --- autoload/project/config.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/project/config.vim b/autoload/project/config.vim index 0882680..9245c03 100644 --- a/autoload/project/config.vim +++ b/autoload/project/config.vim @@ -2,8 +2,8 @@ let s:projects = {} let s:pos = 0 function! s:full_path(arg) abort - let arg = substitute(a:arg, '\v\C/+$', '', '') - let arg = resolve(fnamemodify(arg, ":p")) + let arg = resolve(fnamemodify(a:arg, ":p")) + let arg = substitute(arg, '\v\C/+$', '', '') let arg = substitute(arg, '\v\C\\+$', '', '') return arg endfunction From 3d1681c1db77f208ba8c6dc0e93af49119f2b122 Mon Sep 17 00:00:00 2001 From: Patrick Walsh Date: Sat, 8 Jun 2013 14:42:52 -0600 Subject: [PATCH 2/3] Enhance project launch from welcome screen 1. When nerdtree is used, lcd in the new buffer before nerdtree so the command takes proper effect 2. When file is dir and nerdtree is used, call callbacks to set environment for the new empty file. Also gives a chance for nerdtree ignore settings to be set per project. --- autoload/project/config.vim | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/autoload/project/config.vim b/autoload/project/config.vim index 9245c03..aa30a87 100644 --- a/autoload/project/config.vim +++ b/autoload/project/config.vim @@ -2,7 +2,8 @@ let s:projects = {} let s:pos = 0 function! s:full_path(arg) abort - let arg = resolve(fnamemodify(a:arg, ":p")) + let arg = substitute(a:arg, '\v\C/+$', '', '') + let arg = resolve(fnamemodify(arg, ":p")) let arg = substitute(arg, '\v\C/+$', '', '') let arg = substitute(arg, '\v\C\\+$', '', '') return arg @@ -64,6 +65,19 @@ function! project#config#project_path(arg, ...) abort endif endfunction +function! s:callbackString(title) abort + let project = s:projects[a:title] + let type = project["type"] + let callbacks = project["callbacks"] + let retval = [] + if len(callbacks) > 0 + for callback in callbacks + call add(retval, 'execute "call '.callback.'(\"'.a:title.'\")"') + endfor + endif + return join(retval, " \\| ") +endfunction + function! s:callback(title) abort let project = s:projects[a:title] let type = project["type"] @@ -133,14 +147,16 @@ function! project#config#welcome() abort if v["type"] == "project" let file = v["project"] let lcd = " \\| lcd ".v["project"] + let callback = " \\| " . s:callbackString(v["title"]) else let file = v["event"] let lcd = "" + let callback = "" endif let line = printf(printf(' ['. cnt .']'.padding.'%s '.file, '%-'.max_title_length.'s'), v["title"]) call append('$', line) if get(g:, 'project_use_nerdtree', 0) && isdirectory(file) - execute 'nnoremap '. cnt .' :enew \| NERDTree '. s:escape(file).lcd."" + execute 'nnoremap '. cnt .' :enew '.lcd.callback.' \| NERDTree '. s:escape(file)."" else execute 'nnoremap '. cnt .' :edit '. s:escape(file).lcd."" endif From 591f466de2e6ba645275c58183dbc8265ce5502a Mon Sep 17 00:00:00 2001 From: Patrick Walsh Date: Sat, 8 Jun 2013 14:54:28 -0600 Subject: [PATCH 3/3] Added an option to suppress changes to the title Default functionality stays the same. --- README.md | 2 ++ autoload/project.vim | 18 +++++++++++------- autoload/project/config.vim | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c20f2cd..bb27ec0 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ If you don't want ``Welcome`` to appear when you start vim: let g:project_enable_welcome = 0 " if you want the NERDTree integration. let g:project_use_nerdtree = 1 +" if you want to suppress the gui title changes +let g:project_enable_title_change = 0 set rtp+=~/.vim/bundle/vim-project/ call project#rc("~/Code") diff --git a/autoload/project.vim b/autoload/project.vim index 7846188..072bbeb 100644 --- a/autoload/project.vim +++ b/autoload/project.vim @@ -14,13 +14,17 @@ command! -nargs=0 -bar Welcome \ enew | call project#config#welcome() if has("gui_running") - function! TabTitle() - let title = expand("%:p:t") - let t:title = exists("b:title") ? b:title : title - endfunction - - au VimEnter * set guitablabel=%-2.2N%{gettabvar(v:lnum,'title')} - set title + function! TabTitle() + if get(g:, 'project_enable_title_change', 1) + let title = expand("%:p:t") + let t:title = exists("b:title") ? b:title : title + endif + endfunction + + if get(g:, 'project_enable_title_change', 1) + au VimEnter * set guitablabel=%-2.2N%{gettabvar(v:lnum,'title')} + set title + endif endif if get(g:, 'project_enable_welcome', 1) diff --git a/autoload/project/config.vim b/autoload/project/config.vim index aa30a87..f6eda60 100644 --- a/autoload/project/config.vim +++ b/autoload/project/config.vim @@ -226,7 +226,7 @@ function! s:setup() abort endif execute autocmd endfor - if has("gui_running") + if has("gui_running") && get(g:, 'project_enable_title_change', 1) au BufEnter,BufRead,WinEnter * call TabTitle() au BufEnter,BufRead,WinEnter * let &titlestring = getcwd() endif