vimamsa 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,8 +30,8 @@ class BufferList < Array
30
30
  $buffer_history << @current_buf
31
31
  @recent_ind = 0
32
32
  $hook.call(:change_buffer, $buffer)
33
- qt_set_current_buffer($buffer.id)
34
- qt_set_cursor_pos($buffer.id, $buffer.pos)
33
+ gui_set_current_buffer($buffer.id)
34
+ gui_set_cursor_pos($buffer.id, $buffer.pos)
35
35
  end
36
36
 
37
37
  def switch()
@@ -83,8 +83,8 @@ class BufferList < Array
83
83
  $hook.call(:change_buffer, $buffer)
84
84
  $buffer.set_active
85
85
 
86
- set_window_title("Vimamsa - #{fpath}")
87
- qt_set_current_buffer($buffer.id)
86
+ gui_set_current_buffer($buffer.id)
87
+ gui_set_window_title($buffer.title,$buffer.subtitle)
88
88
 
89
89
  # hpt_scan_images() if $debug # experimental
90
90
  end
data/lib/vimamsa/debug.rb CHANGED
@@ -95,16 +95,16 @@ def run_test(test_id)
95
95
  $buffer = old_buffer
96
96
  end
97
97
 
98
- def qt_sleep(t2)
98
+ #TODO: remove?
99
+ def gui_sleep(t2)
99
100
  t1 = Time.now()
100
101
  while Time.now < t1 + t2
101
- qt_process_events
102
102
  sleep(0.02)
103
103
  end
104
104
  end
105
105
 
106
106
  def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
107
- open_new_file("TODO"); qt_sleep(0.1)
107
+ open_new_file("TODO"); gui_sleep(0.1)
108
108
 
109
109
  ttstart = Time.now
110
110
  Kernel.srand(1231)
@@ -114,7 +114,7 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
114
114
  buf.jump_to_random_pos
115
115
  buf.insert_txt("Z") if rand() > 0.25
116
116
  buf.reset_highlight() if rand() > 0.1
117
- qt_trigger_event
117
+ gui_trigger_event
118
118
 
119
119
  # puts "========line:========="
120
120
  # puts buf.current_line()
@@ -122,12 +122,12 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
122
122
 
123
123
  render_buffer($buffer)
124
124
 
125
- qt_sleep(rand() / 2)
125
+ gui_sleep(rand() / 2)
126
126
  if rand() < (1 / 40.0)
127
127
  buf.revert
128
128
  end
129
129
 
130
- qt_trigger_event
130
+ gui_trigger_event
131
131
  buf.insert_txt("X") if rand() > 0.25
132
132
  render_buffer($buffer)
133
133
 
@@ -1,161 +1,165 @@
1
-
2
1
  # Similar feature as Vim EasyMotion https://github.com/easymotion/vim-easymotion
3
2
  class EasyJump
4
- def initialize()
5
- make_jump_sequence
3
+ # def self.initialize()
4
+ # make_jump_sequence
5
+ # end
6
+
7
+ def self.start()
8
+ @@cur = EasyJump.new
6
9
  end
7
- end
8
10
 
