Skip to content

Commit edf06fa

Browse files
author
Matt Fowles
committed
Add support for formatting java if >= 3.6
1 parent c426e43 commit edf06fa

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

autoload/codefmt.vim

+6-1
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ function! codefmt#GetClangFormatFormatter() abort
188188
endfunction
189189

190190
function l:formatter.AppliesToBuffer() abort
191-
return &filetype is# 'c' || &filetype is# 'cpp' ||
191+
if &filetype is# 'c' || &filetype is# 'cpp' ||
192192
\ &filetype is# 'proto' || &filetype is# 'javascript'
193+
return 1
194+
endif
195+
" Version 3.6 adds support for java
196+
" http://llvm.org/releases/3.6.0/tools/clang/docs/ReleaseNotes.html
197+
return &filetype is# 'java' && s:ClangFormatHasAtLeastVersion([3, 6])
193198
endfunction
194199

195200
""

vroom/clangformat.vroom

+8-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ You can format any buffer with clang-format specifying the formatter explicitly.
7676
@end
7777

7878
Several filetypes will use the clang-format formatter by default: c, cpp,
79-
javascript, and proto.
79+
javascript, and proto. If the version of clang-format is >= 3.6, then it will
80+
also format java files.
8081

8182
@clear
8283
% f();
@@ -99,6 +100,12 @@ javascript, and proto.
99100
$ { "Cursor": 0 }
100101
$ f();
101102

103+
:set filetype=java
104+
:FormatCode
105+
! clang-format .*
106+
$ { "Cursor": 0 }
107+
$ f();
108+
102109
:set filetype=
103110

104111
It can format specific line ranges of code using :FormatLines.

0 commit comments

Comments
 (0)