Mercurial > vim
comparison runtime/indent/java.vim @ 11160:d0a20101ecb2
Update runtime files.
commit https://github.com/vim/vim/commit/036986f1507d223549d110af300144468bd3a1f7
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 16 17:41:02 2017 +0100
Update runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 16 Mar 2017 17:45:05 +0100 |
parents | dd6c2497c997 |
children |
comparison
equal
deleted
inserted
replaced
11159:c13ab9398ce9 | 11160:d0a20101ecb2 |
---|---|
1 " Vim indent file | 1 " Vim indent file |
2 " Language: Java | 2 " Language: Java |
3 " Previous Maintainer: Toby Allsopp <toby.allsopp@peace.com> | 3 " Previous Maintainer: Toby Allsopp <toby.allsopp@peace.com> |
4 " Current Maintainer: Hong Xu <xuhdev@gmail.com> | 4 " Current Maintainer: Hong Xu <hong@topbug.net> |
5 " Last Change: 2012 May 18 | 5 " Homepage: http://www.vim.org/scripts/script.php?script_id=3899 |
6 " Version: 1.0 | 6 " https://github.com/xuhdev/indent-java.vim |
7 " Last Change: 2016 Mar 7 | |
8 " Version: 1.1 | |
7 " License: Same as Vim. | 9 " License: Same as Vim. |
8 " Copyright (c) 2012 Hong Xu | 10 " Copyright (c) 2012-2016 Hong Xu |
9 " Before 2012, this file is maintained by Toby Allsopp. | 11 " Before 2012, this file was maintained by Toby Allsopp. |
10 | 12 |
11 " Only load this indent file when no other was loaded. | 13 " Only load this indent file when no other was loaded. |
12 if exists("b:did_indent") | 14 if exists("b:did_indent") |
13 finish | 15 finish |
14 endif | 16 endif |
27 | 29 |
28 " Only define the function once. | 30 " Only define the function once. |
29 if exists("*GetJavaIndent") | 31 if exists("*GetJavaIndent") |
30 finish | 32 finish |
31 endif | 33 endif |
34 | |
32 let s:keepcpo= &cpo | 35 let s:keepcpo= &cpo |
33 set cpo&vim | 36 set cpo&vim |
34 | 37 |
35 function! SkipJavaBlanksAndComments(startline) | 38 function! SkipJavaBlanksAndComments(startline) |
36 let lnum = a:startline | 39 let lnum = a:startline |
68 " find start of previous line, in case it was a continuation line | 71 " find start of previous line, in case it was a continuation line |
69 let lnum = SkipJavaBlanksAndComments(v:lnum - 1) | 72 let lnum = SkipJavaBlanksAndComments(v:lnum - 1) |
70 | 73 |
71 " If the previous line starts with '@', we should have the same indent as | 74 " If the previous line starts with '@', we should have the same indent as |
72 " the previous one | 75 " the previous one |
73 if getline(lnum) =~ '^\s*@\S\+\s*$' | 76 if getline(lnum) =~ '^\s*@.*$' |
74 return indent(lnum) | 77 return indent(lnum) |
75 endif | 78 endif |
76 | 79 |
77 let prev = lnum | 80 let prev = lnum |
78 while prev > 1 | 81 while prev > 1 |
83 let prev = next_prev | 86 let prev = next_prev |
84 endwhile | 87 endwhile |
85 | 88 |
86 " Try to align "throws" lines for methods and "extends" and "implements" for | 89 " Try to align "throws" lines for methods and "extends" and "implements" for |
87 " classes. | 90 " classes. |
88 if getline(v:lnum) =~ '^\s*\(extends\|implements\)\>' | 91 if getline(v:lnum) =~ '^\s*\(throws\|extends\|implements\)\>' |
89 \ && getline(lnum) !~ '^\s*\(extends\|implements\)\>' | 92 \ && getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>' |
90 let theIndent = theIndent + &sw | 93 let theIndent = theIndent + shiftwidth() |
91 endif | 94 endif |
92 | 95 |
93 " correct for continuation lines of "throws", "implements" and "extends" | 96 " correct for continuation lines of "throws", "implements" and "extends" |
94 let cont_kw = matchstr(getline(prev), | 97 let cont_kw = matchstr(getline(prev), |
95 \ '^\s*\zs\(throws\|implements\|extends\)\>\ze.*,\s*$') | 98 \ '^\s*\zs\(throws\|implements\|extends\)\>\ze.*,\s*$') |
96 if strlen(cont_kw) > 0 | 99 if strlen(cont_kw) > 0 |
97 let amount = strlen(cont_kw) + 1 | 100 let amount = strlen(cont_kw) + 1 |
98 if getline(lnum) !~ ',\s*$' | 101 if getline(lnum) !~ ',\s*$' |
99 let theIndent = theIndent - (amount + &sw) | 102 let theIndent = theIndent - (amount + shiftwidth()) |
100 if theIndent < 0 | 103 if theIndent < 0 |
101 let theIndent = 0 | 104 let theIndent = 0 |
102 endif | 105 endif |
103 elseif prev == lnum | 106 elseif prev == lnum |
104 let theIndent = theIndent + amount | 107 let theIndent = theIndent + amount |
105 if cont_kw ==# 'throws' | 108 if cont_kw ==# 'throws' |
106 let theIndent = theIndent + &sw | 109 let theIndent = theIndent + shiftwidth() |
107 endif | 110 endif |
108 endif | 111 endif |
109 elseif getline(prev) =~ '^\s*\(throws\|implements\|extends\)\>' | 112 elseif getline(prev) =~ '^\s*\(throws\|implements\|extends\)\>' |
110 \ && (getline(prev) =~ '{\s*$' | 113 \ && (getline(prev) =~ '{\s*$' |
111 \ || getline(v:lnum) =~ '^\s*{\s*$') | 114 \ || getline(v:lnum) =~ '^\s*{\s*$') |
112 let theIndent = theIndent - &sw | 115 let theIndent = theIndent - shiftwidth() |
113 endif | 116 endif |
114 | 117 |
115 " When the line starts with a }, try aligning it with the matching {, | 118 " When the line starts with a }, try aligning it with the matching {, |
116 " skipping over "throws", "extends" and "implements" clauses. | 119 " skipping over "throws", "extends" and "implements" clauses. |
117 if getline(v:lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' | 120 if getline(v:lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' |
118 call cursor(v:lnum, 1) | 121 call cursor(v:lnum, 1) |
119 silent normal % | 122 silent normal! % |
120 let lnum = line('.') | 123 let lnum = line('.') |
121 if lnum < v:lnum | 124 if lnum < v:lnum |
122 while lnum > 1 | 125 while lnum > 1 |
123 let next_lnum = SkipJavaBlanksAndComments(lnum - 1) | 126 let next_lnum = SkipJavaBlanksAndComments(lnum - 1) |
124 if getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>' | 127 if getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>' |