icalendar.vim (1497B)
1 " Vim filetype plugin file 2 " Language: iCalendar 3 " Maintainer: Anakin Childerhose <anakin@childerhose.ca> 4 " Latest Change: 2026 Sept 22 5 " License: Vim (see :h license) 6 7 if exists('b:did_ftplugin') 8 finish 9 endif 10 let b:did_ftplugin = 1 11 12 let b:undo_ftplugin = '' 13 14 let s:cpo_save = &cpo 15 set cpo&vim 16 17 if exists('g:loaded_matchit') && !exists('b:match_words') 18 let b:match_words = '\<BEGIN\:.*\>:\<END\:.*\>' 19 let b:undo_ftplugin ..= '| unlet! b:match_words' 20 endif 21 22 function s:icalendarComponentFold() abort 23 if get(b:, 'icalendar_fold_tick', -1) == b:changedtick 24 return get(b:icalendar_fold_levels, v:lnum - 1, '=') 25 endif 26 27 let levels = repeat(['='], line('$')) 28 let depth = 0 29 for match in matchbufline('%', '\C^\%(BEGIN\|END\):.*', 1, '$') 30 if match.text =~# '^BEGIN:' 31 let depth += 1 32 let levels[match.lnum - 1] = '>' .. depth 33 elseif match.text =~# '^END:' && depth > 0 34 let levels[match.lnum - 1] = '<' .. depth 35 let depth -= 1 36 endif 37 endfor 38 39 let b:icalendar_fold_levels = levels 40 let b:icalendar_fold_tick = b:changedtick 41 return get(levels, v:lnum - 1, '=') 42 endfunction 43 44 if has('folding') && exists('*matchbufline') && get(g:, 'icalendar_folding', 0) 45 setlocal foldexpr=s:icalendarComponentFold() 46 setlocal foldmethod=expr 47 let b:undo_ftplugin ..= '| setlocal foldexpr< foldmethod< | unlet! b:icalendar_fold_tick b:icalendar_fold_levels' 48 endif 49 50 let &cpo = s:cpo_save 51 unlet s:cpo_save 52 53 " vim: ts=2 sw=2