Skip to content

Commit 5f7d13a

Browse files
authored
Merge pull request #15 from KroniK907/master
Disable the auto add in all types of comments & explicitly ignore filetypes
2 parents 2ca7a0e + 031dd08 commit 5f7d13a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,33 @@ Or a merely indented comment:
8686

8787
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.
8888

89+
### Ignoring filetypes
90+
91+
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`:
92+
93+
```vim
94+
let g:cosco_filetype_whitelist = ['php', 'javascript']
95+
let g:cosco_filetype_blacklist = ['vim', 'bash']
96+
```
97+
98+
These variables must be declared as a list (array) of languages recognized by vim
99+
100+
**Whitelist**
101+
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.
102+
103+
**Blacklist**
104+
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.
105+
106+
If neither of these variables are declared in the `.vimrc` cosco will work in any filetype.
107+
108+
The `g:cosco_filetype_whitelist` variable will override and ignore the `g:cosco_filetype_blacklist` variable if both variables are declared in your `.vimrc`.
109+
110+
**Getting the current filetype**
111+
You can easily get the current filetype by calling:
112+
```vim
113+
:set ft?
114+
```
115+
89116
## Auto CommaOrSemicolon Insertion Mode (Experimental)
90117

91118
Auto insertion of a comma or a semicolon is also supported through the function:

autoload/cosco.vim

+26-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ endfunction
4040
function! s:hasUnactionableLines()
4141
" Ignores comment lines, if global option is configured
4242
if (g:cosco_ignore_comment_lines == 1)
43-
let l:isComment = synIDattr(synID(line("."),col("."),1),"name") =~ 'omment$'
43+
let l:isComment = synIDattr(synID(line("."),col("."),1),"name") =~ '\ccomment'
4444
if l:isComment
4545
return 1
4646
endif
@@ -57,6 +57,26 @@ function! s:hasUnactionableLines()
5757
endif
5858
endfunction
5959

60+
function! s:ignoreCurrentFiletype()
61+
if(exists("g:cosco_filetype_whitelist"))
62+
for i in g:cosco_filetype_whitelist
63+
if (&ft == i)
64+
return 0
65+
endif
66+
endfor
67+
return 1
68+
elseif(exists("g:cosco_filetype_blacklist"))
69+
for i in g:cosco_filetype_blacklist
70+
if(&ft == i)
71+
return 1
72+
endif
73+
endfor
74+
return 0
75+
else
76+
return 0
77+
endif
78+
endfunction
79+
6080
" =====================
6181
" Filetypes extensions:
6282
" =====================
@@ -107,6 +127,11 @@ function! cosco#commaOrSemiColon()
107127
return
108128
endif
109129

130+
" Dont run if current filetype has been disabled:
131+
if (s:ignoreCurrentFiletype())
132+
return
133+
endif
134+
110135
let b:wasExtensionExecuted = 0
111136

112137
let b:originalLineNum = line('.')

0 commit comments

Comments
 (0)