Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Also add an "outdent" option

Not requested at this time, but easy enough to implement.
  • Loading branch information...
commit b5ead62081d67c0ff4121679e3cd23f12bd7a074 1 parent 244ab19
@AndrewRadev AndrewRadev authored
Showing with 49 additions and 4 deletions.
  1. +11 −4 indent/ruby.vim
  2. +38 −0 spec/indent/private_protected_spec.rb
View
15 indent/ruby.vim
@@ -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
@@ -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
@@ -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
View
38 spec/indent/private_protected_spec.rb
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.