diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 9340f9240e..4a91a70690 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1725,14 +1725,17 @@ Note that these three variables are maintained in the HTML syntax file. Numbers and strings can be recognized in non-Javadoc comments with > :let g:java_comment_strings = 1 -When 'foldmethod' is set to "syntax", blocks of code and multi-line comments -will be folded. No text is usually written in the first line of a multi-line -comment, making folded contents of Javadoc comments less informative with the -default 'foldtext' value; you may opt for showing the contents of a second -line for any comments written in this way, and showing the contents of a first -line otherwise, with > +When 'foldmethod' is set to "syntax", multi-line blocks of code ("b"), plain +comments ("c"), Javadoc comments ("d"), and adjacent "import" declarations +("i") will be folded by default. Syntax items of any supported kind will +remain NOT foldable when its abbreviated name is delisted with > + :let g:java_ignore_folding = "bcdi" +No text is usually written in the first line of a multi-line comment, making +folded contents of Javadoc comments less informative with the default +'foldtext' value; you may opt for showing the contents of a second line for +any comments written in this way, and showing the contents of a first line +otherwise, with > :let g:java_foldtext_show_first_or_second_line = 1 - HTML tags in Javadoc comments can additionally be folded by following the instructions listed under |html-folding| and giving explicit consent with > :let g:java_consent_to_html_syntax_folding = 1 diff --git a/runtime/syntax/java.vim b/runtime/syntax/java.vim index a715331f82..149f5fd5a7 100644 --- a/runtime/syntax/java.vim +++ b/runtime/syntax/java.vim @@ -3,7 +3,7 @@ " Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com> " Former Maintainer: Claudio Fleiner " Repository: https://github.com/zzzyxwvut/java-vim.git -" Last Change: 2025 Oct 04 +" Last Change: 2025 Oct 08 " Please check ":help java.vim" for comments on some of the options " available. @@ -59,6 +59,10 @@ else endfunction endif +function! s:ff.QueryFoldArgForSyntaxItems(kind) abort + return stridx(s:java_ignore_folding, a:kind) < 0 ? "fold" : "" +endfunction + if !exists("*s:ReportOnce") function s:ReportOnce(message) abort echomsg 'syntax/java.vim: ' . a:message @@ -90,6 +94,8 @@ if exists("g:java_foldtext_show_first_or_second_line") setlocal foldtext=JavaSyntaxFoldTextExpr() endif +let s:java_ignore_folding = get(g:, 'java_ignore_folding', '') + " Admit the ASCII dollar sign to keyword characters (JLS-17, §3.8): try exec 'syntax iskeyword ' . &l:iskeyword . ',$' @@ -121,6 +127,11 @@ syn match javaOperator "\\%(\s*(\)\@!" syn match javaExternal "\" contains=javaModuleImport syn keyword javaModuleImport contained module +if !empty(s:ff.QueryFoldArgForSyntaxItems('i')) + " Group and fold adjacent "import" declarations. + syn region javaImportDeclBlock transparent start="\