robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ab20681c52
master
1" Vim indent file 2" Language: Objective-C 3" Maintainer: Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com> 4" Last Change: 2022 Apr 06 5 6" Only load this indent file when no other was loaded. 7if exists ( "b:did_indent" ) 8finish 9endif 10let b: did_indent = 1 11setlocal cindent 12 13" Set the function to do the work. 14setlocal indentexpr = GetObjCIndent () 15 16" To make a colon (:) suggest an indentation other than a goto/switch label, 17setlocal indentkeys -= : 18setlocal indentkeys += <:> 19 20let b: undo_indent = "setl cin< inde< indk<" 21 22" Only define the function once. 23if exists ( "*GetObjCIndent" ) 24finish 25endif 26 27function s: GetWidth ( line , regexp ) 28let end = matchend ( a: line , a: regexp ) 29let width = 0 30let i = 0 31while i < end 32if a: line [ i ] != "\t" 33let width = width + 1 34else 35let width = width + & ts - ( width % & ts ) 36endif 37let i = i + 1 38endwhile 39return width 40endfunction 41 42function s: LeadingWhiteSpace ( line ) 43let end = strlen ( a: line ) 44let width = 0 45let i = 0 46while i < end 47let char = a: line [ i ] 48if char != " " && char != "\t" 49break 50endif 51if char != "\t" 52let width = width + 1 53else 54let width = width + & ts - ( width % & ts ) 55endif 56let i = i + 1 57endwhile 58return width 59endfunction 60 61 62function GetObjCIndent () 63let theIndent = cindent ( v: lnum ) 64 65let prev_line = getline ( v: lnum - 1 ) 66let cur_line = getline ( v: lnum ) 67 68if prev_line !~# ":" || cur_line !~# ":" 69return theIndent 70endif 71 72if prev_line !~# ";" 73let prev_colon_pos = s: GetWidth ( prev_line , ":" ) 74let delta = s: GetWidth ( cur_line , ":" ) - s: LeadingWhiteSpace ( cur_line ) 75let theIndent = prev_colon_pos - delta 76endif 77 78return theIndent 79endfunction