├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── doc └── composer.txt └── plugin └── vim-composer.vim /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Release 0.3.0 2 | * [#18](https://github.com/vim-php/vim-composer/pull/18) Added missing ComposerUpdate function 3 | * [#21](https://github.com/vim-php/vim-composer/pull/21) Added missing CONTRIBUTING.md file 4 | * [#20](https://github.com/vim-php/vim-composer/pull/20) Require and/or init commands 5 | 6 | Release 0.2.0 7 | * [#17](https://github.com/vim-php/vim-composer/pull/17) Improved ComposerKnowWhereCurrentFileIs and readme file 8 | * [#16](https://github.com/vim-php/vim-composer/pull/16) Local variable are now global in ComposerKnowWhereCurrentFileIs 9 | * [#14](https://github.com/vim-php/vim-composer/pull/14) Fixed project path folder 10 | * [#13](https://github.com/vim-php/vim-composer/pull/13) Before ask to CtrlP, ComposerKnowWhereCurrentFileIs ask to composer 11 | 12 | Release 0.1.0 13 | 14 | * [#1](https://github.com/vim-php/vim-composer/pull/1) Download composer.phar in root dir 15 | * [#5](https://github.com/vim-php/vim-composer/pull/5) Close #4 ComposerInstall command 16 | * [#6](https://github.com/vim-php/vim-composer/pull/6) Close #2 init composer.json open command 17 | * [#10](https://github.com/vim-php/vim-composer/pull/10) Close #3 exec custom callback after composer install 18 | * [#11](https://github.com/vim-php/vim-composer/pull/11) Add help 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become contributor 2 | 3 | This plugin is very easy, there is a lot of space for community update, feedback and features request. Help this 4 | project with issues and PRs! 5 | 6 | * fork the project 7 | * apply your changes 8 | * ensure that your code work 9 | * update README.md file 10 | * upfate also doc/composer.txt file 11 | * send a pull request 12 | 13 | Thanks! 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2015, Gianluca Arbezzano, and a number of other of contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim composer 2 | Manage [composer](https://getcomposer.org) in Vim 3 | 4 | ```vim 5 | :ComposerRun 6 | ``` 7 | To run command for example `:ComposerRun validate` run command validate for your json 8 | 9 | ```vim 10 | :ComposerGet 11 | ``` 12 | This command exec the installation flow of composer's install. This process require `curl` 13 | Also remeber that it is possibile run this vim command without enter inside the 14 | editor: `$ vim -c 'ComposerGet' -c 'q'` 15 | 16 | ```vim 17 | :ComposerInstall [--no-dev ..] 18 | ``` 19 | This command exec `composer install`. Now you can attach after this command a custom callback to exec your personal flow. 20 | 21 | ```vim 22 | :ComposerInit [--no-dev ..] 23 | ``` 24 | This command exec `composer init`. 25 | 26 | ```vim 27 | function! MyCallbackFunction() 28 | exec ':silent ! ctags -a %' 29 | endfunction 30 | let g:composer_install_callback = "MyCallbackFunction" 31 | ``` 32 | In this example after every `composer install` I exec a ctags generation 33 | 34 | ```vim 35 | :ComposerUpdate [--no-dev ..] 36 | ``` 37 | This command exec `composer update`. 38 | 39 | ```vim 40 | :ComposerRequireFunc 41 | ``` 42 | This command exec `composer require `. 43 | 44 | ```vim 45 | :ComposerJSON 46 | ``` 47 | This command open `composer.json` 48 | 49 | 50 | ```vim 51 | :ComposerKnowWhereCurrentFileIs 52 | ``` 53 | Instead of use CtrlP directly, this function check if composer's autogenerated files contains exactly one occurrence of curent word. In this case, class file will be opened. CtrlP with current word is called instead. And because is CtrlP wrapper, we suggest to eventually remap the function with p 54 | 55 | nnoremap p :call g:ComposerKnowWhereCurrentFileIs() 56 | 57 | If zero or more than one occurrences are found, ... a Customizable function will be called. This function is called VimComposerCustomBehavior(). When you press p ComposerKnowWhereCurrentFileIs is called. If one file is found it will be opened. If not, this function is called with current word as parameter. If you want, you can call CtrlP. Here an example: 58 | 59 | function! g:VimComposerCustomBehavior(currentWord) 60 | exec "normal \" . a:currentWord 61 | endfunction 62 | 63 | 64 | ## Install 65 | ```vim 66 | Bundle 'vim-php/vim-composer' 67 | ``` 68 | 69 | ## Force composer phar 70 | This plugin support an autodetach test to check the correct path of composer.phar 71 | If this check fails you can try to force correct path 72 | ``` 73 | let g:composer_cmd = "/usr/bin/composer" 74 | ``` 75 | -------------------------------------------------------------------------------- /doc/composer.txt: -------------------------------------------------------------------------------- 1 | *composer.txt* refactoring tools for PHP 2 | 3 | PHP COMPOSER SUPPORT FOR VIM 4 | (requires https://github.com/vim-php/vim-composer) 5 | 6 | ================================================================================ 7 | CONTENTS *VimComposerContents* 8 | 9 | 1. Setup ............................. |VimComposerSetup| 10 | 2. Usage ............................. |VimComposerUsage| 11 | 4. License ........................... |VimComposerLicense| 12 | 5. Contributing ...................... |VimComposerContrib| 13 | 14 | ================================================================================ 15 | SETUP *VimComposerSetup* 16 | 17 | Manage composer https://getcomposer.org in Vim 18 | 19 | Bundle 'vim-php/vim-composer' 20 | 21 | This plugin support an autodetach test to check the correct path of composer.phar 22 | If this check fails you can try to force correct path 23 | 24 | let g:composer_cmd = "/usr/bin/composer" 25 | 26 | ================================================================================ 27 | USAGE *VimComposerUsage* 28 | 29 | :ComposerRun 30 | To run command for example `:ComposerRun validate` run command validate for your json 31 | 32 | :ComposerGet 33 | This command exec the installation flow of composer's install. This process require `curl` 34 | 35 | :ComposerInstall [--no-dev ..] 36 | This command exec `composer install`. Now you can attach after this command a custom callback to exec your personal flow. 37 | 38 | function! MyCallbackFunction() 39 | exec ':silent ! ctags -a %' 40 | endfunction 41 | let g:composer_install_callback = "MyCallbackFunction" 42 | 43 | In this example after every `composer install` I exec a ctags generation 44 | 45 | :ComposerJSON 46 | This command open `composer.json` 47 | 48 | ================================================================================ 49 | LICENSE *VimComposerLicense* 50 | 51 | The MIT License (MIT) 52 | 53 | Copyright (c) 2015 Gianluca Arbezzano 54 | 55 | Permission is hereby granted, free of charge, to any person obtaining a copy of 56 | this software and associated documentation files (the "Software"), to deal in 57 | the Software without restriction, including without limitation the rights to 58 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 59 | the Software, and to permit persons to whom the Software is furnished to do so, 60 | subject to the following conditions: 61 | 62 | The above copyright notice and this permission notice shall be included in all 63 | copies or substantial portions of the Software. 64 | 65 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 66 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 67 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 68 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 69 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 70 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 71 | 72 | ================================================================================ 73 | CONTRIBUTING *VimComposerContrib* 74 | 75 | https://github.com/vim-php/vim-composer 76 | This plugin is very easy, there is a lot of space for community update, feedback and 77 | features request. 78 | Help me with issues and PRs! 79 | Thanks! 80 | -------------------------------------------------------------------------------- /plugin/vim-composer.vim: -------------------------------------------------------------------------------- 1 | " ------------------------------------------------------------------------------ 2 | " Vim Composer {{{ 3 | " 4 | " Author: Gianluca Arbezzano 5 | " 6 | " Description: 7 | " Run Composer from within Vim. 8 | " 9 | " Requires: Vim 6.0 or newer 10 | " 11 | " License: MIT 12 | " 13 | " }}} 14 | " ------------------------------------------------------------------------------ 15 | 16 | if !exists("g:composer_cmd") 17 | if filereadable('./composer.phar') 18 | let g:composer_cmd='php ./composer.phar' 19 | else 20 | let g:composer_cmd='composer' 21 | endif 22 | endif 23 | 24 | 25 | command! -narg=* ComposerInstall call s:ComposerInstallFunc() 26 | command! -narg=* ComposerRun call s:ComposerRunFunc() 27 | command! -narg=* ComposerUpdate call s:ComposerUpdateFunc() 28 | 29 | command! ComposerGet call s:ComposerGetFunc() 30 | command! ComposerInit call s:ComposerInitFunc() 31 | command! ComposerJSON call s:OpenComposerJSON() 32 | command! ComposerRequire call s:ComposerRequireFunc() 33 | command! ComposerDumpAutoload call s:ComposerDumpAutoloadFunc() 34 | 35 | function! s:ComposerRunFunc(action) 36 | let s:action = a:action 37 | let s:composer = '!' . g:composer_cmd . ' ' . s:action 38 | exe s:composer 39 | endfunction 40 | 41 | function! s:ComposerGetFunc() 42 | exe "! curl -Ss https://getcomposer.org/installer | php" 43 | endfunction 44 | 45 | function! s:OpenComposerJSON() 46 | if filereadable("./composer.json") 47 | exe "vsplit ./composer.json" 48 | else 49 | echo "Composer json doesn't exist" 50 | endif 51 | endfunction 52 | 53 | if !exists("g:composer_install_callback") 54 | let g:composer_install_callback = "" 55 | endif 56 | 57 | function! s:ComposerInstallFunc(arg) 58 | exe s:ComposerRunFunc("install") 59 | if len(g:composer_install_callback) > 0 60 | exe "call ".g:composer_install_callback."()" 61 | endif 62 | endfunction 63 | 64 | function! s:ComposerInitFunc() 65 | exe s:ComposerRunFunc("init") 66 | endfunction 67 | 68 | function! s:ComposerUpdateFunc(arg) 69 | exe s:ComposerRunFunc("update") 70 | endfunction 71 | 72 | function! s:ComposerRequireFunc() 73 | exe s:ComposerRunFunc("require") 74 | endfunction 75 | 76 | function! s:ComposerDumpAutoloadFunc() 77 | exe s:ComposerRunFunc("dump-autoload") 78 | endfunction 79 | 80 | function! g:ComposerKnowWhereCurrentFileIs() 81 | let g:currentWord = expand('') 82 | let l:command = "grep " . g:currentWord . " ./vendor/composer -R | awk '{print $6}' | awk -F\\' '{print $2}'" 83 | let l:commandFileFound = l:command . ' | wc -l' 84 | let g:numberOfResults = system(l:commandFileFound) 85 | if g:numberOfResults == 1 86 | let l:fileName = system(l:command) 87 | let l:openFileCommand = 'tabe .' . l:fileName 88 | exec l:openFileCommand 89 | else 90 | call g:VimComposerCustomBehavior(g:currentWord) 91 | endif 92 | endfunction 93 | --------------------------------------------------------------------------------