Class: Textbringer::ProgrammingMode
- Inherits:
-
FundamentalMode
- Object
- Mode
- FundamentalMode
- Textbringer::ProgrammingMode
- Defined in:
- lib/textbringer/modes/programming_mode.rb
Constant Summary collapse
Constants included from Commands
Commands::CLIPBOARD_AVAILABLE, Commands::CTAGS, Commands::ISEARCH_MODE_MAP, Commands::ISEARCH_STATUS, 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.
-
#initialize(buffer) ⇒ ProgrammingMode
constructor
A new instance of ProgrammingMode.
- #newline_and_reindent ⇒ Object
Methods inherited from FundamentalMode
Methods inherited from Mode
define_generic_command, define_syntax, inherited, list, #name, #syntax_table
Methods included from Commands
#current_prefix_arg, define_command, #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, #replace_match, undefine_command, #universal_argument_mode
Methods included from Utils
add_hook, complete_for_minibuffer, message, read_buffer, read_char, read_command_name, read_file_name, read_from_minibuffer, 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.
23 24 25 26 |
# File 'lib/textbringer/modes/programming_mode.rb', line 23 def initialize(buffer) super(buffer) buffer.keymap = PROGRAMMING_MODE_MAP end |
Instance Method Details
#indent_line ⇒ Object
Return true if modified.
29 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 57 |
# File 'lib/textbringer/modes/programming_mode.rb', line 29 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 |
#newline_and_reindent ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/textbringer/modes/programming_mode.rb', line 59 def newline_and_reindent n = 1 if indent_line n += 1 end @buffer.save_excursion do pos = @buffer.point @buffer.beginning_of_line if /\A[ \t]+\z/ =~ @buffer.substring(@buffer.point, pos) @buffer.delete_region(@buffer.point, pos) n += 1 end end @buffer.insert("\n") if indent_line n += 1 end @buffer.merge_undo(n) if n > 1 end |