diff --git a/README.md b/README.md index 8c8773a..dd8502d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ## News +* New command Init * [New feature](#callbacks) ``project#utils#alternate``. To alternate between `file.ext` and ``file_suffix.ext`` or ``fileSuffix.ext`` with the command ``:A`` * [Windows support added](https://twitter.com/amiorin/status/336003331984076800) @@ -7,6 +8,7 @@ A Project is made of : * One directory (the ``root of the project``) * One title (by default the last part of the the ``root of the project``) +* One or more ``inits`` * One or more ``callbacks`` Everytime you open a file nested in the ``root of the project`` @@ -14,10 +16,13 @@ Everytime you open a file nested in the ``root of the project`` * the ``guitablabel`` is set to the ``title`` of the project * the ``callbacks`` of the project are executed +Every time you choose project on the welcome screen, the ``inits`` of the +project are executed. + ![img][0] ## Commands -There are four commands : +There are five commands : * ``Project`` It's used inside the ``.vimrc``. The first parameter is the ``path`` to the project. The second parameter is optional and it is the ``title`` of the @@ -51,6 +56,11 @@ the name a function or an array of function names. This function or these functions are callbacks and they are executed everytime a file nested in the ``root of the project`` is opened with **one parameter** that is the ``title`` of the project. +* ``Init`` +It's used inside the ``.vimrc``. It works just as the ``Callback`` command, except +it is executed _once_ when project is selected on the welcome screen. If welcome +screen is not used (that is, ``g:project_enable_welcome`` is set to 0), this +command does nothing. * ``Welcome`` It's the [``Startify``](https://github.com/mhinz/vim-startify) equivalent. If you don't want ``Welcome`` to appear when you start vim: @@ -145,8 +155,13 @@ Project 'glib' Project 'reloadlive' Project 'flashcards' Project 'leitner' +Init 'leitner' , 'Murphy' Callback 'leitner' , ['AddSpecToPath', 'RemoveTextWidth'] +function! Murphy(title) + colorscheme murphy +endfunction + function! AddSpecToPath(tile) abort setlocal path+=spec endfunction diff --git a/autoload/project.vim b/autoload/project.vim index 7846188..bd79219 100644 --- a/autoload/project.vim +++ b/autoload/project.vim @@ -4,6 +4,9 @@ command! -nargs=+ Project command! -nargs=+ File \ call project#config#title() +command! -nargs=+ Init +\ enew | call project#config#init() + command! -nargs=+ Callback \ call project#config#callback() diff --git a/autoload/project/config.vim b/autoload/project/config.vim index 43c890a..e36330e 100644 --- a/autoload/project/config.vim +++ b/autoload/project/config.vim @@ -24,7 +24,7 @@ function! project#config#project(arg, ...) abort if !isdirectory(project) return endif - let s:projects[title] = { "type": "project", "event": event, "project": project, "title": title, "callbacks": [], "pos": s:pos} + let s:projects[title] = { "type": "project", "event": event, "project": project, "title": title, "callbacks": [], "inits": [], "pos": s:pos} let s:pos += 1 call s:setup() endfunction @@ -42,6 +42,19 @@ function! project#config#callback(title, callback) abort call s:setup() endfunction +function! project#config#init(title, callback) abort + if type(a:callback) == type([]) + let callbacks = a:callback + else + let callbacks = [a:callback] + endif + let project_or_filename = s:projects[a:title] + for callback in callbacks + call add(project_or_filename["inits"], callback) + endfor + call s:setup() +endfunction + function! project#config#title(filename, title) abort let filename = s:full_path(a:filename) if !filereadable(filename) @@ -50,7 +63,7 @@ function! project#config#title(filename, title) abort if !filereadable(filename) return else - let s:projects[a:title] = { "type": "filename", "event": filename, "title": a:title, "callbacks": [], "pos": s:pos } + let s:projects[a:title] = { "type": "filename", "event": filename, "title": a:title, "callbacks": [], "inits": [], "pos": s:pos } let s:pos += 1 call s:setup() endif @@ -144,10 +157,16 @@ function! project#config#welcome() abort endif let line = printf(printf(' ['. cnt .']'.padding.'%s '.file, '%-'.max_title_length.'s'), v["title"]) call append('$', line) + let inits = '' + if (len(v['inits']) > 0) + for i in v['inits'] + let inits = inits . ' \| call '.i.'("'.v["title"].'") ' + endfor + endif if get(g:, 'project_use_nerdtree', 0) && isdirectory(file) - execute 'nnoremap '. cnt .' :enew \| NERDTree '. s:escape(file).lcd."" + execute 'nnoremap '. cnt .' :enew \| NERDTree '. s:escape(file).inits.lcd."" else - execute 'nnoremap '. cnt .' :edit '. s:escape(file).lcd."" + execute 'nnoremap '. cnt .' :edit '. s:escape(file).inits.lcd."" endif let cnt += 1 if cnt == 10