]> git.madduck.net Git - etc/vim.git/blob - indent/mkd.vim

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:

Remove automatic setting of foldlevel
[etc/vim.git] / indent / mkd.vim
1 if exists("b:did_indent") | finish | endif
2 let b:did_indent = 1
3
4 setlocal indentexpr=GetMkdIndent()
5 setlocal nolisp
6 setlocal nosmartindent
7 setlocal autoindent
8
9 " Only define the function once
10 if exists("*GetMkdIndent") | finish | endif
11
12 function! s:is_li_start(line)
13     return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
14       \    a:line =~ '^\s*[*+-] \+'
15 endfunction
16
17 function! s:is_blank_line(line)
18     return a:line =~ '^$'
19 endfunction
20
21 function! s:prevnonblank(lnum)
22     let i = a:lnum
23     while i > 1 && s:is_blank_line(getline(i))
24         let i -= 1
25     endwhile
26     return i
27 endfunction
28
29 function GetMkdIndent()
30     let list_ind = 4
31     " Find a non-blank line above the current line.
32     let lnum = prevnonblank(v:lnum - 1)
33     " At the start of the file use zero indent.
34     if lnum == 0 | return 0 | endif
35     let ind = indent(lnum)
36     let line = getline(lnum)    " Last line
37     let cline = getline(v:lnum) " Current line
38     if s:is_li_start(cline) 
39         " Current line is the first line of a list item, do not change indent
40         return indent(v:lnum)
41     elseif s:is_li_start(line)
42         " Last line is the first line of a list item, increase indent
43         return ind + list_ind
44     else
45         return ind
46     endif
47 endfunction