Closed haruyama closed 7 years ago
So context_filetype.vim sets 'c' to filetype in and after(!) C-style comment lines.
I don't understand it. Please upload the example.
1 package main
2
3 /*
4 */
5
6 func hoge() string {
7 return ""
8 }
Lines 1, 2, 3 and 8 are go
, others are c
.
Oh...
But why
+ \ 'end': '^\s*\*/\s*\_.\{1}\s*import\s\+"C"$', 'filetype': 'c',
fixes the problem?
\n
does not express new-line in Vim regexp.
\_.
expresses all chars including new-line(\{1}
is redundant).
cf: [Vim正規表現-特訓#1]Vimで複数行にまたがる条件で検索 - Qiita
Sorry, My pattern
+ \ 'end': '^\s*\*/\s*\_.\{1}\s*import\s\+"C"$', 'filetype': 'c',
is also not correct. It does not work fine.
I retry searching adequate pattern.
[WIP] Fix cgo support #32
I suppose that curretn range searching scheme is insufficient for cgo support.
I suppose that cgo support has 2 problems.
1: context_filetype.vim supports a range with start pattern without end pattern.This feature works fine in many situation, such as editing following dein.toml:
[[plugins]]
repo = 'Shougo/vimproc.vim'
`toml`
hook_post_update = '''
`vim`
In golang, a C-style (no cgo) comment has a filetype=c start pattern and does not have filetype=c end pattern. This is why a range between line /*
(+1) and EOL(-1) becomes filetype=c.
cf: https://github.com/Shougo/context_filetype.vim/issues/31#issuecomment-319625600
2: Even if disabling without end pattern
support, current context_filetype.vim range searching does not work fine for following go code.
1 /*
2 */
3
4 /*
5 */
6 import "C"
In lines between 2 and 3, context_filetype.vim set filetype=c, this is because start pattern matches line 1 and end pattern matches line 5,6.
I suppose that supporting cgo-like range (end pattern is more important than start) needs another search_range(), which searches end pattern first and start pattern second, contrary to existing search_range().
Most golang users do not write cgo and may use C-style comments, so reverting bf0ff1392e4310b413846f12aad2a61626588065 is one solution.
Current s:default_filetypes.go definition is here. https://github.com/Shougo/context_filetype.vim/commit/bf0ff1392e4310b413846f12aad2a61626588065
'end' pattern matches lines after "*/"(?), So context_filetype.vim sets 'c' to filetype in and after(!) C-style comment lines.
I made simple fix,
'\n'
with'\_.\{1}'
but, it does not work for a file with multi C-sytle comments.
Second and third 'go' are not correctly set(
c
).