Class: Textbringer::RubyMode
- Inherits:
-
ProgrammingMode
- Object
- Mode
- ProgrammingMode
- Textbringer::RubyMode
- Defined in:
- lib/textbringer/modes/ruby_mode.rb
Constant Summary
Constants inherited from ProgrammingMode
ProgrammingMode::PROGRAMMING_MODE_MAP
Constants included from Commands
Commands::ISEARCH_MODE_MAP, Commands::ISEARCH_STATUS, Commands::RE_SEARCH_STATUS, Commands::UNIVERSAL_ARGUMENT_MAP
Constants included from Utils
Utils::HOOKS, Utils::Y_OR_N_MAP
Instance Attribute Summary
Attributes inherited from Mode
Instance Method Summary collapse
- #backward_definition(n = number_prefix_arg || 1) ⇒ Object
- #compile ⇒ Object
- #forward_definition(n = number_prefix_arg || 1) ⇒ Object
-
#indent_line ⇒ Object
Return true if modified.
-
#initialize(buffer) ⇒ RubyMode
constructor
A new instance of RubyMode.
Methods inherited from ProgrammingMode
Methods inherited from Mode
define_generic_command, inherited, list, #name
Methods included from Commands
#current_prefix_arg, define_command, #isearch_done, #isearch_mode, #isearch_pre_command_hook, #isearch_prompt, #isearch_repeat, #isearch_repeat_backward, #isearch_repeat_forward, #isearch_search, list, #match_beginning, #match_end, #match_string, #number_prefix_arg, #replace_match, undefine_command, #universal_argument_mode
Methods included from Utils
#add_hook, #complete, #handle_exception, #message, #read_buffer, #read_char, #read_command_name, #read_file_name, #read_from_minibuffer, #read_single_char, #received_keyboard_quit?, #remove_hook, #run_hooks, #self_insert_and_exit_minibuffer, #set_transient_map, #sit_for, #sleep_for, #y_or_n?, #yes_or_no?
Constructor Details
#initialize(buffer) ⇒ RubyMode
Returns a new instance of RubyMode.
13 14 15 16 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 13 def initialize(buffer) super(buffer) @buffer[:indent_tabs_mode] = CONFIG[:ruby_indent_tabs_mode] end |
Instance Method Details
#backward_definition(n = number_prefix_arg || 1) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 69 def backward_definition(n = number_prefix_arg || 1) tokens = Ripper.lex(@buffer.to_s).reverse @buffer.beginning_of_line n.times do |i| tokens = tokens.drop_while { |(l, c), e, t| l >= @buffer.current_line || e != :on_kw || /\A(?:class|module|def)\z/ !~ t } (line, column), event, text = tokens.first if line.nil? @buffer.beginning_of_buffer break end @buffer.goto_line(line) tokens = tokens.drop(1) end while /\s/ =~ @buffer.char_after @buffer.forward_char end end |
#compile ⇒ Object
90 91 92 93 94 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 90 def compile cmd = read_from_minibuffer("Compile: ", default: default_compile_command) shell_execute(cmd, "*Ruby compile result*") backtrace_mode end |
#forward_definition(n = number_prefix_arg || 1) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 48 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, c), e, t| l < @buffer.current_line || e != :on_kw || /\A(?:class|module|def)\z/ !~ t } (line, column), event, text = tokens.first if line.nil? @buffer.end_of_buffer break end @buffer.goto_line(line) tokens = tokens.drop(1) end while /\s/ =~ @buffer.char_after @buffer.forward_char end end |
#indent_line ⇒ Object
Return true if modified.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 19 def indent_line result = false level = calculate_indentation @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 |