Class: Textbringer::RubyMode
- Inherits:
-
ProgrammingMode
- Object
- Mode
- FundamentalMode
- ProgrammingMode
- Textbringer::RubyMode
- Defined in:
- lib/textbringer/modes/ruby_mode.rb
Defined Under Namespace
Classes: PartialLiteralAnalyzer
Constant Summary
Constants inherited from Mode
Constants included from Commands
Commands::CLIPBOARD_AVAILABLE, Commands::CTAGS, Commands::HELP_RING, Commands::ISEARCH_STATUS, Commands::KEYBOARD_MACROS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS
Constants included from Utils
Utils::COMPLETION, Utils::HOOKS
Instance Attribute Summary
Attributes inherited from Mode
Instance Method Summary collapse
- #backward_definition(n = number_prefix_arg || 1) ⇒ Object
- #comment_start ⇒ Object
- #compile(cmd = read_from_minibuffer("Compile: ", default: default_compile_command)) ⇒ Object
- #default_compile_command ⇒ Object
- #forward_definition(n = number_prefix_arg || 1) ⇒ Object
-
#initialize(buffer) ⇒ RubyMode
constructor
A new instance of RubyMode.
- #symbol_pattern ⇒ Object
- #toggle_test ⇒ Object
Methods inherited from ProgrammingMode
#indent_line, #indent_new_comment_line, #indent_region, #reindent_then_newline_and_indent
Methods inherited from Mode
define_generic_command, define_local_command, define_syntax, inherited, list, #name, #syntax_table
Methods included from Commands
[], #command_help, command_table, #current_prefix_arg, define_command, #execute_keyboard_macro, #get_tags, #isearch_done, #isearch_mode, #isearch_mode?, #isearch_pre_command_hook, #isearch_prompt, #isearch_repeat, #isearch_repeat_backward, #isearch_repeat_forward, #isearch_search, #keymap_bindings, list, #match_beginning, #match_end, #match_string, #number_prefix_arg, #prefix_numeric_value, #read_input_method_name, #read_keyboard_macro, #read_register, #replace_match, undefine_command, #universal_argument_mode
Methods included from Utils
add_hook, background, complete_for_minibuffer, foreground, foreground!, message, read_buffer, read_char, read_command_name, read_encoding, read_event, read_expression, read_file_name, read_from_minibuffer, read_key_sequence, read_object, read_single_char, received_keyboard_quit?, remove_hook, ruby_install_name, run_hooks, self_insert_and_exit_minibuffer, set_transient_map, show_exception, sit_for, sleep_for, y_or_n?, yes_or_no?
Constructor Details
Instance Method Details
#backward_definition(n = number_prefix_arg || 1) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 119 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, _), e, t| l >= @buffer.current_line || e != :on_kw || /\A(?:class|module|def)\z/ !~ t } (line,), = 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 |
#comment_start ⇒ Object
88 89 90 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 88 def comment_start "#" end |
#compile(cmd = read_from_minibuffer("Compile: ", default: default_compile_command)) ⇒ Object
140 141 142 143 144 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 140 def compile(cmd = read_from_minibuffer("Compile: ", default: default_compile_command)) shell_execute(cmd, buffer_name: "*Ruby compile result*", mode: BacktraceMode) end |
#default_compile_command ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 150 def default_compile_command @buffer[:ruby_compile_command] || if File.exist?("Rakefile") prefix = File.exist?("Gemfile") ? "bundle exec " : "" prefix + "rake" elsif @buffer.file_name ruby_install_name + " " + @buffer.file_name else nil end end |
#forward_definition(n = number_prefix_arg || 1) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 98 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| l < @buffer.current_line || e != :on_kw || /\A(?:class|module|def)\z/ !~ t } (line,), = 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 |
#symbol_pattern ⇒ Object
146 147 148 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 146 def symbol_pattern /[\p{Letter}\p{Number}_$@!?]/ end |
#toggle_test ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/textbringer/modes/ruby_mode.rb', line 162 def toggle_test case @buffer.file_name when %r'(.*)/test/(.*/)?test_(.*?)\.rb\z' path = find_test_target_path($1, $2, $3) find_file(path) when %r'(.*)/spec/(.*/)?(.*?)_spec\.rb\z' path = find_test_target_path($1, $2, $3) find_file(path) when %r'(.*)/(?:lib|app)/(.*/)?(.*?)\.rb\z' path = find_test_path($1, $2, $3) find_file(path) else raise EditorError, "Unknown file type" end end |