From 4006ca8641a4cac552f23deaf11bfbd661528a63 Mon Sep 17 00:00:00 2001 From: Simone Gentili Date: Sat, 6 Jun 2015 07:03:30 +0200 Subject: [PATCH] Improved ComposerKnowWhereCurrentFileIs and readme file --- README.md | 10 ++++++++-- plugin/vim-composer.vim | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a116a41..3207966 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,15 @@ This command open `composer.json` ```vim :ComposerKnowWhereCurrentFileIs ``` -This function aims to help you to load files without using ctag. Grep current word inside composer autogenerated files, and if only one occurrence is found, opens file in another tab. If zero or more occurrences are found, simply echoes a string to advice you. To use this in your .vimrc file, just remap function. For example you can use: +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 - map :call ComposerKnowWhereCurrentFileIs() + nnoremap p :call g:ComposerKnowWhereCurrentFileIs() + +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: + + function! g:VimComposerCustomBehavior(currentWord) + exec "normal \" . a:currentWord + endfunction ## Install diff --git a/plugin/vim-composer.vim b/plugin/vim-composer.vim index ee7865e..6d0b9d0 100644 --- a/plugin/vim-composer.vim +++ b/plugin/vim-composer.vim @@ -65,6 +65,6 @@ function! g:ComposerKnowWhereCurrentFileIs() let l:openFileCommand = 'tabe .' . l:fileName exec l:openFileCommand else - echo "No unique file found in composer's generated files" + call g:VimComposerCustomBehavior(g:currentWord) endif endfunction