runtime(java): Manage circularity for every :syn-included syntax file

Commit: 
https://github.com/vim/vim/commit/60310a4b2630a4d3bb0b6da9bc03061ecfbac9ee
Author: Aliaksei Budavei <0x000...@gmail.com>
Date:   Fri Oct 4 20:25:05 2024 +0200

    runtime(java): Manage circularity for every :syn-included syntax file
    
    With "g:markdown_fenced_languages" defined and "java" added
    to its list, a circular dependency between the Markdown and
    Java syntax files will be made.  To break it, no Markdown
    documentation comments will be recognised in fenced blocks
    in Markdown files; in order to view Java source files,
    "java" must be removed from "g:markdown_fenced_languages",
    and this task can be automated as follows.
    
    1) Add to "~/.after/ftplugin/java.vim":
    ------------------------------------------------------------
    if exists("g:markdown_fenced_languages") &&
            \ !(exists("g:java_ignore_javadoc") ||
            \ exists("g:java_ignore_markdown"))
        let s:idx = index(g:markdown_fenced_languages, 'java')
        if s:idx > -1
            call remove(g:markdown_fenced_languages, s:idx)
        endif
        unlet s:idx
    endif
    ------------------------------------------------------------
    
    2) Optionally add to "~/.after/ftplugin/markdown.vim":
    ------------------------------------------------------------
    if exists("g:markdown_fenced_languages") &&
            \ index(g:markdown_fenced_languages, 'java') < 0
        call add(g:markdown_fenced_languages, 'java')
    endif
    ------------------------------------------------------------
    
    (Make sure that the above snippets appear in the files under
    the "ftplugin" NOT "syntax" directory.)
    
    Finally, unless the new version of the syntax file is made
    available from "$VIMRUNTIME" (and from "~/.vim/syntax" if
    necessary), OTHER discoverable file versions will be used
    whose behaviour may interfere with this fix.
    
    related: #15740
    closes: #15796
    
    Signed-off-by: Aliaksei Budavei <0x000...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/syntax/java.vim b/runtime/syntax/java.vim
index 737219afc..307fc2634 100644
--- a/runtime/syntax/java.vim
+++ b/runtime/syntax/java.vim
@@ -3,16 +3,32 @@
 " Maintainer:          Aliaksei Budavei <0x000c70 AT gmail DOT com>
 " Former Maintainer:   Claudio Fleiner <clau...@fleiner.com>
 " Repository:          https://github.com/zzzyxwvut/java-vim.git
-" Last Change:         2024 Sep 28
+" Last Change:         2024 Oct 03
 
-" Please check :help java.vim for comments on some of the options available.
+" Please check ":help java.vim" for comments on some of the options
+" available.
 
-" quit when a syntax file was already loaded
-if !exists("g:main_syntax")
-  if exists("b:current_syntax")
-    finish
+" Do not aggregate syntax items from circular inclusion.
+if exists("b:current_syntax")
+  finish
+endif
+
+if exists("g:main_syntax")
+  " Reject attendant circularity for every :syn-included syntax file,
+  " but ACCEPT FAILURE when "g:main_syntax" is set to "java".
+  if g:main_syntax == 'html'
+    if !exists("g:java_ignore_html")
+      let g:java_ignore_html = 1
+      let s:clear_java_ignore_html = 1
+    endif
+  elseif g:main_syntax == 'markdown'
+    if !exists("g:java_ignore_markdown")
+      let g:java_ignore_markdown = 1
+      let s:clear_java_ignore_markdown = 1
+    endif
   endif
-  " we define it here so that included files can test for it
+else
+  " Allow syntax files that include this file test for its inclusion.
   let g:main_syntax = 'java'
 endif
 
@@ -364,15 +380,17 @@ if !exists("g:java_ignore_javadoc") && (s:with_html || 
s:with_markdown) && g:mai
 
   " Include HTML syntax coloring for Javadoc comments.
   if s:with_html
-    syntax include @javaHtml syntax/html.vim
-    unlet b:current_syntax
+    try
+      syntax include @javaHtml syntax/html.vim
+    finally
+      unlet! b:current_syntax
+    endtry
   endif
 
   " Include Markdown syntax coloring (v7.2.437) for Javadoc comments.
   if s:with_markdown
     try
       syntax include @javaMarkdown syntax/markdown.vim
-      unlet b:current_syntax
       let s:ff.WithMarkdown = s:ff.LeftConstant
     catch /\<E48[45]:/
       call s:ReportOnce(v:exception)
@@ -383,6 +401,8 @@ if !exists("g:java_ignore_javadoc") && (s:with_html || 
s:with_markdown) && g:mai
       hi clear markdownCodeBlock
       hi clear markdownCodeDelimiter
       hi clear markdownLinkDelimiter
+    finally
+      unlet! b:current_syntax
     endtry
   endif
 
@@ -839,6 +859,14 @@ if g:main_syntax == 'java'
   unlet g:main_syntax
 endif
 
