annotate runtime/indent/objc.vim @ 21442:0c134036ff70

Added tag v8.2.1271 for changeset 78d97ee2c707fa1471730ea0b10394187ef1a116
author Bram Moolenaar <Bram@vim.org>
date Wed, 22 Jul 2020 20:30:04 +0200
parents 3fc0f57ecb91
children 11b656e74444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Objective-C
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Last Change: 2004 May 16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal cindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " Set the function to do the work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 setlocal indentexpr=GetObjCIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " To make a colon (:) suggest an indentation other than a goto/swich label,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 setlocal indentkeys-=:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 setlocal indentkeys+=<:>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if exists("*GetObjCIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 function s:GetWidth(line, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 let end = matchend(a:line, a:regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 let width = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let i = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 while i < end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 if a:line[i] != "\t"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let width = width + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let width = width + &ts - (width % &ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let i = i + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 return width
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 function s:LeadingWhiteSpace(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 let end = strlen(a:line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 let width = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let i = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 while i < end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let char = a:line[i]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if char != " " && char != "\t"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 if char != "\t"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 let width = width + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let width = width + &ts - (width % &ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let i = i + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 return width
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 function GetObjCIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 let theIndent = cindent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let prev_line = getline(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let cur_line = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 if prev_line !~# ":" || cur_line !~# ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 return theIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 if prev_line !~# ";"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 let prev_colon_pos = s:GetWidth(prev_line, ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 let delta = s:GetWidth(cur_line, ":") - s:LeadingWhiteSpace(cur_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 let theIndent = prev_colon_pos - delta
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 return theIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 endfunction