Class: Textbringer::ProgrammingMode
- Inherits:
-
FundamentalMode
- Object
- Mode
- FundamentalMode
- Textbringer::ProgrammingMode
- Defined in:
- lib/textbringer/modes/programming_mode.rb
Constant Summary collapse
Constants inherited from Mode
Constants included from Commands
Commands::CLIPBOARD_AVAILABLE, Commands::CTAGS, Commands::HELP_RING, Commands::ISEARCH_MODE_MAP, Commands::ISEARCH_STATUS, Commands::KEYBOARD_MACROS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS, Commands::UNIVERSAL_ARGUMENT_MAP
Constants included from Utils
Utils::COMPLETION, Utils::HOOKS, Utils::Y_OR_N_MAP
Instance Attribute Summary
Attributes inherited from Mode
Instance Method Summary collapse
-
#indent_line ⇒ Object
Return true if modified.
- #indent_region(s = @buffer.mark, e = @buffer.point) ⇒ Object
-
#initialize(buffer) ⇒ ProgrammingMode
constructor
A new instance of ProgrammingMode.
- #reindent_then_newline_and_indent ⇒ Object
Methods inherited from FundamentalMode
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_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, #prefix_numeric_value, #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_file_name, read_from_minibuffer, read_key_sequence, 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
#initialize(buffer) ⇒ ProgrammingMode
Returns a new instance of ProgrammingMode.
24 25 26 27 |
# File 'lib/textbringer/modes/programming_mode.rb', line 24 def initialize(buffer) super(buffer) buffer.keymap = PROGRAMMING_MODE_MAP end |
Instance Method Details
#indent_line ⇒ Object
Return true if modified.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/textbringer/modes/programming_mode.rb', line 30 def indent_line result = false level = calculate_indentation return result if level.nil? || level < 0 @buffer.save_excursion do @buffer.beginning_of_line @buffer.composite_edit do if @buffer.looking_at?(/[ \t]+/) 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) 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 |
#indent_region(s = @buffer.mark, e = @buffer.point) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/textbringer/modes/programming_mode.rb', line 73 def indent_region(s = @buffer.mark, e = @buffer.point) s, e = Buffer.region_boundaries(s, e) end_mark = @buffer.new_mark(e) begin @buffer.save_excursion do @buffer.goto_char(s) until @buffer.end_of_buffer? || @buffer.point_after_mark?(end_mark) indent_line @buffer.forward_line end end ensure end_mark.delete end end |
#reindent_then_newline_and_indent ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/textbringer/modes/programming_mode.rb', line 58 def reindent_then_newline_and_indent @buffer.composite_edit do indent_line @buffer.save_excursion do pos = @buffer.point @buffer.beginning_of_line if /\A[ \t]+\z/.match?(@buffer.substring(@buffer.point, pos)) @buffer.delete_region(@buffer.point, pos) end end @buffer.insert("\n") indent_line end end |