Skip to content

Commit

Permalink
Also add an "outdent" option
Browse files Browse the repository at this point in the history
Not requested at this time, but easy enough to implement.
  • Loading branch information
AndrewRadev committed Oct 19, 2013
1 parent 244ab19 commit b5ead62
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
15 changes: 11 additions & 4 deletions indent/ruby.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
let b:did_indent = 1

if !exists('g:ruby_indent_private_protected_style')
" Possible values: "normal", "indent"
" Possible values: "normal", "indent", "outdent"
let g:ruby_indent_private_protected_style = 'normal'
endif

Expand Down Expand Up @@ -367,15 +367,22 @@ function GetRubyIndent(...)
let line = getline(clnum)
let ind = -1

" If this line is a private/protected keyword, align according to the
" closest class declaration.
if g:ruby_indent_private_protected_style == 'indent'
" If this line is a private/protected keyword, align according to the
" closest class declaration.
if s:Match(clnum, s:private_protected_regex)
let class_line = s:SearchCode(s:class_regex, 'Wb')
if class_line > 0
return indent(class_line) + &sw
endif
endif
elseif g:ruby_indent_private_protected_style == 'outdent'
if s:Match(clnum, s:private_protected_regex)
let class_line = s:SearchCode(s:class_regex, 'Wb')
if class_line > 0
return indent(class_line)
endif
endif
endif

" If we got a closing bracket on an empty line, find its match and indent
Expand Down Expand Up @@ -454,7 +461,7 @@ function GetRubyIndent(...)
let line = getline(lnum)
let ind = indent(lnum)

if g:ruby_indent_private_protected_style == 'indent'
if g:ruby_indent_private_protected_style == 'indent' || g:ruby_indent_private_protected_style == 'outdent'
" If the previous line was a private/protected keyword, add a level of indent
if s:Match(lnum, s:private_protected_regex)
return indent(s:GetMSL(lnum)) + &sw
Expand Down
38 changes: 38 additions & 0 deletions spec/indent/private_protected_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'spec_helper'

describe "Indenting" do
after :each do
vim.command 'let g:ruby_indent_private_protected_style = "normal"'
end

specify "default public/private indenting" do
assert_correct_indenting <<-EOF
class One
Expand Down Expand Up @@ -53,4 +57,38 @@ def three
end
EOF
end

specify "outdented public/private" do
vim.command 'let g:ruby_indent_private_protected_style = "outdent"'

assert_correct_indenting <<-EOF
class One
def two
end
protected
def three
end
private
def four
end
end
EOF

assert_correct_indenting <<-EOF
class One
def two
end
private :two
protected :two
def three
end
end
EOF
end
end

0 comments on commit b5ead62

Please sign in to comment.