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

Add Cython support (#48)
authorAntony Lee <anntzer.lee@gmail.com>
Tue, 21 Jun 2016 18:28:51 +0000 (11:28 -0700)
committerDaniel Hahler <github@thequod.de>
Tue, 21 Jun 2016 18:28:51 +0000 (20:28 +0200)
Just making indents after cdef and cpdef similar to def.  The variable
must be made buffer-local in case one is editing both Python and Cython
sources at the same time.

.gitignore [new file with mode: 0644]
indent/python.vim
spec/indent/indent_spec.rb

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a01ee28
--- /dev/null
@@ -0,0 +1 @@
+.*.swp
index c3c6c03454ad5d0d3a63f2ae8030c0ec910e9b99..4306985849589e65f32734163261d71ab571637b 100644 (file)
@@ -40,7 +40,11 @@ let s:block_rules = {
             \ '^\s*finally\>': ['try', 'except', 'else']
             \ }
 let s:paren_pairs = ['()', '{}', '[]']
-let s:control_statement = '^\s*\(class\|def\|if\|while\|with\|for\|except\)\>'
+if &ft == 'pyrex' || &ft == 'cython'
+    let b:control_statement = '\v^\s*(class|def|if|while|with|for|except|cdef|cpdef)>'
+else
+    let b:control_statement = '\v^\s*(class|def|if|while|with|for|except)>'
+endif
 let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>'
 
 " Skip strings and comments. Return 1 for chars to skip.
@@ -198,7 +202,7 @@ function! s:indent_like_opening_paren(lnum)
     " 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()
+    if text =~# b:control_statement && res == base + s:sw()
         return base + s:sw() * 2
     else
         return res
@@ -259,7 +263,7 @@ function! s:indent_like_previous_line(lnum)
         " If this line is the continuation of a control statement
         " indent further to distinguish the continuation line
         " from the next logical line.
-        if getline(start) =~# s:control_statement
+        if getline(start) =~# b:control_statement
             return base + s:sw() * 2
         endif
 
index 196e11982eb4b99d2ef2b9e59923c38c51fe8160..e43e799b39c6ccbfb486c7d6ac67867dbaab9785 100644 (file)
@@ -457,3 +457,35 @@ describe "vim when using width of 8" do
 
   it_behaves_like "vim"
 end
+
+describe "vim for cython" do
+  before {
+    vim.command "enew"
+    vim.command "set ft=cython"
+    vim.command "runtime indent/python.vim"
+  }
+
+  def shiftwidth
+    @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
+  end
+  def tabstop
+    @tabstop ||= vim.echo("&tabstop").to_i
+  end
+  def indent
+    vim.echo("indent('.')").to_i
+  end
+
+  describe "when using a cdef function definition" do
+      it "indents shiftwidth spaces" do
+          vim.feedkeys 'icdef long_function_name(\<CR>arg'
+          indent.should == shiftwidth * 2
+      end
+  end
+
+  describe "when using a cpdef function definition" do
+      it "indents shiftwidth spaces" do
+          vim.feedkeys 'icpdef long_function_name(\<CR>arg'
+          indent.should == shiftwidth * 2
+      end
+  end
+end