blob: eee7ef015333a44c5e1d43ee0aaa31a90a546d99 [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 Budavei36e667a2024-04-18 23:01:52 +02006" Last Change: 2024 Apr 18
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
10if exists("b:did_ftplugin") | finish | endif
11let b:did_ftplugin = 1
12
13" Make sure the continuation lines below do not cause problems in
14" compatibility mode.
15let s:save_cpo = &cpo
16set cpo-=C
17
Bram Moolenaar071d4272004-06-13 20:20:40 +000018" For filename completion, prefer the .java extension over the .class
19" extension.
20set suffixes+=.class
21
22" Enable gf on import statements. Convert . in the package
23" name to / and append .java to the name, then search the path.
24setlocal includeexpr=substitute(v:fname,'\\.','/','g')
25setlocal suffixesadd=.java
Aliaksei Budavei36e667a2024-04-18 23:01:52 +020026
27" Clean up in case this file is sourced again.
28unlet! s:zip_func_upgradable
29
30" Documented in ":help ft-java-plugin".
31if exists("g:ftplugin_java_source_path") &&
32 \ type(g:ftplugin_java_source_path) == type("")
33 if filereadable(g:ftplugin_java_source_path)
34 if exists("#zip") &&
35 \ g:ftplugin_java_source_path =~# '.\.\%(jar\|zip\)$'
36 if !exists("s:zip_files")
37 let s:zip_files = {}
38 endif
39
40 let s:zip_files[bufnr('%')] = g:ftplugin_java_source_path
41 let s:zip_files[0] = g:ftplugin_java_source_path
42 let s:zip_func_upgradable = 1
43
44 function! JavaFileTypeZipFile() abort
45 let @/ = substitute(v:fname, '\.', '\\/', 'g') . '.java'
46 return get(s:zip_files, bufnr('%'), s:zip_files[0])
47 endfunction
48
49 " E120 for "inex=s:JavaFileTypeZipFile()" before v8.2.3900.
50 setlocal includeexpr=JavaFileTypeZipFile()
51 setlocal suffixesadd<
52 endif
53 else
54 let &l:path = g:ftplugin_java_source_path . ',' . &l:path
55 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000056endif
57
58" Set 'formatoptions' to break comment lines but not other lines,
59" and insert the comment leader when hitting <CR> or using "o".
60setlocal formatoptions-=t formatoptions+=croql
61
62" Set 'comments' to format dashed lists in comments. Behaves just like C.
63setlocal comments& comments^=sO:*\ -,mO:*\ \ ,exO:*/
64
Riley Bruins0a083062024-06-03 20:40:45 +020065setlocal commentstring=//\ %s
Bram Moolenaar071d4272004-06-13 20:20:40 +000066
67" Change the :browse e filter to primarily show Java-related files.
Doug Kearns93197fd2024-01-14 20:59:02 +010068if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000069 let b:browsefilter="Java Files (*.java)\t*.java\n" .
70 \ "Properties Files (*.prop*)\t*.prop*\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010071 \ "Manifest Files (*.mf)\t*.mf\n"
72 if has("win32")
73 let b:browsefilter .= "All Files (*.*)\t*\n"
74 else
75 let b:browsefilter .= "All Files (*)\t*\n"
76 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000077endif
78
79" Undo the stuff we changed.
Bram Moolenaar8b879e72005-03-28 20:49:18 +000080let b:undo_ftplugin = "setlocal suffixes< suffixesadd<" .
Bram Moolenaar071d4272004-06-13 20:20:40 +000081 \ " formatoptions< comments< commentstring< path< includeexpr<" .
82 \ " | unlet! b:browsefilter"
83
Aliaksei Budavei36e667a2024-04-18 23:01:52 +020084" See ":help vim9-mix".
85if !has("vim9script")
86 let &cpo = s:save_cpo
87 unlet s:save_cpo
88 finish
89endif
90
91if exists("s:zip_func_upgradable")
92 delfunction! JavaFileTypeZipFile
93
94 def! s:JavaFileTypeZipFile(): string
95 @/ = substitute(v:fname, '\.', '\\/', 'g') .. '.java'
96 return get(zip_files, bufnr('%'), zip_files[0])
97 enddef
98
99 setlocal includeexpr=s:JavaFileTypeZipFile()
100 setlocal suffixesadd<
101endif
102
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103" Restore the saved compatibility options.
104let &cpo = s:save_cpo
Bram Moolenaar84f72352012-03-11 15:57:40 +0100105unlet s:save_cpo