]> git.madduck.net Git - etc/vim.git/blobdiff - indent/python.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:

prevent tests being shadowed by first line rule
[etc/vim.git] / indent / python.vim
index 7b6580ab69f8c618259c6201d4502f5ff6781802..9b8e9b187bf96182e10097fcad61e59176520c2e 100644 (file)
@@ -19,7 +19,8 @@ setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
 
 let s:maxoff = 50
 let s:block_rules = {
-  \ '^\s*\(elif\|else\)\>': ['if', 'elif'],
+  \ '^\s*elif\>': ['if', 'elif'],
+  \ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'],
   \ '^\s*except\>': ['try', 'except'],
   \ '^\s*finally\>': ['try', 'except', 'else']
   \ }
@@ -80,7 +81,7 @@ function! s:find_opening_paren(...)
     call filter(positions, 'v:val[0]')
     call sort(positions, 's:pair_sort')
 
-    return get(positions, 0, [0, 0])
+    return get(positions, -1, [0, 0])
 endfunction
 
 " Find the start of a multi-line statement
@@ -132,13 +133,22 @@ function! s:indent_like_opening_paren(lnum)
 
     if nothing_after_opening_paren
         if starts_with_closing_paren
-            return base
+            let res = base
         else
-            return base + s:sw()
+            let res = base + s:sw()
         endif
     else
         " Indent to match position of opening paren.
-        return paren_col
+        let res = paren_col
+    endif
+
+    " If this line is the continuation of a control statement
+    " indent further to distinguish the continuation line
+    " from the next logical line.
+    if text =~# s:control_statement && res == base + s:sw()
+        return base + s:sw() * 2
+    else
+        return res
     endif
 endfunction