]> 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:

Make the default mappings buffer local
[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 =~ '^\s*[\*+-]'
14 endfunction
15
16 function! s:is_blank_line(line)
17     return a:line =~ '^$'
18 endfunction
19
20 function! s:prevnonblank(lnum)
21     let i = a:lnum
22     while i > 1 && s:is_blank_line(getline(i))
23         let i -= 1
24     endwhile
25     return i
26 endfunction
27
28 function GetMkdIndent()
29     let list_ind = 4
30     " Find a non-blank line above the current line.
31     let lnum = prevnonblank(v:lnum - 1)
32     " At the start of the file use zero indent.
33     if lnum == 0 | return 0 | endif
34     let ind = indent(lnum)
35     let line = getline(lnum)    " Last line
36     let cline = getline(v:lnum) " Current line
37     if s:is_li_start(cline) 
38         " Current line is the first line of a list item, do not change indent
39         return indent(v:lnum)
40     elseif s:is_li_start(line)
41         " Last line is the first line of a list item, increase indent
42         return ind + list_ind
43     else
44         return ind
45     endif
46 endfunction