Files
Anakin Childerhose 7c049d5ce1 patch 9.2.1128: filetype: icalendar files are not recognized
Problem:  filetype: icalendar files are not recognized
Solution: Detect *.ics files as icalendar filetype, include
          syntax and filetype plugins (Anakin Childerhose).

Reference:
https://datatracker.ietf.org/doc/html/rfc5545

closes: #21356

Assisted-By: Claude Opus 5
Signed-off-by: Anakin Childerhose <anakin@childerhose.ca>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2026-09-24 19:12:16 +00:00

54 lines
1.5 KiB
VimL

" Vim filetype plugin file
" Language: iCalendar
" Maintainer: Anakin Childerhose <anakin@childerhose.ca>
" Latest Change: 2026 Sept 22
" License: Vim (see :h license)
if exists('b:did_ftplugin')
finish
endif
let b:did_ftplugin = 1
let b:undo_ftplugin = ''
let s:cpo_save = &cpo
set cpo&vim
if exists('g:loaded_matchit') && !exists('b:match_words')
let b:match_words = '\<BEGIN\:.*\>:\<END\:.*\>'
let b:undo_ftplugin ..= '| unlet! b:match_words'
endif
function s:icalendarComponentFold() abort
if get(b:, 'icalendar_fold_tick', -1) == b:changedtick
return get(b:icalendar_fold_levels, v:lnum - 1, '=')
endif
let levels = repeat(['='], line('$'))
let depth = 0
for match in matchbufline('%', '\C^\%(BEGIN\|END\):.*', 1, '$')
if match.text =~# '^BEGIN:'
let depth += 1
let levels[match.lnum - 1] = '>' .. depth
elseif match.text =~# '^END:' && depth > 0
let levels[match.lnum - 1] = '<' .. depth
let depth -= 1
endif
endfor
let b:icalendar_fold_levels = levels
let b:icalendar_fold_tick = b:changedtick
return get(levels, v:lnum - 1, '=')
endfunction
if has('folding') && exists('*matchbufline') && get(g:, 'icalendar_folding', 0)
setlocal foldexpr=s:icalendarComponentFold()
setlocal foldmethod=expr
let b:undo_ftplugin ..= '| setlocal foldexpr< foldmethod< | unlet! b:icalendar_fold_tick b:icalendar_fold_levels'
endif
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: ts=2 sw=2