+if exists("s:clear_java_ignore_html")
+  unlet! s:clear_java_ignore_html g:java_ignore_html
+endif
+
+if exists("s:clear_java_ignore_markdown")
+  unlet! s:clear_java_ignore_markdown g:java_ignore_markdown
+endif
+
 let b:spell_options = "contained"
 let &cpo = s:cpo_save
 unlet s:cpo_save s:ff s:with_html s:with_markdown
diff --git a/runtime/syntax/testdir/dumps/markdown_circularity_00.dump 
b/runtime/syntax/testdir/dumps/markdown_circularity_00.dump
new file mode 100644
index 000000000..57227bed7
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/markdown_circularity_00.dump
@@ -0,0 +1,20 @@
+>N+0&#ffffff0|o| |c|o|d|e| |i|s| |r|e|c|o|g|n|i|s|e|d| |i|n| |H|T|M|L| 
|s|n|i|p@1|e|t|s|.| @35
+@75
+|~+0#e000e06&@2|h|t|m|l| +0#0000000&@67
+|<+0#00e0e07&|p+0#af5f00255&|r|e|>+0#00e0e07&|<|c+0#af5f00255&|o|d|e|>+0#00e0e07&|
 +0#0000000&@63
+|/|*@1| |H|T|M|L| |s|y|n|t|a|x| |c|i|r|c|u|l|a|r|i|t|y| |t|e|s|t|s|.| |*|/| @37
+|c|l|a|s@1| |H|T|M|L|S|y|n|t|a|x|C|i|r|c|u|l|a|r|i|t|y|T|e|s|t|s| @42
+|{| @73
+@4|/@2| |@|h|i|d@1|e|n| @59
+@4|/@2| @67
+@4|/@2| |@|p|a|r|a|m| |a|r|g|s| |o|p|t|i|o|n|a|l| |c|o|m@1|a|n|d|-|l|i|n|e| 
|a|r|g|u|m|e|n|t|s| @23
+@4|p|u|b|l|i|c| |s|t|a|t|i|c| |v|o|i|d| |m|a|i|n|(|S|t|r|i|n|g|[|]| 
|a|r|g|s|)| @32
+@4|{| @69
+@8|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"@2| @44
+@12|`@2|j|a|v|a| @55
+@12|c|l|a|s@1| |S|y|n|t|a|x|C|i|r|c|u|l|a|r|i|t|y|T|e|s|t|s| @34
+@12|{| @61
+@16|p|u|b|l|i|c| |s|t|a|t|i|c| |v|o|i|d| |m|a|i|n|(|S|t|r|i|n|g|[|]| 
|a|r|g|s|)| @20
+@16|{| @57
+@20|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"|.|"|)|;| @30
+@57|1|,|1| @10|T|o|p| 
diff --git a/runtime/syntax/testdir/dumps/markdown_circularity_01.dump 
b/runtime/syntax/testdir/dumps/markdown_circularity_01.dump
new file mode 100644
index 000000000..8edb7d809
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/markdown_circularity_01.dump
@@ -0,0 +1,20 @@
+| +0&#ffffff0@11|`@2|j|a|v|a| @55
+@12|c|l|a|s@1| |S|y|n|t|a|x|C|i|r|c|u|l|a|r|i|t|y|T|e|s|t|s| @34
+@12|{| @61
+@16|p|u|b|l|i|c| |s|t|a|t|i|c| |v|o|i|d| |m|a|i|n|(|S|t|r|i|n|g|[|]| 
|a|r|g|s|)| @20
+@16|{| @57
+@20>S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"|.|"|)|;| @30
+@16|}| @57
+@12|}| @61
+@12|`@2| @59
+@8|"@2|)|;| @61
+@4|}| @69
+|}| @73
+|<+0#00e0e07&|/|c+0#af5f00255&|o|d|e|>+0#00e0e07&|<|/|p+0#af5f00255&|r|e|>+0#00e0e07&|
 +0#0000000&@61
+|~+0#e000e06&@2| +0#0000000&@71
+@75
+@75
+|M|a|r|k|d|o|w|n| |d|o|c|u|m|e|n|t|a|t|i|o|n| |c|o|m@1|e|n|t|s| |a|r|e| 
|n|o|t| |r|e|c|o|g|n|i|s|e|d| |i|n| |J|a|v|a| |s|n|i|p@1|e|t|s|.| @6
+@75
+|`+0#e000e06&@2|j|a|v|a| +0#0000000&@67
+@57|1|9|,|2|1| @8|3|7|%| 
diff --git a/runtime/syntax/testdir/dumps/markdown_circularity_02.dump 
b/runtime/syntax/testdir/dumps/markdown_circularity_02.dump
new file mode 100644
index 000000000..64b447bfa
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/markdown_circularity_02.dump
@@ -0,0 +1,20 @@
+|`+0#e000e06#ffffff0@2|j|a|v|a| +0#0000000&@67
+|/+0#0000e05&|*@1| +0#e000e06&|J|a|v|a| |s|y|n|t|a|x| |c|i|r|c|u|l|a|r|i|t|y| 
|t|e|s|t|s|.| +0#0000e05&|*|/| +0#0000000&@37
+|c+0#00e0003&|l|a|s@1| 
+0#0000000&|J|a|v|a|S|y|n|t|a|x|C|i|r|c|u|l|a|r|i|t|y|T|e|s|t|s| @42
+|{| @73
+@4|/+0#0000e05&@2| |@|h|i|d@1|e|n| +0#0000000&@59
+@4>/+0#0000e05&@2| +0#0000000&@67
+@4|/+0#0000e05&@2| |@|p|a|r|a|m| |a|r|g|s| |o|p|t|i|o|n|a|l| 
|c|o|m@1|a|n|d|-|l|i|n|e| |a|r|g|u|m|e|n|t|s| +0#0000000&@23
+@4|p+0#00e0003&|u|b|l|i|c| +0#0000000&|s+0#00e0003&|t|a|t|i|c| 
+0#0000000&|v+0#00e0003&|o|i|d| 
+0#0000000&|m|a|i|n|(|S+0#e000002&|t|r|i|n|g|[+0#0000000&|]| |a|r|g|s|)| @32
+@4|{| @69
+@8|S+0#e000e06&|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"@2| +0#0000000&@44
+| +0#e000002&@11|<|p|r|e|>|<|c|o|d|e|>| +0#0000000&@51
+| +0#e000002&@11|c|l|a|s@1| |S|y|n|t|a|x|C|i|r|c|u|l|a|r|i|t|y|T|e|s|t|s| 
+0#0000000&@34
+| +0#e000002&@11|{| +0#0000000&@61
+| +0#e000002&@15|p|u|b|l|i|c| |s|t|a|t|i|c| |v|o|i|d| 
|m|a|i|n|(|S|t|r|i|n|g|[|]| |a|r|g|s|)| +0#0000000&@20
+| +0#e000002&@15|{| +0#0000000&@57
+| +0#e000002&@19|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"|.|"|)|;| 
+0#0000000&@30
+| +0#e000002&@15|}| +0#0000000&@57
+| +0#e000002&@11|}| +0#0000000&@61
+| +0#e000002&@11|<|/|c|o|d|e|>|<|/|p|r|e|>| +0#0000000&@49
+@57|3|7|,|5| @9|8@1|%| 
diff --git a/runtime/syntax/testdir/dumps/markdown_circularity_03.dump 
b/runtime/syntax/testdir/dumps/markdown_circularity_03.dump
new file mode 100644
index 000000000..8fae785b8
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/markdown_circularity_03.dump
@@ -0,0 +1,20 @@
+| +0#e000002#ffffff0@11|<|/|c|o|d|e|>|<|/|p|r|e|>| +0#0000000&@49
+| +0#e000002&@7|"+0#e000e06&@2|)|;+0#0000000&| @61
+@4|}| @69
+|}| @73
+>`+0#e000e06&@2| +0#0000000&@71
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|5|4|,|1| @9|B|o|t| 
diff --git a/runtime/syntax/testdir/input/markdown_circularity.markdown 
b/runtime/syntax/testdir/input/markdown_circularity.markdown
new file mode 100644
index 000000000..8f442a9ee
--- /dev/null
+++ b/runtime/syntax/testdir/input/markdown_circularity.markdown
@@ -0,0 +1,54 @@
+No code is recognised in HTML snippets.
+
+~~~html
+<pre><code>
+/** HTML syntax circularity tests. */
+class HTMLSyntaxCircularityTests
+{
+    /// @hidden
+    ///
+    /// @param args optional command-line arguments
+    public static void main(String[] args)
+    {
+        System.out.println("""
+            ```java
+            class SyntaxCircularityTests
+            {
+                public static void main(String[] args)
+                {
+                    System.out.println(".");
+                }
+            }
+            ```
+        """);
+    }
+}
+</code></pre>
+~~~
+
+
+Markdown documentation comments are not recognised in Java snippets.
+
+```java
+/** Java syntax circularity tests. */
+class JavaSyntaxCircularityTests
+{
+    /// @hidden
+    ///
+    /// @param args optional command-line arguments
+    public static void main(String[] args)
+    {
+        System.out.println("""
+            <pre><code>
+            class SyntaxCircularityTests
+            {
+                public static void main(String[] args)
+                {
+                    System.out.println(".");
+                }
+            }
+            </code></pre>
+        """);
+    }
+}
+```
diff --git a/runtime/syntax/testdir/input/setup/markdown_circularity.vim 
b/runtime/syntax/testdir/input/setup/markdown_circularity.vim
new file mode 100644
index 000000000..a0b2d985a
--- /dev/null
+++ b/runtime/syntax/testdir/input/setup/markdown_circularity.vim
@@ -0,0 +1,4 @@
+unlet! g:java_ignore_javadoc g:java_ignore_markdown
+let g:java_highlight_debug = 1
+let g:java_highlight_java_lang = 1
+let g:markdown_fenced_languages = ['html', 'java']

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1swnId-00Bfhk-1C%40256bit.org.

Raspunde prin e-mail lui