diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-07-11 04:05:51 +0000 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-07-29 02:12:31 +0000 |
commit | a98a6996c291b3e300d27b791eded9eed333d677 (patch) | |
tree | 51d92f6cac128f938cd0aaa9a8dd0ce7a83d63a9 /runtime/indent/java.vim | |
parent | 66bc13163398786c88e20b7cdd61c66978b4d3fb (diff) | |
download | rneovim-a98a6996c291b3e300d27b791eded9eed333d677.tar.gz rneovim-a98a6996c291b3e300d27b791eded9eed333d677.tar.bz2 rneovim-a98a6996c291b3e300d27b791eded9eed333d677.zip |
re-integrate runtime/ vim-patch:0 #938
Vim runtime files based on 7.4.384 / hg changeset 7090d7f160f7
Excluding:
Amiga icons (*.info, icons/)
doc/hangulin.txt
tutor/
spell/
lang/ (only used for menu translations)
macros/maze/, macros/hanoi/, macros/life/, macros/urm/
These were used to test vi compatibility.
termcap
"Demonstration of a termcap file (for the Amiga and Archimedes)"
Helped-by: Rich Wareham <rjw57@cam.ac.uk>
Helped-by: John <john.schmidt.h@gmail.com>
Helped-by: Yann <yann@yann-salaun.com>
Helped-by: Christophe Badoit <c.badoit@lesiteimmo.com>
Helped-by: drasill <github@tof2k.com>
Helped-by: Tae Sandoval Murgan <taecilla@gmail.com>
Helped-by: Lowe Thiderman <lowe.thiderman@gmail.com>
Diffstat (limited to 'runtime/indent/java.vim')
-rw-r--r-- | runtime/indent/java.vim | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/runtime/indent/java.vim b/runtime/indent/java.vim new file mode 100644 index 0000000000..e0aec0faef --- /dev/null +++ b/runtime/indent/java.vim @@ -0,0 +1,147 @@ +" Vim indent file +" Language: Java +" Previous Maintainer: Toby Allsopp <toby.allsopp@peace.com> +" Current Maintainer: Hong Xu <xuhdev@gmail.com> +" Last Change: 2012 May 18 +" Version: 1.0 +" License: Same as Vim. +" Copyright (c) 2012 Hong Xu +" Before 2012, this file is maintained by Toby Allsopp. + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" Indent Java anonymous classes correctly. +setlocal cindent cinoptions& cinoptions+=j1 + +" The "extends" and "implements" lines start off with the wrong indent. +setlocal indentkeys& indentkeys+=0=extends indentkeys+=0=implements + +" Set the function to do the work. +setlocal indentexpr=GetJavaIndent() + +let b:undo_indent = "set cin< cino< indentkeys< indentexpr<" + +" Only define the function once. +if exists("*GetJavaIndent") + finish +endif +let s:keepcpo= &cpo +set cpo&vim + +function! SkipJavaBlanksAndComments(startline) + let lnum = a:startline + while lnum > 1 + let lnum = prevnonblank(lnum) + if getline(lnum) =~ '\*/\s*$' + while getline(lnum) !~ '/\*' && lnum > 1 + let lnum = lnum - 1 + endwhile + if getline(lnum) =~ '^\s*/\*' + let lnum = lnum - 1 + else + break + endif + elseif getline(lnum) =~ '^\s*//' + let lnum = lnum - 1 + else + break + endif + endwhile + return lnum +endfunction + +function GetJavaIndent() + + " Java is just like C; use the built-in C indenting and then correct a few + " specific cases. + let theIndent = cindent(v:lnum) + + " If we're in the middle of a comment then just trust cindent + if getline(v:lnum) =~ '^\s*\*' + return theIndent + endif + + " find start of previous line, in case it was a continuation line + let lnum = SkipJavaBlanksAndComments(v:lnum - 1) + + " If the previous line starts with '@', we should have the same indent as + " the previous one + if getline(lnum) =~ '^\s*@\S\+\s*$' + return indent(lnum) + endif + + let prev = lnum + while prev > 1 + let next_prev = SkipJavaBlanksAndComments(prev - 1) + if getline(next_prev) !~ ',\s*$' + break + endif + let prev = next_prev + endwhile + + " Try to align "throws" lines for methods and "extends" and "implements" for + " classes. + if getline(v:lnum) =~ '^\s*\(extends\|implements\)\>' + \ && getline(lnum) !~ '^\s*\(extends\|implements\)\>' + let theIndent = theIndent + &sw + endif + + " correct for continuation lines of "throws", "implements" and "extends" + let cont_kw = matchstr(getline(prev), + \ '^\s*\zs\(throws\|implements\|extends\)\>\ze.*,\s*$') + if strlen(cont_kw) > 0 + let amount = strlen(cont_kw) + 1 + if getline(lnum) !~ ',\s*$' + let theIndent = theIndent - (amount + &sw) + if theIndent < 0 + let theIndent = 0 + endif + elseif prev == lnum + let theIndent = theIndent + amount + if cont_kw ==# 'throws' + let theIndent = theIndent + &sw + endif + endif + elseif getline(prev) =~ '^\s*\(throws\|implements\|extends\)\>' + \ && (getline(prev) =~ '{\s*$' + \ || getline(v:lnum) =~ '^\s*{\s*$') + let theIndent = theIndent - &sw + endif + + " When the line starts with a }, try aligning it with the matching {, + " skipping over "throws", "extends" and "implements" clauses. + if getline(v:lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' + call cursor(v:lnum, 1) + silent normal % + let lnum = line('.') + if lnum < v:lnum + while lnum > 1 + let next_lnum = SkipJavaBlanksAndComments(lnum - 1) + if getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>' + \ && getline(next_lnum) !~ ',\s*$' + break + endif + let lnum = prevnonblank(next_lnum) + endwhile + return indent(lnum) + endif + endif + + " Below a line starting with "}" never indent more. Needed for a method + " below a method with an indented "throws" clause. + let lnum = SkipJavaBlanksAndComments(v:lnum - 1) + if getline(lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' && indent(lnum) < theIndent + let theIndent = indent(lnum) + endif + + return theIndent +endfunction + +let &cpo = s:keepcpo +unlet s:keepcpo + +" vi: sw=2 et |