My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. "=============================================================================
  2. " $Id: syntax.vim 558 2012-04-10 08:00:00Z luc.hermitte $
  3. " File: autoload/lh/syntax.vim {{{1
  4. " Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
  5. " <URL:http://code.google.com/p/lh-vim/>
  6. " License: GPLv3 with exceptions
  7. " <URL:http://code.google.com/p/lh-vim/wiki/License>
  8. " Version: 3.1.0
  9. " Created: 05th Sep 2007
  10. " Last Update: $Date: 2012-04-10 10:00:00 +0200 (mar 10 avr 2012) $ (05th Sep 2007)
  11. "------------------------------------------------------------------------
  12. " Description: «description»
  13. "
  14. "------------------------------------------------------------------------
  15. " Installation:
  16. " Drop it into {rtp}/autoload/lh/
  17. " Vim 7+ required.
  18. " History: «history»
  19. " v1.0.0:
  20. " Creation ;
  21. " Functions moved from lhVimSpell
  22. " v3.0.0: GPLv3
  23. " v3.1.0: lh#syntax#is_a_comment()
  24. " TODO:
  25. " function, to inject "contained", see lhVimSpell approach
  26. " }}}1
  27. "=============================================================================
  28. "=============================================================================
  29. let s:cpo_save=&cpo
  30. set cpo&vim
  31. "------------------------------------------------------------------------
  32. " ## Functions {{{1
  33. " # Debug {{{2
  34. function! lh#syntax#verbose(level)
  35. let s:verbose = a:level
  36. endfunction
  37. function! s:Verbose(expr)
  38. if exists('s:verbose') && s:verbose
  39. echomsg a:expr
  40. endif
  41. endfunction
  42. function! lh#syntax#debug(expr)
  43. return eval(a:expr)
  44. endfunction
  45. " # Public {{{2
  46. " Functions: Show name of the syntax kind of a character {{{3
  47. function! lh#syntax#name_at(l,c, ...)
  48. let what = a:0 > 0 ? a:1 : 0
  49. return synIDattr(synID(a:l, a:c, what),'name')
  50. endfunction
  51. function! lh#syntax#NameAt(l,c, ...)
  52. let what = a:0 > 0 ? a:1 : 0
  53. return lh#syntax#name_at(a:l, a:c, what)
  54. endfunction
  55. function! lh#syntax#name_at_mark(mark, ...)
  56. let what = a:0 > 0 ? a:1 : 0
  57. return lh#syntax#name_at(line(a:mark), col(a:mark), what)
  58. endfunction
  59. function! lh#syntax#NameAtMark(mark, ...)
  60. let what = a:0 > 0 ? a:1 : 0
  61. return lh#syntax#name_at_mark(a:mark, what)
  62. endfunction
  63. " Functions: skip string, comment, character, doxygen {{{3
  64. func! lh#syntax#skip_at(l,c)
  65. return lh#syntax#name_at(a:l,a:c) =~? 'string\|comment\|character\|doxygen'
  66. endfun
  67. func! lh#syntax#SkipAt(l,c)
  68. return lh#syntax#skip_at(a:l,a:c)
  69. endfun
  70. func! lh#syntax#skip()
  71. return lh#syntax#skip_at(line('.'), col('.'))
  72. endfun
  73. func! lh#syntax#Skip()
  74. return lh#syntax#skip()
  75. endfun
  76. func! lh#syntax#skip_at_mark(mark)
  77. return lh#syntax#skip_at(line(a:mark), col(a:mark))
  78. endfun
  79. func! lh#syntax#SkipAtMark(mark)
  80. return lh#syntax#skip_at_mark(a:mark)
  81. endfun
  82. " Command: :SynShow Show current syntax kind {{{3
  83. command! SynShow echo 'hi<'.lh#syntax#name_at_mark('.',1).'> trans<'
  84. \ lh#syntax#name_at_mark('.',0).'> lo<'.
  85. \ synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name').'> ## '
  86. \ lh#list#transform(synstack(line("."), col(".")), [], 'synIDattr(v:1_, "name")')
  87. " Function: lh#syntax#list_raw(name) : string {{{3
  88. function! lh#syntax#list_raw(name)
  89. let a_save = @a
  90. try
  91. redir @a
  92. exe 'silent! syn list '.a:name
  93. redir END
  94. let res = @a
  95. finally
  96. let @a = a_save
  97. endtry
  98. return res
  99. endfunction
  100. " Function: lh#syntax#list(name) : List {{{3
  101. function! lh#syntax#list(name)
  102. let raw = lh#syntax#list_raw(a:name)
  103. let res = []
  104. let lines = split(raw, '\n')
  105. let started = 0
  106. for l in lines
  107. if started
  108. let li = (l =~ 'links to') ? '' : l
  109. elseif l =~ 'xxx'
  110. let li = matchstr(l, 'xxx\s*\zs.*')
  111. let started = 1
  112. else
  113. let li = ''
  114. endif
  115. if strlen(li) != 0
  116. let li = substitute(li, 'contained\S*\|transparent\|nextgroup\|skipwhite\|skipnl\|skipempty', '', 'g')
  117. let kinds = split(li, '\s\+')
  118. call extend(res, kinds)
  119. endif
  120. endfor
  121. return res
  122. endfunction
  123. " Function: lh#syntax#is_a_comment(mark) : bool {{{3
  124. function! lh#syntax#is_a_comment(mark)
  125. let stack = synstack(line(a:mark), col(a:mark))
  126. for syn in stack
  127. if synIDattr(syn, 'name') =~? 'comment'
  128. return 1
  129. endif
  130. endfor
  131. return 0
  132. endfunction
  133. " Functions }}}1
  134. "------------------------------------------------------------------------
  135. let &cpo=s:cpo_save
  136. "=============================================================================
  137. " vim600: set fdm=marker: