shougo / context_filetype.vim Goto Github PK
View Code? Open in Web Editor NEWContext filetype library for Vim script
License: Other
Context filetype library for Vim script
License: Other
test command:echom neocomplete#get_context_filetype()
in <script>block, command show 'javascript', it works.
in <style>block,command show 'html', not 'css'.
I have added following lines to my .vimrc:
if !exists('g:context_filetype#same_filetypes')
let g:context_filetype#filetypes = {}
endif
let g:context_filetype#filetypes.svelte =
\ [
\ {'filetype' : 'javascript', 'start' : '<script>', 'end' : '</script>'},
\ {'filetype' : 'css', 'start' : '<style>', 'end' : '</style>'},
\ ]
This helps with javascript autocompletion but css autocompletion does not work.
Adding this helps with css autocomplete but I think this shouldn't be necessary:
autocmd FileType svelte setlocal omnifunc=csscomplete#CompleteCSS
Any ideas what's wrong?
My .vimrc can be found here https://github.com/daliusd/cfg/blob/master/.vimrc if it is necessary.
Hello Shougo.
I've been using neocomplcache and I have some configurations options in my .vimrc of course...
So, in order to migrate to neocomplete, do we have to do anything? or just doing something like %s/neocomplache/neocomplete/g
would be enough?
Finally, if there's anything we need to do for this migration, it might be a good idea to include it in the README somewhere?
Thanks for the great plugin(s)!
#1 から派生。
巨大なファイルの場合だと重いという事で実際の処理速度を測ってみました。
function! s:context_filetype(num)
let start_time = reltime()
for i in range(a:num)
call context_filetype#get()
endfor
return str2float(reltimestr(reltime(start_time))) / a:num
endfunction
function! Check()
let num = 10
" context_filetype#get() の1回辺りの処理時間を計測
echo s:context_filetype(num)
endfunction
適当なファイルが無かったので eval.txt(約8000行)をバッファにコピーし、行頭python << HOGEHOGE
、行末にHOGEHOGE
を追加して、set filetype=vim
として試してみました。
以下の各行でcall Check()
した結果です。
また、stopline と timeout は使用していない状態です。
また、コンテキストがネストしているとその分だけ searchpos を処理する回数が増えるので更に時間がかかると思います。
個人的には stopline の閾値だけがユーザ側で設定出来れば十分だと思います。
試しに下記のように autocmd CursorMoved で処理するようにしてみました。
これを↑のファイルで動作させてみたんですが個人的にはあまり重いとは感じないレベルでした。
augroup test-context_filetype
autocmd!
autocmd CursorMoved,CursorMovedI * echo context_filetype#get()
augroup END
今すぐやるわけではないですが覚書程度につくっておきます。
g:context_filetype#filetypes
等のグローバルオプションの扱いをどうするかSame as Shougo/neocomplete.vim#491. Moved because this issue pertains to context_filetype.vim.
再現手順は上記と同様です。
#44 マージ後に追加設定なしで、以下の操作がエラーします
function precious#context_filetype[2]..99[5]..context_filetype#get_filetype[2]..context_filetype#get[3]..<SNR>327_get_nest[1]..<SNR>327_get_context[20]..<SNR>327_search_range の処理中にエラーが検出されました:
行 28:
E65: 不正な後方参照です
function precious#context_filetype[2]..99[5]..context_filetype#get_filetype の処理中にエラーが検出されました:
行 2:
E121: 未定義の変数です: filetype
(preciousのエラーも出ますが、参考までに付けています)
以下のデバッグコードを入れ
echom 'end forward search:' end_pattern
let end_forward = searchpos(end_pattern, 'ncW', stopline_forward)
再現させると
end forward search: \1\V'''\m
となりました。
searchposへ \1
を含んだパターンが入ったためのようです。
マージ前のcontext_filetypeが残っている環境での動作に問題ないことは確認しました。
https://github.com/Shougo/context_filetype.vim/blob/master/autoload/context_filetype.vim#L170
In .vue
file we can write like <template lang="pug">
but if we write so then filetype of the block will simply become html
.
Current s:default_filetypes.go definition is here.
bf0ff13
\ 'go': [
\ {
\ 'start': '^\s*/\*$',
\ 'end': '^\s*\*/\n\s*import\s\+"C"$', 'filetype': 'c',
\ },
'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}'
diff --git a/autoload/context_filetype.vim b/autoload/context_filetype.vim
index 1d3ba8a..b5ebb09 100644
--- a/autoload/context_filetype.vim
+++ b/autoload/context_filetype.vim
@@ -319,7 +319,7 @@ let s:default_filetypes = {
\ 'go': [
\ {
\ 'start': '^\s*/\*$',
- \ 'end': '^\s*\*/\n\s*import\s\+"C"$', 'filetype': 'c',
+ \ 'end': '^\s*\*/\s*\_.\{1}\s*import\s\+"C"$', 'filetype': 'c',
\ },
\ ],
\}"}}}
but, it does not work for a file with multi C-sytle comments.
package main
`go`
/*
`go`
*/
`go`
/*
`c`
*/
import "C"
`go`
Second and third 'go' are not correctly set(c
).
Hi,
Would it be possible to add support for VueJS custom blocks ? The custom blocks can have any name:
<someName>
</someName>
Here, get_filetype() could return someName or vue-someName. This would be useful for toggling comments inside those blocks. (currently i'm copying the default configuration for vue and adding each custom block manually)
Thanks.
Error detected while processing function neocomplete#handler#_do_auto_complete..neocomplete#helper#is_omni..neocomplete#get_context_filetype..neocomplete#context_filetype#set..context_filet
ype#get_filetype..context_filetype#get..<SNR>45_get_nest..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest
_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl
..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SN
R>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_
get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_n
est_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_i
mpl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..
<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>
45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_ge
t_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nes
t_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_imp
l..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_nest_impl..<SNR>45_get_context..<SNR>45_search_range:
line 1:
E132: Function call depth is higher than 'maxfuncdepth'
set nocompatible
filetype off
if has('vim_starting')
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
call neobundle#rc(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'Shougo/neocomplete', {
\ 'depends': ['Shougo/context_filetype.vim']
\ }
filetype plugin indent on
let g:neocomplete#enable_at_startup = 1
https://gist.github.com/pocke/36989eb82b1315d78a6e
set ft=markdown
するインサートモードに入らなくても再現する場合もありました。
'depends': ['Shougo/context_filetype.vim']
の部分を削除したところ、再現しませんでした。Shougo さんとコーディングスタイルがだいぶ違う感じなので共通化する為のまとめとか。
他に決めておいたほうがいいものがあれば教えて下さい。
そこまで多人数で開発する予定はない(と思う)ので、大まかな部分(全体的なインデントとか)だけ決めておいて細かい部分(どこにスペースを開けるかとか)は特に決めないでもいいと思っているんですがどうでしょうか。
neosnippet.vimのissue
から移ってきました
吉永です
ただ補完が出来ないと言うより、制限、仕様のような気がしていますが、念の為ご報告ということで
最後に動画を載せましたが
感想として
I found that there is nothing mentioned about the usage of context_filetype.vim. It should be mentioned in the wiki or the doc at least.
This is a test.md
:
---
title: "Habits"
author: John Doe
date: March 22, 2005
output:
pdf_document:
includes:
in_header: header.tex
before_body: doc_prefix.tex
after_body: doc_suffix.tex
---
# H1 Title
## H2 Title
I try caw.vim and I expect:
---
title: "Habits"
author: John Doe
# date: March 22, 2005
output:
pdf_document:
includes:
in_header: header.tex
before_body: doc_prefix.tex
after_body: doc_suffix.tex
---
# H1 Title
## H2 Title
However:
---
title: "Habits"
author: John Doe
<!-- date: March 22, 2005 -->
output:
pdf_document:
includes:
in_header: header.tex
before_body: doc_prefix.tex
after_body: doc_suffix.tex
---
# H1 Title
## H2 Title
I notice caw.vim use context_filetype.vim. So does it detect front matter of markdown as YAML?
if !exists('g:context_filetype#same_filetypes')
let g:context_filetype#filetypes = {}
endif
let g:context_filetype#filetypes.svelte = [
\ {'filetype' :'javascript', 'start': '<script>', 'end': '</script>'},
\ {'filetype' :'css', 'start': '<style>', 'end': '</style>'},
\ ]
call deoplete#custom#var('omni', 'functions', {
\ 'css': ['csscomplete#CompleteCSS'],
\})
It let css-completion work,
but javascript doesn't work with YCM, inside HTML.
Even with deoplete, comment out the YCM.
call deoplete#custom#option('omni_patterns', {
\ 'javascript': '[^. *\t]\.\w*',
\ 'go': '[^. *\t]\.\w*',
\})
In .js it work.
But in html it doesn't work too.
最近 dein.vim 用にtomlで hook_* 系にマッチするルールを追加してみて、これは便利だと感動しながら他にも使い所を考えてたらすぐに感じた事です。
例えばTOML一つにしても、今はまだ toml を使う機会はあまり多くありませんが、今後は色んなアプリケーションでtoml形式のファイルを扱うようになってくる予感がしています。
そうしてグローバルな g:context_filetype#filetypes
の同じ filetype に対する設定を追加しはじめると設定の競合が起きてきそうな事と不用なパターンの検索で遅くなりそうな事を問題に感じました。
ファイル名が dein*.toml
のときだけ toml に hook_* 系のルールを追加したいという場合は、autocmd
で b:context_filetype#filetypes
を定義してやることでグローバル設定と合わせてこれも使うという事が出来ると良いのかなと思います。
When this plugin enabled and using nvim >= 0.6.0 with iTerm2 on Mac, nvim could be blocked for more than a second sometimes.
To reproduce, type command :h a
and :h b
many times.
My computer:
MacOS 12.1
Processor: 2.6 GHz 6-Core Intel Core i7
Memory: 16 GB 2667 MHz DDR4
No happens on vim8 or other terminal.
現在(branch/precious)、コンテキストのデータを取得する関数として
context_filetype#get()
- コンテキストの filetype を返すcontext_filetype#get_range()
- コンテキストの範囲を返すを使用する事ができます。
で、この2つの関数なのですが場合によってはcontext_filetype#get()
とcontext_filetype#get_range()
を同時に呼び出すこともあると思います。
しかし、この場合、2つの関数の内部で殆ど同じ処理を行なっているので処理が重複してしまい無駄が発生します。
そこで次のような関数に変更するのはどうでしょうか。
context_filetype#get_range()
- コンテキストの範囲を返す(変更なし)context_filetype#get_filetype()
- コンテキストの filetype を返す(context_filetype#get()
から名前の変更)context_filetype#get()
- コンテキストの範囲と filetype をまとめて返す(機能変更)context_filetype#get_range()
とcontext_filetype#get_filetype()
はcontext_filetype#get()
のラッパー関数です。
context_filetype#get()
が返す内容は下記のようなフォーマットを考えています。
{
"filetype" : "vim",
"range" : [[3, 2], [10, 2]]
}
" もうちょっと細かく分割するのもあり?
" {
" "filetype" : "vim",
" "range" : {
" "start" : [3, 2],
" "end" : [10, 2]
" }
" }
片方のデータが欲しい場合は context_filetype#get_range()
や context_filetype#get_filetype()
を使用し、両方(全て)のデータが欲しい場合はcontext_filetype#get()
を使用します。
こんな感じに変更するのはどうでしょうか。
(あとこれを考えて思ったんですが、プラグイン名はcontext_filetype
よりもcontext
の方がすっきりするんじゃないかと思いました。context#get_filetype()
、context#get_range()
Hi there, love your work,
am using dein with toml configuration and im using caw for commenting which uses context_filetype.
in the gif im trying to show that the context_filetype is behaving a little weird with comments.
normally when at the end of a multiline comment in toml (''') the detected filetype is toml, but when i comment the line out it becomes vim.
i try to show this by moving around and echoing g:context_filetype#get_filetype() in diffrent places, commented and not.
in the end you can see when i try to toggle the comments for block and my cursor ends up at the bottom, it detects vim filetype and creates new vim comments instead of removing the toml comments.
but if i end up at the top where it detects toml it uncomments.
ざっとまとめてみたので上げてみます。
#1 でも話に出てきたのですが、ユーザが設定する変数とライブラリ側のデフォルトの設定を明確に区別したいという考えです。
ライブラリ側の設定をg:context_filetype#filetypes_default
、ユーザ側の設定をg:context_filetype_filetypes
というのはどうでしょうか。
!exists('g:context_filetype#filetypes')
等でチェックを行う必要がないg:context_filetype#filetypes
を初期化したり破壊してしまう危険性が減る
g:context_filetype#filetypes
を直接操作している為、その危険性は十分ありうるg:context_filetype_filetypes
へ1回の記述で設定する方がわかりやすいのではないだろうかg:context_filetype_filetypes
へと追加してもらうg:context_filetype#filetypes_default
とg:context_filetype_filetypes
の両方を使用して判定する
g:context_filetype_filetypes
の設定が優先されるlet g:context_filetype_filetypes = {
\ "perl6" : {
\ [
\ {
\ 'filetype' : 'pir',
\ 'start' : 'Q:PIR\s*{',
\ 'end' : '}'
\ }
\ ],
\ },
\ "vim" : {
\ [
\ {
\ 'filetype' : 'python',
\ 'start' : '^\s*python <<\s*\(\h\w*\)',
\ 'end' : '^\1'
\ }
\ ]
\ }
\}
" if !exists('g:context_filetype#filetypes')
" let g:context_filetype#filetypes = {}
" endif
" let g:context_filetype#filetypes.perl6 =
" \ [{'filetype' : 'pir', 'start' : 'Q:PIR\s*{', 'end' : '}'}]
" let g:context_filetype#filetypes.vim =
" \ [{'filetype' : 'python',
" \ 'start' : '^\s*python <<\s*\(\h\w*\)', 'end' : '^\1'}]
気になるのは毎回マージするコストですかね。
@osyo_mangaさんが独自にvim-preciousというよく似たプラグインを開発しているようです。
ライブラリが分散するのは良くないので、統一しようと考えています。
https://github.com/osyo-manga/vim-precious
まずは、@osyo_mangaさんが何をやりたいのか説明してもらえますか?
Hi there, I've tried this plugin with Deoplete and omnicomplete, and It didn't work when typing css in style tag in html. I've read the doc to try to set some values, but I found that this plugin comes with default values that should work without settings. Something wrong? more info on this issue
I have added following lines to my .vimrc:
if !exists('g:context_filetype#same_filetypes')
let g:context_filetype#filetypes = {}
endif
let g:context_filetype#filetypes.svelte = [
\ {'filetype' :'javascript', 'start': '<script>', 'end': '</script>'},
\ {'filetype' :'css', 'start': '<style>', 'end': '</style>'},
\ ]
call deoplete#custom#var('omni', 'functions', {
\ 'css': ['csscomplete#CompleteCSS'],
\})
It lets css-completion work, but javascript doesn't work with YCM, inside HTML.
then to add following lines to my .vimrc:
call deoplete#custom#option('omni_patterns', {
\ 'javascript': '[^. *\t]\.\w*',
\ 'go': '[^. *\t]\.\w*',
\})
In .js it work.
But in html it doesn't work too.
Originally posted by @yangxyo in #41 (comment)
in case of <div sytle="***"
i wrote this for reference:
{
\ 'start': '\sstyle="',
\ 'end': '\sstyle="[^"]*\zs"', 'filetype': 'css',
}
正規表現エンジン NFA を使用している場合に context_filetype#get()
が遅くなるケースがあったので報告しておきます。
同じバッファで処理時間を測ってみた場合、以下のようになりました。
行位置 | NFAの有無 | 処理時間(ms) |
---|---|---|
1000 | なし | 0.0019 |
1000 | あり | 0.0151 |
2500 | なし | 0.0034 |
2500 | あり | 0.0828 |
※g:context_filetype#search_offset
はデフォルト値
現状では g:context_filetype#search_offset
の値を小さくしたり、NFA を使用しないようにすることで回避することが可能です。
この問題は context_filetype.vim を使用しているプラグイン(neocomplete.vim 等)に影響してくると思います。
set fileencodings=utf-8,cp932
および set fileencodings=cp932,utf-8
両方で発生CP932の日本語を含むhtmlファイルを開いた時、scriptタグ内にカーソルを移動するとfileencodingがUTF-8に変更されます。html部、js部両方に2バイト文字が含まれます。
I'm puzzled at this, I want to use this to set filetype,
is anyone tyied? is it a good idea? and how to set autocmd?
thanks very muck!!!
Hello; I am trying to figure out how to configure and use this library/plugin. I am using https://github.com/preservim/nerdcommenter plugin for comments, and would like to comment CSS block in HTML document correctly as well, for that I have the following configuration in vimrc:
if !exists('g:context_filetype#filetypes')
let g:context_filetype#filetypes = {}
endif
let g:context_filetype#filetypes.vim =
\ [
\ {'filetype' : 'css', 'start' : '<style>', 'end' : '</style>'},
\ ]
But it does not work, because apparently I need somehow else to connect nerdcommenter, but do not understand how. Can you point to a solution/mistakes? Thx!
git を使用した多人数の経験がないので正しいのかはわからないんですがわたしの開発イメージをまとめてみました
とか考えているんですがどうでしょう。
他にも『ガンガン master へ push していく』や『いや、branch/dev を作ってそこで開発するべきだ!』みたいな意見があったら教えてもらえると助かります。
ここら辺は最初にある程度の方針だけ決めておいて、開発していくうちに修正していけばいいかなーと考えています。
まぁそこまで頻繁に開発が行われるのかはわかりませんが。
Hi Shougo
Please help me - I tried all I could think of, but couldn't get this done..
I am using your neco syntax for filename.m
files and getting completion with deoplete all right.
I also confirm that context_filetype plugin works well with deoplete-jedi within markdown like this
markdown
``` python
# python complete works here with jedi
```
When I use the filetype (mathematica) mma
associated with files filename.m
,
markdown
``` mma
syntax completion doesn't work here
```
I have tried adding (after reading some of the questions here)
call deoplete#custom#source('omni', 'functions', {
\ 'mma': ['syntaxcomplete#Complete']
\})
to my init.vim, but it doesn't work. I don't know what I should do!
And more importantly, thank you so much for your plugin. Your work is awesome!
in markdown file
``` java
//here can use neosnippet,and java syntax identity
//but can not use javacomplete2,maybe it is issue of jc2
```html
omnifunc works well
```javascript
omnifunc not work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.