diff --git a/autoload/vimprj.vim b/autoload/vimprj.vim index 7074a5a..84445ae 100644 --- a/autoload/vimprj.vim +++ b/autoload/vimprj.vim @@ -10,6 +10,11 @@ " current file (types :make ), then vimprj swithed to the " 'default' settings. " *) 1.10 - fixed issue with spaces in paths (thanks to Alexey Shevchenko) +" *) 1.11 - added $VIMPRJ_PROJECT_ROOT variable, which is set to the root of +" the currently active project. +" - default behavior changed: now, by default, Vimprj doesn't change +" your current working directory. +" Set g:vimprj_changeCurDirIfVimprjFound if you want it to do so. " g:vimprj#dRoots - DICTIONARY with info about $INDEXER_PROJECT_ROOTs @@ -35,7 +40,7 @@ " [0, 1, 2, ...] - LIST KEY. At this moment, only 0 is available " ["file"] - key for s:dProjFilesParsed " ["name"] - name of project -" +" if v:version < 700 @@ -117,7 +122,7 @@ endif " all dependencies is ok -let g:vimprj#version = 110 +let g:vimprj#version = 111 let g:vimprj#loaded = 1 let s:boolInitialized = 0 @@ -158,8 +163,6 @@ function! vimprj#applyVimprjSettings(sVimprjKey) call ChangeDirToVimprj(g:vimprj#dRoots[ a:sVimprjKey ]["cd_path"]) - " для каждого проекта, в который входит файл, добавляем tags и path - call _AddToDebugLog(s:DEB_LEVEL__ALL, 'function end: __ApplyVimprjSettings__', {}) endfunction @@ -168,7 +171,6 @@ function! vimprj#getVimprjKeyOfFile(iFileNum) endfunction -" задаем пустые массивы с данными function! vimprj#init() if s:boolInitialized return @@ -190,7 +192,7 @@ function! vimprj#init() endif if !exists('g:vimprj_changeCurDirIfVimprjFound') - let g:vimprj_changeCurDirIfVimprjFound = 1 + let g:vimprj_changeCurDirIfVimprjFound = 0 endif if !exists('g:vimprj_sourceScriptsOnlyIfVimprjChanged') @@ -198,7 +200,7 @@ function! vimprj#init() endif - " задаем пустые массивы с данными + " initialize empty arrays let g:vimprj#dRoots = {} let g:vimprj#dFiles = {} let g:vimprj#iCurFileNum = -1 @@ -224,7 +226,7 @@ function! vimprj#init() \ 'ApplySettingsForFile' : {}, \ } - " указываем обработчик открытия нового файла: OnFileOpen + " OnFileOpen handler augroup Vimprj_LoadFile autocmd! Vimprj_LoadFile BufReadPost autocmd! Vimprj_LoadFile BufNewFile @@ -232,12 +234,13 @@ function! vimprj#init() autocmd Vimprj_LoadFile BufNewFile * call OnFileOpen(bufnr(expand(''))) augroup END - " указываем обработчик входа в другой буфер: OnBufEnter + " OnBufEnter handler augroup Vimprj_BufEnter autocmd! Vimprj_BufEnter BufEnter autocmd Vimprj_BufEnter BufEnter * call OnBufEnter(bufnr(expand(''))) augroup END + " OnBufSave handler augroup Vimprj_BufWritePost autocmd! Vimprj_BufWritePost BufWritePost autocmd Vimprj_BufWritePost BufWritePost * call OnBufSave() @@ -253,13 +256,11 @@ endfunction -" Парсит директорию проекта (директорию, в которой лежит директория .vimprj) -" Добавляет новый vimprj_root +" Parse the directory folder (the directory which contains `.vimprj` dir) " " @param lProjectRoots list with paths to projs dir -" (this is list instead of string because we need to support nested +" (this is a list instead of a string because we need to support nested " projs) - function! ParseNewVimprjRoot(lProjectRoots) let l:sLastVimprjFolder = "" @@ -314,7 +315,7 @@ function! CreateDefaultProjectIfNotAlready() \ 'sVimprjDirName' : '' \ }) - " создаем дефолтный "проект" + " create default "project" call ChangeDirToVimprj(substitute(s:sStartCwd, ' ', '\\ ', 'g')) call AddNewVimprjRoot("default", [], s:sStartCwd) "call TakeAccountOfFile(0, 'default') @@ -416,10 +417,10 @@ function! ExecHooks(sHooksgroup, dParams) endfunction -" добавляет новый vimprj root, заполняет его текущими параметрами +" Add new vimprj root, fill it with current params " -" ВНИМАНИЕ! "текущими" параметрами - это означает, что на момент вызова -" этого метода все .vim файлы из .vimprj уже должны быть выполнены! +" NOTE: "current params" means that when this function is called, all +" .vimprj/*.vim files should be sourced already! function! AddNewVimprjRoot(sVimprjKey, lPaths, sCdPath) if !has_key(g:vimprj#dRoots, a:sVimprjKey) @@ -462,13 +463,13 @@ endfunction -" returns if we should to skip this buffer ('skipped' buffers are not handled -" by vimprj plugin at all) +" returns if we should skip this buffer ('skipped' buffers are not handled by +" vimprj plugin at all) function! NeedSkipBuffer(iFileNum) " COMMENTED!! file should be readable - " commented because of we should parse creation of new files, - " which isn't readable at BufNewFile. + " commented because we should parse creation of new files, which isn't + " readable at BufNewFile. " "if !filereadable(bufname(a:iFileNum)) "return 1 @@ -536,10 +537,10 @@ function! SourceVimprjFiles(sPath) endfunction function! ChangeDirToVimprj(sPath) - " переключаем рабочую директорию + " switch working dir if (g:vimprj_changeCurDirIfVimprjFound) exec "cd ".a:sPath - " ???? иначе не работает + " ???? very strange, but sometimes it doesn't work otherwise exec "cd ".a:sPath endif endfunction @@ -558,6 +559,9 @@ function! GetVimprjRootOfFile(iFileNum) let l:sCurPath = l:sDirname while (l:i < g:vimprj_recurseUpCount) let l:sTmp = simplify(l:sCurPath.'/'.g:vimprj_dirNameForSearch) + if has("win32unix") + let l:sTmp = substitute(l:sTmp, '//', '/', 'g') + endif if isdirectory(l:sTmp) || filereadable(l:sTmp) " directory or file with needed name found @@ -568,9 +572,12 @@ function! GetVimprjRootOfFile(iFileNum) "break endif - + " get upper path let l:sNextCurPath = simplify(l:sCurPath.'/..') + if has("win32unix") + let l:sNextCurPath = substitute(l:sNextCurPath, '//', '/', 'g') + endif if (l:sNextCurPath == l:sCurPath) " we reached root of filesystem. break now break @@ -583,16 +590,15 @@ function! GetVimprjRootOfFile(iFileNum) if !empty(l:sProjectRoot) " .vimprj directory or file is found. - " проверяем, не открыли ли мы файл из директории .vimprj (или, если это - " файл, то не открыли ли мы этот файл) + " + " Let's check if the file in question is a file from .vimprj + " directory let l:sPathToDirNameForSearch = l:sProjectRoot.'/'.g:vimprj_dirNameForSearch - "let l:iPathToDNFSlen = strlen(l:sPathToDirNameForSearch) - - "if strpart(l:sFilename, 0, l:iPathToDNFSlen) == l:sPathToDirNameForSearch " открытый файл - из директории .vimprj, так что для него if dfrank#util#IsFileInSubdir(l:sFilename, l:sPathToDirNameForSearch) - " НЕ будем применять настройки из этой директории. + " Yes, we opened a file from .vimprj dir. So, we're not going to + " apply settings from .vimprj dir. let l:sProjectRoot = '' endif @@ -673,7 +679,7 @@ function! OnFileOpen(iFileNum) \ 'sVimprjDirName' : '' \ }) - " создаем дефолтный "проект" + " create default "project" call ChangeDirToVimprj(substitute(s:sStartCwd, ' ', '\\ ', 'g')) call AddNewVimprjRoot("default", [], s:sStartCwd) "call TakeAccountOfFile(0, 'default') @@ -695,6 +701,8 @@ function! OnFileOpen(iFileNum) call SetCurrentFile(l:iFileNum) + let $VIMPRJ_PROJECT_ROOT = g:vimprj#dRoots[ l:sVimprjKey ].proj_root + call ExecHooks('OnFileOpen', { \ 'iFileNum' : l:iFileNum, \ }) diff --git a/doc/auxiliary/cur_changes.txt b/doc/auxiliary/cur_changes.txt new file mode 100644 index 0000000..d20a60f --- /dev/null +++ b/doc/auxiliary/cur_changes.txt @@ -0,0 +1,3 @@ + +*) Refactor. Added new dependency: script-library DfrankUtil (vimscript #3884) + diff --git a/doc/auxiliary/vim_org.txt b/doc/auxiliary/vim_org.txt new file mode 100644 index 0000000..992c020 --- /dev/null +++ b/doc/auxiliary/vim_org.txt @@ -0,0 +1,104 @@ +Please note: there's dependency DfrankUtil (vimscript #3884) + + * * * + +Many times i faced a problem. That's the story: + +I'd like to use 3-space indent in my projects. +No tabs, especially three spaces. One day i need to work on another project +written by someone else, and there's 4 spaces indent. Or maybe tabs. + +I need to work on this project too, and i need to leave existing formatting +options. + +I strongly dislike that i have to switch these options by hand: &shiftwidth, +&tabstop, &expandtab. + +And then i decided to write this plugin to make my life easier. + +Using this plugin is quite easy. You need to create in the root directory of +your project new directory ".vimprj" and put any number of files "*.vim" in it. +Every time you open new file in Vim, plugin looks for ".vimprj" directory up +by tree, and if it is found, then all *.vim files from it will be sourced. + +OR: you can just put file ".vimprj", then this file will be sourced. +Name ".vimprj" can be changed by editing option g:vimprj_dirNameForSearch . + +Usually for my own projects i create just one file .vimprj/my.vim with the +following contents: > + + let &tabstop = 3 + let &shiftwidth = 3 + set expandtab + +(my .vimprj directory also contain tags and other project-specific files, +so, i'd prefer to use directory instead of just one file.) + +and for other projects i create file with appropriate options. + +Now, when i open file from my project, file my.vim is sourced. When i open +file from some another project, its own file with options is sourced too. Of +course, when i switch buffer, this files are sourced too if project is +changed. + +So, i always have correct options, and simultaneus work on several projects +with different formatting options is not painful anymore for me. + +And, of course, you can use it not only to manage formatting options. For +instance, in some my projects i use mapping to open project window +(from plugin project.tar.gz), but for some java projects i use Eclim, and +should be mapped to another command (to open Eclim's project). +All these options can also be stated in .vimprj dir. + +There is an issue: as i already said, i would like to use shiftwidth=3. Say, +i open some file from my project with shiftwidth=3. All ok here. Then i open +file from another project with shiftwidth=4. All is still ok. Then i open some +file not from any project (there's no ".vimprj" directory). Of course, i would +like to use my favorite options (e.g. shiftwidth=3), but now shiftwidth is 4, +because it was changed when i opened last project. It leads us to the fact +that we should define default options. But here let me make a digression. + +Plugin provides some hooks for any other plugin. For instance, plugin +Indexer (since version 4.0) uses these hooks to provide correct behavior +when user works on different project simultaneusly. + +Right now i have not documented yet all these hooks, because of lack of +free time, but i just tell you about one hook, to let you specify your +default options. + +This is a hook "SetDefaultOptions". Now i show you an example. Please insert +in your .vimrc the following, just specify your own default options instead of +mine ones: > + + function! SetMainDefaults() + + " your default options goes here! + set tabstop=3 + set shiftwidth=3 + set expandtab + + endfunction + + call SetMainDefaults() + + " initialize vimprj plugin + call vimprj#init() + + " define a hook + function! g:vimprj#dHooks['SetDefaultOptions']['main_options'](dParams) + call SetMainDefaults() + endfunction + +Now vimprj plugin will call your function SetMainDefaults just before sourcing +all *.vim files from .vimprj directory, and when you open file not from any +project. + +If you are interesting about another hooks, you can just look how is they used +in Indexer plugin (since version 4.0). I hope one day i will write all this here. =) + +Please NOTE: by default this plugin will change your current dir +to project's dir if ".vimprj" is found. +More detailed read in help: type :help vimprj-options , look for an option +g:vimprj_changeCurDirIfVimprjFound + +Development repository (Mercurial) : http://hg.dfrank.ru/vim/bundle/vimprj diff --git a/doc/vimprj.txt b/doc/vimprj.txt index 7f8080e..a1ecf01 100644 --- a/doc/vimprj.txt +++ b/doc/vimprj.txt @@ -4,10 +4,10 @@ By Dmitry Frank - dimon.frank@gmail.com + mail@dmitryfrank.com Firstly: if you have any questions regards this plugin, feel free -to email me: dimon.frank@gmail.com +to email me: mail@dmitryfrank.com *vimprj* *vimprj-plugin* @@ -24,19 +24,19 @@ Please note: there's some dependencies. Please read |vimprj-dependencies|. * * * -Many times i faced a problem. That's the story: +Many times I faced a problem. That's the story: I'd like to use 3-space indent in my projects. -No tabs, especially three spaces. One day i need to work on another project +No tabs, especially three spaces. One day I need to work on another project written by someone else, and there's 4 spaces indent. Or maybe tabs. -I need to work on this project too, and i need to leave existing formatting +I need to work on this project too, and I need to leave existing formatting options. -I strongly dislike that i have to switch these options by hand: &shiftwidth, +I strongly dislike that I have to switch these options by hand: &shiftwidth, &tabstop, &expandtab. -And then i decided to write this plugin to make my life easier. +And then I decided to write this plugin to make my life easier. Using this plugin is quite easy. You need to create in the root directory of your project new directory ".vimprj" and put any number of files "*.vim" in it. @@ -46,7 +46,7 @@ by tree, and if it is found, then all *.vim files from it will be sourced. OR: you can just put file ".vimprj", then this file will be sourced. Name ".vimprj" can be changed by editing option g:vimprj_dirNameForSearch . -Usually for my own projects i create just one file .vimprj/my.vim with the +Usually for my own projects I create just one file .vimprj/my.vim with the following contents: > let &tabstop = 3 @@ -54,41 +54,41 @@ following contents: > set expandtab This my .vimprj directory also contain tags and other project-specific files, -so, i'd prefer to use directory instead of just one file. +so, I'd prefer to use directory instead of just one file. -and for other projects i create files with appropriate options. +and for other projects I create files with appropriate options. -Now, when i open file from my project, file my.vim is sourced. When i open +Now, when I open file from my project, file my.vim is sourced. When I open file from some another project, its own file with options is sourced too. Of -course, when i switch buffer, this files are sourced too if project is +course, when I switch buffer, this files are sourced too if project is changed. -So, i always have correct options, and simultaneus work on several projects +So, I always have correct options, and simultaneus work on several projects with different formatting options is not painful anymore for me. And, of course, you can use it not only to manage formatting options. For -instance, in some my projects i use mapping to open project window -(from plugin project.tar.gz), but for some java projects i use Eclim, and +instance, in some my projects I use mapping to open project window +(from plugin project.tar.gz), but for some java projects I use Eclim, and should be mapped to another command (to open Eclim's project). All these options can also be stated in .vimprj dir. -There is an issue: as i already said, i would like to use shiftwidth=3. Say, -i open some file from my project with shiftwidth=3. All ok here. Then i open -file from another project with shiftwidth=4. All is still ok. Then i open some -file not from any project (there's no ".vimprj" directory). Of course, i would +There is an issue: as I already said, I would like to use shiftwidth=3. Say, +I open some file from my project with shiftwidth=3. All ok here. Then I open +file from another project with shiftwidth=4. All is still ok. Then I open some +file not from any project (there's no ".vimprj" directory). Of course, I would like to use my favorite options (e.g. shiftwidth=3), but now shiftwidth is 4, -because it was changed when i opened last project. It leads us to the fact +because it was changed when I opened last project. It leads us to the fact that we should define default options. But here let me make a digression. Plugin provides some hooks for any other plugin. For instance, plugin Indexer (since version 4.0) uses these hooks to provide correct behavior when user works on different project simultaneusly. -Right now i have not documented yet all these hooks, because of lack of -free time, but i just tell you about one hook, to let you specify your +Right now I have not documented yet all these hooks, because of lack of +free time, but I just tell you about one hook, to let you specify your default options. -This is a hook "SetDefaultOptions". Now i show you an example. Please insert +This is a hook "SetDefaultOptions". Now I show you an example. Please insert in your .vimrc the following, just specify your own default options instead of mine ones: > @@ -116,7 +116,7 @@ all *.vim files from .vimprj directory, and when you open file not from any project. If you are interesting about another hooks, you can just look how is they used -in Indexer plugin. I hope one day i will write all this here. =) +in Indexer plugin. I hope one day I will write all this here. =) ======================================================================== @@ -141,20 +141,18 @@ g:vimprj_dirNameForSearch (default: '.vimprj') if you don't like name ".vimprj" for some reason, you can change it. -g:vimprj_changeCurDirIfVimprjFound (default: 1) +g:vimprj_changeCurDirIfVimprjFound (default: 0) - Plugin changes current directory to directory in which ".vimprj" is found, - unless you defined g:vimprj_changeCurDirIfVimprjFound = 0 . + If set, Vimprj changes current directory to directory in which ".vimprj" is + found. - I found it quite useful: when i work on some project, i always have - root of my project as current directory. It becomes changed when i switch + I found it quite useful: when I work on some project, I always have + root of my project as current directory. It becomes changed when I switch to buffer from another project. - If i open some file not from any project, then my current directory becomes + If I open some file not from any project, then my current directory becomes a directory from what Vim was started. - If you don't like it, please let g:vimprj_changeCurDirIfVimprjFound = 0 . - ======================================================================== COMMANDS *vimprj-commands*