]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Switch to expression-based folding.
authorBen Williams <bwilliams@gryphonnetworks.com>
Thu, 15 Nov 2012 20:48:44 +0000 (15:48 -0500)
committerBen Williams <bwilliams@gryphonnetworks.com>
Thu, 15 Nov 2012 20:48:44 +0000 (15:48 -0500)
Syntax-based folding was way too slow in very large Markdown files. Add
a new file after/ftplugin/mkd.vim with a foldexpr function to determine
folds. The function is based on Steve Losh's gist at
https://gist.github.com/1038710

after/ftplugin/mkd.vim [new file with mode: 0644]
syntax/mkd.vim

diff --git a/after/ftplugin/mkd.vim b/after/ftplugin/mkd.vim
new file mode 100644 (file)
index 0000000..f04ae2b
--- /dev/null
@@ -0,0 +1,51 @@
+" folding for Markdown headers, both styles (atx- and setex-)
+" http://daringfireball.net/projects/markdown/syntax#header
+"
+" this code can be placed in file
+"   $HOME/.vim/after/ftplugin/markdown.vim
+"
+" original version from Steve Losh's gist: https://gist.github.com/1038710
+
+func! Foldexpr_markdown(lnum)
+    if (a:lnum == 0)
+        let l0 = getline(a:lnum)
+    else
+        let l0 = getline(a:lnum-1)
+    endif
+
+    let l1 = getline(a:lnum)
+
+    let l2 = getline(a:lnum+1)
+
+    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 l0 =~ '^#'
+        " current line starts with hashes
+        return '>'.matchend(l0, '^#\+')
+    elseif a:lnum == 1
+        " fold any 'preamble'
+        return '>1'
+    else
+        " keep previous foldlevel
+        return '='
+    endif
+endfunc
+
+setlocal foldexpr=Foldexpr_markdown(v:lnum)
+setlocal foldmethod=expr
+
+"---------- everything after this is optional -----------------------
+" change the following fold options to your liking
+" see ':help fold-options' for more
+setlocal foldenable
+setlocal foldlevel=0
+setlocal foldcolumn=0
+set foldmethod=expr
+set foldopen-=search
index 8f3fd86ad30a7c152083b1f6c6f8ff0cf94bd4fd..c99968dd2ac3581a858fc32aeb49de9aca2038a4 100644 (file)
@@ -86,27 +86,6 @@ syn region htmlH6       start="^\s*######"              end="\($\|#\+\)" contain
 syn match  htmlH1       /^.\+\n=\+$/ contains=@Spell
 syn match  htmlH2       /^.\+\n-\+$/ contains=@Spell
 
-
-
-" fold region for headings
-syn region mkdHeaderFold
-    \ start="^\s*\z(#\+\)"
-    \ skip="^\s*\z1#\+"
-    \ end="^\(\s*#\)\@="
-    \ fold contains=TOP
-
-" fold region for lists
-syn region mkdListFold
-    \ start="^\z(\s*\)\*\z(\s*\)"
-    \ skip="^\z1 \z2\s*[^#]"
-    \ end="^\(.\)\@="
-    \ fold contains=TOP
-
-syn sync fromstart
-setlocal foldmethod=syntax
-
-
-
 "highlighting for Markdown groups
 HtmlHiLink mkdString       String
 HtmlHiLink mkdCode          String