diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 08:50:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 08:50:31 +0000 |
commit | aed8ce9da277f5ecffe968b324f242c41c3b752a (patch) | |
tree | d2e538394cb7a8a7c42a4aac6ccf1a8e3256999b /runtime/indent/objc.vim | |
parent | Initial commit. (diff) | |
download | vim-aed8ce9da277f5ecffe968b324f242c41c3b752a.tar.xz vim-aed8ce9da277f5ecffe968b324f242c41c3b752a.zip |
Adding upstream version 2:9.0.1378.upstream/2%9.0.1378upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'runtime/indent/objc.vim')
-rw-r--r-- | runtime/indent/objc.vim | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/runtime/indent/objc.vim b/runtime/indent/objc.vim new file mode 100644 index 0000000..1d10705 --- /dev/null +++ b/runtime/indent/objc.vim @@ -0,0 +1,79 @@ +" Vim indent file +" Language: Objective-C +" Maintainer: Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com> +" Last Change: 2022 Apr 06 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 +setlocal cindent + +" Set the function to do the work. +setlocal indentexpr=GetObjCIndent() + +" To make a colon (:) suggest an indentation other than a goto/switch label, +setlocal indentkeys-=: +setlocal indentkeys+=<:> + +let b:undo_indent = "setl cin< inde< indk<" + +" Only define the function once. +if exists("*GetObjCIndent") + finish +endif + +function s:GetWidth(line, regexp) + let end = matchend(a:line, a:regexp) + let width = 0 + let i = 0 + while i < end + if a:line[i] != "\t" + let width = width + 1 + else + let width = width + &ts - (width % &ts) + endif + let i = i + 1 + endwhile + return width +endfunction + +function s:LeadingWhiteSpace(line) + let end = strlen(a:line) + let width = 0 + let i = 0 + while i < end + let char = a:line[i] + if char != " " && char != "\t" + break + endif + if char != "\t" + let width = width + 1 + else + let width = width + &ts - (width % &ts) + endif + let i = i + 1 + endwhile + return width +endfunction + + +function GetObjCIndent() + let theIndent = cindent(v:lnum) + + let prev_line = getline(v:lnum - 1) + let cur_line = getline(v:lnum) + + if prev_line !~# ":" || cur_line !~# ":" + return theIndent + endif + + if prev_line !~# ";" + let prev_colon_pos = s:GetWidth(prev_line, ":") + let delta = s:GetWidth(cur_line, ":") - s:LeadingWhiteSpace(cur_line) + let theIndent = prev_colon_pos - delta + endif + + return theIndent +endfunction |