9
- def easy_jump(direction)
10
- # message "EASY JUMP"
11
- visible_range = get_visible_area()
12
- visible_text = $buffer[visible_range[0]..visible_range[1]]
13
- wsmarks = scan_word_start_marks(visible_text)
14
- line_starts = scan_indexes(visible_text, /^/)
15
- lsh = Hash[line_starts.collect { |x| [x, true] }]
16
- wsmh = Hash[wsmarks.collect { |x| [x, true] }]
17
-
18
- wsmarks.select! { |x|
19
- r = true
20
- r = false if lsh[x] or lsh[x - 1] or lsh[x - 2]
21
- r
22
- }
23
-
24
- linestart_buf = (line_starts).collect { |x| x + visible_range[0] }
25
- wsmarks_buf = (wsmarks).collect { |x| x + visible_range[0] }
26
-
27
- # All line starts should be accessible with just two key presses, so put them first in order
28
- # Other word start positions ordered by distance from current pos
29
- wsmarks_buf.sort_by! { |x| (x - $buffer.pos).abs }
30
- $easy_jump_wsmarks = linestart_buf + wsmarks_buf
31
-
32
- $jump_sequence = make_jump_sequence($easy_jump_wsmarks.size)
33
-
34
- $input_char_call_func = method(:easy_jump_input_char)
35
- $kbd.set_mode(:readchar)
36
- $easy_jump_input = ""
37
- easy_jump_draw
38
- end
11
+ def initialize()
12
+ # message "EASY JUMP"
13
+ visible_range = get_visible_area()
14
+ visible_text = buf[visible_range[0]..visible_range[1]]
15
+ wsmarks = scan_word_start_marks(visible_text)
16
+ line_starts = scan_indexes(visible_text, /^/)
17
+ lsh = Hash[line_starts.collect { |x| [x, true] }]
18
+ wsmh = Hash[wsmarks.collect { |x| [x, true] }]
19
+
20
+ wsmarks.select! { |x|
21
+ r = true
22
+ r = false if lsh[x] or lsh[x - 1] or lsh[x - 2]
23
+ r
24
+ }
25
+
26
+ linestart_buf = (line_starts).collect { |x| x + visible_range[0] }
27
+ wsmarks_buf = (wsmarks).collect { |x| x + visible_range[0] }
28
+
29
+ # All line starts should be accessible with just two key presses, so put them first in order
30
+ # Other word start positions ordered by distance from current pos
31
+ wsmarks_buf.sort_by! { |x| (x - buf.pos).abs }
32
+ @easy_jump_wsmarks = linestart_buf + wsmarks_buf
39
33
 
40
- def easy_jump_input_char(c)
41
- # vma.paint_stack = []
42
- puts "EASY JUMP: easy_jump_input_char [#{c}]"
43
- $easy_jump_input << c.upcase
44
- if $jump_sequence.include?($easy_jump_input)
45
- jshash = Hash[$jump_sequence.map.with_index.to_a]
46
- nthword = jshash[$easy_jump_input]
47
- puts "nthword:#{nthword} #{[$easy_jump_wsmarks[nthword],$jump_sequence[nthword]]}"
48
- $buffer.set_pos($easy_jump_wsmarks[nthword])
49
- $kbd.set_mode(:command)
50
- $input_char_call_func = nil
51
- $jump_sequence = []
52
- $vmag.clear_overlay()
34
+ @jump_sequence = make_jump_sequence(@easy_jump_wsmarks.size)
35
+
36
+ vma.kbd.set_keyhandling_override(self.method(:easy_jump_input_char))
37
+ @easy_jump_input = ""
38
+ easy_jump_draw
53
39
  end
54
- if $easy_jump_input.size > 2
55
- $kbd.set_mode(:command)
56
- $input_char_call_func = nil
57
- $jump_sequence = []
58
- $vmag.clear_overlay()
40
+
41
+ def easy_jump_input_char(c, event_type)
42
+ return true if event_type != :key_press
43
+ # vma.paint_stack = []
44
+ puts "EASY JUMP: easy_jump_input_char [#{c}]"
45
+ @easy_jump_input << c.upcase
46
+ if @jump_sequence.include?(@easy_jump_input)
47
+ jshash = Hash[@jump_sequence.map.with_index.to_a]
48
+ nthword = jshash[@easy_jump_input]
49
+ puts "nthword:#{nthword} #{[@easy_jump_wsmarks[nthword], @jump_sequence[nthword]]}"
50
+ buf.set_pos(@easy_jump_wsmarks[nthword])
51
+ # @kbd.set_mode(:command)
52
+ vma.kbd.remove_keyhandling_override
53
+ @jump_sequence = []
54
+ vma.gui.clear_overlay()
55
+ end
56
+ if @easy_jump_input.size > 2
57
+ # @kbd.set_mode(:command)
58
+ vma.kbd.remove_keyhandling_override
59
+ @jump_sequence = []
60
+ vma.gui.clear_overlay()
61
+ end
62
+ return true
59
63
  end
