various improvements mostly email
[distro-setup] / .vim / autoload / SyntaxAttr.vim
1 " EXAMPLE SETUP
2 "
3 " Show the syntax group name of the item under cursor.
4 " map -a :call SyntaxAttr()<CR>
5
6 function! SyntaxAttr()
7 let synid = ""
8 let guifg = ""
9 let guibg = ""
10 let gui = ""
11
12 let id1 = synID(line("."), col("."), 1)
13 let tid1 = synIDtrans(id1)
14
15 if synIDattr(id1, "name") != ""
16 let synid = "group: " . synIDattr(id1, "name")
17 if (tid1 != id1)
18 let synid = synid . '->' . synIDattr(tid1, "name")
19 endif
20 let id0 = synID(line("."), col("."), 0)
21 if (synIDattr(id1, "name") != synIDattr(id0, "name"))
22 let synid = synid . " (" . synIDattr(id0, "name")
23 let tid0 = synIDtrans(id0)
24 if (tid0 != id0)
25 let synid = synid . '->' . synIDattr(tid0, "name")
26 endif
27 let synid = synid . ")"
28 endif
29 endif
30
31 " Use the translated id for all the color & attribute lookups; the linked id yields blank values.
32 if (synIDattr(tid1, "fg") != "" )
33 let guifg = " guifg=" . synIDattr(tid1, "fg") . "(" . synIDattr(tid1, "fg#") . ")"
34 endif
35 if (synIDattr(tid1, "bg") != "" )
36 let guibg = " guibg=" . synIDattr(tid1, "bg") . "(" . synIDattr(tid1, "bg#") . ")"
37 endif
38 if (synIDattr(tid1, "bold" ))
39 let gui = gui . ",bold"
40 endif
41 if (synIDattr(tid1, "italic" ))
42 let gui = gui . ",italic"
43 endif
44 if (synIDattr(tid1, "reverse" ))
45 let gui = gui . ",reverse"
46 endif
47 if (synIDattr(tid1, "inverse" ))
48 let gui = gui . ",inverse"
49 endif
50 if (synIDattr(tid1, "underline"))
51 let gui = gui . ",underline"
52 endif
53 if (gui != "" )
54 let gui = substitute(gui, "^,", " gui=", "")
55 endif
56
57 echohl MoreMsg
58 let message = synid . guifg . guibg . gui
59 if message == ""
60 echohl WarningMsg
61 let message = "<no syntax group here>"
62 endif
63 echo message
64 echohl None
65 endfunction