Skip to content

Commit

Permalink
Merge pull request #15 from KroniK907/master
Browse files Browse the repository at this point in the history
Disable the auto add in all types of comments & explicitly ignore filetypes
  • Loading branch information
lfilho authored Jul 23, 2017
2 parents 2ca7a0e + 031dd08 commit 5f7d13a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 26 additions & 1 deletion autoload/cosco.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
" =====================
Expand Down Expand Up @@ -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('.')
Expand Down

0 comments on commit 5f7d13a

Please sign in to comment.