annotate runtime/indent/objc.vim @ 29033:0059a17d7a2a

Added tag v8.2.5038 for changeset 361b46a07f5edd372b3a3ca580bdbf06bd425bb9
author Bram Moolenaar <Bram@vim.org>
date Sun, 29 May 2022 15:15:06 +0200
parents 6dd88e45d47d
children
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>
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
4 " Last Change: 2022 Apr 06
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 setlocal cindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " Set the function to do the work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal indentexpr=GetObjCIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 7
diff changeset
16 " To make a colon (:) suggest an indentation other than a goto/switch label,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 setlocal indentkeys-=:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentkeys+=<:>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
20 let b:undo_indent = "setl cin< inde< indk<"
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
21
7
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