60
- end
61
64
 
62
- def easy_jump_draw()
63
- # puts $jump_sequence.inspect
64
- # puts $easy_jump_wsmarks.inspect
65
- $vmag.start_overlay_draw
66
- for i in 0..($easy_jump_wsmarks.size - 1)
67
- $vmag.overlay_draw_text($jump_sequence[i], $easy_jump_wsmarks[i])
65
+ def easy_jump_draw()
66
+ # puts @jump_sequence.inspect
67
+ # puts @easy_jump_wsmarks.inspect
68
+ vma.gui.start_overlay_draw
69
+ for i in 0..(@easy_jump_wsmarks.size - 1)
70
+ vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i])
71
+ end
72
+ vma.gui.end_overlay_draw
73
+
74
+ return
75
+ return if @jump_sequence.empty?
76
+ puts "EASY JUMP DRAW"
77
+ screen_cord = cpp_function_wrapper(0, [@easy_jump_wsmarks])
78
+ screen_cord = screen_cord[1..@jump_sequence.size]
79
+ screen_cord.each_with_index { |point, i|
80
+ mark_str = @jump_sequence[i]
81
+ #puts "draw #{point[0]}x#{point[1]}"
82
+ draw_text(mark_str, point[0] + 3, point[1])
83
+ #break if m > @cpos
84
+ }
68
85
  end
69
- $vmag.end_overlay_draw
70
-
71
- return
72
- return if $jump_sequence.empty?
73
- puts "EASY JUMP DRAW"
74
- screen_cord = cpp_function_wrapper(0, [$easy_jump_wsmarks])
75
- screen_cord = screen_cord[1..$jump_sequence.size]
76
- screen_cord.each_with_index { |point, i|
77
- mark_str = $jump_sequence[i]
78
- #puts "draw #{point[0]}x#{point[1]}"
79
- draw_text(mark_str, point[0] + 3, point[1])
80
- #break if m > $cpos
81
- }
82
- end
83
86
 
84
- def make_jump_sequence(num_items)
85
- left_hand = "asdfvgbqwertzxc123".upcase.split("")
86
- right_hand = "jklhnnmyuiop890".upcase.split("")
87
+ def make_jump_sequence(num_items)
88
+ left_hand = "asdfvgbqwertzxc123".upcase.split("")
89
+ right_hand = "jklhnnmyuiop890".upcase.split("")
87
90
 
88
- sequence = []
89
- left_hand_fast = "asdf".upcase.split("")
90
- right_hand_fast = "jkl;".upcase.split("")
91
+ sequence = []
92
+ left_hand_fast = "asdf".upcase.split("")
93
+ right_hand_fast = "jkl;".upcase.split("")
91
94
 
92
- left_hand_slow = "wergc".upcase.split("") # v
93
- right_hand_slow = "uiophnm,".upcase.split("")
95
+ left_hand_slow = "wergc".upcase.split("") # v
96
+ right_hand_slow = "uiophnm,".upcase.split("")
94
97
 
95
- left_hand_slow2 = "tzx23".upcase.split("")
96
- right_hand_slow2 = "yb9'".upcase.split("")
98
+ left_hand_slow2 = "tzx23".upcase.split("")
99
+ right_hand_slow2 = "yb9'".upcase.split("")
97
100
 
98
- # Rmoved characters that can be mixed: O0Q, 8B, I1, VY
101
+ # Rmoved characters that can be mixed: O0Q, 8B, I1, VY
99
102
 
100
- left_fast_slow = Array.new(left_hand_fast).concat(left_hand_slow)
101
- right_fast_slow = Array.new(right_hand_fast).concat(right_hand_slow)
103
+ left_fast_slow = Array.new(left_hand_fast).concat(left_hand_slow)
104
+ right_fast_slow = Array.new(right_hand_fast).concat(right_hand_slow)
102
105
 
