mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
vim-patch:5ddcecf: runtime(help): Add better support for language annotation highlighting
closes: vim/vim#162385ddcecf05f
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Co-authored-by: Christian Brabandt <cb@256bit.org> Co-authored-by: h_east <h.east.727@gmail.com> (cherry picked from commit60b866049c
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
35a66f74c7
commit
e68d3ef886
@@ -373,17 +373,38 @@ To quote a block of ex-commands verbatim, place a greater than (>) character
|
|||||||
at the end of the line before the block and a less than (<) character as the
|
at the end of the line before the block and a less than (<) character as the
|
||||||
first non-blank on a line following the block. Any line starting in column 1
|
first non-blank on a line following the block. Any line starting in column 1
|
||||||
also implicitly stops the block of ex-commands before it. E.g. >
|
also implicitly stops the block of ex-commands before it. E.g. >
|
||||||
function Example_Func()
|
function Example_Func()
|
||||||
echo "Example"
|
echo "Example"
|
||||||
endfunction
|
endfunction
|
||||||
<
|
<
|
||||||
It's possible to add Vim syntax highlighting support to code examples. This
|
|
||||||
can be done by adding "vim" after the greater than (>) character (">vim").
|
To add annotation in the block, place the annotation (ex: "lua") after a
|
||||||
|
greater than (>) character. E.g: >lua
|
||||||
|
print("hello")
|
||||||
|
<
|
||||||
|
Note: uses lua syntax highlighting, if "lua" key is in
|
||||||
|
|g:help_example_languages|.
|
||||||
|
|
||||||
|
It's possible to add Vim syntax highlighting support to code examples.
|
||||||
E.g: >vim
|
E.g: >vim
|
||||||
function Example_Func()
|
function Example_Func()
|
||||||
echo "Example"
|
echo "Example"
|
||||||
endfunction
|
endfunction
|
||||||
<
|
<
|
||||||
|
*g:help_example_languages*
|
||||||
|
If you want to change the syntax highlighting in the block, you can
|
||||||
|
change it like this: >
|
||||||
|
:let g:help_example_languages = #{ vim: 'vim', sh: 'bash' }
|
||||||
|
The key represents the annotation marker name, and the value is the 'syntax'
|
||||||
|
name. By default, help files support only Vim script highlighting.
|
||||||
|
Note: When setting "g:help_example_languages", if you do not include "vim"
|
||||||
|
key, the Vim syntax highlighting will not be enabled. If you set it to an
|
||||||
|
empty value, syntax highlighting for embedded languages will be disabled.
|
||||||
|
|
||||||
|
Further note: including additional syntax languages into help files may not
|
||||||
|
always work perfectly, if the included 'syntax' script does not account for
|
||||||
|
such an import.
|
||||||
|
*help-notation*
|
||||||
The following are highlighted differently in a Vim help file:
|
The following are highlighted differently in a Vim help file:
|
||||||
- a special key name expressed either in <> notation as in <PageDown>, or
|
- a special key name expressed either in <> notation as in <PageDown>, or
|
||||||
as a Ctrl character as in CTRL-X
|
as a Ctrl character as in CTRL-X
|
||||||
|
@@ -12,28 +12,36 @@ endif
|
|||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
|
if !exists('g:help_example_languages')
|
||||||
|
let g:help_example_languages = #{ vim: 'vim' }
|
||||||
|
endif
|
||||||
|
|
||||||
syn match helpHeadline "^[A-Z.][-A-Z0-9 .,()_']*?\=\ze\(\s\+\*\|$\)"
|
syn match helpHeadline "^[A-Z.][-A-Z0-9 .,()_']*?\=\ze\(\s\+\*\|$\)"
|
||||||
syn match helpSectionDelim "^===.*===$"
|
syn match helpSectionDelim "^===.*===$"
|
||||||
syn match helpSectionDelim "^---.*--$"
|
syn match helpSectionDelim "^---.*--$"
|
||||||
|
|
||||||
unlet! b:current_syntax
|
|
||||||
" sil! to prevent E403
|
|
||||||
silent! syntax include @VimScript syntax/vim.vim
|
|
||||||
|
|
||||||
" Nvim: support language annotation in codeblocks
|
|
||||||
if has("conceal")
|
if has("conceal")
|
||||||
syn region helpExample matchgroup=helpIgnore start=" >[a-z0-9]*$" start="^>[a-z0-9]*$" end="^[^ \t]"me=e-1 end="^<" concealends
|
syn region helpExample matchgroup=helpIgnore
|
||||||
syn region helpExampleVimScript matchgroup=helpIgnore
|
\ start="\%(^\| \)>[a-z0-9]*$" end="^[^ \t]"me=e-1 end="^<" concealends
|
||||||
\ start=/^>vim$/ start=/ >vim$/
|
|
||||||
\ end=/^[^ \t]/me=e-1 end=/^</ concealends
|
|
||||||
\ contains=@VimScript keepend
|
|
||||||
else
|
else
|
||||||
syn region helpExample matchgroup=helpIgnore start=" >[a-z0-9]*$" start="^>[a-z0-9]*$" end="^[^ \t]"me=e-1 end="^<"
|
syn region helpExample matchgroup=helpIgnore
|
||||||
syn region helpExampleVimScript matchgroup=helpIgnore
|
\ start="\%(^\| \)>[a-z0-9]*$" end="^[^ \t]"me=e-1 end="^<"
|
||||||
\ start=/^>vim$/ start=/ >vim$/
|
|
||||||
\ end=/^[^ \t]/me=e-1 end=/^</
|
|
||||||
\ contains=@VimScript keepend
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
for [s:lang, s:syntax] in g:help_example_languages->items()
|
||||||
|
unlet! b:current_syntax
|
||||||
|
" silent! to prevent E403
|
||||||
|
execute 'silent! syn include' $'@helpExampleHighlight_{s:lang}'
|
||||||
|
\ $'syntax/{s:syntax}.vim'
|
||||||
|
|
||||||
|
execute $'syn region helpExampleHighlight_{s:lang} matchgroup=helpIgnore'
|
||||||
|
\ $'start=/\%(^\| \)>{s:lang}$/'
|
||||||
|
\ 'end=/^[^ \t]/me=e-1 end=/^</'
|
||||||
|
\ (has("conceal") ? 'concealends' : '')
|
||||||
|
\ $'contains=@helpExampleHighlight_{s:lang} keepend'
|
||||||
|
endfor
|
||||||
|
unlet! s:lang s:syntax
|
||||||
|
|
||||||
syn match helpHyperTextJump "\\\@<!|[#-)!+-~]\+|" contains=helpBar
|
syn match helpHyperTextJump "\\\@<!|[#-)!+-~]\+|" contains=helpBar
|
||||||
syn match helpHyperTextEntry "\*[#-)!+-~]\+\*\s"he=e-1 contains=helpStar
|
syn match helpHyperTextEntry "\*[#-)!+-~]\+\*\s"he=e-1 contains=helpStar
|
||||||
syn match helpHyperTextEntry "\*[#-)!+-~]\+\*$" contains=helpStar
|
syn match helpHyperTextEntry "\*[#-)!+-~]\+\*$" contains=helpStar
|
||||||
|
Reference in New Issue
Block a user