@@ -30,6 +30,33 @@ if exists("b:current_syntax")
30
30
finish
31
31
endif
32
32
33
+ if ! exists (' g:main_syntax' )
34
+ " This is an Erlang source file, and this is the main execution of
35
+ " syntax/erlang.vim.
36
+ let g: main_syntax = ' erlang'
37
+ elseif g: main_syntax == ' erlang'
38
+ " This is an Erlang source file, and this is an inner execution of
39
+ " syntax/erlang.vim. For example:
40
+ "
41
+ " 1. The main execution of syntax/erlang.vim included syntax/markdown.vim
42
+ " because "g:erlang_use_markdown_for_docs == 1".
43
+ "
44
+ " 2. syntax/markdown.vim included syntax/erlang.vim because
45
+ " "g:markdown_fenced_languages == ['erlang']". This is the inner
46
+ " execution of syntax/erlang.vim.
47
+ "
48
+ " To avoid infinite recursion with Markdown and Erlang including each other,
49
+ " and to avoid the inner syntax/erlang.vim execution messing up the
50
+ " variables of the outer erlang.vim execution, we finish executing the inner
51
+ " erlang.vim.
52
+ "
53
+ " In the inner execution, we already have the Erlang syntax items included,
54
+ " so the highlighting of Erlang within Markdown within Erlang will be
55
+ " acceptable. It won't highlight Markdown inside Erlang inside Markdown
56
+ " inside Erlang.
57
+ finish
58
+ endif
59
+
33
60
let s: cpo_save = &cpo
34
61
set cpo &vim
35
62
@@ -50,7 +77,12 @@ let s:old_style = (exists("g:erlang_old_style_highlight") &&
50
77
"
51
78
" * "g:erlang_use_markdown_for_docs == 0" (default): Disable Markdown
52
79
" highlighting in docstrings.
53
- if exists (" g:erlang_use_markdown_for_docs" )
80
+ "
81
+ " If "g:main_syntax" is not 'erlang', this is not an Erlang source file but
82
+ " for example a Markdown file, and syntax/markdown.vim is including
83
+ " syntax/erlang.vim. To avoid infinite recursion with Markdown and Erlang
84
+ " including each other, we disable sourcing syntax/markdown.vim in this case.
85
+ if exists (" g:erlang_use_markdown_for_docs" ) && g: main_syntax == ' erlang'
54
86
let s: use_markdown = g: erlang_use_markdown_for_docs
55
87
else
56
88
let s: use_markdown = 0
@@ -364,9 +396,12 @@ hi def link erlangExtra Statement
364
396
hi def link erlangSignal Statement
365
397
endif
366
398
367
-
368
399
let b: current_syntax = " erlang"
369
400
401
+ if g: main_syntax == # ' erlang'
402
+ unlet g: main_syntax
403
+ endif
404
+
370
405
let &cpo = s: cpo_save
371
406
unlet s: cpo_save
372
407
0 commit comments