3
3
" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
4
4
" Former Maintainer: Claudio Fleiner <[email protected] >
5
5
" Repository: https://github.com/zzzyxwvut/java-vim.git
6
- " Last Change: 2025 Oct 04
6
+ " Last Change: 2025 Oct 08
7
7
8
8
" Please check ":help java.vim" for comments on some of the options
9
9
" available.
59
59
endfunction
60
60
endif
61
61
62
+ function ! s: ff .QueryFoldArgForSyntaxItems (kind) abort
63
+ return stridx (s: java_ignore_folding , a: kind ) < 0 ? " fold" : " "
64
+ endfunction
65
+
62
66
if ! exists (" *s:ReportOnce" )
63
67
function s: ReportOnce (message) abort
64
68
echomsg ' syntax/java.vim: ' . a: message
@@ -90,6 +94,8 @@ if exists("g:java_foldtext_show_first_or_second_line")
90
94
setlocal foldtext = JavaSyntaxFoldTextExpr ()
91
95
endif
92
96
97
+ let s: java_ignore_folding = get (g: , ' java_ignore_folding' , ' ' )
98
+
93
99
" Admit the ASCII dollar sign to keyword characters (JLS-17, §3.8):
94
100
try
95
101
exec ' syntax iskeyword ' . &l: iskeyword . ' ,$'
@@ -121,6 +127,11 @@ syn match javaOperator "\<var\>\%(\s*(\)\@!"
121
127
syn match javaExternal " \< import\s\+ module\> " contains =javaModuleImport
122
128
syn keyword javaModuleImport contained module
123
129
130
+ if ! empty (s: ff .QueryFoldArgForSyntaxItems (' i' ))
131
+ " Group and fold adjacent "import" declarations.
132
+ syn region javaImportDeclBlock transparent start =" \< import\s\+\K " skip =" \< import\s\+\K " end =" ^" contains =javaExternal,@javaClasses,javaComment,javaLineComment fold
133
+ endif
134
+
124
135
" Since the yield statement, which could take a parenthesised operand,
125
136
" and _qualified_ yield methods get along within the switch block
126
137
" (JLS-17, §3.8), it seems futile to make a region definition for this
@@ -380,7 +391,7 @@ syn keyword javaLabelDefault contained default
380
391
syn keyword javaLabelVarType contained var
381
392
" Allow for the contingency of the enclosing region not being able to
382
393
" _keep_ its _end_, e.g. case ':':.
383
- syn region javaLabelWhenClause contained transparent matchgroup =javaLabel start =" \< when\> " matchgroup =NONE end =" :" me =e - 1 end =" ->" me =e - 2 contains =TOP,javaExternal,javaLambdaDef
394
+ syn region javaLabelWhenClause contained transparent matchgroup =javaLabel start =" \< when\> " matchgroup =NONE end =" :" me =e - 1 end =" ->" me =e - 2 contains =TOP,javaImportDeclBlock, javaExternal,javaLambdaDef
384
395
385
396
" Comments
386
397
syn keyword javaTodo contained TODO FIXME XXX
@@ -396,7 +407,7 @@ if exists("g:java_comment_strings")
396
407
syn cluster javaCommentSpecial2 add =javaComment2String,javaCommentCharacter,javaNumber,javaStrTempl
397
408
endif
398
409
399
- syn region javaComment matchgroup =javaCommentStart start =" /\* " end =" \* /" contains =@javaCommentSpecial,javaTodo,javaCommentError,javaSpaceError,@Spell fold
410
+ exec ' syn region javaComment matchgroup=javaCommentStart start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,javaCommentError,javaSpaceError,@Spell ' . s: ff . QueryFoldArgForSyntaxItems ( ' c ' )
400
411
syn match javaCommentStar contained " ^\s *\* [^/]" me =e - 1
401
412
syn match javaCommentStar contained " ^\s *\* $"
402
413
syn match javaLineComment " //.*" contains =@javaCommentSpecial2,javaTodo,javaCommentMarkupTag,javaSpaceError,@Spell
@@ -510,7 +521,7 @@ if !exists("g:java_ignore_javadoc") && (s:with_html || s:with_markdown) && g:mai
510
521
endtry
511
522
512
523
if s: with_markdown
513
- syn region javaMarkdownComment start =" ///" skip =" ^\s *///.*$" end =" ^" keepend contains =javaMarkdownCommentTitle,javaMarkdownShortcutLink,@javaMarkdown,@javaDocTags,javaTodo,@Spell nextgroup =javaMarkdownCommentTitle fold
524
+ exec ' syn region javaMarkdownComment start="///" skip="^\s*///.*$" end="^" keepend contains=javaMarkdownCommentTitle,javaMarkdownShortcutLink,@javaMarkdown,@javaDocTags,javaTodo,@Spell nextgroup=javaMarkdownCommentTitle ' . s: ff . QueryFoldArgForSyntaxItems ( ' d ' )
514
525
syn match javaMarkdownCommentMask contained " ^\s *///"
515
526
exec ' syn region javaMarkdownCommentTitle contained matchgroup=javaMarkdownComment start="\%(///.*\r\=\n\s*\)\@' . s: ff .PeekFor (' javaMarkdownCommentTitle' , 120 ) . ' <!///" matchgroup=javaMarkdownCommentTitle end="\.$" end="\.[ \t\r]\@=" end="\n\%(\s*///\s*$\)\@=" end="\%(^\s*///\s*\)\@' . s: ff .PeekFor (' javaMarkdownCommentTitle' , 120 ) . ' <=@"me=s-2,he=s-1 contains=javaMarkdownShortcutLink,@javaMarkdown,javaMarkdownCommentMask,javaTodo,@Spell,@javaDocTags'
516
527
exec ' syn region javaMarkdownCommentTitle contained matchgroup=javaMarkdownComment start="\%(///.*\r\=\n\s*\)\@' . s: ff .PeekFor (' javaMarkdownCommentTitle' , 120 ) . ' <!///\s*\%({@return\>\)\@=" matchgroup=javaMarkdownCommentTitle end="}\%(\s*\.*\)*" contains=javaMarkdownShortcutLink,@javaMarkdown,javaMarkdownCommentMask,javaTodo,@Spell,@javaDocTags,javaTitleSkipBlock'
@@ -565,7 +576,7 @@ if !exists("g:java_ignore_javadoc") && (s:with_html || s:with_markdown) && g:mai
565
576
endif
566
577
567
578
if s: with_html
568
- syn region javaDocComment start =" /\*\* " end =" \* /" keepend contains =javaCommentTitle,@javaHtml,@javaDocTags,javaTodo,javaCommentError,javaSpaceError,@Spell fold
579
+ exec ' syn region javaDocComment start="/\*\*" end="\*/" keepend contains=javaCommentTitle,@javaHtml,@javaDocTags,javaTodo,javaCommentError,javaSpaceError,@Spell ' . s: ff . QueryFoldArgForSyntaxItems ( ' d ' )
569
580
exec ' syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*" matchgroup=javaCommentTitle end="\.$" end="\.[ \t\r]\@=" end="\%(^\s*\**\s*\)\@' . s: ff .PeekFor (' javaCommentTitle' , 120 ) . ' <=@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@javaHtml,javaCommentStar,javaTodo,javaCommentError,javaSpaceError,@Spell,@javaDocTags'
570
581
syn region javaCommentTitle contained matchgroup =javaDocComment start =" /\*\*\s *\r\=\n\=\s *\* *\s *\% ({@return\>\)\@ =" matchgroup =javaCommentTitle end =" }\% (\s *\. *\) *" contains =@javaHtml,javaCommentStar,javaTodo,javaCommentError,javaSpaceError,@Spell,@javaDocTags,javaTitleSkipBlock
571
582
syn region javaCommentTitle contained matchgroup =javaDocComment start =" /\*\*\s *\r\=\n\=\s *\* *\s *\% ({@summary\>\)\@ =" matchgroup =javaCommentTitle end =" }" contains =@javaHtml,javaCommentStar,javaTodo,javaCommentError,javaSpaceError,@Spell,@javaDocTags,javaTitleSkipBlock
@@ -690,7 +701,7 @@ syn region javaString start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=
690
701
syn match javaTextBlockError + """\s *"""+
691
702
692
703
if s: ff .IsAnyRequestedPreviewFeatureOf ([430 ])
693
- syn region javaStrTemplEmbExp contained matchgroup =javaStrTempl start =" \\ {" end =" }" contains =TOP
704
+ syn region javaStrTemplEmbExp contained matchgroup =javaStrTempl start =" \\ {" end =" }" contains =TOP,javaImportDeclBlock
694
705
exec ' syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s: ff .PeekFor (' javaStrTempl' , 80 ) . ' <="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell'
695
706
exec ' syn region javaStrTempl start=+\%(\.[[:space:]\n]*\)\@' . s: ff .PeekFor (' javaStrTempl' , 80 ) . ' <="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell'
696
707
hi def link javaStrTempl Macro
@@ -751,7 +762,7 @@ if exists("g:java_highlight_functions")
751
762
" in order to not include javaFuncDef.
752
763
syn region javaParenE transparent matchgroup =javaParen start =" (" end =" )" contains =@javaEnumConstants,javaInParen
753
764
syn region javaParenE transparent matchgroup =javaParen start =" \[ " end =" \] " contains =@javaEnumConstants
754
- syn cluster javaEnumConstants contains =TOP,javaTopEnumDeclaration,javaFuncDef,javaParenT
765
+ syn cluster javaEnumConstants contains =TOP,javaTopEnumDeclaration,javaImportDeclBlock, javaFuncDef,javaParenT
755
766
unlet s: indent s: last
756
767
else
757
768
" This is the "style" variant (:help ft-java-syntax).
@@ -822,7 +833,7 @@ syn region javaBlockOther transparent matchgroup=javaBlockOtherStart start="{" e
822
833
823
834
" Try not to fold top-level-type bodies under assumption that there is
824
835
" but one such body.
825
- exec ' syn region javaBlock transparent matchgroup=javaBlockStart start="\%(^\|^\S[^:]\+\)\@' . s: ff .PeekFor (' javaBlock' , 120 ) . ' <!{" end="}" fold '
836
+ exec ' syn region javaBlock transparent matchgroup=javaBlockStart start="\%(^\|^\S[^:]\+\)\@' . s: ff .PeekFor (' javaBlock' , 120 ) . ' <!{" end="}" ' . s: ff . QueryFoldArgForSyntaxItems ( ' b ' )
826
837
827
838
" See "D.2.1 Anonymous Classes" at
828
839
" https://web.archive.org/web/20010821025330/java.sun.com/docs/books/jls/first_edition/html/1.1Update.html#12959.
@@ -966,7 +977,7 @@ endif
966
977
967
978
let b: spell_options = " contained"
968
979
let &cpo = s: cpo_save
969
- unlet s: cpo_save s: ff s: with_html s: with_markdown
980
+ unlet s: cpo_save s: ff s: java_ignore_folding s: with_html s: with_markdown
970
981
971
982
" See ":help vim9-mix".
972
983
if ! has (" vim9script" )
0 commit comments