From 8ecfe25f05e4e5933c744950fd9becfa296c5cb2 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 24 May 2017 00:00:00 +0200 Subject: [PATCH] file creation --- autoload/ingo/syntaxitem.vim | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 autoload/ingo/syntaxitem.vim diff --git a/autoload/ingo/syntaxitem.vim b/autoload/ingo/syntaxitem.vim new file mode 100644 index 0000000..c8ad856 --- /dev/null +++ b/autoload/ingo/syntaxitem.vim @@ -0,0 +1,51 @@ +" ingo/syntaxitem.vim: Functions for retrieving information about syntax items. +" +" DEPENDENCIES: +" +" Copyright: (C) 2011-2013 Ingo Karkat +" The VIM LICENSE applies to this script; see ':help copyright'. +" +" Maintainer: Ingo Karkat +" +" REVISION DATE REMARKS +" 1.005.001 02-May-2013 file creation + +if exists('*synstack') +function! ingo#syntaxitem#IsOnSyntax( pos, syntaxItemPattern ) + " Taking the example of comments: + " Other syntax groups (e.g. Todo) may be embedded in comments. We must thus + " check whole stack of syntax items at the cursor position for comments. + " Comments are detected via the translated, effective syntax name. (E.g. in + " Vimscript, "vimLineComment" is linked to "Comment".) + for l:id in synstack(a:pos[1], a:pos[2]) + let l:actualSyntaxItemName = synIDattr(l:id, 'name') + let l:effectiveSyntaxItemName = synIDattr(synIDtrans(l:id), 'name') +"****D echomsg '****' l:actualSyntaxItemName . '->' . l:effectiveSyntaxItemName + if l:actualSyntaxItemName =~# a:syntaxItemPattern || l:effectiveSyntaxItemName =~# a:syntaxItemPattern + return 1 + endif + endfor + return 0 +endfunction +else +function! ingo#syntaxitem#IsOnSyntax( pos, syntaxItemPattern ) + " Taking the example of comments: + " Other syntax groups (e.g. Todo) may be embedded in comments. As the + " synstack() function is not available, we can only try to get the actual + " syntax ID and the one of the syntax item that determines the effective + " color. + " Comments are detected via the translated, effective syntax name. (E.g. in + " Vimscript, "vimLineComment" is linked to "Comment".) + for l:id in [synID(a:pos[1], a:pos[2], 0), synID(a:pos[1], a:pos[2], 1)] + let l:actualSyntaxItemName = synIDattr(l:id, 'name') + let l:effectiveSyntaxItemName = synIDattr(synIDtrans(l:id), 'name') +"****D echomsg '****' l:actualSyntaxItemName . '->' . l:effectiveSyntaxItemName + if l:actualSyntaxItemName =~# a:syntaxItemPattern || l:effectiveSyntaxItemName =~# a:syntaxItemPattern + return 1 + endif + endfor + return 0 +endfunction +endif + +" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :