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 | 2e25247 | 2024-12-27 16:46:36 +0100 | [diff] [blame] | 6 | " Last Change: 2024 Dec 25 |
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 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 93 | """" Support pre- and post-compiler actions for SpotBugs. |
| 94 | if (!empty(get(g:, 'spotbugs_properties', {})) || |
| 95 | \ !empty(get(b:, 'spotbugs_properties', {}))) && |
| 96 | \ filereadable($VIMRUNTIME . '/compiler/spotbugs.vim') |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 97 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 98 | function! s:SpotBugsGetProperty(name, default) abort |
| 99 | return get( |
| 100 | \ {s:spotbugs_properties_scope}spotbugs_properties, |
| 101 | \ a:name, |
| 102 | \ a:default) |
| 103 | endfunction |
| 104 | |
| 105 | function! s:SpotBugsHasProperty(name) abort |
| 106 | return has_key( |
| 107 | \ {s:spotbugs_properties_scope}spotbugs_properties, |
| 108 | \ a:name) |
| 109 | endfunction |
| 110 | |
| 111 | function! s:SpotBugsGetProperties() abort |
| 112 | return {s:spotbugs_properties_scope}spotbugs_properties |
| 113 | endfunction |
| 114 | |
| 115 | " Work around ":bar"s and ":autocmd"s. |
Aliaksei Budavei | 2e25247 | 2024-12-27 16:46:36 +0100 | [diff] [blame] | 116 | function! JavaFileTypeExecuteActionOnce(cleanup_cmd, action_cmd) abort |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 117 | try |
| 118 | execute a:cleanup_cmd |
| 119 | finally |
| 120 | execute a:action_cmd |
| 121 | endtry |
| 122 | endfunction |
| 123 | |
| 124 | if exists("b:spotbugs_properties") |
| 125 | let s:spotbugs_properties_scope = 'b:' |
| 126 | |
| 127 | " Merge global entries, if any, in buffer-local entries, favouring |
| 128 | " defined buffer-local ones. |
| 129 | call extend( |
| 130 | \ b:spotbugs_properties, |
| 131 | \ get(g:, 'spotbugs_properties', {}), |
| 132 | \ 'keep') |
| 133 | elseif exists("g:spotbugs_properties") |
| 134 | let s:spotbugs_properties_scope = 'g:' |
| 135 | endif |
| 136 | |
| 137 | let s:commands = {} |
| 138 | |
| 139 | for s:name in ['DefaultPreCompilerCommand', |
| 140 | \ 'DefaultPreCompilerTestCommand', |
| 141 | \ 'DefaultPostCompilerCommand'] |
| 142 | if s:SpotBugsHasProperty(s:name) |
| 143 | let s:commands[s:name] = remove( |
| 144 | \ s:SpotBugsGetProperties(), |
| 145 | \ s:name) |
| 146 | endif |
| 147 | endfor |
| 148 | |
| 149 | if s:SpotBugsHasProperty('compiler') |
| 150 | " XXX: Postpone loading the script until all state, if any, has been |
| 151 | " collected. |
| 152 | if !empty(s:commands) |
| 153 | let g:spotbugs#state = { |
| 154 | \ 'compiler': remove(s:SpotBugsGetProperties(), 'compiler'), |
| 155 | \ 'commands': copy(s:commands), |
| 156 | \ } |
| 157 | else |
| 158 | let g:spotbugs#state = { |
| 159 | \ 'compiler': remove(s:SpotBugsGetProperties(), 'compiler'), |
| 160 | \ } |
| 161 | endif |
| 162 | |
| 163 | " Merge default entries in global (or buffer-local) entries, favouring |
| 164 | " defined global (or buffer-local) ones. |
| 165 | call extend( |
| 166 | \ {s:spotbugs_properties_scope}spotbugs_properties, |
| 167 | \ spotbugs#DefaultProperties(), |
| 168 | \ 'keep') |
| 169 | elseif !empty(s:commands) |
| 170 | " XXX: Postpone loading the script until all state, if any, has been |
| 171 | " collected. |
| 172 | let g:spotbugs#state = {'commands': copy(s:commands)} |
| 173 | endif |
| 174 | |
| 175 | unlet s:commands s:name |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 176 | let s:request = 0 |
| 177 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 178 | if s:SpotBugsHasProperty('PostCompilerAction') |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 179 | let s:request += 4 |
| 180 | endif |
| 181 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 182 | if s:SpotBugsHasProperty('PreCompilerTestAction') |
| 183 | let s:dispatcher = printf('call call(%s, [])', |
| 184 | \ string(s:SpotBugsGetProperties().PreCompilerTestAction)) |
| 185 | let s:request += 2 |
| 186 | endif |
| 187 | |
| 188 | if s:SpotBugsHasProperty('PreCompilerAction') |
| 189 | let s:dispatcher = printf('call call(%s, [])', |
| 190 | \ string(s:SpotBugsGetProperties().PreCompilerAction)) |
| 191 | let s:request += 1 |
| 192 | endif |
| 193 | |
| 194 | " Adapt the tests for "s:FindClassFiles()" from "compiler/spotbugs.vim". |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 195 | if (s:request == 3 || s:request == 7) && |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 196 | \ (!empty(s:SpotBugsGetProperty('sourceDirPath', [])) && |
| 197 | \ !empty(s:SpotBugsGetProperty('classDirPath', [])) && |
| 198 | \ !empty(s:SpotBugsGetProperty('testSourceDirPath', [])) && |
| 199 | \ !empty(s:SpotBugsGetProperty('testClassDirPath', []))) |
| 200 | function! s:DispatchAction(paths_action_pairs) abort |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 201 | let name = expand('%:p') |
| 202 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 203 | for [paths, Action] in a:paths_action_pairs |
| 204 | for path in paths |
| 205 | if name =~# (path . '.\{-}\.java\=$') |
| 206 | call Action() |
| 207 | return |
| 208 | endif |
| 209 | endfor |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 210 | endfor |
| 211 | endfunction |
| 212 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 213 | let s:dir_cnt = min([ |
| 214 | \ len(s:SpotBugsGetProperties().sourceDirPath), |
| 215 | \ len(s:SpotBugsGetProperties().classDirPath)]) |
| 216 | let s:test_dir_cnt = min([ |
| 217 | \ len(s:SpotBugsGetProperties().testSourceDirPath), |
| 218 | \ len(s:SpotBugsGetProperties().testClassDirPath)]) |
| 219 | |
| 220 | " Do not break up path pairs with filtering! |
| 221 | let s:dispatcher = printf('call s:DispatchAction(%s)', |
| 222 | \ string([[s:SpotBugsGetProperties().sourceDirPath[0 : s:dir_cnt - 1], |
| 223 | \ s:SpotBugsGetProperties().PreCompilerAction], |
| 224 | \ [s:SpotBugsGetProperties().testSourceDirPath[0 : s:test_dir_cnt - 1], |
| 225 | \ s:SpotBugsGetProperties().PreCompilerTestAction]])) |
| 226 | unlet s:test_dir_cnt s:dir_cnt |
| 227 | endif |
| 228 | |
| 229 | if exists("s:dispatcher") |
| 230 | function! s:ExecuteActions(pre_action, post_action) abort |
| 231 | try |
| 232 | execute a:pre_action |
| 233 | catch /\<E42:/ |
| 234 | execute a:post_action |
| 235 | endtry |
| 236 | endfunction |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 237 | endif |
| 238 | |
| 239 | if s:request |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 240 | if exists("b:spotbugs_syntax_once") || empty(join(getline(1, 8), '')) |
| 241 | let s:actions = [{'event': 'User'}] |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 242 | else |
| 243 | " XXX: Handle multiple FileType events when vimrc contains more |
| 244 | " than one filetype setting for the language, e.g.: |
| 245 | " :filetype plugin indent on |
| 246 | " :autocmd BufRead,BufNewFile *.java setlocal filetype=java ... |
| 247 | " XXX: DO NOT ADD b:spotbugs_syntax_once TO b:undo_ftplugin ! |
| 248 | let b:spotbugs_syntax_once = 1 |
| 249 | let s:actions = [{ |
| 250 | \ 'event': 'Syntax', |
| 251 | \ 'once': 1, |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 252 | \ }, { |
| 253 | \ 'event': 'User', |
| 254 | \ }] |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 255 | endif |
| 256 | |
| 257 | for s:idx in range(len(s:actions)) |
| 258 | if s:request == 7 || s:request == 6 || s:request == 5 |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 259 | let s:actions[s:idx].cmd = printf('call s:ExecuteActions(%s, %s)', |
| 260 | \ string(s:dispatcher), |
| 261 | \ string(printf('compiler spotbugs | call call(%s, [])', |
| 262 | \ string(s:SpotBugsGetProperties().PostCompilerAction)))) |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 263 | elseif s:request == 4 |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 264 | let s:actions[s:idx].cmd = printf( |
| 265 | \ 'compiler spotbugs | call call(%s, [])', |
| 266 | \ string(s:SpotBugsGetProperties().PostCompilerAction)) |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 267 | elseif s:request == 3 || s:request == 2 || s:request == 1 |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 268 | let s:actions[s:idx].cmd = printf('call s:ExecuteActions(%s, %s)', |
| 269 | \ string(s:dispatcher), |
| 270 | \ string('compiler spotbugs')) |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 271 | else |
| 272 | let s:actions[s:idx].cmd = '' |
| 273 | endif |
| 274 | endfor |
| 275 | |
| 276 | if !exists("#java_spotbugs") |
| 277 | augroup java_spotbugs |
| 278 | augroup END |
| 279 | endif |
| 280 | |
| 281 | " The events are defined in s:actions. |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 282 | silent! autocmd! java_spotbugs User <buffer> |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 283 | silent! autocmd! java_spotbugs Syntax <buffer> |
| 284 | |
| 285 | for s:action in s:actions |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 286 | if has_key(s:action, 'once') |
| 287 | execute printf('autocmd java_spotbugs %s <buffer> ' . |
Aliaksei Budavei | 2e25247 | 2024-12-27 16:46:36 +0100 | [diff] [blame] | 288 | \ 'call JavaFileTypeExecuteActionOnce(%s, %s)', |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 289 | \ s:action.event, |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 290 | \ string(printf('autocmd! java_spotbugs %s <buffer>', |
| 291 | \ s:action.event)), |
| 292 | \ string(s:action.cmd)) |
| 293 | else |
| 294 | execute printf('autocmd java_spotbugs %s <buffer> %s', |
| 295 | \ s:action.event, |
| 296 | \ s:action.cmd) |
| 297 | endif |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 298 | endfor |
| 299 | |
Aliaksei Budavei | 2e25247 | 2024-12-27 16:46:36 +0100 | [diff] [blame] | 300 | if s:SpotBugsHasProperty('PostCompilerActionExecutor') && |
| 301 | \ (s:request == 7 || s:request == 6 || |
| 302 | \ s:request == 5 || s:request == 4) |
| 303 | let s:augroup = s:SpotBugsGetProperty( |
| 304 | \ 'augroupForPostCompilerAction', |
| 305 | \ 'java_spotbugs_post') |
| 306 | let s:augroup = !empty(s:augroup) ? s:augroup : 'java_spotbugs_post' |
| 307 | |
| 308 | for s:candidate in ['java_spotbugs_post', s:augroup] |
| 309 | if !exists("#" . s:candidate) |
| 310 | execute printf('augroup %s | augroup END', s:candidate) |
| 311 | endif |
| 312 | endfor |
| 313 | |
| 314 | silent! autocmd! java_spotbugs_post User <buffer> |
| 315 | |
| 316 | " Define a User ":autocmd" to define a once-only ShellCmdPost |
| 317 | " ":autocmd" that will invoke "PostCompilerActionExecutor" and let |
| 318 | " it decide whether to proceed with ":compiler spotbugs" etc.; and |
| 319 | " seek explicit synchronisation with ":doautocmd ShellCmdPost" by |
| 320 | " omitting "nested" for "java_spotbugs_post" and "java_spotbugs". |
| 321 | execute printf('autocmd java_spotbugs_post User <buffer> ' . |
| 322 | \ 'call JavaFileTypeExecuteActionOnce(%s, %s)', |
| 323 | \ string(printf('autocmd! %s ShellCmdPost <buffer>', s:augroup)), |
| 324 | \ string(printf('autocmd %s ShellCmdPost <buffer> ' . |
| 325 | \ 'call JavaFileTypeExecuteActionOnce(%s, %s)', |
| 326 | \ s:augroup, |
| 327 | \ string(printf('autocmd! %s ShellCmdPost <buffer>', s:augroup)), |
| 328 | \ string(printf('call call(%s, [%s])', |
| 329 | \ string(s:SpotBugsGetProperties().PostCompilerActionExecutor), |
| 330 | \ string(printf('compiler spotbugs | call call(%s, [])', |
| 331 | \ string(s:SpotBugsGetProperties().PostCompilerAction)))))))) |
| 332 | endif |
| 333 | |
| 334 | unlet! s:candidate s:augroup s:action s:actions s:idx s:dispatcher |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 335 | endif |
| 336 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 337 | delfunction s:SpotBugsGetProperties |
| 338 | delfunction s:SpotBugsHasProperty |
| 339 | delfunction s:SpotBugsGetProperty |
| 340 | unlet! s:request s:spotbugs_properties_scope |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 341 | endif |
| 342 | |
| 343 | function! JavaFileTypeCleanUp() abort |
| 344 | setlocal suffixes< suffixesadd< formatoptions< comments< commentstring< path< includeexpr< |
| 345 | unlet! b:browsefilter |
| 346 | |
Aliaksei Budavei | 2e25247 | 2024-12-27 16:46:36 +0100 | [diff] [blame] | 347 | " The concatenated ":autocmd" removals may be misparsed as an ":autocmd". |
| 348 | " A _once-only_ ShellCmdPost ":autocmd" is always a call-site definition. |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 349 | silent! autocmd! java_spotbugs User <buffer> |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 350 | silent! autocmd! java_spotbugs Syntax <buffer> |
Aliaksei Budavei | 2e25247 | 2024-12-27 16:46:36 +0100 | [diff] [blame] | 351 | silent! autocmd! java_spotbugs_post User <buffer> |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 352 | endfunction |
| 353 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 354 | " Undo the stuff we changed. |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 355 | let b:undo_ftplugin = 'call JavaFileTypeCleanUp() | delfunction JavaFileTypeCleanUp' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 356 | |
Aliaksei Budavei | 36e667a | 2024-04-18 23:01:52 +0200 | [diff] [blame] | 357 | " See ":help vim9-mix". |
| 358 | if !has("vim9script") |
| 359 | let &cpo = s:save_cpo |
| 360 | unlet s:save_cpo |
| 361 | finish |
| 362 | endif |
| 363 | |
| 364 | if exists("s:zip_func_upgradable") |
| 365 | delfunction! JavaFileTypeZipFile |
| 366 | |
| 367 | def! s:JavaFileTypeZipFile(): string |
| 368 | @/ = substitute(v:fname, '\.', '\\/', 'g') .. '.java' |
| 369 | return get(zip_files, bufnr('%'), zip_files[0]) |
| 370 | enddef |
| 371 | |
| 372 | setlocal includeexpr=s:JavaFileTypeZipFile() |
| 373 | setlocal suffixesadd< |
| 374 | endif |
| 375 | |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 376 | if exists("*s:DispatchAction") |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 377 | def! s:DispatchAction(paths_action_pairs: list<list<any>>) |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 378 | const name: string = expand('%:p') |
| 379 | |
Aliaksei Budavei | 368ef5a | 2024-12-16 21:37:54 +0100 | [diff] [blame] | 380 | for [paths: list<string>, Action: func: any] in paths_action_pairs |
| 381 | for path in paths |
| 382 | if name =~# (path .. '.\{-}\.java\=$') |
| 383 | Action() |
| 384 | return |
| 385 | endif |
| 386 | endfor |
Konfekt | 65311c6 | 2024-11-28 21:06:09 +0100 | [diff] [blame] | 387 | endfor |
| 388 | enddef |
| 389 | endif |
| 390 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 391 | " Restore the saved compatibility options. |
| 392 | let &cpo = s:save_cpo |
Bram Moolenaar | 84f7235 | 2012-03-11 15:57:40 +0100 | [diff] [blame] | 393 | unlet s:save_cpo |
Aliaksei Budavei | 85f054a | 2024-09-30 19:40:04 +0200 | [diff] [blame] | 394 | " vim: fdm=syntax sw=4 ts=8 noet sta |