lib/textbringer/modes/ruby_mode.rb in textbringer-0.1.7 vs lib/textbringer/modes/ruby_mode.rb in textbringer-0.1.8
- old
+ new
@@ -10,10 +10,69 @@
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
+ define_syntax :comment, /
+ (?: \#.*(?:\\\n.*)*(?:\z|(?<!\\)\n) ) |
+ (?: ^=begin (?:.|\n)* (?> ^=end \b ) )
+ /x
+
+ define_syntax :keyword, /
+ (?<![$@.]) \b (?: (?:
+ class | module | def | undef | begin | rescue | ensure | end |
+ if | unless | then | elsif | else | case | when | while | until |
+ for | break | next | redo | retry | in | do | return | yield |
+ super | self | nil | true | false | and | or | not | alias
+ ) \b | defined\? )
+ /x
+
+ define_syntax :string, /
+ (?: (?<! [a-zA-Z] ) \? (:? [^\\\s] | \\ . ) ) |
+ (?: %[qQrwWsix]?\{ (?: [^\\}] | \\ . )* \} ) |
+ (?: %[qQrwWsix]?\( (?: [^\\)] | \\ . )* \) ) |
+ (?: %[qQrwWsix]?\[ (?: [^\\\]] | \\ . )* \] ) |
+ (?: %[qQrwWsix]?< (?: [^\\>] | \\ . )* > ) |
+ (?:
+ %[qQrwWsix]?
+ (?<string_delimiter>[^{(\[<a-zA-Z0-9\s\u{0100}-\u{10ffff}])
+ (?: (?! \k<string_delimiter> ) [^\\] | \\ . )*
+ \k<string_delimiter>
+ ) |
+ (?:
+ (?<! \$ )
+ " (?: [^\\"] | \\ . )* "
+ ) |
+ (?:
+ (?<! \$ )
+ ' (?: [^\\'] | \\ . )* '
+ ) |
+ (?:
+ (?<! [$.] | def | def \s )
+ ` (?: [^\\`] | \\ . )* `
+ ) |
+ (?:
+ (?<=
+ ^ |
+ \b and | \b or | \b while | \b until | \b unless | \b if |
+ \b elsif | \b when | \b not | \b then | \b else |
+ [;~=!|&(,\[<>?:*+-]
+ ) \s*
+ \/ (?: [^\\\/] | \\ . )* \/[iomxneus]*
+ ) |
+ (?:
+ (?<! class | class \s | [\]})"'.] | :: | \w )
+ <<-?(?<heredoc_quote>['"`]?)
+ (?<heredoc_terminator>
+ [_a-zA-Z\u{0100}-\u{10ffff}]
+ [_a-zA-Z0-9\u{0100}-\u{10ffff}]*
+ )
+ \k<heredoc_quote>
+ (?> (?:.|\n)*? \k<heredoc_terminator> )
+ )
+ /x
+
def initialize(buffer)
super(buffer)
@buffer[:indent_level] = CONFIG[:ruby_indent_level]
@buffer[:indent_tabs_mode] = CONFIG[:ruby_indent_tabs_mode]
end
@@ -60,12 +119,12 @@
end
end
def compile(cmd = read_from_minibuffer("Compile: ",
default: default_compile_command))
- shell_execute(cmd, "*Ruby compile result*")
- backtrace_mode
+ shell_execute(cmd, buffer_name: "*Ruby compile result*",
+ mode: BacktraceMode)
end
def symbol_pattern
/[\p{Letter}\p{Number}_$@!?]/
end
@@ -174,10 +233,12 @@
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
+ last_event == :on_period ||
+ (last_event == :on_comma &&
+ event != :on_lbrace && event != :on_lbracket)
indentation += @buffer[:indent_level]
end
indentation
end
end