Class: VER::Text::Insert

Inherits:
Mark show all
Defined in:
lib/ver/text/insert.rb

Overview

Mostly a Mark, but has to generate Movement event and sometimes change modes.

Constant Summary

Constants inherited from Mark

Mark::MATCHING_BRACE_LEFT, Mark::MATCHING_BRACE_RIGHT

Constants inherited from Struct

Struct::CACHE

Instance Attribute Summary

Attributes inherited from Mark

#buffer, #name

Instance Method Summary collapse

Methods inherited from Mark

#<<, #change_at, #change_next_word_end, #changing, #char, #char=, #chunk_char_type, #copying, #delete, #deleting, #down_nonblank, #encoding_rot13, #end_of_buffer, #end_of_sentence, #first_line, #forward_jump_end, #go_char, #go_first_nonblank, #go_line_char, #go_percent, #gravity, #gravity=, #home_of_line, #index, #insert, #insert_indented_newline, #insert_newline, #insert_selection, #insert_tab, #inspect, #killing, #last_char, #last_line, #line, #line=, #lower_casing, #matching_brace, #matching_brace_indices, #middle_of_line, #next, #next_char, #next_chunk, #next_chunk_end, #next_line_nonblank, #next_word, #next_word_end, #prev_char, #prev_chunk, #prev_line_nonblank, #prev_word, #prev_word_end, #previous, #start_of_buffer, #start_of_line, #to_s, #to_tcl, #toggle_casing, #unset, #upper_casing, #virtual, #virtual_motion, #word_char_type

Methods included from Position

#+, #-, #<=>, #bbox, #compare, #copy_line, #decrease_number, #delete, #delete_line, #delta, #dlineinfo, #dump, #formatted_binary, #formatted_exponential, #formatted_float, #formatted_hex, #formatted_number, #formatted_octal, #get, #increase_number, #insert, #inspect, #kill_line, #lineend, #linestart, #see, #tag_names, #tags, #to_a

Methods inherited from Struct

new

Constructor Details

#initialize(buffer) ⇒ Insert

Returns a new instance of Insert.



6
7
8
# File 'lib/ver/text/insert.rb', line 6

def initialize(buffer)
  super(buffer, :insert)
end

Instance Method Details

#backward_jump(count) ⇒ Object

Same as Mark#backward_jump, but generate <<Movement>> event.



40
41
42
43
# File 'lib/ver/text/insert.rb', line 40

def backward_jump(count)
  super
  Tk::Event.generate(buffer, '<<Movement>>')
end

#change(count = buffer.prefix_count) ⇒ Object



26
27
28
29
30
31
# File 'lib/ver/text/insert.rb', line 26

def change(count = buffer.prefix_count)
  from, to = "insert", "insert + #{count} displaychars"
  range = buffer.range(buffer.index(from), buffer.index(to))
  range.kill
  buffer.minor_mode(:control, :insert)
end

#change_line(count = buffer.prefix_count) ⇒ Object

Kill contents of the line at position, switch from control to insert mode. Always leaves an empty line and sets the insert mark inside that.



19
20
21
22
23
24
# File 'lib/ver/text/insert.rb', line 19

def change_line(count = buffer.prefix_count)
  from, to = "insert linestart", "insert + #{count - 1} lines lineend"
  range = buffer.range(buffer.index(from), buffer.index(to))
  range.kill
  buffer.minor_mode(:control, :insert)
end

#forward_jump(count) ⇒ Object

Same as Mark#forward_jump, but generate <<Movement>> event.



34
35
36
37
# File 'lib/ver/text/insert.rb', line 34

def forward_jump(count)
  super
  Tk::Event.generate(buffer, '<<Movement>>')
end

#insert_char_aboveObject



62
63
64
65
66
67
68
69
# File 'lib/ver/text/insert.rb', line 62

def insert_char_above
  index = buffer.index("#{self} - 1 lines")

  if index.line < line && index.char == char
    char = index.get
    buffer.insert(self, char) unless char == "\n"
  end
end

#insert_char_belowObject



71
72
73
74
75
76
77
78
# File 'lib/ver/text/insert.rb', line 71

def insert_char_below
  index = buffer.index("#{self} + 1 lines")

  if index.line > line && index.char == char
    char = index.get
    buffer.insert(self, char) unless char == "\n"
  end
end

#insert_digraphObject



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ver/text/insert.rb', line 101

def insert_digraph
  buffer.major_mode.read 2 do |*events|
    require 'ver/digraphs'
    first, last = events.first.unicode, events.last.unicode
    if found = DIGRAPHS["#{first}#{last}"]
    elsif found = DIGRAPHS["#{last}#{first}"]
    else
      # some kinda error?
    end

    buffer.insert(self, found) if found
  end
end

#insert_indented_newline_belowObject



86
87
88
89
# File 'lib/ver/text/insert.rb', line 86

def insert_indented_newline_below
  super
  buffer.minor_mode(:control, :insert)
end

#insert_newline_aboveObject



96
97
98
99
# File 'lib/ver/text/insert.rb', line 96

def insert_newline_above
  super
  buffer.minor_mode(:control, :insert)
end

#insert_newline_belowObject



80
81
82
83
84
# File 'lib/ver/text/insert.rb', line 80

def insert_newline_below
  return insert_indented_newline_below if buffer.options.autoindent
  super
  buffer.minor_mode(:control, :insert)
end

#next_line(count = buffer.prefix_count) ⇒ Object

Go to next line, maintaining the display char position. Only on Insert, as Buffer#up_down_line tracks the position.



53
54
55
# File 'lib/ver/text/insert.rb', line 53

def next_line(count = buffer.prefix_count)
  up_down_line(count.abs)
end

#next_page(count = buffer.prefix_count) ⇒ Object

Scroll down the view of buffer by count number of pages. Also sets the insert mark to the position it used to be on the old view.



129
130
131
# File 'lib/ver/text/insert.rb', line 129

def next_page(count = buffer.prefix_count)
  set(buffer.tk_next_page_pos(count))
end

#prev_line(count = buffer.prefix_count) ⇒ Object

Go to previous line, maintaining the display char position. Only on Insert, as Buffer#up_down_line tracks the position.



47
48
49
# File 'lib/ver/text/insert.rb', line 47

def prev_line(count = buffer.prefix_count)
  up_down_line(-count.abs)
end

#prev_page(count = buffer.prefix_count) ⇒ Object

Set insert mark to a position in the previous page in buffer. Also sets the insert mark to the position it used to be on the old view.



120
121
122
# File 'lib/ver/text/insert.rb', line 120

def prev_page(count = buffer.prefix_count)
  set(buffer.tk_prev_page_pos(count))
end

#set(index) ⇒ Object Also known as: index=



10
11
12
13
# File 'lib/ver/text/insert.rb', line 10

def set(index)
  buffer.mark_set(self, index)
  Tk::Event.generate(buffer, '<<Movement>>')
end

#toggle_case!Object



133
134
135
# File 'lib/ver/text/insert.rb', line 133

def toggle_case!
  super
end

#up_down_line(count) ⇒ Object

Only on Insert, as Buffer#up_down_line tracks the position.



58
59
60
# File 'lib/ver/text/insert.rb', line 58

def up_down_line(count)
  set(buffer.up_down_line(count))
end