Permalink
Browse files

added vim_markdown_better_folding option

  • Loading branch information...
1 parent 1cf6264 commit c8d9717faff310b5ebd7c49b139c31e42b8377f7 @rcmdnk committed Nov 19, 2014
Showing with 62 additions and 60 deletions.
  1. +4 −0 README.md
  2. +58 −60 after/ftplugin/markdown.vim
View
@@ -25,6 +25,10 @@ Syntax highlighting, matching rules and mappings for [the original Markdown](htt
for codeblock syntaxes</strike>
* Original [vim-markdown-quote-syntax](https://github.com/joker1007/vim-markdown-quote-syntax)
has now these features.
+* Better folding
+ * `let g:vim_markdown_better_folding=1` allows better folding, especially
+ for YAML block, Jekyll/Octopress codeblock.
+ * Note: It may make it slow for large files.
If you use [Vundle](https://github.com/gmarik/Vundle.vim), do:
@@ -7,84 +7,82 @@
" original version from Steve Losh's gist: https://gist.github.com/1038710
func! Foldexpr_markdown(lnum)
- " Get syntaxes
- let syn0 = synIDattr(synID(a:lnum-1,1,1), 'name')
- let syn1 = synIDattr(synID(a:lnum,1,1), 'name')
- let syn2 = synIDattr(synID(a:lnum+1,1,1), 'name')
+ " Get line contents
+ let l0 = getline(a:lnum-1)
+ let l1 = getline(a:lnum)
+ let l2 = getline(a:lnum+1)
- " YAML block
- if syn1 == 'yamlDelimiter'
- if a:lnum == 1
- return 'a1'
- else
- return 's1'
- endif
- endif
- if syn1 == 'yamlBlockMappingKey'
- return '='
- endif
+ if get(g:, 'vim_markdown_better_folding', 0)
+ " Get syntaxes
+ let syn0 = synIDattr(synID(a:lnum-1,1,1), 'name')
+ let syn1 = synIDattr(synID(a:lnum,1,1), 'name')
+ let syn2 = synIDattr(synID(a:lnum+1,1,1), 'name')
- " Code
- if syn1 == 'mkdDelimiter' || syn1 == 'liquidTag'
- if syn2 == 'mkdCode'
- return 'a1'
- elseif syn0 == 'mkdCode'
- return 's1'
+ " YAML block
+ if syn1 == 'yamlDelimiter'
+ if a:lnum == 1
+ return 'a1'
+ else
+ return 's1'
+ endif
+ endif
+ if syn1 == 'yamlBlockMappingKey'
+ return '='
endif
- endif
- " Code with vim-markdown-quote-syntax
- if syn1 == 'markdownCodeDelimiter'
- if syn0 == ''
- return 'a1'
- elseif syn2 == ''
- return 's1'
+ " Code
+ if syn1 == 'mkdDelimiter' || syn1 == 'liquidTag'
+ if syn2 == 'mkdCode'
+ return 'a1'
+ elseif syn0 == 'mkdCode'
+ return 's1'
+ endif
endif
- endif
- " Code with four spaces
- if syn1 == 'mkdCode'
- if syn0 == ''
- " Avoid one line code
- if syn2 != ''
+ " Code with vim-markdown-quote-syntax
+ if syn1 == 'markdownCodeDelimiter'
+ if syn0 == ''
return 'a1'
+ elseif syn2 == ''
+ return 's1'
endif
- elseif syn2 == ''
- return 's1'
endif
- endif
- " Liquid Comment
- if syn1 == 'liquidComment'
- if syn0 != 'liquidComment'
- return 'a1'
- elseif syn2 != 'liquidComment'
- return 's1'
+ " Code with four spaces
+ if syn1 == 'mkdCode'
+ if syn0 == ''
+ " Avoid one line code
+ if syn2 != ''
+ return 'a1'
+ endif
+ elseif syn2 == ''
+ return 's1'
+ endif
+ endif
+
+ " Liquid Comment
+ if syn1 == 'liquidComment'
+ if syn0 != 'liquidComment'
+ return 'a1'
+ elseif syn2 != 'liquidComment'
+ return 's1'
+ endif
endif
endif
" Section
- if syn0 =~ 'htmlH[0-9]' || syn1 =~ 'htmlH[0-9]' || syn2 =~ 'htmlH[0-9]'
- " Get lines
- let l0 = getline(a:lnum-1)
- let l1 = getline(a:lnum)
- let l2 = getline(a:lnum+1)
-
- if syn2 =~ 'htmlH[0-9]'
- if l2 =~ '^==\+\s*'
- " next line is underlined (level 1)
- return '>1'
- elseif l2 =~ '^--\+\s*'
- " next line is underlined (level 2)
- return '>2'
- endif
- elseif syn1 =~ 'htmlH[0-9]' && l1 =~ '^#'
+ if l2 =~ '^==\+\s*'
+ " next line is underlined (level 1)
+ return '>1'
+ elseif l2 =~ '^--\+\s*'
+ " next line is underlined (level 2)
+ return '>2'
+ elseif l1 =~ '^#'
" don't include the section title in the fold
return '-1'
- elseif syn0 =~ 'htmlH[0-9]' && l0 =~ '^#'
+ elseif l0 =~ '^#[^!]'
" current line starts with hashes
return '>'.matchend(l0, '^#\+')
- endif
endif
" keep previous foldlevel

0 comments on commit c8d9717

Please sign in to comment.