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