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

Better support for bullet insertion and auto indentation in list items.
authorDanqi Wang <beyondwdq@gmail.com>
Wed, 26 Mar 2014 02:36:00 +0000 (10:36 +0800)
committerDanqi Wang <dwang@dytechlab.com>
Tue, 15 Apr 2014 06:20:20 +0000 (14:20 +0800)
1. Added setlocal formatoptions-=c to disable automatically inserting bullets when auto-wrapping with textwidth.
2. Added indent/mkd.vim to support auto indent in list.

indent/mkd.vim [new file with mode: 0755]
syntax/mkd.vim

diff --git a/indent/mkd.vim b/indent/mkd.vim
new file mode 100755 (executable)
index 0000000..a26ac0e
--- /dev/null
@@ -0,0 +1,46 @@
+if exists("b:did_indent") | finish | endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetMkdIndent()
+setlocal nolisp
+setlocal nosmartindent
+setlocal autoindent
+
+" Only define the function once
+if exists("*GetMkdIndent") | finish | endif
+
+function! s:is_li_start(line)
+    return a:line =~ '^\s*[\*+-]'
+endfunction
+
+function! s:is_blank_line(line)
+    return a:line =~ '^$'
+endfunction
+
+function! s:prevnonblank(lnum)
+    let i = a:lnum
+    while i > 1 && s:is_blank_line(getline(i))
+        let i -= 1
+    endwhile
+    return i
+endfunction
+
+function GetMkdIndent()
+    let list_ind = 4
+    " Find a non-blank line above the current line.
+    let lnum = prevnonblank(v:lnum - 1)
+    " At the start of the file use zero indent.
+    if lnum == 0 | return 0 | endif
+    let ind = indent(lnum)
+    let line = getline(lnum)    " Last line
+    let cline = getline(v:lnum) " Current line
+    if s:is_li_start(cline) 
+        " Current line is the first line of a list item, do not change indent
+        return indent(v:lnum)
+    elseif s:is_li_start(line)
+        " Last line is the first line of a list item, increase indent
+        return ind + list_ind
+    else
+        return ind
+    endif
+endfunction
index d6233d24c99e60d29886bee18795a2b966994d6c..e10bbc33f5223a7fe5ff91e3fa33b59ce3bd7187 100644 (file)
@@ -119,6 +119,8 @@ HtmlHiLink mkdDelimiter     Delimiter
 
 " Automatically insert bullets
 setlocal formatoptions+=r
 
 " Automatically insert bullets
 setlocal formatoptions+=r
+" Do not automatically insert bullets when auto-wrapping with text-width
+setlocal formatoptions-=c
 " Accept various markers as bullets
 setlocal comments=b:*,b:+,b:-
 
 " Accept various markers as bullets
 setlocal comments=b:*,b:+,b:-