Class: Move

Inherits:
Object show all
Defined in:
lib/xiki/move.rb

Overview

Provides different ways of moving cursor.

Class Method Summary collapse

Class Method Details

.backward(count = nil) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/xiki/move.rb', line 164

def self.backward count=nil
  count ||= Keys.prefix# :clear => true
  count ||= 1
  case count
  when :u; $el.backward_word 1
  when :uu; $el.backward_word 2
  when :uuu; $el.backward_word 3
  else
    $el.backward_char count
  end
end

.bottomObject



196
197
198
# File 'lib/xiki/move.rb', line 196

def self.bottom
  $el.end_of_buffer
end

.forward(count = nil) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/xiki/move.rb', line 176

def self.forward count=nil

  count ||= Keys.prefix# :clear => true
  count ||= 1
  case count
  when :u
    $el.forward_word 1
  when :uu
    $el.forward_word 2
  when :uuu
    $el.forward_word 3
  else
    $el.forward_char(count) rescue nil   # In case tried to move past end
  end
end

.to_axisObject

Moves cursor to left of line:

Move.to_axis Move.to_axiss



233
234
235
236
237
# File 'lib/xiki/move.rb', line 233

def self.to_axis
  n = Keys.prefix_n   # Check for numeric prefix
  Line.next(n) if n.is_a? Fixnum   # If there, move down
  Line.to_left
end

.to_column(n = nil) ⇒ Object

Move to the specified column.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/xiki/move.rb', line 123

def self.to_column n=nil

  prefix = Keys.prefix :clear=>1

  # If dash+, go to specific char
  if prefix == :-
    return View.cursor = Keys.input(:prompt=>"Point to go to: ", :timed=>1).to_i
  end

  n = n || prefix || Keys.input(:prompt=>"column to go to: ").to_i
  if n < 0
    Move.to_end
    n = $el.abs(n)
    n > length = Line.txt.length and n = length
    Move.backward n
    return
  end
  $el.move_to_column n# - 1
end

.to_end(n = nil) ⇒ Object

Moves cursor to left of line:

Move.to_end



242
243
244
245
246
# File 'lib/xiki/move.rb', line 242

def self.to_end n=nil
  n ||= Keys.prefix_n   # Check for numeric prefix
  Line.next(n) if n.is_a? Fixnum   # If there, move down
  Line.to_right
end

.to_indentObject

Go to last line having indent



7
8
9
10
11
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
42
43
44
45
46
47
48
# File 'lib/xiki/move.rb', line 7

def self.to_indent
  direction_down = true   # Assume down
  prefix = Keys.prefix
  line = Line.value

  if prefix.is_a? Fixnum   # If U, reverse
    indent = prefix   # If numeric, make that be the indent
  else
    direction_down = ! direction_down if line =~ /^ *(end|\]|\}|\))$/   # If end of block, reverse direction

    if prefix == :u   # If U, reverse
      direction_down = false
    else
    end
  end

  column = View.column
  indent ||= Line.indent(line).size

  # If negative, reverse direction and amke positive
  if indent < 0
    direction_down = false
    indent = 0 - indent
  end

  orig = Location.new
  # Search for matching in right direction
  if direction_down == false
    Line.to_left
    success = Search.backward "^ \\{#{indent}\\}[^ \t\n]"
  else
    Line.next
    success = Search.forward "^ \\{#{indent}\\}[^ \t\n]"
  end

  Move.to_column prefix.is_a?(Fixnum) ? indent : column

  unless success
    View.beep
    orig.go
  end
end

.to_juniorObject

Move to file in tree (not dir) ?



220
221
222
223
224
225
226
227
# File 'lib/xiki/move.rb', line 220

def self.to_junior
  Keys.prefix_times.times do
    # Move to line without / at end
    Line.next if Line.matches(/^ +[+-]? ?[a-zA-Z_-].+[^\/\n]$/)
    $el.re_search_forward "^ +[+-]? ?[a-zA-Z_-].+[^\/\n]$"
    Line.to_words
  end
