diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-12-30 19:53:38 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-12-30 19:53:38 +1300 |
commit | eb133bd8aea1800ea6ad75bd1642a4c4271bf1c9 (patch) | |
tree | 655c338ee0dbd8b02a9372248e2c833f50211f50 | |
parent | Remove unneeded map#() autoload function (diff) | |
download | dotfiles-eb133bd8aea1800ea6ad75bd1642a4c4271bf1c9.tar.gz dotfiles-eb133bd8aea1800ea6ad75bd1642a4c4271bf1c9.zip |
Move Markdown folding into function
-rw-r--r-- | vim/autoload/markdown.vim | 23 | ||||
-rw-r--r-- | vim/ftplugin/markdown.vim | 24 |
2 files changed, 24 insertions, 23 deletions
diff --git a/vim/autoload/markdown.vim b/vim/autoload/markdown.vim index 6c8187a0..cdd14c12 100644 --- a/vim/autoload/markdown.vim +++ b/vim/autoload/markdown.vim @@ -1,3 +1,26 @@ +" Let's try this heading-based fold method out (Tim Pope) +function! markdown#Fold() + let line = getline(v:lnum) + + " Regular headers + let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') + if depth > 0 + return '>' . depth + endif + + " Setext style headings + if line =~# '^.\+$' + let nextline = getline(v:lnum + 1) + if nextline =~# '^=\+$' + return '>1' + elseif nextline =~# '^-\+$' + return '>2' + endif + endif + + return '=' +endfunction + " Add an underline under a heading function! markdown#Heading(char) abort diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index 2b4087a5..8c5cb029 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -18,29 +18,7 @@ let &l:formatlistpat = '^\s*\d\+\.\s\+\|^[-*+]\s\+\|^\[^\ze[^\]]\+\]:' let b:undo_ftplugin .= '|setlocal formatoptions< formatlistpat<' " Let's try this heading-based fold method out (Tim Pope) -function! MarkdownFold() - let line = getline(v:lnum) - - " Regular headers - let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') - if depth > 0 - return '>' . depth - endif - - " Setext style headings - if line =~# '^.\+$' - let nextline = getline(v:lnum + 1) - if nextline =~# '^=\+$' - return '>1' - elseif nextline =~# '^-\+$' - return '>2' - endif - endif - - return '=' -endfunction -let b:undo_ftplugin .= '|delfunction MarkdownFold' -setlocal foldexpr=MarkdownFold() +setlocal foldexpr=markdown#Fold() setlocal foldmethod=expr let b:undo_ftplugin .= '|setlocal foldexpr< foldmethod<' |