robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
1.5 KiB53 linesraw
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
7if exists('b:did_ftplugin')
8  finish
9endif
10let b:did_ftplugin = 1
11
12let b:undo_ftplugin = ''
13
14let s:cpo_save = &cpo
15set cpo&vim
16
17if exists('g:loaded_matchit') && !exists('b:match_words')
18  let b:match_words = '\<BEGIN\:.*\>:\<END\:.*\>'
19  let b:undo_ftplugin ..= '| unlet! b:match_words'
20endif
21
22function 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, '=')
42endfunction
43
44if 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'
48endif
49
50let &cpo = s:cpo_save
51unlet s:cpo_save
52
53" vim: ts=2 sw=2