end

.to_last_window(options = {}) ⇒ Object



109
110
111
112
113
114
# File 'lib/xiki/move.rb', line 109

def self.to_last_window options={}

  View.to_nth(View.list.size - 1)

  Effects.blink(:what=>:line) if options[:blink]
end

.to_line(n = nil) ⇒ Object



116
117
118
119
120
# File 'lib/xiki/move.rb', line 116

def self.to_line n=nil
  # Use arg or numeric prefix or get input
  n = n || $el.elvar.current_prefix_arg || Keys.input(:prompt=>"Go to line number: ")
  $el.goto_line n.to_i
end

.to_next_paragraph(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xiki/move.rb', line 50

def self.to_next_paragraph options={}
  prefix = Keys.prefix :clear=>1
  if prefix == :u   # If C-u, just go to end
    if Line.blank?
      Line.value(2) =~ /./ ?   # If on blank line but next line has stuff, just move down
        Line.next :
        Move.to_next_paragraph
    end

    Search.forward "^[ \t]*$", :go_anyway=>1

    Move.to_axis
    return
  end

  return Line.next if options[:no_skip] && Line.blank? && Line.value(2) =~ /./   # Don't skip if right before paragraph

  prefix = prefix.is_a?(Fixnum) ? prefix : 1
  prefix.times do
    Search.forward "\n[ \t]*\\(\n+[ \t]*\\)+", :go_anyway=>1
  end
  $el.beginning_of_line
end

.to_other_bracketObject

Go to opposite bracket



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/xiki/move.rb', line 144

def self.to_other_bracket
  prefix = Keys.prefix
  # If prefix or after closing bracket, go backward
  last_char = $el.point == 1 ? "" : $el.buffer_substring($el.point-1, $el.point)

  # If numeric prefix
  if prefix.class == Fixnum
    if prefix > 0
      prefix.times { $el.forward_sexp }
    else
      (0-prefix).times { $el.backward_sexp }
    end
  elsif prefix == :u or last_char =~ /[)}\]'">]/
    $el.backward_sexp
  # Otherwise, go forward
  else
    $el.forward_sexp
  end
end

.to_previous_paragraphObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/xiki/move.rb', line 74

def self.to_previous_paragraph
  prefix = Keys.prefix :clear=>1
  if prefix == :u   # If C-u, just go to end

    # If line before us isn't blank, move past this paragraph first
    Move.to_previous_paragraph if Line.value(0) =~ /./

    Search.backward ".", :go_anyway=>1   # Go to non-blank line
    Line.next
    return
  end

  prefix = prefix.is_a?(Fixnum) ? prefix : 1

  prefix.times do
    $el.skip_chars_backward "\n "
    $el.re_search_backward "\n[ \t]*\\(\n+[ \t]*\\)+", nil, 1
  end
  $el.skip_chars_forward "\n "
  $el.beginning_of_line
end

.to_quoteObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/xiki/move.rb', line 200

def self.to_quote
  prefix = Keys.prefix :clear=>true
  if prefix.nil?
    times = 1
    Keys.clear_prefix
  elsif prefix.is_a? Fixnum
    times = prefix
    View.to_relative
  end

  (times||1).times do
    Line.next if Line.matches(/^ *\|/)
    $el.re_search_forward "^ *|"
    $el.backward_char
  end

  # If on a quote, move off
end

.to_window(n, options = {}) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/xiki/move.rb', line 96

def self.to_window n, options={}

  views = View.list   # Get views in this window

  if n >= views.size   # If they wanted to go further than exists
    $el.select_window(views[views.size - 1])
  else
    $el.select_window(views[n-1])
  end

  Effects.blink(:what=>:line) if options[:blink]
end

.topObject



192
193
194
# File 'lib/xiki/move.rb', line 192

def self.top
  $el.beginning_of_buffer
end