1
0
mirror of https://github.com/amix/vimrc synced 2025-06-30 11:54:59 +08:00

Updated plugins

This commit is contained in:
Amir
2020-12-04 22:15:32 +01:00
parent e83f5ea2e7
commit a06964dd3b
261 changed files with 6955 additions and 2773 deletions

View File

@ -433,6 +433,12 @@ The following requires `:filetype plugin on`.
- `:Tocv`: Same as `:Toc` for symmetry with `:Toch` and `:Tocv`.
- `:InsertToc`: Insert table of contents at the current line.
An optional argument can be used to specify how many levels of headers to display in the table of content, e.g., to display up to and including `h3`, use `:InsertToc 3`.
- `:InsertNToc`: Same as `:InsertToc`, but the format of `h2` headers in the table of contents is a numbered list, rather than a bulleted list.
## Credits
The main contributors of vim-markdown are:

View File

@ -4,5 +4,5 @@ if !has('patch-7.4.480')
endif
" markdown filetype file
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} setfiletype markdown
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} setfiletype markdown
au BufRead,BufNewFile *.{md,mdx,mdown,mkd,mkdn,markdown,mdwn} setfiletype markdown
au BufRead,BufNewFile *.{md,mdx,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} setfiletype markdown

View File

@ -154,6 +154,58 @@ function! s:GetHeaderLevel(...)
endif
endfunction
" Return list of headers and their levels.
"
function! s:GetHeaderList()
let l:bufnr = bufnr('%')
let l:fenced_block = 0
let l:front_matter = 0
let l:header_list = []
let l:vim_markdown_frontmatter = get(g:, "vim_markdown_frontmatter", 0)
for i in range(1, line('$'))
let l:lineraw = getline(i)
let l:l1 = getline(i+1)
let l:line = substitute(l:lineraw, "#", "\\\#", "g")
" exclude lines in fenced code blocks
if l:line =~ '````*' || l:line =~ '\~\~\~\~*'
if l:fenced_block == 0
let l:fenced_block = 1
elseif l:fenced_block == 1
let l:fenced_block = 0
endif
" exclude lines in frontmatters
elseif l:vim_markdown_frontmatter == 1
if l:front_matter == 1
if l:line == '---'
let l:front_matter = 0
endif
elseif i == 1
if l:line == '---'
let l:front_matter = 1
endif
endif
endif
" match line against header regex
if join(getline(i, i + 1), "\n") =~ s:headersRegexp && l:line =~ '^\S'
let l:is_header = 1
else
let l:is_header = 0
endif
if l:is_header == 1 && l:fenced_block == 0 && l:front_matter == 0
" remove hashes from atx headers
if match(l:line, "^#") > -1
let l:line = substitute(l:line, '\v^#*[ ]*', '', '')
let l:line = substitute(l:line, '\v[ ]*#*$', '', '')
endif
" append line to list
let l:level = s:GetHeaderLevel(i)
let l:item = {'level': l:level, 'text': l:line, 'lnum': i, 'bufnr': bufnr}
let l:header_list = l:header_list + [l:item]
endif
endfor
return l:header_list
endfunction
" Returns the level of the header at the given line.
"
" If there is no header at the given line, returns `0`.
@ -175,6 +227,7 @@ endfunction
function! s:MoveToParentHeader()
let l:linenum = s:GetParentHeaderLineNumber()
if l:linenum != 0
call setpos("''", getpos('.'))
call cursor(l:linenum, 1)
else
echo 'no parent header'
@ -303,65 +356,38 @@ function! s:Toc(...)
endif
let l:bufnr = bufnr('%')
let l:cursor_line = line('.')
let l:cursor_header = 0
let l:fenced_block = 0
let l:front_matter = 0
let l:header_list = []
let l:header_max_len = 0
let l:vim_markdown_toc_autofit = get(g:, "vim_markdown_toc_autofit", 0)
let l:vim_markdown_frontmatter = get(g:, "vim_markdown_frontmatter", 0)
for i in range(1, line('$'))
let l:lineraw = getline(i)
let l:l1 = getline(i+1)
let l:line = substitute(l:lineraw, "#", "\\\#", "g")
if l:line =~ '````*' || l:line =~ '\~\~\~\~*'
if l:fenced_block == 0
let l:fenced_block = 1
elseif l:fenced_block == 1
let l:fenced_block = 0
endif
elseif l:vim_markdown_frontmatter == 1
if l:front_matter == 1
if l:line == '---'
let l:front_matter = 0
endif
elseif i == 1
if l:line == '---'
let l:front_matter = 1
endif
endif
endif
if l:line =~ '^#\+' || (l:l1 =~ '^=\+\s*$' || l:l1 =~ '^-\+\s*$') && l:line =~ '^\S'
let l:is_header = 1
else
let l:is_header = 0
endif
if l:is_header == 1 && l:fenced_block == 0 && l:front_matter == 0
" append line to location list
let l:item = {'lnum': i, 'text': l:line, 'valid': 1, 'bufnr': l:bufnr, 'col': 1}
let l:header_list = l:header_list + [l:item]
" set header number of the cursor position
if l:cursor_header == 0
if i == l:cursor_line
let l:cursor_header = len(l:header_list)
elseif i > l:cursor_line
let l:cursor_header = len(l:header_list) - 1
endif
endif
" keep track of the longest header size (heading level + title)
let l:total_len = stridx(l:line, ' ') + strdisplaywidth(l:line)
if l:total_len > l:header_max_len
let l:header_max_len = l:total_len
endif
endif
endfor
call setloclist(0, l:header_list)
let l:header_list = s:GetHeaderList()
let l:indented_header_list = []
if len(l:header_list) == 0
echom "Toc: No headers."
return
endif
let l:header_max_len = 0
let l:vim_markdown_toc_autofit = get(g:, "vim_markdown_toc_autofit", 0)
for h in l:header_list
" set header number of the cursor position
if l:cursor_header == 0
let l:header_line = h.lnum
if l:header_line == l:cursor_line
let l:cursor_header = index(l:header_list, h) + 1
elseif l:header_line > l:cursor_line
let l:cursor_header = index(l:header_list, h)
endif
endif
" indent header based on level
let l:text = repeat(' ', h.level-1) . h.text
" keep track of the longest header size (heading level + title)
let l:total_len = strdisplaywidth(l:text)
if l:total_len > l:header_max_len
let l:header_max_len = l:total_len
endif
" append indented line to list
let l:item = {'lnum': h.lnum, 'text': l:text, 'valid': 1, 'bufnr': h.bufnr, 'col': 1}
let l:indented_header_list = l:indented_header_list + [l:item]
endfor
call setloclist(0, l:indented_header_list)
if l:window_type ==# 'horizontal'
lopen
@ -369,7 +395,8 @@ function! s:Toc(...)
vertical lopen
" auto-fit toc window when possible to shrink it
if (&columns/2) > l:header_max_len && l:vim_markdown_toc_autofit == 1
execute 'vertical resize ' . (l:header_max_len + 1)
" header_max_len + 1 space for first header + 3 spaces for line numbers
execute 'vertical resize ' . (l:header_max_len + 1 + 3)
else
execute 'vertical resize ' . (&columns/2)
endif
@ -382,27 +409,84 @@ function! s:Toc(...)
for i in range(1, line('$'))
" this is the location-list data for the current item
let d = getloclist(0)[i-1]
" atx headers
if match(d.text, "^#") > -1
let l:level = len(matchstr(d.text, '#*', 'g'))-1
let d.text = substitute(d.text, '\v^#*[ ]*', '', '')
let d.text = substitute(d.text, '\v[ ]*#*$', '', '')
" setex headers
else
let l:next_line = getbufline(d.bufnr, d.lnum+1)
if match(l:next_line, "=") > -1
let l:level = 0
elseif match(l:next_line, "-") > -1
let l:level = 1
endif
endif
call setline(i, repeat(' ', l:level). d.text)
call setline(i, d.text)
endfor
setlocal nomodified
setlocal nomodifiable
execute 'normal! ' . l:cursor_header . 'G'
endfunction
function! s:InsertToc(format, ...)
if a:0 > 0
if type(a:1) != type(0)
echohl WarningMsg
echomsg '[vim-markdown] Invalid argument, must be an integer >= 2.'
echohl None
return
endif
let l:max_level = a:1
if l:max_level < 2
echohl WarningMsg
echomsg '[vim-markdown] Maximum level cannot be smaller than 2.'
echohl None
return
endif
else
let l:max_level = 0
endif
let l:toc = []
let l:header_list = s:GetHeaderList()
if len(l:header_list) == 0
echom "InsertToc: No headers."
return
endif
if a:format ==# 'numbers'
let l:h2_count = 0
for header in l:header_list
if header.level == 2
let l:h2_count += 1
endif
endfor
let l:max_h2_number_len = strlen(string(l:h2_count))
else
let l:max_h2_number_len = 0
endif
let l:h2_count = 0
for header in l:header_list
let l:level = header.level
if l:level == 1
" skip level-1 headers
continue
elseif l:max_level != 0 && l:level > l:max_level
" skip unwanted levels
continue
elseif l:level == 2
" list of level-2 headers can be bullets or numbers
if a:format ==# 'bullets'
let l:indent = ''
let l:marker = '* '
else
let l:h2_count += 1
let l:number_len = strlen(string(l:h2_count))
let l:indent = repeat(' ', l:max_h2_number_len - l:number_len)
let l:marker = l:h2_count . '. '
endif
else
let l:indent = repeat(' ', l:max_h2_number_len + 2 * (l:level - 2))
let l:marker = '* '
endif
let l:text = '[' . header.text . ']'
let l:link = '(#' . substitute(tolower(header.text), '\v[ ]+', '-', 'g') . ')'
let l:line = l:indent . l:marker . l:text . l:link
let l:toc = l:toc + [l:line]
endfor
call append(line('.'), l:toc)
endfunction
" Convert Setex headers in range `line1 .. line2` to Atx.
"
" Return the number of conversions.
@ -679,6 +763,8 @@ command! -buffer Toc call s:Toc()
command! -buffer Toch call s:Toc('horizontal')
command! -buffer Tocv call s:Toc('vertical')
command! -buffer Toct call s:Toc('tab')
command! -buffer -nargs=? InsertToc call s:InsertToc('bullets', <args>)
command! -buffer -nargs=? InsertNToc call s:InsertToc('numbers', <args>)
" Heavily based on vim-notes - http://peterodding.com/code/vim/notes/
if exists('g:vim_markdown_fenced_languages')
@ -702,7 +788,7 @@ function! s:MarkdownHighlightSources(force)
" Look for code blocks in the current file
let filetypes = {}
for line in getline(1, '$')
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*')
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*\ze.*')
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
endfor
if !exists('b:mkd_known_filetypes')
@ -733,7 +819,7 @@ function! s:MarkdownHighlightSources(force)
else
let include = '@' . toupper(filetype)
endif
let command = 'syntax region %s matchgroup=%s start="^\s*```\s*%s$" matchgroup=%s end="\s*```$" keepend contains=%s%s'
let command = 'syntax region %s matchgroup=%s start="^\s*```\s*%s.*$" matchgroup=%s end="\s*```$" keepend contains=%s%s'
execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') && get(g:, 'vim_markdown_conceal', 1) && get(g:, 'vim_markdown_conceal_code_blocks', 1) ? ' concealends' : '')
execute printf('syntax cluster mkdNonListItem add=%s', group)

