Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LeafCage/2650386 to your computer and use it in GitHub Desktop.
Save LeafCage/2650386 to your computer and use it in GitHub Desktop.
シンタックスハイライトをincludeする関数が意図したとおりに動かない。引数の一つ目については意図通り。2つめからがおかしい。
function! Include_syntax(...)
for pickedft in a:000
exe 'syn include @'.pickedft.' syntax/'.pickedft.'.vim'
exe 'syn region Syscommon_'.pickedft.' matchgroup=Syscommon_metamodify start=/^>|'.pickedft.'|\n/rs=e end=/^||</re=s-1 contains=@'.pickedft.' keepend'
endfor
hi Syscommon_metamodify gui=bold guifg=lightblue guibg=gray35
endfunction
"想定利用法
"例えば行頭に'>|vim|'と書くと次の行からvimのシンタックスが適用される
"この効果は行頭に'||<'がある行まで続く
"例
>|vim|
let s:niconico = 'nicov'
noremap <c-a> a
||<
>|python|
print "Hallow"
||<
"問題点
"なぜか引数の二つ目以降をハイライトしてくれない。
"たとえば、引数に、'python','vim','perl'を与えた場合、
シンタックスをincludeできているのは'python'だけである。
@LeafCage
Copy link
Author

解決した。
syntax定義ファイルでは、多重ロードを避けるために先頭でb:current_syntaxと言う変数の存在をチェックしている。つまり、syn include する前に unlet! b:current_syntax を実行する必要がある。
for pickedft in a:000
unlet! b:current_syntax
exe 'syn include @'.pickedft.' syntax/'.pickedft.'.vim'
exe 'syn region Syscommon_'.pickedft.' matchgroup=Syscommon_metamodify start=/^>|'.pickedft.'|\n/rs=e end=/^||</re=s-1 contains=@'.pickedft.' keepend'
endfor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment