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.
1 if exists("b:did_indent") | finish | endif
4 setlocal indentexpr=GetMarkdownIndent()
8 " Automatically insert bullets
9 setlocal formatoptions+=r
10 " Do not automatically insert bullets when auto-wrapping with text-width
11 setlocal formatoptions-=c
12 " Accept various markers as bullets
13 setlocal comments=b:*,b:+,b:-
15 " Automatically continue blockquote on line break
16 setlocal comments+=b:>
18 " Only define the function once
19 if exists("*GetMarkdownIndent") | finish | endif
21 function! s:is_mkdCode(lnum)
22 let name = synIDattr(synID(a:lnum, 1, 0), 'name')
23 return (name =~ '^mkd\%(Code$\|Snippet\)' || name != '' && name !~ '^\%(mkd\|html\)')
26 function! s:is_li_start(line)
27 return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
28 \ a:line =~ '^\s*[*+-] \+'
31 function! s:is_blank_line(line)
35 function! s:prevnonblank(lnum)
37 while i > 1 && s:is_blank_line(getline(i))
43 function GetMarkdownIndent()
44 if v:lnum > 2 && s:is_blank_line(getline(v:lnum - 1)) && s:is_blank_line(getline(v:lnum - 2))
48 " Find a non-blank line above the current line.
49 let lnum = prevnonblank(v:lnum - 1)
50 " At the start of the file use zero indent.
51 if lnum == 0 | return 0 | endif
52 let ind = indent(lnum)
53 let line = getline(lnum) " Last line
54 let cline = getline(v:lnum) " Current line
55 if s:is_li_start(cline)
56 " Current line is the first line of a list item, do not change indent
58 elseif s:is_li_start(line)
62 " Last line is the first line of a list item, increase indent