lib/textbringer/modes/ruby_mode.rb in textbringer-0.1.6 vs lib/textbringer/modes/ruby_mode.rb in textbringer-0.1.7
- old
+ new
@@ -5,50 +5,21 @@
module Textbringer
CONFIG[:ruby_indent_level] = 2
CONFIG[:ruby_indent_tabs_mode] = false
class RubyMode < ProgrammingMode
- self.file_name_pattern = /\A(?:.*\.(?:rb|ru|rake|thor)|
- (?:Gem|Rake|Cap|Thor|Vagrant|Guard|Pod)file)\z/ix
+ self.file_name_pattern =
+ /\A(?:.*\.(?:rb|ru|rake|thor|jbuilder|gemspec|podspec)|
+ (?:Gem|Rake|Cap|Thor|Vagrant|Guard|Pod)file)\z/ix
self.interpreter_name_pattern = /ruby/i
def initialize(buffer)
super(buffer)
+ @buffer[:indent_level] = CONFIG[:ruby_indent_level]
@buffer[:indent_tabs_mode] = CONFIG[:ruby_indent_tabs_mode]
end
- # Return true if modified.
- def indent_line
- result = false
- level = calculate_indentation
- return result if level.nil?
- @buffer.save_excursion do
- @buffer.beginning_of_line
- has_space = @buffer.looking_at?(/[ \t]+/)
- if has_space
- s = @buffer.match_string(0)
- break if /\t/ !~ s && s.size == level
- @buffer.delete_region(@buffer.match_beginning(0),
- @buffer.match_end(0))
- else
- break if level == 0
- end
- @buffer.indent_to(level)
- if has_space
- @buffer.merge_undo(2)
- end
- result = true
- end
- pos = @buffer.point
- @buffer.beginning_of_line
- @buffer.forward_char while /[ \t]/ =~ @buffer.char_after
- if @buffer.point < pos
- @buffer.goto_char(pos)
- end
- result
- end
-
def forward_definition(n = number_prefix_arg || 1)
tokens = Ripper.lex(@buffer.to_s)
@buffer.forward_line
n.times do |i|
tokens = tokens.drop_while { |(l, _), e, t|
@@ -161,13 +132,15 @@
@buffer.save_excursion do
@buffer.beginning_of_line
bol_pos = @buffer.point
tokens = Ripper.lex(@buffer.substring(@buffer.point_min,
@buffer.point))
- _, event, = tokens.last
+ _, event, text = tokens.last
if event == :on_tstring_beg ||
event == :on_heredoc_beg ||
+ event == :on_regexp_beg ||
+ (event == :on_regexp_end && text.size > 1) ||
event == :on_tstring_content
return nil
end
line, column, event, = find_nearest_beginning_token(tokens)
if event == :on_lparen
@@ -195,17 +168,17 @@
@buffer.goto_char(bol_pos)
if line.nil? ||
@buffer.looking_at?(/[ \t]*([}\])]|(end|else|elsif|when|rescue|ensure)\b)/)
indentation = base_indentation
else
- indentation = base_indentation + @buffer[:ruby_indent_level]
+ indentation = base_indentation + @buffer[:indent_level]
end
_, last_event, last_text = tokens.reverse_each.find { |_, e, _|
e != :on_sp && e != :on_nl && e != :on_ignored_nl
}
if (last_event == :on_op && last_text != "|") ||
last_event == :on_period
- indentation += @buffer[:ruby_indent_level]
+ indentation += @buffer[:indent_level]
end
indentation
end
end