diff --git a/README.md b/README.md index a8bf6f5..8542443 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,33 @@ Or a merely indented comment: And the cursor is placed anywhere before the `//`, it won't work as vim won't identify the current cursor position's syntax to be a comment. Pull Requests are welcome to improve this. +### Ignoring filetypes + +If you want to explicitly declare a set of filetypes that cosco will ignore you can add one of the following lines to your `.vimrc`: + +```vim +let g:cosco_filetype_whitelist = ['php', 'javascript'] +let g:cosco_filetype_blacklist = ['vim', 'bash'] +``` + +These variables must be declared as a list (array) of languages recognized by vim + +**Whitelist** +The `g:cosco_filetype_whitelist` variable is used to declare a list of filetypes that cosco will work in. If this variable is declared, cosco will ignore any filetype that is not specified in the whitelist variable. + +**Blacklist** +The `g:cosco_filetype_blacklist` variable is used to declare a list of filetypes that cosco will ignore. If this variable is declared, cosco will ignore any filetype that is specified in the blacklist variable. + +If neither of these variables are declared in the `.vimrc` cosco will work in any filetype. + +The `g:cosco_filetype_whitelist` variable will override and ignore the `g:cosco_filetype_blacklist` variable if both variables are declared in your `.vimrc`. + +**Getting the current filetype** +You can easily get the current filetype by calling: +```vim +:set ft? +``` + ## Auto CommaOrSemicolon Insertion Mode (Experimental) Auto insertion of a comma or a semicolon is also supported through the function: diff --git a/autoload/cosco.vim b/autoload/cosco.vim index 3ea1c24..c13002e 100644 --- a/autoload/cosco.vim +++ b/autoload/cosco.vim @@ -40,7 +40,7 @@ endfunction function! s:hasUnactionableLines() " Ignores comment lines, if global option is configured if (g:cosco_ignore_comment_lines == 1) - let l:isComment = synIDattr(synID(line("."),col("."),1),"name") =~ 'omment$' + let l:isComment = synIDattr(synID(line("."),col("."),1),"name") =~ '\ccomment' if l:isComment return 1 endif @@ -57,6 +57,26 @@ function! s:hasUnactionableLines() endif endfunction +function! s:ignoreCurrentFiletype() + if(exists("g:cosco_filetype_whitelist")) + for i in g:cosco_filetype_whitelist + if (&ft == i) + return 0 + endif + endfor + return 1 + elseif(exists("g:cosco_filetype_blacklist")) + for i in g:cosco_filetype_blacklist + if(&ft == i) + return 1 + endif + endfor + return 0 + else + return 0 + endif +endfunction + " ===================== " Filetypes extensions: " ===================== @@ -107,6 +127,11 @@ function! cosco#commaOrSemiColon() return endif + " Dont run if current filetype has been disabled: + if (s:ignoreCurrentFiletype()) + return + endif + let b:wasExtensionExecuted = 0 let b:originalLineNum = line('.')