1
0

highlighting.vim 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. if exists('g:loaded_syntastic_notifier_highlighting') || !exists('g:loaded_syntastic_plugin')
  2. finish
  3. endif
  4. let g:loaded_syntastic_notifier_highlighting = 1
  5. " Highlighting requires getmatches introduced in 7.1.040
  6. let s:has_highlighting = v:version > 701 || (v:version == 701 && has('patch040'))
  7. lockvar s:has_highlighting
  8. let g:SyntasticHighlightingNotifier = {}
  9. let s:setup_done = 0
  10. " Public methods {{{1
  11. function! g:SyntasticHighlightingNotifier.New() abort " {{{2
  12. let newObj = copy(self)
  13. if !s:setup_done
  14. call self._setup()
  15. let s:setup_done = 1
  16. lockvar s:setup_done
  17. endif
  18. return newObj
  19. endfunction " }}}2
  20. function! g:SyntasticHighlightingNotifier.enabled() abort " {{{2
  21. return s:has_highlighting && syntastic#util#var('enable_highlighting')
  22. endfunction " }}}2
  23. " Sets error highlights in the current window
  24. function! g:SyntasticHighlightingNotifier.refresh(loclist) abort " {{{2
  25. if self.enabled()
  26. call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'highlighting: refresh')
  27. call self._reset()
  28. let buf = bufnr('')
  29. let issues = filter(a:loclist.copyRaw(), 'v:val["bufnr"] == buf')
  30. for item in issues
  31. let group = 'Syntastic' . get(item, 'subtype', '') . ( item['type'] ==? 'E' ? 'Error' : 'Warning' )
  32. " The function `Syntastic_{filetype}_{checker}_GetHighlightRegex` is
  33. " used to override default highlighting.
  34. if has_key(item, 'hl')
  35. call matchadd(group, '\%' . item['lnum'] . 'l' . item['hl'])
  36. elseif get(item, 'col', 0)
  37. if get(item, 'vcol', 0)
  38. let lastcol = virtcol([item['lnum'], '$'])
  39. let coltype = 'v'
  40. else
  41. let lastcol = col([item['lnum'], '$'])
  42. let coltype = 'c'
  43. endif
  44. let lcol = min([lastcol, item['col']])
  45. call matchadd(group, '\%' . item['lnum'] . 'l\%' . lcol . coltype)
  46. endif
  47. endfor
  48. endif
  49. endfunction " }}}2
  50. " Remove all error highlights from the window
  51. " @vimlint(EVL103, 1, a:loclist)
  52. function! g:SyntasticHighlightingNotifier.reset(loclist) abort " {{{2
  53. if s:has_highlighting
  54. call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'highlighting: reset')
  55. call self._reset()
  56. endif
  57. endfunction " }}}2
  58. " @vimlint(EVL103, 0, a:loclist)
  59. " }}}1
  60. " Private methods {{{1
  61. " One time setup: define our own highlighting
  62. function! g:SyntasticHighlightingNotifier._setup() abort " {{{2
  63. if s:has_highlighting
  64. if !hlexists('SyntasticError')
  65. highlight link SyntasticError SpellBad
  66. endif
  67. if !hlexists('SyntasticWarning')
  68. highlight link SyntasticWarning SpellCap
  69. endif
  70. if !hlexists('SyntasticStyleError')
  71. highlight link SyntasticStyleError SyntasticError
  72. endif
  73. if !hlexists('SyntasticStyleWarning')
  74. highlight link SyntasticStyleWarning SyntasticWarning
  75. endif
  76. endif
  77. endfunction " }}}2
  78. function! g:SyntasticHighlightingNotifier._reset() abort " {{{2
  79. for match in getmatches()
  80. if stridx(match['group'], 'Syntastic') == 0
  81. call matchdelete(match['id'])
  82. endif
  83. endfor
  84. endfunction " }}}2
  85. " }}}1
  86. " vim: set sw=4 sts=4 et fdm=marker: