vimamsa 0.1.5 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/vimamsa +4 -2
- data/lib/vimamsa/ack.rb +0 -4
- data/lib/vimamsa/actions.rb +26 -38
- data/lib/vimamsa/buffer.rb +117 -60
- data/lib/vimamsa/buffer_list.rb +27 -3
- data/lib/vimamsa/buffer_manager.rb +83 -0
- data/lib/vimamsa/conf.rb +21 -0
- data/lib/vimamsa/debug.rb +9 -8
- data/lib/vimamsa/easy_jump.rb +129 -125
- data/lib/vimamsa/editor.rb +66 -48
- data/lib/vimamsa/file_finder.rb +7 -8
- data/lib/vimamsa/file_history.rb +15 -8
- data/lib/vimamsa/file_manager.rb +9 -8
- data/lib/vimamsa/gui.rb +560 -0
- data/lib/vimamsa/gui_menu.rb +110 -0
- data/lib/vimamsa/gui_select_window.rb +177 -0
- data/lib/vimamsa/gui_sourceview.rb +294 -0
- data/lib/vimamsa/hyper_plain_text.rb +8 -10
- data/lib/vimamsa/{default_key_bindings.rb → key_actions.rb} +71 -190
- data/lib/vimamsa/key_binding_tree.rb +48 -36
- data/lib/vimamsa/key_bindings_vimlike.rb +260 -0
- data/lib/vimamsa/macro.rb +6 -6
- data/lib/vimamsa/main.rb +1 -2
- data/lib/vimamsa/rbvma.rb +25 -1031
- data/lib/vimamsa/search.rb +1 -5
- data/lib/vimamsa/search_replace.rb +4 -6
- data/lib/vimamsa/version.rb +1 -1
- data/vimamsa.gemspec +1 -1
- metadata +12 -5
@@ -0,0 +1,83 @@
|
|
1
|
+
class BufferManager
|
2
|
+
attr_reader :buf
|
3
|
+
@@cur = nil # Current object of class
|
4
|
+
|
5
|
+
def self.cur()
|
6
|
+
return @@cur
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.init()
|
10
|
+
vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
|
11
|
+
reg_act(:bmgr_select, proc { buf.module.select_line }, "")
|
12
|
+
reg_act(:bmgr_close, proc { buf.module.close_selected }, "")
|
13
|
+
|
14
|
+
reg_act(:start_buf_manager, proc { BufferManager.new.run; vma.kbd.set_mode(:buf_mgr) }, "Buffer manager")
|
15
|
+
|
16
|
+
bindkey "bmgr enter", :bmgr_select
|
17
|
+
bindkey "bmgr c", :bmgr_close
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize()
|
21
|
+
@buf = nil
|
22
|
+
@line_to_id = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def buf_of_current_line()
|
26
|
+
l = @buf.lpos - @header.size
|
27
|
+
return nil if l < 0
|
28
|
+
bufid = @line_to_id[l]
|
29
|
+
buf_i = vma.buffers.get_buffer_by_id(bufid)
|
30
|
+
return buf_i
|
31
|
+
end
|
32
|
+
|
33
|
+
def close_selected
|
34
|
+
buf_i = buf_of_current_line()
|
35
|
+
if buf_i.nil?
|
36
|
+
message("buf already closed")
|
37
|
+
return
|
38
|
+
end
|
39
|
+
vma.buffers.close_other_buffer(buf_i)
|
40
|
+
end
|
41
|
+
|
42
|
+
def select_line
|
43
|
+
buf_i = buf_of_current_line()
|
44
|
+
return if buf_i.nil?
|
45
|
+
|
46
|
+
vma.buffers.close_current_buffer()
|
47
|
+
vma.buffers.set_current_buffer(buf_i)
|
48
|
+
@@cur = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def run
|
52
|
+
if !@@cur.nil? #One instance open already
|
53
|
+
#Close it
|
54
|
+
buf_i = vma.buffers.get_buffer_by_id(@@cur.buf.id)
|
55
|
+
vma.buffers.close_buffer(buf_i)
|
56
|
+
end
|
57
|
+
@@cur = self
|
58
|
+
@header = []
|
59
|
+
@header << "Current buffers:"
|
60
|
+
@header << "keys: <enter> to select, <c> to close buffer"
|
61
|
+
@header << "=" * 40
|
62
|
+
|
63
|
+
s = ""
|
64
|
+
s << @header.join("\n")
|
65
|
+
s << "\n"
|
66
|
+
i = 0
|
67
|
+
for b in vma.buffers.sort_by { |x| x.list_str }
|
68
|
+
x = b.list_str
|
69
|
+
s << "#{x}\n"
|
70
|
+
@line_to_id[i] = b.id
|
71
|
+
i += 1
|
72
|
+
end
|
73
|
+
|
74
|
+
if @buf.nil?
|
75
|
+
@buf = create_new_file(nil, s)
|
76
|
+
@buf.module = self
|
77
|
+
@buf.active_kbd_mode = :buf_mgr
|
78
|
+
else
|
79
|
+
@buf.set_content(s)
|
80
|
+
end
|
81
|
+
@buf.set_line_and_column_pos(@header.size, 0)
|
82
|
+
end
|
83
|
+
end
|
data/lib/vimamsa/conf.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$cnf = {} # TODO
|
2
|
+
|
3
|
+
def conf(id)
|
4
|
+
return $cnf[id]
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_conf(id, val)
|
8
|
+
$cnf[id] = val
|
9
|
+
end
|
10
|
+
|
11
|
+
def setcnf(id, val)
|
12
|
+
set_conf(id, val)
|
13
|
+
end
|
14
|
+
|
15
|
+
setcnf :indent_based_on_last_line, true
|
16
|
+
setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc", ".php", ".sh", ".m", ".gd", ".js"]
|
17
|
+
|
18
|
+
|
19
|
+
setcnf "log.verbose", 1
|
20
|
+
setcnf :tab_width, 4
|
21
|
+
|
data/lib/vimamsa/debug.rb
CHANGED
@@ -21,8 +21,9 @@ def debug_dump_deltas()
|
|
21
21
|
end
|
22
22
|
|
23
23
|
$log_messages = []
|
24
|
-
|
25
|
-
|
24
|
+
|
25
|
+
def log_message(message,vlevel)
|
26
|
+
puts message if conf("log.verbose") >= vlevel
|
26
27
|
$log_messages << message
|
27
28
|
end
|
28
29
|
|
@@ -95,16 +96,16 @@ def run_test(test_id)
|
|
95
96
|
$buffer = old_buffer
|
96
97
|
end
|
97
98
|
|
98
|
-
|
99
|
+
#TODO: remove?
|
100
|
+
def gui_sleep(t2)
|
99
101
|
t1 = Time.now()
|
100
102
|
while Time.now < t1 + t2
|
101
|
-
qt_process_events
|
102
103
|
sleep(0.02)
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
107
|
def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
|
107
|
-
open_new_file("TODO");
|
108
|
+
open_new_file("TODO"); gui_sleep(0.1)
|
108
109
|
|
109
110
|
ttstart = Time.now
|
110
111
|
Kernel.srand(1231)
|
@@ -114,7 +115,7 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
|
|
114
115
|
buf.jump_to_random_pos
|
115
116
|
buf.insert_txt("Z") if rand() > 0.25
|
116
117
|
buf.reset_highlight() if rand() > 0.1
|
117
|
-
|
118
|
+
gui_trigger_event
|
118
119
|
|
119
120
|
# puts "========line:========="
|
120
121
|
# puts buf.current_line()
|
@@ -122,12 +123,12 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
|
|
122
123
|
|
123
124
|
render_buffer($buffer)
|
124
125
|
|
125
|
-
|
126
|
+
gui_sleep(rand() / 2)
|
126
127
|
if rand() < (1 / 40.0)
|
127
128
|
buf.revert
|
128
129
|
end
|
129
130
|
|
130
|
-
|
131
|
+
gui_trigger_event
|
131
132
|
buf.insert_txt("X") if rand() > 0.25
|
132
133
|
render_buffer($buffer)
|
133
134
|
|
data/lib/vimamsa/easy_jump.rb
CHANGED
@@ -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
|
-
|
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
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
|
41
|
+
def easy_jump_input_char(c, event_type)
|
42
|
+
return true if event_type != :key_press
|
43
|
+
# vma.paint_stack = []
|
44
|
+
debug "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
|
+
debug "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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
def easy_jump_draw()
|
66
|
+
# debug @jump_sequence.inspect
|
67
|
+
# debug @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
|
+
debug "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
|
+
#debug "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
|
-
|
86
|
-
|
87
|
+
def make_jump_sequence(num_items)
|
88
|
+
left_hand = "asdfvgbqwertzxc123".upcase.split("")
|
89
|
+
right_hand = "jklhnnmyuiop890".upcase.split("")
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
+
sequence = []
|
92
|
+
left_hand_fast = "asdf".upcase.split("")
|
93
|
+
right_hand_fast = "jkl;".upcase.split("")
|
91
94
|
|
92
|
-
|
93
|
-
|
95
|
+
left_hand_slow = "wergc".upcase.split("") # v
|
96
|
+
right_hand_slow = "uiophnm,".upcase.split("")
|
94
97
|
|
95
|
-
|
96
|
-
|
98
|
+
left_hand_slow2 = "tzx23".upcase.split("")
|
99
|
+
right_hand_slow2 = "yb9'".upcase.split("")
|
97
100
|
|
98
|
-
|
101
|
+
# Rmoved characters that can be mixed: O0Q, 8B, I1, VY
|
99
102
|
|
100
|
-
|
101
|
-
|
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
|
-
|
104
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
+
left_hand_fast.each { |x|
|
110
|
+
left_hand_fast.each { |y|
|
111
|
+
sequence << "#{x}#{y}"
|
112
|
+
}
|
109
113
|
}
|
110
|
-
}
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
+
right_hand_fast.each { |x|
|
116
|
+
right_hand_fast.each { |y|
|
117
|
+
sequence << "#{x}#{y}"
|
118
|
+
}
|
115
119
|
}
|
116
|
-
}
|
117
120
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
+
right_hand_fast.each { |x|
|
122
|
+
left_hand_fast.each { |y|
|
123
|
+
sequence << "#{x}#{y}"
|
124
|
+
}
|
121
125
|
}
|
122
|
-
}
|
123
126
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
+
left_hand_fast.each { |x|
|
128
|
+
right_hand_fast.each { |y|
|
129
|
+
sequence << "#{x}#{y}"
|
130
|
+
}
|
127
131
|
}
|
128
|
-
}
|
129
132
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
+
left_hand_slow.each { |x|
|
134
|
+
right_fast_slow.each { |y|
|
135
|
+
sequence << "#{x}#{y}"
|
136
|
+
}
|
133
137
|
}
|
134
|
-
}
|
135
138
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
+
right_hand_slow.each { |x|
|
140
|
+
left_fast_slow.each { |y|
|
141
|
+
sequence << "#{x}#{y}"
|
142
|
+
}
|
139
143
|
}
|
140
|
-
}
|
141
144
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
+
#printf("Size of sequence: %d\n",sequence.size)
|
162
|
+
#debug sequence.inspect
|
163
|
+
return sequence
|
164
|
+
end
|
161
165
|
end
|