vimamsa 0.1.5 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
def e_move_forward_char
|
3
2
|
buf.move(FORWARD_CHAR)
|
4
3
|
end
|
@@ -29,249 +28,133 @@ def is_visual_mode()
|
|
29
28
|
return 0
|
30
29
|
end
|
31
30
|
|
32
|
-
reg_act(:easy_jump, proc { easy_jump(:visible_area) }, "Easy jump")
|
33
|
-
bindkey "VC s", :easy_jump
|
34
|
-
|
35
|
-
reg_act(:savedebug, "savedebug", "Save debug info")
|
36
|
-
|
37
|
-
# reg_act(:file_finder, "gui_file_finder", "Fuzzy file finder")
|
38
|
-
|
39
|
-
reg_act(:open_file_dialog, "open_file_dialog", "Open file")
|
40
|
-
reg_act(:create_new_file, "create_new_file", "Create new file")
|
41
|
-
reg_act(:backup_all_buffers, "backup_all_buffers", "Backup all buffers")
|
42
|
-
reg_act(:invoke_ack_search, "invoke_ack_search", "Invoke ack search")
|
43
|
-
reg_act(:e_move_forward_char, "e_move_forward_char", "")
|
44
|
-
reg_act(:e_move_backward_char, "e_move_backward_char", "")
|
45
|
-
reg_act(:history_switch_backwards, "history_switch_backwards", "")
|
46
|
-
reg_act(:history_switch_forwards, "history_switch_forwards", "")
|
47
|
-
|
48
|
-
reg_act(:center_on_current_line, "center_on_current_line", "")
|
49
|
-
|
50
|
-
# a = Action.new(:transform_upcase, "Transform selection upcase", proc{ buf.transform_selection(:upcase) } , [:selection])
|
51
|
-
|
52
|
-
reg_act(:run_last_macro, proc { $macro.run_last_macro }, "Run last recorded or executed macro")
|
53
|
-
bindkey ["VCB M","B m"], :run_last_macro
|
54
|
-
|
55
|
-
bindkey "VC , m f", [:find_macro_gui, proc{$macro.find_macro_gui}, "Find named macro"]
|
56
|
-
bindkey "C , m n", [:gui_name_macro, proc{$macro.gui_name_macro}, "Name last macro"]
|
57
|
-
|
58
31
|
|
32
|
+
reg_act(:enable_debug, proc { $debug=true }, "Enable debug")
|
33
|
+
reg_act(:disable_debug, proc {$debug=false }, "Disable debug")
|
34
|
+
|
35
|
+
reg_act(:easy_jump, proc { EasyJump.start }, "Easy jump")
|
36
|
+
reg_act(:savedebug, "savedebug", "Save debug info", { :group => :debug })
|
37
|
+
reg_act(:open_file_dialog, "open_file_dialog", "Open file", { :group => :file })
|
38
|
+
reg_act(:create_new_file, "create_new_file", "Create new file", { :group => :file })
|
39
|
+
reg_act(:backup_all_buffers, proc{backup_all_buffers}, "Backup all buffers", { :group => :file })
|
40
|
+
reg_act(:e_move_forward_char, "e_move_forward_char", "", { :group => :move })
|
41
|
+
reg_act(:e_move_backward_char, "e_move_backward_char", "", { :group => :move })
|
42
|
+
reg_act(:history_switch_backwards, "history_switch_backwards", "", { :group => :file })
|
43
|
+
reg_act(:history_switch_forwards, "history_switch_forwards", "", { :group => :file })
|
44
|
+
reg_act(:center_on_current_line, "center_on_current_line", "", { :group => :view })
|
45
|
+
reg_act(:run_last_macro, proc { $macro.run_last_macro }, "Run last recorded or executed macro", { :group => :macro })
|
59
46
|
reg_act(:jump_to_next_edit, "jump_to_next_edit", "")
|
60
47
|
reg_act(:jump_to_last_edit, proc { buf.jump_to_last_edit }, "")
|
61
|
-
|
62
|
-
|
63
48
|
reg_act(:jump_to_random, proc { buf.jump_to_random_pos }, "")
|
64
|
-
|
65
|
-
|
66
|
-
reg_act(:insert_new_line, proc { buf.insert_new_line()}, "")
|
67
|
-
bindkey "I enter", :insert_new_line
|
68
|
-
|
49
|
+
reg_act(:insert_new_line, proc { buf.insert_new_line() }, "")
|
69
50
|
reg_act(:show_key_bindings, proc { show_key_bindings }, "Show key bindings")
|
70
|
-
bindkey "C , ; s k", :show_key_bindings #TODO: better binding
|
71
|
-
|
72
51
|
reg_act(:put_file_path_to_clipboard, proc { buf.put_file_path_to_clipboard }, "Put file path of current file to clipboard")
|
73
|
-
bindkey "C , , c b", :put_file_path_to_clipboard #TODO: better binding or remove?
|
74
|
-
|
75
52
|
# reg_act(:encrypt_file, proc{buf.set_encrypted},"Set current file to encrypt on save")
|
76
53
|
reg_act(:encrypt_file, proc { encrypt_cur_buffer }, "Set current file to encrypt on save")
|
77
|
-
bindkey "C , , e", :encrypt_file #TODO: better binding
|
78
|
-
|
79
54
|
reg_act(:set_unencrypted, proc { buf.set_unencrypted }, "Set current file to save unencrypted")
|
80
|
-
|
81
|
-
|
82
|
-
reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
|
83
|
-
|
55
|
+
reg_act(:set_executable, proc { buf.set_executable }, "Set current file permissions to executable")
|
56
|
+
reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
|
84
57
|
reg_act(:close_current_buffer, proc { bufs.close_current_buffer(true) }, "Close current buffer")
|
85
|
-
bindkey "C , c b", :close_current_buffer
|
86
|
-
|
87
58
|
reg_act(:comment_selection, proc { buf.comment_selection }, "")
|
88
|
-
bindkey "V ctrl-c", :comment_selection
|
89
|
-
|
90
59
|
reg_act(:delete_char_forward, proc { buf.delete(CURRENT_CHAR_FORWARD) }, "Delete char forward")
|
91
|
-
bindkey "C x", :delete_char_forward
|
92
|
-
|
93
60
|
reg_act(:load_theme, proc { load_theme }, "Load theme")
|
94
|
-
bindkey "C , , l t", :load_theme
|
95
|
-
|
96
61
|
reg_act(:gui_file_finder, proc { vma.FileFinder.start_gui }, "Fuzzy file finder")
|
97
|
-
bindkey "C , f", :gui_file_finder
|
98
|
-
|
99
|
-
|
100
62
|
reg_act(:gui_file_history_finder, proc { vma.FileHistory.start_gui }, "Fuzzy file history finder")
|
101
|
-
bindkey "C , h", :gui_file_history_finder
|
102
|
-
|
103
|
-
|
104
63
|
reg_act(:gui_search_replace, proc { gui_search_replace }, "Search and replace")
|
105
|
-
bindkey "C , r r", :gui_search_replace
|
106
|
-
bindkey "V , r r", :gui_search_replace
|
107
|
-
|
108
64
|
reg_act(:set_style_bold, proc { buf.style_transform(:bold) }, "Set text weight to bold")
|
109
|
-
bindkey "V , t b", :set_style_bold
|
110
|
-
|
111
65
|
reg_act(:set_style_link, proc { buf.style_transform(:link) }, "Set text as link")
|
112
|
-
bindkey "V , t l", :set_style_link
|
113
|
-
|
114
66
|
reg_act(:V_join_lines, proc { vma.buf.convert_selected_text(:joinlines) }, "Join lines")
|
115
|
-
bindkey "V J", :V_join_lines
|
116
|
-
|
117
|
-
|
118
67
|
reg_act(:clear_formats, proc { buf.style_transform(:clear) }, "Clear style formats")
|
119
|
-
bindkey "V , t c", :clear_formats
|
120
|
-
|
121
68
|
reg_act(:set_line_style_heading, proc { buf.set_line_style(:heading) }, "Set style of current line as heading")
|
122
|
-
bindkey "C , t h", :set_line_style_heading
|
123
|
-
|
124
69
|
reg_act(:set_line_style_h1, proc { buf.set_line_style(:h1) }, "Set cur line as Heading 1")
|
125
|
-
bindkey "C , t 1", :set_line_style_h1
|
126
70
|
reg_act(:set_line_style_h2, proc { buf.set_line_style(:h2) }, "Set cur line as Heading 1")
|
127
|
-
bindkey "C , t 2", :set_line_style_h2
|
128
71
|
reg_act(:set_line_style_h3, proc { buf.set_line_style(:h3) }, "Set cur line as Heading 1")
|
129
|
-
bindkey "C , t 3", :set_line_style_h3
|
130
72
|
reg_act(:set_line_style_h4, proc { buf.set_line_style(:h4) }, "Set cur line as Heading 1")
|
131
|
-
bindkey "C , t 4", :set_line_style_h4
|
132
|
-
|
133
|
-
|
134
73
|
reg_act(:set_line_style_bold, proc { buf.set_line_style(:bold) }, "Set style of current line as bold")
|
135
|
-
bindkey "C , t b", :set_line_style_bold
|
136
|
-
|
137
74
|
reg_act(:set_line_style_title, proc { buf.set_line_style(:title) }, "Set style of current line as title")
|
138
|
-
bindkey "C , t t", :set_line_style_title
|
139
|
-
|
140
75
|
reg_act(:clear_line_styles, proc { buf.set_line_style(:clear) }, "Clear styles of current line")
|
141
|
-
bindkey "C , t c", :clear_line_styles
|
142
|
-
|
143
76
|
reg_act(:gui_select_buffer, proc { $kbd.set_mode("S"); gui_select_buffer }, "Select buffer")
|
144
|
-
bindkey "C , b", :gui_select_buffer
|
145
|
-
|
146
77
|
reg_act :open_file_dialog, "open_file_dialog", "Open file"
|
147
|
-
# bindkey "C , f o", :open_file_dialog
|
148
|
-
bindkey "CI ctrl-o", :open_file_dialog
|
149
|
-
|
150
78
|
reg_act :minibuffer_end, proc { minibuffer_end }
|
151
|
-
bindkey "M enter", :minibuffer_end
|
152
|
-
|
153
79
|
reg_act(:invoke_replace, "invoke_replace", "")
|
154
80
|
reg_act(:diff_buffer, "diff_buffer", "")
|
155
|
-
|
156
81
|
# reg_act(:invoke_grep_search, proc{invoke_grep_search}, "")
|
157
82
|
reg_act(:invoke_grep_search, proc { gui_grep }, "Grep current buffer")
|
158
|
-
|
159
|
-
|
160
83
|
reg_act(:ack_search, proc { gui_ack }, "") #invoke_ack_search
|
161
|
-
bindkey "C , a", :ack_search
|
162
|
-
|
163
84
|
reg_act :update_file_index, proc { update_file_index }, "Update file index"
|
164
|
-
|
165
|
-
|
166
85
|
reg_act :delete_to_word_end, proc { buf.delete2(:to_word_end) }, "Delete to file end"
|
167
|
-
bindkey "C d w", :delete_to_word_end
|
168
|
-
|
169
86
|
reg_act :delete_to_line_start, proc { buf.delete2(:to_line_start) }, "Delete to line start"
|
170
|
-
bindkey "C d 0", :delete_to_line_start
|
171
|
-
|
172
|
-
|
173
|
-
bindkey "C , , f", :file_finder
|
174
|
-
bindkey "VC h", :e_move_backward_char
|
175
|
-
|
176
|
-
bindkey "C , , .", :backup_all_buffers
|
177
|
-
|
178
|
-
|
179
|
-
bindkey "C z ", :start_browse_mode
|
180
|
-
bindkey "B h", :history_switch_backwards
|
181
|
-
bindkey "B l", :history_switch_forwards
|
182
|
-
#bindkey 'B z', :center_on_current_line
|
183
|
-
bindkey "B z", "center_on_current_line();call(:exit_browse_mode)"
|
184
|
-
|
185
87
|
reg_act :start_browse_mode, proc { $kbd.set_mode(:browse); $kbd.set_default_mode(:browse) }, "Start browse mode"
|
186
|
-
|
187
|
-
|
88
|
+
reg_act :exit_browse_mode, proc {
|
89
|
+
bufs.add_current_buf_to_history(); $kbd.set_mode(:command); $kbd.set_default_mode(:command)
|
188
90
|
}, "Exit browse mode"
|
189
|
-
#TODO: Need to deside which of these is best:
|
190
|
-
bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
|
191
|
-
|
192
|
-
reg_act :page_down, proc {page_down}
|
193
|
-
reg_act :page_up, proc {page_up}
|
194
|
-
bindkey "B s", :page_up
|
195
|
-
bindkey "B d", :page_down
|
196
|
-
bindkey "B s", :page_up
|
197
|
-
bindkey "B d", :page_down
|
198
|
-
|
199
|
-
reg_act :jump_to_start_of_buffer, proc{buf.jump(START_OF_BUFFER)}, "Jump to start of buffer"
|
200
|
-
reg_act :jump_to_end_of_buffer, proc{buf.jump(END_OF_BUFFER)}, "Jump to end of buffer"
|
201
|
-
|
202
|
-
bindkey "B i", :jump_to_start_of_buffer
|
203
|
-
bindkey "B o", :jump_to_end_of_buffer
|
204
|
-
|
205
|
-
bindkey "B c", :close_current_buffer
|
206
|
-
bindkey "B ;", "buf.jump_to_last_edit"
|
207
|
-
bindkey "B q", :jump_to_last_edit
|
208
|
-
bindkey "B w", :jump_to_next_edit
|
209
|
-
|
210
|
-
bindkey "C , d", :diff_buffer
|
211
|
-
bindkey "C , g", :invoke_grep_search
|
212
|
-
#bindkey 'C , g', proc{invoke_grep_search}
|
213
91
|
|
92
|
+
reg_act :page_down, proc { page_down }
|
93
|
+
reg_act :page_up, proc { page_up }
|
94
|
+
reg_act :jump_to_start_of_buffer, proc { buf.jump(START_OF_BUFFER) }, "Jump to start of buffer"
|
95
|
+
reg_act :jump_to_end_of_buffer, proc { buf.jump(END_OF_BUFFER) }, "Jump to end of buffer"
|
214
96
|
reg_act(:auto_indent_buffer, proc { buf.indent }, "Auto format buffer")
|
215
|
-
|
216
|
-
|
217
|
-
bindkey "C , , u", :update_file_index
|
218
|
-
|
219
|
-
bindkey "C , s a", "buf.save_as()"
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
reg_act(:execute_current_line_in_terminal, proc { buf.execute_current_line_in_terminal }, "Execute current line in terminal")
|
224
|
-
|
97
|
+
reg_act(:execute_current_line_in_terminal, proc { buf.execute_current_line_in_terminal }, "Execute current line in terminalL")
|
98
|
+
reg_act(:execute_current_line_in_terminal_autoclose, proc { buf.execute_current_line_in_terminal(true) }, "Execute current line in terminal. Close after execution.")
|
225
99
|
reg_act(:show_images, proc { hpt_scan_images() }, "Show images inserted with ⟦img:file.png⟧ syntax")
|
226
|
-
|
227
100
|
reg_act(:delete_current_file, proc { bufs.delete_current_buffer() }, "Delete current file")
|
228
101
|
|
102
|
+
act_list = {
|
103
|
+
# File handling
|
104
|
+
:buf_save => { :proc => proc { buf.save },
|
105
|
+
:desc => "Save buffer", :group => :file },
|
229
106
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
107
|
+
:buf_save_as => { :proc => proc { buf.save_as },
|
108
|
+
:desc => "Save file as", :group => :file },
|
109
|
+
:buf_new => { :proc => proc { create_new_file() }, :desc => "Create a new file", :group => :file },
|
110
|
+
:buf_revert => { :proc => proc { buf.revert },
|
111
|
+
:desc => "Reload file from disk", :group => :file },
|
112
|
+
:buf_backup => { :proc => proc { buf.backup() }, :desc => "Backup current file", :group => :file },
|
234
113
|
|
114
|
+
:edit_redo => { :proc => proc { buf.redo },
|
115
|
+
:desc => "Redo edit", :group => :edit },
|
235
116
|
|
236
|
-
|
237
|
-
|
238
|
-
# bindkey "C , f", :start_file_selector
|
117
|
+
:edit_undo => { :proc => proc { buf.undo },
|
118
|
+
:desc => "Undo edit", :group => :edit },
|
239
119
|
|
240
|
-
|
120
|
+
:find_in_buffer => { :proc => proc { invoke_search },
|
121
|
+
:desc => "Find", :group => :edit },
|
241
122
|
|
242
|
-
# bindkey "fexp l" , [:fexp_right,proc{puts "==fexp_right=="},""]
|
243
|
-
# bindkey "fexp esc" , [:fexp_quit,proc{$kbd.set_mode(:command)},""]
|
244
|
-
# bindkey "fexp enter" , [:fexp_select,proc{buf.module.select_line},""]
|
245
123
|
|
246
|
-
#
|
124
|
+
# { :proc => proc { },
|
125
|
+
# :desc => "", :group => : },
|
247
126
|
|
248
|
-
|
249
|
-
|
127
|
+
:search_actions => { :proc => proc { search_actions },
|
128
|
+
:desc => "Search actions", :group => :search },
|
250
129
|
|
130
|
+
:quit => { :proc => proc { _quit },
|
131
|
+
:desc => "Quit", :group => :app },
|
251
132
|
|
252
|
-
|
253
|
-
default_keys = {
|
133
|
+
}
|
254
134
|
|
255
|
-
|
256
|
-
|
257
|
-
|
135
|
+
for k, v in act_list
|
136
|
+
reg_act(k, v[:proc], v[:desc])
|
137
|
+
end
|
138
|
+
|
139
|
+
act_list_todo = {
|
258
140
|
|
259
141
|
# Buffer handling
|
260
|
-
|
261
|
-
|
142
|
+
# : => {proc => proc {bufs.switch}, :desc => "", :group => :},
|
143
|
+
:buf_switch_to_last => { :proc => proc { bufs.switch_to_last_buf },
|
144
|
+
:desc => "", :group => :file },
|
262
145
|
# 'C , s'=> 'gui_select_buffer',
|
263
|
-
|
264
|
-
|
146
|
+
:buf_revert => { :proc => proc { buf.revert },
|
147
|
+
:desc => "Reload/revert file from disk", :group => :file },
|
148
|
+
:buf_close => { :proc => proc { bufs.close_current_buffer },
|
149
|
+
:desc => "Close current file", :group => :file },
|
265
150
|
#"C , b" => '$kbd.set_mode("S");gui_select_buffer',
|
266
|
-
"C , n b" => "create_new_file()",
|
267
|
-
"C , ." => "buf.backup()",
|
268
|
-
# "C , , ." => "backup_all_buffers()",
|
269
|
-
"VC , , s" => "search_actions()",
|
270
151
|
|
271
152
|
|
272
153
|
# MOVING
|
273
154
|
# 'VC h' => 'buf.move(BACKWARD_CHAR)',
|
274
|
-
|
155
|
+
:m_forward_char => { :proc => proc { buf.move(FORWARD_CHAR) },
|
156
|
+
:desc => "Move cursor one char forward",
|
157
|
+
:group => :move },
|
275
158
|
"VC j" => "buf.move(FORWARD_LINE)",
|
276
159
|
"VC k" => "buf.move(BACKWARD_LINE)",
|
277
160
|
|
@@ -291,7 +174,7 @@ default_keys = {
|
|
291
174
|
"VC F <char>" => "buf.jump_to_next_instance_of_char(<char>,BACKWARD)",
|
292
175
|
"VC f space" => "buf.jump_to_next_instance_of_char(' ')",
|
293
176
|
"VC F space" => "buf.jump_to_next_instance_of_char(' ',BACKWARD)",
|
294
|
-
|
177
|
+
|
295
178
|
"VC /[1-9]/" => "set_next_command_count(<char>)",
|
296
179
|
# 'VC number=/[0-9]/+ g'=> 'jump_to_line(<number>)',
|
297
180
|
# 'VC X=/[0-9]/+ * Y=/[0-9]/+ '=> 'x_times_y(<X>,<Y>)',
|
@@ -346,7 +229,6 @@ default_keys = {
|
|
346
229
|
"C /[1-9]/" => "set_next_command_count(<char>)",
|
347
230
|
|
348
231
|
# Command mode only:
|
349
|
-
"C ctrl-r" => "buf.redo()", # TODO:???
|
350
232
|
"C R" => "buf.redo()",
|
351
233
|
"C v" => "buf.start_visual_mode",
|
352
234
|
"C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
|
@@ -380,7 +262,7 @@ default_keys = {
|
|
380
262
|
# Visual mode only:
|
381
263
|
"V esc" => "buf.end_visual_mode",
|
382
264
|
"V ctrl!" => "buf.end_visual_mode",
|
383
|
-
"V y" => "buf.copy_active_selection",
|
265
|
+
"V y" => "buf.copy_active_selection(:foo)",
|
384
266
|
"V g U" => "buf.transform_selection(:upcase)",
|
385
267
|
"V g u" => "buf.transform_selection(:downcase)",
|
386
268
|
"V g c" => "buf.transform_selection(:capitalize)",
|
@@ -405,20 +287,19 @@ default_keys = {
|
|
405
287
|
# Macros
|
406
288
|
# (experimental, may not work correctly)
|
407
289
|
# "C q a" => '$macro.start_recording("a")',
|
408
|
-
"VC q <char>" =>
|
290
|
+
"VC q <char>" => "$macro.start_recording(<char>)",
|
409
291
|
"VC q($macro.is_recording==true) " => "$macro.end_recording", # TODO
|
410
292
|
# 'C q'=> '$macro.end_recording', #TODO
|
411
293
|
"C q v" => "$macro.end_recording",
|
412
294
|
# 'C v'=> '$macro.end_recording',
|
413
295
|
# "C M" => '$macro.run_last_macro',
|
414
|
-
"C @ <char>" =>
|
296
|
+
"C @ <char>" => "$macro.run_macro(<char>)",
|
415
297
|
"C , m S" => '$macro.save_macro("a")',
|
416
|
-
"C , m s" =>
|
298
|
+
"C , m s" => "$macro.save",
|
417
299
|
"C , t r" => "run_tests()",
|
418
300
|
|
419
301
|
"C ." => "repeat_last_action", # TODO
|
420
302
|
"VC ;" => "repeat_last_find",
|
421
|
-
"CV Q" => "_quit",
|
422
303
|
"CV ctrl-q" => "_quit",
|
423
304
|
"CV , R" => "restart_application",
|
424
305
|
"I ctrl!" => "$kbd.set_mode(:command)",
|
@@ -443,6 +324,6 @@ default_keys = {
|
|
443
324
|
# "I return" => 'buf.insert_new_line()',
|
444
325
|
}
|
445
326
|
|
446
|
-
default_keys.each { |key, value|
|
447
|
-
|
448
|
-
}
|
327
|
+
# default_keys.each { |key, value|
|
328
|
+
# bindkey(key, value)
|
329
|
+
# }
|
@@ -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,28 +114,34 @@ 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|
|
116
128
|
parent.children.each { |c|
|
117
129
|
# printf(" KEY MATCH: ")
|
118
|
-
#
|
130
|
+
# debug [c.key_name, key_name].inspect
|
119
131
|
if c.key_name == key_name and c.eval_rule == ""
|
120
132
|
new_state << c
|
121
133
|
elsif c.key_name == key_name and c.eval_rule != ""
|
122
|
-
|
134
|
+
debug "CHECK EVAL: #{c.eval_rule}"
|
123
135
|
if eval(c.eval_rule)
|
124
136
|
new_state << c
|
125
|
-
|
137
|
+
debug "EVAL TRUE"
|
126
138
|
else
|
127
|
-
|
139
|
+
debug "EVAL FALSE"
|
128
140
|
end
|
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
|
@@ -185,7 +195,7 @@ class KeyBindingTree
|
|
185
195
|
end
|
186
196
|
|
187
197
|
@state_trail = [@mode_root_state]
|
188
|
-
#
|
198
|
+
# debug get_state_trail_str()
|
189
199
|
# $next_command_count = nil # TODO: set somewhere else?
|
190
200
|
end
|
191
201
|
|
@@ -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
|
|
@@ -293,20 +305,19 @@ class KeyBindingTree
|
|
293
305
|
|
294
306
|
if new_state != nil
|
295
307
|
@state_trail << new_state
|
296
|
-
|
297
|
-
# #
|
308
|
+
debug get_state_trail_str()
|
309
|
+
# # debug "CUR STATE: #{@state_trail.collect{|x| x.to_s}.join}"
|
298
310
|
# s_trail = ""
|
299
311
|
# for st in @state_trail
|
300
312
|
# st = st[0] if st.class == Array
|
301
313
|
# s_trail << " #{st.to_s}"
|
302
314
|
# end
|
303
|
-
#
|
315
|
+
# debug "CUR STATE: #{s_trail}"
|
304
316
|
# for cstate in new_state[0].children
|
305
317
|
# act_s = "..."
|
306
318
|
# act_s = cstate.action.to_s if cstate.action != nil
|
307
|
-
#
|
319
|
+
# debug " #{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
|
|
@@ -319,7 +330,7 @@ class KeyBindingTree
|
|
319
330
|
end
|
320
331
|
|
321
332
|
if event_type == :key_release and c == "shift!"
|
322
|
-
# Pressing a modifier key (shift)
|
333
|
+
# Pressing a modifier key (shift) sets state back to root
|
323
334
|
# only on key release when no other key has been pressed
|
324
335
|
# after said modifier key (shift).
|
325
336
|
set_state_to_root
|
@@ -328,21 +339,21 @@ 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 }
|
335
346
|
|
336
347
|
if s_act.any? and !state_with_children.any?
|
337
348
|
eval_s = s_act.first.action if eval_s == nil
|
338
|
-
|
339
|
-
|
349
|
+
debug "FOUND MATCH:#{eval_s}"
|
350
|
+
debug "CHAR: #{c}"
|
340
351
|
c.gsub!("\\", %q{\\\\} * 4) # Escape \ -chars
|
341
352
|
c.gsub!("'", "#{'\\' * 4}'") # Escape ' -chars
|
342
353
|
|
343
354
|
eval_s.gsub!("<char>", "'#{c}'") if eval_s.class == String
|
344
|
-
|
345
|
-
|
355
|
+
debug eval_s
|
356
|
+
debug c
|
346
357
|
handle_key_bindigs_action(eval_s, c)
|
347
358
|
set_state_to_root
|
348
359
|
end
|
@@ -354,7 +365,7 @@ class KeyBindingTree
|
|
354
365
|
# Receive keyboard event from Qt
|
355
366
|
def handle_key_event(event)
|
356
367
|
start_profiler
|
357
|
-
#
|
368
|
+
# debug "GOT KEY EVENT: #{key.inspect}"
|
358
369
|
debug "GOT KEY EVENT:: #{event} #{event[2]}"
|
359
370
|
debug "|#{event.inspect}|"
|
360
371
|
$debuginfo["cur_event"] = event
|
@@ -381,11 +392,11 @@ class KeyBindingTree
|
|
381
392
|
end
|
382
393
|
end
|
383
394
|
|
384
|
-
#
|
385
|
-
#
|
386
|
-
#
|
387
|
-
#
|
388
|
-
#
|
395
|
+
# debug "----D------------"
|
396
|
+
# debug @modifiers.inspect
|
397
|
+
# debug event.inspect
|
398
|
+
# debug event[4] & ALTMODIFIER
|
399
|
+
# debug "-----------------"
|
389
400
|
|
390
401
|
@modifiers.delete(keycode) if event_type == KEY_RELEASE
|
391
402
|
|
@@ -411,7 +422,7 @@ class KeyBindingTree
|
|
411
422
|
if $translate_table.include?(keycode)
|
412
423
|
key_str2 = $translate_table[keycode].downcase
|
413
424
|
end
|
414
|
-
#
|
425
|
+
# debug "key_str=|#{key_str}| key_str=|#{key_str.inspect}| key_str2=|#{key_str2}|"
|
415
426
|
prefixed_key_str = key_prefix + key_str2
|
416
427
|
|
417
428
|
# Space is only key in $event_keysym_translate_table
|
@@ -419,7 +430,7 @@ class KeyBindingTree
|
|
419
430
|
key_str = " " if key_str == "space" # HACK
|
420
431
|
|
421
432
|
# if keycode == @last_event[0] and event_type == KEY_RELEASE
|
422
|
-
#
|
433
|
+
# debug "KEY! key_str=|#{key_str}| prefixed_key_str=|#{prefixed_key_str}|"
|
423
434
|
# end
|
424
435
|
|
425
436
|
if key_str != "" or prefixed_key_str != ""
|
@@ -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
|
@@ -474,7 +485,7 @@ class KeyBindingTree
|
|
474
485
|
m = key.match(/^(\S+)\s(\S.*)$/)
|
475
486
|
if m
|
476
487
|
modetmp = m[1]
|
477
|
-
|
488
|
+
debug [key, modetmp, m].inspect
|
478
489
|
modes = modetmp.split("") if modetmp.match(/^\p{Lu}+$/) # Uppercase
|
479
490
|
modes = [modetmp] if modetmp.match(/^\p{Ll}+$/) # Lowercase
|
480
491
|
keydef = m[2]
|
@@ -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
|
|
@@ -556,10 +568,10 @@ class KeyBindingTree
|
|
556
568
|
# debug("NameError with eval cmd #{action}: " + $!.to_s)
|
557
569
|
# raise
|
558
570
|
rescue Exception => e
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
571
|
+
debug "BACKTRACE"
|
572
|
+
debug e.backtrace
|
573
|
+
debug e.inspect
|
574
|
+
debug "BACKTRACE END"
|
563
575
|
if $!.class == SystemExit
|
564
576
|
exit
|
565
577
|
else
|