103
- left_hand_all = Array.new(left_hand_fast).concat(left_hand_slow).concat(left_hand_slow2)
104
- right_hand_all = Array.new(right_hand_fast).concat(right_hand_slow).concat(right_hand_slow2)
106
+ left_hand_all = Array.new(left_hand_fast).concat(left_hand_slow).concat(left_hand_slow2)
107
+ right_hand_all = Array.new(right_hand_fast).concat(right_hand_slow).concat(right_hand_slow2)
105
108
 
106
- left_hand_fast.each { |x|
107
- left_hand_fast.each { |y|
108
- sequence << "#{x}#{y}"
109
+ left_hand_fast.each { |x|
110
+ left_hand_fast.each { |y|
111
+ sequence << "#{x}#{y}"
112
+ }
109
113
  }
110
- }
111
114
 
112
- right_hand_fast.each { |x|
113
- right_hand_fast.each { |y|
114
- sequence << "#{x}#{y}"
115
+ right_hand_fast.each { |x|
116
+ right_hand_fast.each { |y|
117
+ sequence << "#{x}#{y}"
118
+ }
115
119
  }
116
- }
117
120
 
118
- right_hand_fast.each { |x|
119
- left_hand_fast.each { |y|
120
- sequence << "#{x}#{y}"
121
+ right_hand_fast.each { |x|
122
+ left_hand_fast.each { |y|
123
+ sequence << "#{x}#{y}"
124
+ }
121
125
  }
122
- }
123
126
 
124
- left_hand_fast.each { |x|
125
- right_hand_fast.each { |y|
126
- sequence << "#{x}#{y}"
127
+ left_hand_fast.each { |x|
128
+ right_hand_fast.each { |y|
129
+ sequence << "#{x}#{y}"
130
+ }
127
131
  }
128
- }
129
132
 
130
- left_hand_slow.each { |x|
131
- right_fast_slow.each { |y|
132
- sequence << "#{x}#{y}"
133
+ left_hand_slow.each { |x|
134
+ right_fast_slow.each { |y|
135
+ sequence << "#{x}#{y}"
136
+ }
133
137
  }
134
- }
135
138
 
136
- right_hand_slow.each { |x|
137
- left_fast_slow.each { |y|
138
- sequence << "#{x}#{y}"
139
+ right_hand_slow.each { |x|
140
+ left_fast_slow.each { |y|
141
+ sequence << "#{x}#{y}"
142
+ }
139
143
  }
140
- }
141
144
 
142
- left_hand_slow2.each { |x|
143
- right_hand_all.each { |y|
144
- left_hand_all.each { |z|
145
- sequence << "#{x}#{y}#{z}"
145
+ left_hand_slow2.each { |x|
146
+ right_hand_all.each { |y|
147
+ left_hand_all.each { |z|
148
+ sequence << "#{x}#{y}#{z}"
149
+ }
146
150
  }
147
151
  }
148
- }
149
152
 
150
- right_hand_slow2.each { |x|
151
- left_hand_all.each { |y|
152
- right_hand_all.each { |z|
153
- sequence << "#{x}#{y}#{z}"
153
+ right_hand_slow2.each { |x|
154
+ left_hand_all.each { |y|
155
+ right_hand_all.each { |z|
156
+ sequence << "#{x}#{y}#{z}"
157
+ }
154
158
  }
155
159
  }
156
- }
157
160
 
158
- #printf("Size of sequence: %d\n",sequence.size)
159
- #puts sequence.inspect
160
- return sequence
161
+ #printf("Size of sequence: %d\n",sequence.size)
162
+ #puts sequence.inspect
163
+ return sequence
164
+ end
161
165
  end
@@ -19,9 +19,14 @@ def handle_drag_and_drop(fname)
19
19
  buf.handle_drag_and_drop(fname)
20
20
  end
21
21
 
22
+ def mkdir_if_not_exists(_dirpath)
23
+ dirpath = File.expand_path(_dirpath)
24
+ Dir.mkdir(dirpath) unless File.exist?(dirpath)
25
+ end
26
+
22
27
  class Editor
23
- attr_reader :file_content_search_paths, :file_name_search_paths
24
- attr_accessor :converters, :fh, :paint_stack
28
+ attr_reader :file_content_search_paths, :file_name_search_paths, :gui
29
+ attr_accessor :converters, :fh, :paint_stack, :kbd
25
30
  #attr_writer :call_func, :update_highlight
26
31
 
27
32
  def initialize()
@@ -37,6 +42,25 @@ class Editor
37
42
  @converters = {}
38
43
  @paint_stack = []
39
44
  @_plugins = {}
45
+
46
+ end
47
+
48
+ def open_file_listener(added)
49
+ if !added.empty?
50
+ for fp in added
51
+ sleep 0.1
52
+ x = IO.read(fp)
53
+ File.delete(fp)
54
+ for f in x.lines
55
+ f.gsub!("\n", "")
56
+ if File.exist?(f)
57
+ if file_is_text_file(f)
58
+ jump_to_file(f)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
40
64
  end
41
65
 
42
66
  def start
@@ -47,6 +71,8 @@ class Editor
47
71
  # GLib::Idle.add(proc{ puts "IDLEFUNC"})
48
72
  # GLib::Idle.add(proc { idle_func })
49
73
 
74
+ @gui = $vmag #TODO
75
+
50
76
  $hook = Hook.new
51
77
  register_plugin(:Hook, $hook)
52
78
  $macro = Macro.new
@@ -61,7 +87,8 @@ class Editor
61
87
 
62
88
  debug "ARGV: " + ARGV.inspect
63
89
  # build_key_bindings_tree
64
- $kbd = KeyBindingTree.new()
90
+ @kbd = KeyBindingTree.new()
91
+ $kbd = @kbd
65
92
  $kbd.add_mode("C", :command)
66
93
  $kbd.add_mode("I", :insert)
67
94
  $kbd.add_mode("V", :visual)
@@ -69,13 +96,20 @@ class Editor
69
96
  $kbd.add_mode("R", :readchar)
70
97
  $kbd.add_mode("B", :browse)
71
98
  $kbd.set_default_mode(:command)
72
- require "vimamsa/default_key_bindings"
99
+ require "vimamsa/key_bindings_vimlike"
73
100
  sleep(0.03)
74
101
 
75
102
  FileManager.init
76
103
 
77
- dot_dir = File.expand_path("~/.vimamsa")
78
- Dir.mkdir(dot_dir) unless File.exist?(dot_dir)
104
+ mkdir_if_not_exists("~/.vimamsa")
105
+ mkdir_if_not_exists("~/.vimamsa/backup")
106
+ mkdir_if_not_exists("~/.vimamsa/listen")
107
+ listen_dir = File.expand_path "~/.vimamsa/listen"
108
+ listener = Listen.to(listen_dir) do |modified, added, removed|
109
+ puts(modified: modified, added: added, removed: removed)
110
+ open_file_listener(added)
111
+ end
112
+ listener.start
79
113
 
80
114
  $cnf[:theme] = "Twilight_edit"
81
115
  $cnf[:syntax_highlight] = true
@@ -84,7 +118,7 @@ class Editor
84
118
  $cnf = eval(IO.read(settings_path))
85
119
  end
86
120
 
87
- # set_qt_style(1)
121
+ # set_gui_style(1)
88
122
 
89
123
  # Limit file search to these extensions:
90
124
  $find_extensions = [".txt", ".h", ".c", ".cpp", ".hpp", ".rb"]
@@ -114,7 +148,7 @@ class Editor
114
148
  if fname
115
149
  buffer = Buffer.new(read_file("", fname), fname)
116
150
  else
117
- buffer = Buffer.new("INIT\n")
151
+ buffer = Buffer.new(" \n")
118
152
  end
119
153
  $buffers << buffer
120
154
 
@@ -203,8 +237,7 @@ class Editor
203
237
  # Register converter
204
238
  def reg_conv(converter, converter_id)
205
239
  @converters[converter_id] = converter
206
- reg_act(converter_id, proc { $buffer.convert_selected_text(converter_id) }, "Converter #{converter_id}", [:selection])
207
- # reg_act(converter_id, "$buffer.convert_selected_text(:#{converter_id})", "Converter #{converter_id}", [:selection])
240
+ reg_act(converter_id, proc { $buffer.convert_selected_text(converter_id) }, "Converter #{converter_id}", { :scope => [:selection] })
208
241
  end
209
242
 
210
243
  def apply_conv(converter_id, txt)
@@ -231,10 +264,8 @@ class Editor
231
264
  end
232
265
 
233
266
  def _quit()
234
- # Shut down the Qt thread before the ruby thread
235
267
  vma.shutdown
236
- qt_quit
237
- exit
268
+ Gtk.main_quit
238
269
  end
239
270
 
240
271
  def fatal_error(msg)
@@ -243,14 +274,13 @@ def fatal_error(msg)
243
274
  end
244
275
 
245
276
  def file_saveas(filename)
246
- $buffer.set_filename(filename)
247
- $buffer.save()
277
+ buf.save_as_callback(filename)
248
278
  end
249
279
 
250
280
  def open_file_dialog()
251
281
  path = ""
252
282
  path = $buffer.fname if $buffer.fname
253
- qt_open_file_dialog(File.dirname(path))
283
+ gui_open_file_dialog(File.dirname(path))
254
284
  end
255
285
 
256
286
  def system_clipboard_changed(clipboard_contents)
@@ -384,9 +414,9 @@ def minibuffer_new_char(c)
384
414
  #$buffer = $minibuffer
385
415
  end
386
416
 
387
- def readchar_new_char(c)
388
- $input_char_call_func.call(c)
389
- end
417
+ # def readchar_new_char(c)
418
+ # $input_char_call_func.call(c)
419
+ # end
390
420
 
391
421
  def minibuffer_delete()
392
422
  $minibuffer.delete(BACKWARD_CHAR)
@@ -432,7 +462,7 @@ GUESS_ENCODING_ORDER = [
432
462
  def create_new_file(filename = nil, file_contents = "\n")
433
463
  debug "NEW FILE CREATED"
434
464
  buffer = Buffer.new(file_contents)
435
- qt_set_current_buffer(buffer.id) #TODO: remove?
465
+ # gui_set_current_buffer(buffer.id) #TODO: remove?
436
466
  $buffers << buffer
437
467
  return buffer
438
468
  end
@@ -458,7 +488,7 @@ def load_buffer(fname)
458
488
  end
459
489
  debug("LOAD BUFFER: #{fname}")
460
490
  buffer = Buffer.new(read_file("", fname), fname)
461
- # qt_set_current_buffer(buffer.id)
491
+ # gui_set_current_buffer(buffer.id)
462
492
  buffer.set_active
463
493
  debug("DONE LOAD: #{fname}")
464
494
  #buf = filter_buffer(buffer)
@@ -493,7 +523,6 @@ def open_new_file(filename, file_contents = "")
493
523
  fname = filename
494
524
  load_buffer(fname)
495
525
  end
496
- set_window_title("Vimamsa - #{File.basename(filename)}")
497
526
  end
498
527
 
499
528
  def scan_word_start_marks(search_str)
@@ -506,10 +535,6 @@ def draw_text(str, x, y)
506
535
  vma.paint_stack << [4, x, y, str]
507
536
  end
508
537
 
509
- def center_on_current_line__2del()
510
- center_where_cursor
511
- end
512
-
513
538
  def hook_draw()
514
539
  # TODO: as hook.register
515
540
  # easy_jump_draw()
@@ -527,8 +552,6 @@ def render_buffer(buffer = 0, reset = 0)
527
552
  t1 = Time.now
528
553
  hook_draw()
529
554
 
530
- render_text(tmpbuf, pos, selection_start, reset) #TODO: remove?
531
-
532
555
  if $buffer.need_redraw?
533
556
  hpt_scan_images() if $debug #experimental
534
557
  end