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

correctly indent after parens in control structures
authorJohann Klähn <kljohann@gmail.com>
Fri, 8 Nov 2013 19:53:33 +0000 (20:53 +0100)
committerJohann Klähn <kljohann@gmail.com>
Sat, 4 Jan 2014 10:50:23 +0000 (11:50 +0100)
fixes #7

indent/python.vim
spec/indent/indent_spec.rb

index 7b6580ab69f8c618259c6201d4502f5ff6781802..3b64cf4263985de8341580f6ca77b9857ed5832f 100644 (file)
@@ -132,13 +132,22 @@ function! s:indent_like_opening_paren(lnum)
 
     if nothing_after_opening_paren
         if starts_with_closing_paren
 
     if nothing_after_opening_paren
         if starts_with_closing_paren
-            return base
+            let res = base
         else
         else
-            return base + s:sw()
+            let res = base + s:sw()
         endif
     else
         " Indent to match position of opening paren.
         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
 
     endif
 endfunction
 
index a622cf8ef29139c225b7515f7b69328a8d9114bc..df402e8cb9fc25c11f984d2b8fa4656865b5f24f 100644 (file)
@@ -88,6 +88,47 @@ shared_examples_for "vim" do
       end
   end
 
       end
   end
 
+  describe "when using parens and control statements" do
+    it "avoids ambiguity by using extra indentation" do
+      vim.feedkeys 'iif (111 and\<CR>'
+      if shiftwidth == 4
+        indent.should == shiftwidth * 2
+      else
+        indent.should == 4
+      end
+      vim.feedkeys '222):\<CR>'
+      indent.should == shiftwidth
+      vim.feedkeys 'pass\<CR>'
+      indent.should == 0
+    end
+
+    it "still aligns parens properly if not ambiguous" do
+      vim.feedkeys 'iwhile (111 and\<CR>'
+      indent.should == 7
+      vim.feedkeys '222):\<CR>'
+      indent.should == shiftwidth
+      vim.feedkeys 'pass\<CR>'
+      indent.should == 0
+    end
+
+    it "still handles multiple parens correctly" do
+      vim.feedkeys 'iif (111 and (222 and 333\<CR>'
+      indent.should == 13
+      vim.feedkeys 'and 444\<CR>'
+      indent.should == 13
+      vim.feedkeys ')\<CR>'
+      if shiftwidth == 4
+        indent.should == shiftwidth * 2
+      else
+        indent.should == 4
+      end
+      vim.feedkeys 'and 555):\<CR>'
+      indent.should == shiftwidth
+      vim.feedkeys 'pass\<CR>'
+      indent.should == 0
+    end
+  end
+
   describe "when a line breaks with a manual '\\'" do
     it "indents shiftwidth spaces on normal line" do
         vim.feedkeys 'ivalue = test + \\\\\<CR>'
   describe "when a line breaks with a manual '\\'" do
     it "indents shiftwidth spaces on normal line" do
         vim.feedkeys 'ivalue = test + \\\\\<CR>'