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

Indent correctly after lines with '#'s in strings
authorLeoMao <lmao20001@gmail.com>
Sun, 21 Jul 2013 13:33:11 +0000 (21:33 +0800)
committerHynek Schlawack <hs@ox.cx>
Sat, 9 Nov 2013 14:07:00 +0000 (15:07 +0100)
Fixes #5.

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

index c632c7bebf7eeb8d1925b51c7d03835b82c99d76..4d1edc2310908c6cd2f36160c7349b6435a756e0 100644 (file)
@@ -3,7 +3,6 @@
 " Maintainer:       Hynek Schlawack <hs@ox.cx>
 " Prev Maintainer:  Eric Mc Sween <em@tomcom.de> (address invalid)
 " Original Author:  David Bustos <bustos@caltech.edu> (address invalid)
-" Last Change:      2012-06-21
 " License:          Public Domain
 
 " Only load this indent file when no other was loaded.
@@ -176,6 +175,12 @@ function! GetPythonPEPIndent(lnum)
 
     " If the previous line ended with a colon and is not a comment, indent
     " relative to statement start.
+    let pline = substitute(pline, '\\\\', '', 'g')
+    if v:version > 703 || (v:version == 703 && has('patch1037'))
+        let pline = substitute(pline, '".\{-}\\\@1<!"\|''.\{-}\\\@1<!''', '', 'g')
+    else
+        let pline = substitute(pline, '".\{-}\\\@<!"\|''.\{-}\\\@<!''', '', 'g')
+    endif
     if pline =~ '^[^#]*:\s*\(#.*\)\?$'
         return indent(sslnum) + &sw
     endif
index 38ce1920b8271b5036419a3c503210cd4ab0509b..21d14b7d9f30523f03c0dac8ecbb5a1c666ce47b 100644 (file)
@@ -67,6 +67,20 @@ describe "vim" do
     end
   end
 
+  describe "when '#' is contained in a string that is followed by a colon" do
+    it "indents by one level" do
+        vim.feedkeys 'iif "some#thing" == "test":#test\<CR>pass'
+        indent.should == shiftwidth
+    end
+  end
+
+  describe "when '#' is not contained in a string and is followed by a colon" do
+    it "does not indent" do
+        vim.feedkeys 'iif "some#thing" == "test"#:test\<CR>'
+        indent.should == 0
+    end
+  end
+
   describe "when using simple control structures" do
       it "indents shiftwidth spaces" do
           vim.feedkeys 'iwhile True:\<CR>pass'