Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 2 | " Language: Java |
Aliaksei Budavei | 4052474 | 2024-04-14 19:57:00 +0300 | [diff] [blame] | 3 | " Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com> |
| 4 | " Former Maintainer: Dan Sharp |
| 5 | " Repository: https://github.com/zzzyxwvut/java-vim.git |
Aliaksei Budavei | 85f054a | 2024-09-30 19:40:04 +0200 | [diff] [blame] | 6 | " Last Change: 2024 Sep 26 |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 7 | " 2024 Jan 14 by Vim Project (browsefilter) |
Riley Bruins | 0a08306 | 2024-06-03 20:40:45 +0200 | [diff] [blame] | 8 | " 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10 | " Make sure the continuation lines below do not cause problems in |
| 11 | " compatibility mode. |
| 12 | let s:save_cpo = &cpo |
| 13 | set cpo-=C |
| 14 | |
Aliaksei Budavei | 85f054a | 2024-09-30 19:40:04 +0200 | [diff] [blame] | 15 | if (exists("g:java_ignore_javadoc") || exists("g:java_ignore_markdown")) && |
| 16 | \ exists("*javaformat#RemoveCommonMarkdownWhitespace") |
| 17 | delfunction javaformat#RemoveCommonMarkdownWhitespace |
| 18 | unlet! g:loaded_javaformat |
| 19 | endif |
| 20 | |
| 21 | if exists("b:did_ftplugin") |
| 22 | let &cpo = s:save_cpo |
| 23 | unlet s:save_cpo |
| 24 | finish |
| 25 | endif |
| 26 | |
| 27 | let b:did_ftplugin = 1 |
| 28 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 29 | " For filename completion, prefer the .java extension over the .class |
| 30 | " extension. |
| 31 | set 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. |
| 35 | setlocal includeexpr=substitute(v:fname,'\\.','/','g') |
| 36 | setlocal suffixesadd=.java |
Aliaksei Budavei | 36e667a | 2024-04-18 23:01:52 +0200 | [diff] [blame] | 37 | |
| 38 | " Clean up in case this file is sourced again. |
| 39 | unlet! s:zip_func_upgradable |
| 40 | |
Aliaksei Budavei | 85f054a | 2024-09-30 19:40:04 +0200 | [diff] [blame] | 41 | """" STRIVE TO REMAIN COMPATIBLE FOR AT LEAST VIM 7.0. |
| 42 | |
Aliaksei Budavei | 36e667a | 2024-04-18 23:01:52 +0200 | [diff] [blame] | 43 | " Documented in ":help ft-java-plugin". |
| 44 | if 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 69 | endif |
| 70 | |
| 71 | " Set 'formatoptions' to break comment lines but not other lines, |
| 72 | " and insert the comment leader when hitting <CR> or using "o". |
| 73 | setlocal formatoptions-=t formatoptions+=croql |
| 74 | |
Aliaksei Budavei | 85f054a | 2024-09-30 19:40:04 +0200 | [diff] [blame] | 75 | " Set 'comments' to format Markdown Javadoc comments and dashed lists |
| 76 | " in other multi-line comments (it behaves just like C). |
| 77 | setlocal comments& comments^=:///,sO:*\ -,mO:*\ \ ,exO:*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 78 | |
Riley Bruins | 0a08306 | 2024-06-03 20:40:45 +0200 | [diff] [blame] | 79 | setlocal commentstring=//\ %s |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 80 | |
| 81 | " Change the :browse e filter to primarily show Java-related files. |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 82 | if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 83 | let b:browsefilter="Java Files (*.java)\t*.java\n" . |
| 84 | \ "Properties Files (*.prop*)\t*.prop*\n" . |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 85 | \ "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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 91 | endif |
| 92 | |
| 93 | " Undo the stuff we changed. |
Bram Moolenaar | 8b879e7 | 2005-03-28 20:49:18 +0000 | [diff] [blame] | 94 | let b:undo_ftplugin = "setlocal suffixes< suffixesadd<" . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | \ " formatoptions< comments< commentstring< path< includeexpr<" . |
| 96 | \ " | unlet! b:browsefilter" |
| 97 | |
Aliaksei Budavei | 36e667a | 2024-04-18 23:01:52 +0200 | [diff] [blame] | 98 | " See ":help vim9-mix". |
| 99 | if !has("vim9script") |
| 100 | let &cpo = s:save_cpo |
| 101 | unlet s:save_cpo |
| 102 | finish |
| 103 | endif |
| 104 | |
| 105 | if 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< |
| 115 | endif |
| 116 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 117 | " Restore the saved compatibility options. |
| 118 | let &cpo = s:save_cpo |
Bram Moolenaar | 84f7235 | 2012-03-11 15:57:40 +0100 | [diff] [blame] | 119 | unlet s:save_cpo |
Aliaksei Budavei | 85f054a | 2024-09-30 19:40:04 +0200 | [diff] [blame] | 120 | " vim: fdm=syntax sw=4 ts=8 noet sta |