blob: 55b358374fc4fb5d324965899bfb49a97efda818 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
Doug Kearns93197fd2024-01-14 20:59:02 +01002" Language: Java
Aliaksei Budavei40524742024-04-14 19:57:00 +03003" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
4" Former Maintainer: Dan Sharp
5" Repository: https://github.com/zzzyxwvut/java-vim.git
Aliaksei Budavei85f054a2024-09-30 19:40:04 +02006" Last Change: 2024 Sep 26
Doug Kearns93197fd2024-01-14 20:59:02 +01007" 2024 Jan 14 by Vim Project (browsefilter)
Riley Bruins0a083062024-06-03 20:40:45 +02008" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar071d4272004-06-13 20:20:40 +000010" Make sure the continuation lines below do not cause problems in
11" compatibility mode.
12let s:save_cpo = &cpo
13set cpo-=C
14
Aliaksei Budavei85f054a2024-09-30 19:40:04 +020015if (exists("g:java_ignore_javadoc") || exists("g:java_ignore_markdown")) &&
16 \ exists("*javaformat#RemoveCommonMarkdownWhitespace")
17 delfunction javaformat#RemoveCommonMarkdownWhitespace
18 unlet! g:loaded_javaformat
19endif
20
21if exists("b:did_ftplugin")
22 let &cpo = s:save_cpo
23 unlet s:save_cpo
24 finish
25endif
26
27let b:did_ftplugin = 1
28
Bram Moolenaar071d4272004-06-13 20:20:40 +000029" For filename completion, prefer the .java extension over the .class
30" extension.
31set suffixes+=.class
32
33" Enable gf on import statements. Convert . in the package
34" name to / and append .java to the name, then search the path.
35setlocal includeexpr=substitute(v:fname,'\\.','/','g')
36setlocal suffixesadd=.java
Aliaksei Budavei36e667a2024-04-18 23:01:52 +020037
38" Clean up in case this file is sourced again.
39unlet! s:zip_func_upgradable
40
Aliaksei Budavei85f054a2024-09-30 19:40:04 +020041"""" STRIVE TO REMAIN COMPATIBLE FOR AT LEAST VIM 7.0.
42
Aliaksei Budavei36e667a2024-04-18 23:01:52 +020043" Documented in ":help ft-java-plugin".
44if exists("g:ftplugin_java_source_path") &&
45 \ type(g:ftplugin_java_source_path) == type("")
46 if filereadable(g:ftplugin_java_source_path)
47 if exists("#zip") &&
48 \ g:ftplugin_java_source_path =~# '.\.\%(jar\|zip\)$'
49 if !exists("s:zip_files")
50 let s:zip_files = {}
51 endif
52
53 let s:zip_files[bufnr('%')] = g:ftplugin_java_source_path
54 let s:zip_files[0] = g:ftplugin_java_source_path
55 let s:zip_func_upgradable = 1
56
57 function! JavaFileTypeZipFile() abort
58 let @/ = substitute(v:fname, '\.', '\\/', 'g') . '.java'
59 return get(s:zip_files, bufnr('%'), s:zip_files[0])
60 endfunction
61
62 " E120 for "inex=s:JavaFileTypeZipFile()" before v8.2.3900.
63 setlocal includeexpr=JavaFileTypeZipFile()
64 setlocal suffixesadd<
65 endif
66 else
67 let &l:path = g:ftplugin_java_source_path . ',' . &l:path
68 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000069endif
70
71" Set 'formatoptions' to break comment lines but not other lines,
72" and insert the comment leader when hitting <CR> or using "o".
73setlocal formatoptions-=t formatoptions+=croql
74
Aliaksei Budavei85f054a2024-09-30 19:40:04 +020075" Set 'comments' to format Markdown Javadoc comments and dashed lists
76" in other multi-line comments (it behaves just like C).
77setlocal comments& comments^=:///,sO:*\ -,mO:*\ \ ,exO:*/
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
Riley Bruins0a083062024-06-03 20:40:45 +020079setlocal commentstring=//\ %s
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
81" Change the :browse e filter to primarily show Java-related files.
Doug Kearns93197fd2024-01-14 20:59:02 +010082if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000083 let b:browsefilter="Java Files (*.java)\t*.java\n" .
84 \ "Properties Files (*.prop*)\t*.prop*\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010085 \ "Manifest Files (*.mf)\t*.mf\n"
86 if has("win32")
87 let b:browsefilter .= "All Files (*.*)\t*\n"
88 else
89 let b:browsefilter .= "All Files (*)\t*\n"
90 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000091endif
92
93" Undo the stuff we changed.
Bram Moolenaar8b879e72005-03-28 20:49:18 +000094let b:undo_ftplugin = "setlocal suffixes< suffixesadd<" .
Bram Moolenaar071d4272004-06-13 20:20:40 +000095 \ " formatoptions< comments< commentstring< path< includeexpr<" .
96 \ " | unlet! b:browsefilter"
97
Aliaksei Budavei36e667a2024-04-18 23:01:52 +020098" See ":help vim9-mix".
99if !has("vim9script")
100 let &cpo = s:save_cpo
101 unlet s:save_cpo
102 finish
103endif
104
105if exists("s:zip_func_upgradable")
106 delfunction! JavaFileTypeZipFile
107
108 def! s:JavaFileTypeZipFile(): string
109 @/ = substitute(v:fname, '\.', '\\/', 'g') .. '.java'
110 return get(zip_files, bufnr('%'), zip_files[0])
111 enddef
112
113 setlocal includeexpr=s:JavaFileTypeZipFile()
114 setlocal suffixesadd<
115endif
116
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117" Restore the saved compatibility options.
118let &cpo = s:save_cpo
Bram Moolenaar84f72352012-03-11 15:57:40 +0100119unlet s:save_cpo
Aliaksei Budavei85f054a2024-09-30 19:40:04 +0200120" vim: fdm=syntax sw=4 ts=8 noet sta