Skip to content

Commit

Permalink
Added support for passing flags to the script from Vim.
Browse files Browse the repository at this point in the history
Closes ycm-core#1
  • Loading branch information
rdnetto committed Apr 5, 2015
1 parent 756b915 commit 23ec1df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It is reasonably fast, taking ~10 seconds to generate a configuration file for t
## Usage
Run ```./config-gen.py PROJECT_DIRECTORY```, where ```PROJECT_DIRECTORY``` is the root directory of your project's build system (i.e. the one containing the root Makefile, etc.)

YCM-Generator can also be used as a Vim plugin. Once installed with Vundle/NeoBundle/etc., use the ```:YcmGenerateConfig``` command to generate a config file for the current directory.
YCM-Generator can also be used as a Vim plugin. Once installed with Vundle/NeoBundle/etc., use the ```:YcmGenerateConfig``` command to generate a config file for the current directory. This command accepts the same arguments as ```./config-gen.py```, but does not require the project directory to be specified (it defaults to the current working directory).

## Requirements and Limitations
* Requirements:
Expand Down
13 changes: 10 additions & 3 deletions plugin/ycm-generator.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@

let s:config_gen = expand("<sfile>:p:h:h") . "/config_gen.py"

command -nargs=0 YcmGenerateConfig call s:YcmGenerateConfig()
command -nargs=? YcmGenerateConfig call s:YcmGenerateConfig("<args>")

function s:YcmGenerateConfig(flags)
let l:cmd = "! " . s:config_gen . " " . a:flags

" Only append the working directory if the last option is not a flag
let l:split_flags = split(a:flags)
if len(l:split_flags) == 0 || l:split_flags[-1] =~ "^-"
let l:cmd = l:cmd . " " . getcwd()
endif

function s:YcmGenerateConfig()
let l:cmd = "! " . s:config_gen . " " . getcwd()
execute l:cmd
endfunction

0 comments on commit 23ec1df

Please sign in to comment.