vimamsa 0.1.4 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/vimamsa +30 -22
- data/ext/vmaext/vmaext.c +0 -3
- data/lib/vimamsa/ack.rb +0 -4
- data/lib/vimamsa/actions.rb +20 -32
- data/lib/vimamsa/buffer.rb +113 -57
- data/lib/vimamsa/buffer_list.rb +4 -4
- data/lib/vimamsa/debug.rb +6 -6
- data/lib/vimamsa/easy_jump.rb +129 -125
- data/lib/vimamsa/editor.rb +64 -31
- data/lib/vimamsa/file_finder.rb +2 -2
- data/lib/vimamsa/file_history.rb +12 -5
- data/lib/vimamsa/gui.rb +562 -0
- data/lib/vimamsa/gui_gtk_sourceview.rb +294 -0
- data/lib/vimamsa/gui_menu.rb +100 -0
- data/lib/vimamsa/gui_select_window.rb +177 -0
- data/lib/vimamsa/gui_sourceview.rb +294 -0
- data/lib/vimamsa/{default_key_bindings.rb → key_actions.rb} +71 -191
- data/lib/vimamsa/key_binding_tree.rb +21 -9
- data/lib/vimamsa/key_bindings_vimlike.rb +260 -0
- data/lib/vimamsa/macro.rb +1 -1
- data/lib/vimamsa/main.rb +1 -2
- data/lib/vimamsa/rbvma.rb +17 -965
- data/lib/vimamsa/search.rb +0 -4
- data/lib/vimamsa/search_replace.rb +1 -2
- data/lib/vimamsa/util.rb +1 -1
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +1 -31
- data/vimamsa.gemspec +2 -1
- metadata +25 -5
@@ -53,7 +53,7 @@ end
|
|
53
53
|
|
54
54
|
class KeyBindingTree
|
55
55
|
attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action
|
56
|
-
attr_reader :mode_root_state, :state_trail
|
56
|
+
attr_reader :mode_root_state, :state_trail, :act_bindings
|
57
57
|
|
58
58
|
def initialize()
|
59
59
|
@modes = {}
|
@@ -67,6 +67,10 @@ class KeyBindingTree
|
|
67
67
|
|
68
68
|
@modifiers = [] # TODO: create a queue
|
69
69
|
@last_event = [nil, nil, nil, nil, nil]
|
70
|
+
|
71
|
+
@override_keyhandling_callback = nil
|
72
|
+
# Allows h["foo"]["faa"]=1
|
73
|
+
@act_bindings = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
70
74
|
end
|
71
75
|
|
72
76
|
def set_default_mode(label)
|
@@ -110,6 +114,14 @@ class KeyBindingTree
|
|
110
114
|
return nil
|
111
115
|
end
|
112
116
|
|
117
|
+
def set_keyhandling_override(_callback)
|
118
|
+
@override_keyhandling_callback = _callback
|
119
|
+
end
|
120
|
+
|
121
|
+
def remove_keyhandling_override()
|
122
|
+
@override_keyhandling_callback = nil
|
123
|
+
end
|
124
|
+
|
113
125
|
def match(key_name)
|
114
126
|
new_state = []
|
115
127
|
@match_state.each { |parent|
|
@@ -129,9 +141,7 @@ class KeyBindingTree
|
|
129
141
|
end
|
130
142
|
}
|
131
143
|
}
|
132
|
-
|
133
|
-
# Ripl.start :binding => binding
|
134
|
-
end
|
144
|
+
|
135
145
|
|
136
146
|
if new_state.any? # Match found
|
137
147
|
@match_state = new_state
|
@@ -242,8 +252,10 @@ class KeyBindingTree
|
|
242
252
|
# $cur_key_dict = $key_bind_dict[$context[:mode]]
|
243
253
|
print "MATCH KEY CONF: #{[c, translated_c]}" if $debug
|
244
254
|
|
245
|
-
|
246
|
-
|
255
|
+
if !@override_keyhandling_callback.nil?
|
256
|
+
ret = @override_keyhandling_callback.call(c, event_type)
|
257
|
+
return if ret
|
258
|
+
end
|
247
259
|
|
248
260
|
eval_s = nil
|
249
261
|
|
@@ -306,7 +318,6 @@ class KeyBindingTree
|
|
306
318
|
# act_s = cstate.action.to_s if cstate.action != nil
|
307
319
|
# puts " #{cstate.to_s} #{act_s}"
|
308
320
|
# end
|
309
|
-
# Ripl.start :binding => binding
|
310
321
|
# new_state[0].children.collect{|x|x.to_s}
|
311
322
|
end
|
312
323
|
|
@@ -328,7 +339,7 @@ class KeyBindingTree
|
|
328
339
|
|
329
340
|
printf("\n") if $debug
|
330
341
|
else
|
331
|
-
|
342
|
+
|
332
343
|
# Don't execute action if one of the states has children
|
333
344
|
state_with_children = new_state.select { |s| s.children.any? }
|
334
345
|
s_act = new_state.select { |s| s.action != nil }
|
@@ -432,7 +443,7 @@ class KeyBindingTree
|
|
432
443
|
@last_event = event #TODO: outside if?
|
433
444
|
end
|
434
445
|
|
435
|
-
#
|
446
|
+
# gui_refresh_cursor
|
436
447
|
|
437
448
|
event_handle_time = Time.now - t1
|
438
449
|
debug "RB key event handle time: #{event_handle_time}" if event_handle_time > 1 / 40.0
|
@@ -484,6 +495,7 @@ class KeyBindingTree
|
|
484
495
|
|
485
496
|
modes.each { |mode_id|
|
486
497
|
mode_bind_key(mode_id, keydef, action)
|
498
|
+
@act_bindings[mode_id][action] = keydef
|
487
499
|
}
|
488
500
|
end
|
489
501
|
|
@@ -0,0 +1,260 @@
|
|
1
|
+
|
2
|
+
bindkey ["VCB M","B m"], :run_last_macro
|
3
|
+
|
4
|
+
bindkey "VC s", :easy_jump
|
5
|
+
bindkey "VC , m f", [:find_macro_gui, proc{$macro.find_macro_gui}, "Find named macro"]
|
6
|
+
bindkey "C , m n", [:gui_name_macro, proc{$macro.gui_name_macro}, "Name last macro"]
|
7
|
+
bindkey "C , j r", :jump_to_random
|
8
|
+
bindkey "I enter", :insert_new_line
|
9
|
+
bindkey "C , ; s k", :show_key_bindings #TODO: better binding
|
10
|
+
bindkey "C , , c b", :put_file_path_to_clipboard #TODO: better binding or remove?
|
11
|
+
bindkey "C , , e", :encrypt_file #TODO: better binding
|
12
|
+
bindkey "C , ; u", :set_unencrypted #TODO: better binding
|
13
|
+
bindkey "C , c b", :close_current_buffer
|
14
|
+
bindkey "V ctrl-c", :comment_selection
|
15
|
+
bindkey "C x", :delete_char_forward
|
16
|
+
bindkey "C , , l t", :load_theme
|
17
|
+
bindkey "C , f", :gui_file_finder
|
18
|
+
bindkey "C , h", :gui_file_history_finder
|
19
|
+
bindkey "C , r r", :gui_search_replace
|
20
|
+
bindkey "V , r r", :gui_search_replace
|
21
|
+
bindkey "V , t b", :set_style_bold
|
22
|
+
bindkey "V , t l", :set_style_link
|
23
|
+
bindkey "V J", :V_join_lines
|
24
|
+
bindkey "V , t c", :clear_formats
|
25
|
+
bindkey "C , t h", :set_line_style_heading
|
26
|
+
bindkey "C , t 1", :set_line_style_h1
|
27
|
+
bindkey "C , t 2", :set_line_style_h2
|
28
|
+
bindkey "C , t 3", :set_line_style_h3
|
29
|
+
bindkey "C , t 4", :set_line_style_h4
|
30
|
+
bindkey "C , t b", :set_line_style_bold
|
31
|
+
bindkey "C , t t", :set_line_style_title
|
32
|
+
bindkey "C , t c", :clear_line_styles
|
33
|
+
bindkey "C , b", :gui_select_buffer
|
34
|
+
# bindkey "C , f o", :open_file_dialog
|
35
|
+
bindkey "CI ctrl-o", :open_file_dialog
|
36
|
+
# bindkey "M enter", :minibuffer_end
|
37
|
+
bindkey "C , a", :ack_search
|
38
|
+
bindkey "C d w", :delete_to_word_end
|
39
|
+
bindkey "C d 0", :delete_to_line_start
|
40
|
+
bindkey "C , , f", :file_finder
|
41
|
+
bindkey "VC h", :e_move_backward_char
|
42
|
+
bindkey "C , , .", :backup_all_buffers
|
43
|
+
bindkey "C z ", :start_browse_mode
|
44
|
+
bindkey "B h", :history_switch_backwards
|
45
|
+
bindkey "B l", :history_switch_forwards
|
46
|
+
#bindkey 'B z', :center_on_current_line
|
47
|
+
bindkey "B z", "center_on_current_line();call(:exit_browse_mode)"
|
48
|
+
bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
|
49
|
+
bindkey "B s", :page_up
|
50
|
+
bindkey "B d", :page_down
|
51
|
+
bindkey "B s", :page_up
|
52
|
+
bindkey "B d", :page_down
|
53
|
+
bindkey "B i", :jump_to_start_of_buffer
|
54
|
+
bindkey "B o", :jump_to_end_of_buffer
|
55
|
+
bindkey "B c", :close_current_buffer
|
56
|
+
bindkey "B ;", "buf.jump_to_last_edit"
|
57
|
+
bindkey "B q", :jump_to_last_edit
|
58
|
+
bindkey "B w", :jump_to_next_edit
|
59
|
+
bindkey "C , d", :diff_buffer
|
60
|
+
bindkey "C , g", :invoke_grep_search
|
61
|
+
#bindkey 'C , g', proc{invoke_grep_search}
|
62
|
+
bindkey "C , v", :auto_indent_buffer
|
63
|
+
bindkey "C , , d", :savedebug
|
64
|
+
bindkey "C , , u", :update_file_index
|
65
|
+
bindkey "C , s a", :buf_save_as
|
66
|
+
bindkey "C d d", [:delete_line, proc{buf.delete_line}, "Delete current line"]
|
67
|
+
bindkey "C enter || C return", [:line_action,proc{buf.handle_line_action()}, "Line action"]
|
68
|
+
bindkey "C p" , [:paste_after,proc{buf.paste(AFTER)},""] # TODO: implement as replace for visual mode
|
69
|
+
bindkey "V d" , [:delete_selection,proc{buf.delete(SELECTION)},""]
|
70
|
+
|
71
|
+
default_keys = {
|
72
|
+
|
73
|
+
# File handling
|
74
|
+
"C ctrl-s" => :buf_save,
|
75
|
+
|
76
|
+
# Buffer handling
|
77
|
+
"C B" => "bufs.switch",
|
78
|
+
"C tab" => "bufs.switch_to_last_buf",
|
79
|
+
# 'C , s'=> 'gui_select_buffer',
|
80
|
+
"C , r v b" => :buf_revert,
|
81
|
+
"C , c b" => "bufs.close_current_buffer",
|
82
|
+
#"C , b" => '$kbd.set_mode("S");gui_select_buffer',
|
83
|
+
"C , n b" => :buf_new,
|
84
|
+
# "C , , ." => "backup_all_buffers()",
|
85
|
+
"VC , , s" => :search_actions,
|
86
|
+
|
87
|
+
|
88
|
+
# MOVING
|
89
|
+
# 'VC h' => 'buf.move(BACKWARD_CHAR)',
|
90
|
+
"VC l" => "buf.move(FORWARD_CHAR)",
|
91
|
+
"VC j" => "buf.move(FORWARD_LINE)",
|
92
|
+
"VC k" => "buf.move(BACKWARD_LINE)",
|
93
|
+
|
94
|
+
"VC pagedown" => "page_down",
|
95
|
+
"VC pageup" => "page_up",
|
96
|
+
|
97
|
+
"VCI left" => "buf.move(BACKWARD_CHAR)",
|
98
|
+
"VCI right" => "buf.move(FORWARD_CHAR)",
|
99
|
+
"VCI down" => "buf.move(FORWARD_LINE)",
|
100
|
+
"VCI up" => "buf.move(BACKWARD_LINE)",
|
101
|
+
|
102
|
+
"VC w" => "buf.jump_word(FORWARD,WORD_START)",
|
103
|
+
"VC b" => "buf.jump_word(BACKWARD,WORD_START)",
|
104
|
+
"VC e" => "buf.jump_word(FORWARD,WORD_END)",
|
105
|
+
# 'C '=> 'buf.jump_word(BACKWARD,END)',#TODO
|
106
|
+
"VC f <char>" => "buf.jump_to_next_instance_of_char(<char>)",
|
107
|
+
"VC F <char>" => "buf.jump_to_next_instance_of_char(<char>,BACKWARD)",
|
108
|
+
"VC f space" => "buf.jump_to_next_instance_of_char(' ')",
|
109
|
+
"VC F space" => "buf.jump_to_next_instance_of_char(' ',BACKWARD)",
|
110
|
+
|
111
|
+
"VC /[1-9]/" => "set_next_command_count(<char>)",
|
112
|
+
# 'VC number=/[0-9]/+ g'=> 'jump_to_line(<number>)',
|
113
|
+
# 'VC X=/[0-9]/+ * Y=/[0-9]/+ '=> 'x_times_y(<X>,<Y>)',
|
114
|
+
"VC ^" => "buf.jump(BEGINNING_OF_LINE)",
|
115
|
+
"VC G($next_command_count!=nil)" => "buf.jump_to_line()",
|
116
|
+
"VC 0($next_command_count!=nil)" => "set_next_command_count(<char>)",
|
117
|
+
"VC 0($next_command_count==nil)" => "buf.jump(BEGINNING_OF_LINE)",
|
118
|
+
# 'C 0'=> 'buf.jump(BEGINNING_OF_LINE)',
|
119
|
+
"VC g g" => "buf.jump(START_OF_BUFFER)",
|
120
|
+
"VC g ;" => "buf.jump_to_last_edit",
|
121
|
+
"VC G" => "buf.jump(END_OF_BUFFER)",
|
122
|
+
# 'VC z z' => 'center_on_current_line',
|
123
|
+
"VC *" => "buf.jump_to_next_instance_of_word",
|
124
|
+
|
125
|
+
"C , e" => "invoke_command", # Currently eval
|
126
|
+
|
127
|
+
"VC /" => :find_in_buffer,
|
128
|
+
|
129
|
+
# READCHAR bindings
|
130
|
+
|
131
|
+
"R <char>" => "readchar_new_char(<char>)",
|
132
|
+
|
133
|
+
"C n" => "$search.jump_to_next()",
|
134
|
+
"C N" => "$search.jump_to_previous()",
|
135
|
+
|
136
|
+
# Debug
|
137
|
+
"C , d r p" => "start_ripl",
|
138
|
+
"C , D" => "debug_print_buffer",
|
139
|
+
"C , c s" => "bufs.close_scrap_buffers",
|
140
|
+
"C , d b" => "debug_print_buffer",
|
141
|
+
"C , d c" => "debug_dump_clipboard",
|
142
|
+
"C , d d" => "debug_dump_deltas",
|
143
|
+
"VC O" => "buf.jump(END_OF_LINE)",
|
144
|
+
"VC $" => "buf.jump(END_OF_LINE)",
|
145
|
+
|
146
|
+
"C o" => 'buf.jump(END_OF_LINE);buf.insert_txt("\n");$kbd.set_mode(:insert)',
|
147
|
+
"C X" => 'buf.jump(END_OF_LINE);buf.insert_txt("\n");',
|
148
|
+
"C A" => "buf.jump(END_OF_LINE);$kbd.set_mode(:insert)",
|
149
|
+
"C I" => "buf.jump(FIRST_NON_WHITESPACE);$kbd.set_mode(:insert)",
|
150
|
+
"C a" => "buf.move(FORWARD_CHAR);$kbd.set_mode(:insert)",
|
151
|
+
"C J" => "buf.join_lines()",
|
152
|
+
"C u" => "buf.undo()",
|
153
|
+
|
154
|
+
"C ^" => "buf.jump(BEGINNING_OF_LINE)",
|
155
|
+
"C /[1-9]/" => "set_next_command_count(<char>)",
|
156
|
+
|
157
|
+
# Command mode only:
|
158
|
+
"C ctrl-r" => "buf.redo()", # TODO:???
|
159
|
+
"C R" => "buf.redo()",
|
160
|
+
"C v" => "buf.start_visual_mode",
|
161
|
+
"C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
|
162
|
+
"C space <char>" => "buf.insert_txt(<char>)",
|
163
|
+
"C space space" => "buf.insert_txt(' ')",
|
164
|
+
"C y y" => "buf.copy_line",
|
165
|
+
"C y O" => "buf.copy(:to_line_end)",
|
166
|
+
"C y 0" => "buf.copy(:to_line_start)",
|
167
|
+
"C y e" => "buf.copy(:to_word_end)", # TODO
|
168
|
+
#### Deleting
|
169
|
+
"C x" => "buf.delete(CURRENT_CHAR_FORWARD)",
|
170
|
+
# 'C d k'=> 'delete_line(BACKWARD)', #TODO
|
171
|
+
# 'C d j'=> 'delete_line(FORWARD)', #TODO
|
172
|
+
# 'C d d'=> 'buf.delete_cur_line',
|
173
|
+
"C d e" => "buf.delete2(:to_word_end)",
|
174
|
+
"C d O" => "buf.delete2(:to_line_end)",
|
175
|
+
"C d $" => "buf.delete2(:to_line_end)",
|
176
|
+
# 'C d e'=> 'buf.delete_to_next_word_end',
|
177
|
+
"C d <num> e" => "delete_next_word",
|
178
|
+
"C r <char>" => "buf.replace_with_char(<char>)", # TODO
|
179
|
+
"C , l b" => "load_buffer_list",
|
180
|
+
"C , l l" => "save_buffer_list",
|
181
|
+
"C , r <char>" => "set_register(<char>)", # TODO
|
182
|
+
"C , p <char>" => "buf.paste(BEFORE,<char>)", # TODO
|
183
|
+
|
184
|
+
"C ctrl-c" => "buf.comment_line()",
|
185
|
+
"C ctrl-x" => "buf.comment_line(:uncomment)",
|
186
|
+
|
187
|
+
# 'C 0($next_command_count==nil)'=> 'jump_to_beginning_of_line',
|
188
|
+
|
189
|
+
# Visual mode only:
|
190
|
+
"V esc" => "buf.end_visual_mode",
|
191
|
+
"V ctrl!" => "buf.end_visual_mode",
|
192
|
+
"V y" => "buf.copy_active_selection()",
|
193
|
+
"V a y" => "buf.copy_active_selection(:append)",
|
194
|
+
"V g U" => "buf.transform_selection(:upcase)",
|
195
|
+
"V g u" => "buf.transform_selection(:downcase)",
|
196
|
+
"V g c" => "buf.transform_selection(:capitalize)",
|
197
|
+
"V g s" => "buf.transform_selection(:swapcase)",
|
198
|
+
"V g r" => "buf.transform_selection(:reverse)",
|
199
|
+
|
200
|
+
"V x" => "buf.delete(SELECTION)",
|
201
|
+
# "V ctrl-c" => "buf.comment_selection",
|
202
|
+
"V ctrl-x" => "buf.comment_selection(:uncomment)",
|
203
|
+
|
204
|
+
"CI ctrl-v" => "buf.paste(BEFORE)",
|
205
|
+
"CI backspace" => "buf.delete(BACKWARD_CHAR)",
|
206
|
+
|
207
|
+
# Marks
|
208
|
+
"CV m <char>" => "buf.mark_current_position(<char>)",
|
209
|
+
'CV \' <char>' => "buf.jump_to_mark(<char>)",
|
210
|
+
# "CV ''" =>'jump_to_mark(NEXT_MARK)', #TODO
|
211
|
+
|
212
|
+
"C i" => "$kbd.set_mode(:insert)",
|
213
|
+
"C ctrl!" => "$kbd.set_mode(:insert)",
|
214
|
+
|
215
|
+
# Macros
|
216
|
+
# (experimental, may not work correctly)
|
217
|
+
# "C q a" => '$macro.start_recording("a")',
|
218
|
+
"VC q <char>" => '$macro.start_recording(<char>)',
|
219
|
+
"VC q($macro.is_recording==true) " => "$macro.end_recording", # TODO
|
220
|
+
# 'C q'=> '$macro.end_recording', #TODO
|
221
|
+
"C q v" => "$macro.end_recording",
|
222
|
+
# 'C v'=> '$macro.end_recording',
|
223
|
+
# "C M" => '$macro.run_last_macro',
|
224
|
+
"C @ <char>" => '$macro.run_macro(<char>)',
|
225
|
+
"C , m S" => '$macro.save_macro("a")',
|
226
|
+
"C , m s" => '$macro.save',
|
227
|
+
"C , t r" => "run_tests()",
|
228
|
+
|
229
|
+
# "C ." => "repeat_last_action", # TODO
|
230
|
+
"VC ;" => "repeat_last_find",
|
231
|
+
# "CV Q" => :quit,
|
232
|
+
"CV ctrl-q" => :quit,
|
233
|
+
"CV , R" => "restart_application",
|
234
|
+
"I ctrl!" => "$kbd.set_mode(:command)",
|
235
|
+
"C shift!" => "buf.save",
|
236
|
+
"I <char>" => "buf.insert_txt(<char>)",
|
237
|
+
"I esc" => "$kbd.set_mode(:command)",
|
238
|
+
|
239
|
+
"I ctrl-d" => "buf.delete2(:to_word_end)",
|
240
|
+
|
241
|
+
# INSERT MODE: Moving
|
242
|
+
"I ctrl-a" => "buf.jump(BEGINNING_OF_LINE)",
|
243
|
+
"I ctrl-b" => "buf.move(BACKWARD_CHAR)",
|
244
|
+
"I ctrl-f" => "buf.move(FORWARD_CHAR)",
|
245
|
+
"I ctrl-n" => "buf.move(FORWARD_LINE)",
|
246
|
+
"I ctrl-p" => "buf.move(BACKWARD_LINE)",
|
247
|
+
"I ctrl-e" => "buf.jump(END_OF_LINE)", # context: mode:I, buttons down: {C}
|
248
|
+
"I alt-f" => "buf.jump_word(FORWARD,WORD_START)",
|
249
|
+
"I alt-b" => "buf.jump_word(BACKWARD,WORD_START)",
|
250
|
+
|
251
|
+
"I tab" => 'buf.insert_txt(" ")',
|
252
|
+
"I space" => 'buf.insert_txt(" ")',
|
253
|
+
# "I return" => 'buf.insert_new_line()',
|
254
|
+
}
|
255
|
+
|
256
|
+
default_keys.each { |key, value|
|
257
|
+
bindkey(key, value)
|
258
|
+
}
|
259
|
+
|
260
|
+
|
data/lib/vimamsa/macro.rb
CHANGED
@@ -58,7 +58,7 @@ class Macro
|
|
58
58
|
$macro_search_list = l
|
59
59
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
60
60
|
|
61
|
-
|
61
|
+
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
62
62
|
"gui_find_macro_select_callback",
|
63
63
|
"gui_find_macro_update_callback")
|
64
64
|
end
|
data/lib/vimamsa/main.rb
CHANGED
@@ -28,7 +28,6 @@ $search_dirs = []
|
|
28
28
|
$errors = []
|
29
29
|
|
30
30
|
$cur_register = "a"
|
31
|
-
$input_char_call_func = nil
|
32
31
|
$debuginfo = {}
|
33
32
|
|
34
33
|
$jump_sequence = []
|
@@ -51,7 +50,7 @@ end
|
|
51
50
|
|
52
51
|
require "vimamsa/editor.rb"
|
53
52
|
|
54
|
-
# load "
|
53
|
+
# load "gui_funcs.rb"
|
55
54
|
|
56
55
|
$vma = Editor.new
|
57
56
|
def vma()
|