View File

@ -103,8 +103,8 @@ execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(`\{3,}\)[^`]*$/ end=/^\s*\z1`*\s*$/' . s:concealcode
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@<!\~\~/ end=/\(\([^\\]\|^\)\\\)\@<!\~\~/' . s:concealcode
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\z1\~*\s*$/' . s:concealcode
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<pre[^>]*\\\@<!>" end="</pre>"' . s:concealcode
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<code[^>]*\\\@<!>" end="</code>"' . s:concealcode
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<pre\(\|\_s[^>]*\)\\\@<!>" end="</pre>"' . s:concealcode
execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<code\(\|\_s[^>]*\)\\\@<!>" end="</code>"' . s:concealcode
syn region mkdFootnote start="\[^" end="\]"
syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
syn match mkdCode /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/

View File

@ -120,28 +120,28 @@ Execute (check TOC):
let res = getloclist(0)
let elem = res[0]
AssertEqual elem.lnum, 1
AssertEqual elem.text, '# chap 1'
AssertEqual elem.text, 'chap 1'
let elem = res[1]
AssertEqual elem.lnum, 15
AssertEqual elem.text, '## chap 1.1'
AssertEqual elem.text, ' chap 1.1'
let elem = res[2]
AssertEqual elem.lnum, 25
AssertEqual elem.text, '### chap 1.1.1'
AssertEqual elem.text, ' chap 1.1.1'
let elem = res[3]
AssertEqual elem.lnum, 30
AssertEqual elem.text, '# chap 2'
AssertEqual elem.text, 'chap 2'
let elem = res[4]
AssertEqual elem.lnum, 34
AssertEqual elem.text, '## chap 2.1'
AssertEqual elem.text, ' chap 2.1'
let elem = res[5]
AssertEqual elem.lnum, 41
AssertEqual elem.text, '# chap 3'
AssertEqual elem.text, 'chap 3'
let elem = res[6]
AssertEqual elem.lnum, 45
AssertEqual elem.text, 'chap 4'
let elem = res[7]
AssertEqual elem.lnum, 50
AssertEqual elem.text, 'chap 4.1'
AssertEqual elem.text, ' chap 4.1'
Given markdown;
---
@ -174,5 +174,5 @@ Execute (check Toc of yaml front matter):
AssertEqual len(res), 1
let elem = res[0]
AssertEqual elem.lnum, 8
AssertEqual elem.text, 'heading'
AssertEqual elem.text, ' heading'
unlet g:vim_markdown_frontmatter

View File

@ -0,0 +1,147 @@
Given markdown;
# a
## Foo Level 2
### Foo Level 3
#### Foo Level 4
Bar Level 2
-----------
### Bar Level 3
Execute (InsertToc format):
:2
:call append('.', '')
:InsertToc
Expect (format):
# a
* [Foo Level 2](#foo-level-2)
* [Foo Level 3](#foo-level-3)
* [Foo Level 4](#foo-level-4)
* [Bar Level 2](#bar-level-2)
* [Bar Level 3](#bar-level-3)
## Foo Level 2
### Foo Level 3
#### Foo Level 4
Bar Level 2
-----------
### Bar Level 3
Given markdown;
# a
## Foo Level 2
### Foo Level 3
#### Foo Level 4
Bar Level 2
-----------
### Bar Level 3
Execute (InsertToc only h2 headers):
:2
:call append('.', '')
:InsertToc 2
Expect (only h2 headers):
# a
* [Foo Level 2](#foo-level-2)
* [Bar Level 2](#bar-level-2)
## Foo Level 2
### Foo Level 3
#### Foo Level 4
Bar Level 2
-----------
### Bar Level 3
Given markdown;
# a
## Foo Level 2
### Foo Level 3
#### Foo Level 4
Bar Level 2
-----------
## Baz Level 2
## Foobar Level 2
## Foobaz Level 2
## Barfoo Level 2
## Barbaz Level 2
## Bazfoo Level 2
## Bazbar Level 2
## Foobarbaz Level 2
Execute (InsertNToc format, and up to h3 headers):
:2
:call append('.', '')
:InsertNToc 3
Expect (format, and up to h3 headers):
# a
1. [Foo Level 2](#foo-level-2)
* [Foo Level 3](#foo-level-3)
2. [Bar Level 2](#bar-level-2)
3. [Baz Level 2](#baz-level-2)
4. [Foobar Level 2](#foobar-level-2)
5. [Foobaz Level 2](#foobaz-level-2)
6. [Barfoo Level 2](#barfoo-level-2)
7. [Barbaz Level 2](#barbaz-level-2)
8. [Bazfoo Level 2](#bazfoo-level-2)
9. [Bazbar Level 2](#bazbar-level-2)
10. [Foobarbaz Level 2](#foobarbaz-level-2)
## Foo Level 2
### Foo Level 3
#### Foo Level 4
Bar Level 2
-----------
## Baz Level 2
## Foobar Level 2
## Foobaz Level 2
## Barfoo Level 2
## Barbaz Level 2
## Bazfoo Level 2
## Bazbar Level 2
## Foobarbaz Level 2

View File

@ -739,12 +739,18 @@ def a
end
```
```ruby {linenos=table,hl_lines=[8,"15-17"],linenostart=199}
class b
end
```
Execute (fenced code block syntax with a language specifier):
let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax')
call b:func(0)
AssertEqual SyntaxOf('include'), 'cInclude'
AssertEqual SyntaxOf('code'), 'mkdSnippetCPP'
AssertEqual SyntaxOf('def'), 'rubyDefine'
AssertEqual SyntaxOf('class'), 'rubyClass'
Given markdown;
``` c++
@ -958,12 +964,12 @@ $$ \frac{a}{b} $$
Execute (math tex highlighting):
let g:vim_markdown_math=0
syn off | syn on
AssertNotEqual SyntaxOf('sqrt'), 'texStatement'
AssertNotEqual SyntaxOf('frac'), 'texStatement'
AssertNotEqual SyntaxOf('sqrt')[0:2], 'tex'
AssertNotEqual SyntaxOf('frac')[0:2], 'tex'
let g:vim_markdown_math=1
syn off | syn on
AssertEqual SyntaxOf('sqrt'), 'texStatement'
AssertEqual SyntaxOf('frac'), 'texStatement'
AssertEqual SyntaxOf('sqrt')[0:2], 'tex'
AssertEqual SyntaxOf('frac')[0:2], 'tex'
Given markdown;
$a b[$ c
@ -986,7 +992,7 @@ Execute (math ends with $$):
AssertNotEqual SyntaxOf('c')[0:2], 'tex'
Given markdown;
$(0 \le 1)$
$(0 \leq 1)$
Execute (math conceal in $):
if has('conceal')
@ -997,20 +1003,21 @@ Execute (math conceal in $):
AssertEqual synconcealed(1, 2)[0], 0
AssertEqual synconcealed(1, 3)[0], 0
AssertEqual synconcealed(1, 4)[0], 0
AssertEqual synconcealed(1, 5)[0], 1, '\le'
AssertEqual synconcealed(1, 5)[0], 1, '\leq'
AssertEqual synconcealed(1, 6)[0], 1
AssertEqual synconcealed(1, 7)[0], 1
AssertEqual synconcealed(1, 8)[0], 0
AssertEqual synconcealed(1, 8)[0], 1
AssertEqual synconcealed(1, 9)[0], 0
AssertEqual synconcealed(1, 10)[0], 0
AssertEqual synconcealed(1, 11)[0], 1, '$'
AssertEqual synconcealed(1, 11)[0], 0
AssertEqual synconcealed(1, 12)[0], 1, '$'
setlocal conceallevel=0
endif
Given markdown;
$$
\omega
0 \le 1
0 \leq 1
$$
Execute (math conceal in $$):
@ -1021,8 +1028,8 @@ Execute (math conceal in $$):
AssertEqual synconcealed(1, 1)[0], 1, '$$'
AssertEqual synconcealed(2, 1)[0], 1, '\omega'
AssertEqual synconcealed(3, 1)[0], 0, '0'
AssertEqual synconcealed(3, 3)[0], 1, '\le'
AssertEqual synconcealed(3, 7)[0], 0, '1'
AssertEqual synconcealed(3, 3)[0], 1, '\leq'
AssertEqual synconcealed(3, 8)[0], 0, '1'
AssertEqual synconcealed(4, 1)[0], 1, '$$'
setlocal conceallevel=0
endif