mirror of
https://github.com/tpope/vim-markdown.git
synced 2025-11-14 12:53:48 -05:00
Clean up folding code
This commit is contained in:
@@ -19,15 +19,17 @@ else
|
|||||||
let b:undo_ftplugin = "setl cms< com< fo< flp<"
|
let b:undo_ftplugin = "setl cms< com< fo< flp<"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! MarkdownFold()
|
function! s:NotCodeBlock(lnum) abort
|
||||||
|
return synIDattr(synID(v:lnum, 1, 1), 'name') !=# 'markdownCode'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! MarkdownFold() abort
|
||||||
let line = getline(v:lnum)
|
let line = getline(v:lnum)
|
||||||
|
|
||||||
" Regular headers
|
|
||||||
if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum)
|
if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum)
|
||||||
return ">" . match(line, ' ')
|
return ">" . match(line, ' ')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Setext style headings
|
|
||||||
let nextline = getline(v:lnum + 1)
|
let nextline = getline(v:lnum + 1)
|
||||||
if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1)
|
if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1)
|
||||||
return ">1"
|
return ">1"
|
||||||
@@ -40,11 +42,21 @@ function! MarkdownFold()
|
|||||||
return "="
|
return "="
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:NotCodeBlock(lnum)
|
function! s:HashIndent(lnum) abort
|
||||||
return synIDattr(synID(v:lnum, 1, 1), 'name') !=# 'markdownCode'
|
let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
|
||||||
|
if len(hash_header)
|
||||||
|
return hash_header
|
||||||
|
else
|
||||||
|
let nextline = getline(a:lnum + 1)
|
||||||
|
if nextline =~# '^=\+\s*$'
|
||||||
|
return '#'
|
||||||
|
elseif nextline =~# '^-\+\s*$'
|
||||||
|
return '##'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! MarkdownFoldText()
|
function! MarkdownFoldText() abort
|
||||||
let hash_indent = s:HashIndent(v:foldstart)
|
let hash_indent = s:HashIndent(v:foldstart)
|
||||||
let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
|
let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
|
||||||
let foldsize = (v:foldend - v:foldstart + 1)
|
let foldsize = (v:foldend - v:foldstart + 1)
|
||||||
@@ -52,22 +64,6 @@ function! MarkdownFoldText()
|
|||||||
return hash_indent.' '.title.' '.linecount
|
return hash_indent.' '.title.' '.linecount
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:HashIndent(lnum)
|
|
||||||
let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
|
|
||||||
if len(hash_header) > 0
|
|
||||||
" hashtag header
|
|
||||||
return hash_header
|
|
||||||
else
|
|
||||||
" == or -- header
|
|
||||||
let nextline = getline(a:lnum + 1)
|
|
||||||
if nextline =~ '^=\+\s*$'
|
|
||||||
return repeat('#', 1)
|
|
||||||
elseif nextline =~ '^-\+\s*$'
|
|
||||||
return repeat('#', 2)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if has("folding") && exists("g:markdown_folding")
|
if has("folding") && exists("g:markdown_folding")
|
||||||
setlocal foldexpr=MarkdownFold()
|
setlocal foldexpr=MarkdownFold()
|
||||||
setlocal foldmethod=expr
|
setlocal foldmethod=expr
|
||||||
|
|||||||
Reference in New Issue
Block a user