From: Antony Lee Date: Tue, 21 Jun 2016 18:28:51 +0000 (-0700) Subject: Add Cython support (#48) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/2dcdd210d617e6941ec2d025a80ea16652441a2f Add Cython support (#48) 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. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01ee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/indent/python.vim b/indent/python.vim index c3c6c03..4306985 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -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 diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 196e119..e43e799 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -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(\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(\arg' + indent.should == shiftwidth * 2 + end + end +end