Class: Textbringer::ProgrammingMode

Inherits:
FundamentalMode show all
Defined in:
lib/textbringer/modes/programming_mode.rb

Direct Known Subclasses

CMode, RubyMode

Constant Summary

Constants inherited from Mode

Mode::DEFAULT_SYNTAX_TABLE

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

#buffer

Instance Method Summary collapse

Methods inherited from FundamentalMode

#symbol_pattern

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

#initialize(buffer) ⇒ ProgrammingMode

Returns a new instance of ProgrammingMode.



26
27
28
29
# File 'lib/textbringer/modes/programming_mode.rb', line 26

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

Instance Method Details

#comment_startObject



107
108
109
# File 'lib/textbringer/modes/programming_mode.rb', line 107

def comment_start
  nil
end

#indent_lineObject

Return true if modified.



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
58
# File 'lib/textbringer/modes/programming_mode.rb', line 32

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_new_comment_lineObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/textbringer/modes/programming_mode.rb', line 91

def indent_new_comment_line
  if comment_start.nil?
    @buffer.newline
    return
  end
  s = @buffer.save_excursion {
    @buffer.beginning_of_line
    if @buffer.looking_at?(/[ \t]*#{comment_start}+[ \t]*/)
      @buffer.match_string(0)
    else
      ""
    end
  }
  @buffer.insert("\n" + s)
end

#indent_region(s = @buffer.mark, e = @buffer.point) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/textbringer/modes/programming_mode.rb', line 75

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_indentObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/textbringer/modes/programming_mode.rb', line 60

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