robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
6eaf10502c
master
1" Vim indent file 2" Language: C# 3" Maintainer: Nick Jensen <nickspoon@gmail.com> 4" Former Maintainers: Aquila Deus 5" Johannes Zellner <johannes@zellner.org> 6" Last Change: 2020-03-26 7" License: Vim (see :h license) 8" Repository: https://github.com/nickspoons/vim-cs 9 10if exists ( 'b:did_indent' ) 11finish 12endif 13let b: did_indent = 1 14 15let s: save_cpo = & cpoptions 16set cpoptions & vim 17 18 19setlocal indentexpr = GetCSIndent (v:lnum) 20 21function ! s: IsCompilerDirective ( line ) 22" Exclude #region and #endregion - these should be indented normally 23return a: line =~# '^\s*#' && ! s: IsRegionDirective ( a: line ) 24endf 25 26function ! s: IsRegionDirective ( line ) 27return a: line =~# '^\s*#\s*region' || a: line =~# '^\s*#\s*endregion' 28endf 29 30function ! s: IsAttributeLine ( line ) 31return a: line =~# '^\s*\[[A-Za-z]' && a: line =~# '\]$' 32endf 33 34function ! s: FindPreviousNonCompilerDirectiveLine ( start_lnum ) 35for delta in range ( 0 , a: start_lnum ) 36let lnum = a: start_lnum - delta 37let line = getline ( lnum ) 38if ! s: IsCompilerDirective ( line ) && ! s: IsRegionDirective ( line ) 39return lnum 40endif 41endfor 42return 0 43endf 44 45function ! GetCSIndent ( lnum ) abort 46" Hit the start of the file, use zero indent. 47if a: lnum == 0 48return 0 49endif 50 51let this_line = getline ( a: lnum ) 52 53" Compiler directives use zero indent if so configured. 54let is_first_col_macro = s: IsCompilerDirective ( this_line ) && stridx ( & l: cinkeys , '0#' ) >= 0 55if is_first_col_macro 56return cindent ( a: lnum ) 57endif 58 59let lnum = s: FindPreviousNonCompilerDirectiveLine ( a: lnum - 1 ) 60let previous_code_line = getline ( lnum ) 61if s: IsAttributeLine ( previous_code_line ) 62return indent ( lnum ) 63elseif s: IsRegionDirective ( this_line ) 64return cindent ( lnum ) 65else 66return cindent ( a: lnum ) 67endif 68endfunction 69 70let b: undo_indent = 'setlocal indentexpr<' 71 72let & cpoptions = s: save_cpo 73unlet s: save_cpo 74 75" vim:et:sw=2:sts=2