Module: VER::Methods::Move

Included in:
VER::Methods, Shortcuts
Defined in:
lib/ver/methods/move.rb

Constant Summary collapse

GO_MATCHING_RIGHT =
{
  '(' => ')',
  '{' => '}',
  '[' => ']',
  '<' => '>',
}
GO_MATCHING_LEFT =
GO_MATCHING_RIGHT.invert

Instance Method Summary collapse

Instance Method Details

#backward_char(count = 1) ⇒ Object

Move cursor count characters left.



44
45
46
# File 'lib/ver/methods/move.rb', line 44

def backward_char(count = 1)
  mark_set :insert, "insert - #{count} char"
end

#backward_word(count = 1) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ver/methods/move.rb', line 143

def backward_word(count = 1)
  count.times do
    original_type = type = char_type(get(:insert))
    changed = 0

    begin
      original_pos = index(:insert)
      execute :mark, :set, :insert, 'insert - 1 chars'
      break if index(:insert) == original_pos

      type = char_type(get(:insert))
      changed += 1 if type != original_type
      original_type = type
    end until changed > 0 && type != :space

    type = char_type(get('insert - 1 chars'))

    while type == original_type
      original_pos = index(:insert)
      execute :mark, :set, :insert, 'insert - 1 chars'
      break if index(:insert) == original_pos

      type = char_type(get('insert - 1 chars'))
    end
  end

  Tk::Event.generate(self, '<<Movement>>')
rescue => ex
  VER.error(ex)
end

#beginning_of_line(count = nil) ⇒ Object



53
54
55
# File 'lib/ver/methods/move.rb', line 53

def beginning_of_line(count = nil)
  mark_set :insert, 'insert display linestart'
end

#end_of_file(count = nil) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/ver/methods/move.rb', line 80

def end_of_file(count = nil)
  if count
    mark_set :insert, "#{count}.0"
  else
    mark_set :insert, :end
  end
end

#end_of_line(count = nil) ⇒ Object



57
58
59
# File 'lib/ver/methods/move.rb', line 57

def end_of_line(count = nil)
  mark_set :insert, 'insert display lineend'
end

#eol_then_insert_mode(count = nil) ⇒ Object



61
62
63
64
# File 'lib/ver/methods/move.rb', line 61

def eol_then_insert_mode(count = nil)
  end_of_line
  start_insert_mode
end

#forward_char(count = 1) ⇒ Object

Move cursor count characters right.



49
50
51
# File 'lib/ver/methods/move.rb', line 49

def forward_char(count = 1)
  mark_set :insert, "insert + #{count} char"
end

#forward_char_then_insert_modeObject



71
72
73
74
# File 'lib/ver/methods/move.rb', line 71

def forward_char_then_insert_mode
  forward_char
  start_insert_mode
end

#forward_word(count = 1) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ver/methods/move.rb', line 116

def forward_word(count = 1)
  count.times do
    original_type = type = char_type(get(:insert))
    changed = 0

    begin
      original_pos = index(:insert)
      execute :mark, :set, :insert, 'insert + 1 chars'
      break if  original_pos == index(:insert)

      type = char_type(get(:insert))
      changed += 1 if type != original_type
      original_type = type
    end until changed > 0 && type != :space
  end

  Tk::Event.generate(self, '<<Movement>>')
rescue => ex
  VER.error(ex)
end

#go_line(number = 0) ⇒ Object



76
77
78
# File 'lib/ver/methods/move.rb', line 76

def go_line(number = 0)
  mark_set :insert, "#{number}.0"
end

#matching_brace(count = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ver/methods/move.rb', line 12

def matching_brace(count = nil)
  opening = get(:insert)

  if closing = GO_MATCHING_RIGHT[opening]
    search = method(:search_all)
    level = 1
    start = 'insert + 1 chars'
  elsif closing = GO_MATCHING_LEFT[opening]
    search = method(:rsearch_all)
    level = 1
    start = 'insert'
  else
    return
  end

  needle = Regexp.union(opening, closing)

  search.call(needle, start) do |match, pos, from|
    if match == opening
      level += 1
    elsif match == closing
      level -= 1
    end

    if level < 1
      mark_set :insert, pos
      return
    end
  end
end

#next_line(count = 1) ⇒ Object



112
113
114
# File 'lib/ver/methods/move.rb', line 112

def next_line(count = 1)
  mark_set :insert, tk_next_line_pos(count)
end

#page_down(count = 1) ⇒ Object



104
105
106
# File 'lib/ver/methods/move.rb', line 104

def page_down(count = 1)
  mark_set :insert, tk_next_page_pos(count)
end

#page_up(count = 1) ⇒ Object

HACK: but it’s just too good to do it manually



100
101
102
# File 'lib/ver/methods/move.rb', line 100

def page_up(count = 1)
  mark_set :insert, tk_prev_page_pos(count)
end

#previous_line(count = 1) ⇒ Object



108
109
110
# File 'lib/ver/methods/move.rb', line 108

def previous_line(count = 1)
  mark_set :insert, tk_prev_line_pos(count)
end

#sol_then_insert_modeObject



66
67
68
69
# File 'lib/ver/methods/move.rb', line 66

def sol_then_insert_mode
  beginning_of_line
  start_insert_mode
end

#virtual_movement(name, count = 1) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/ver/methods/move.rb', line 88

def virtual_movement(name, count = 1)
  pos = index(:insert)
  __send__(name, count)
  mark = index(:insert)
  mark_set :insert, pos
  return [pos, mark].sort
rescue => ex
  VER.error(ex)
end

#word_right_end(count = 1) ⇒ Object



137
138
139
140
141
# File 'lib/ver/methods/move.rb', line 137

def word_right_end(count = 1)
  count.times do
    mark_set :insert, tk_next_word_pos_end('insert')
  end
end