Class: Textbringer::ProgrammingMode

Inherits:
Mode
  • Object
show all
Defined in:
lib/textbringer/modes/programming_mode.rb

Direct Known Subclasses

RubyMode

Constant Summary collapse

PROGRAMMING_MODE_MAP =
Keymap.new

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

#buffer

Instance Method Summary collapse

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) ⇒ ProgrammingMode

Returns a new instance of ProgrammingMode.



21
22
23
24
# File 'lib/textbringer/modes/programming_mode.rb', line 21

def initialize(buffer)
  super(buffer)
  buffer.keymap = PROGRAMMING_MODE_MAP
end

Instance Method Details

#newline_and_reindentObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/textbringer/modes/programming_mode.rb', line 26

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\s+\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