vimamsa 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,294 @@
1
+
2
+ class VSourceView < GtkSource::View
3
+ def initialize(title = nil)
4
+ # super(:toplevel)
5
+ super()
6
+ puts "vsource init"
7
+ @last_keyval = nil
8
+ @last_event = [nil, nil]
9
+
10
+ signal_connect "button-press-event" do |_widget, event|
11
+ if event.button == Gdk::BUTTON_PRIMARY
12
+ # puts "Gdk::BUTTON_PRIMARY"
13
+ false
14
+ elsif event.button == Gdk::BUTTON_SECONDARY
15
+ # puts "Gdk::BUTTON_SECONDARY"
16
+ true
17
+ else
18
+ true
19
+ end
20
+ end
21
+
22
+ signal_connect("key_press_event") do |widget, event|
23
+ handle_key_event(event, :key_press_event)
24
+ true
25
+ end
26
+
27
+ signal_connect("key_release_event") do |widget, event|
28
+ handle_key_event(event, :key_release_event)
29
+ true
30
+ end
31
+
32
+ signal_connect("move-cursor") do |widget, event|
33
+ $update_cursor = true
34
+ false
35
+ end
36
+
37
+ signal_connect "button-release-event" do |widget, event|
38
+ $buffer.set_pos(buffer.cursor_position)
39
+ false
40
+ end
41
+ @curpos_mark = nil
42
+ end
43
+
44
+ def handle_key_event(event, sig)
45
+ if $update_cursor
46
+ curpos = buffer.cursor_position
47
+ puts "MOVE CURSOR: #{curpos}"
48
+ buf.set_pos(curpos)
49
+ $update_cursor = false
50
+ end
51
+ puts $view.visible_rect.inspect
52
+
53
+ puts "key event"
54
+ puts event
55
+
56
+ key_name = event.string
57
+ if event.state.control_mask?
58
+ key_name = Gdk::Keyval.to_name(event.keyval)
59
+ # Gdk::Keyval.to_name()
60
+ end
61
+
62
+ keyval_trans = {}
63
+ keyval_trans[Gdk::Keyval::KEY_Control_L] = "ctrl"
64
+ keyval_trans[Gdk::Keyval::KEY_Control_R] = "ctrl"
65
+
66
+ keyval_trans[Gdk::Keyval::KEY_Escape] = "esc"
67
+
68
+ keyval_trans[Gdk::Keyval::KEY_Return] = "enter"
69
+ keyval_trans[Gdk::Keyval::KEY_ISO_Enter] = "enter"
70
+ keyval_trans[Gdk::Keyval::KEY_KP_Enter] = "enter"
71
+ keyval_trans[Gdk::Keyval::KEY_Alt_L] = "alt"
72
+ keyval_trans[Gdk::Keyval::KEY_Alt_R] = "alt"
73
+
74
+ keyval_trans[Gdk::Keyval::KEY_BackSpace] = "backspace"
75
+ keyval_trans[Gdk::Keyval::KEY_KP_Page_Down] = "pagedown"
76
+ keyval_trans[Gdk::Keyval::KEY_KP_Page_Up] = "pageup"
77
+ keyval_trans[Gdk::Keyval::KEY_Page_Down] = "pagedown"
78
+ keyval_trans[Gdk::Keyval::KEY_Page_Up] = "pageup"
79
+ keyval_trans[Gdk::Keyval::KEY_Left] = "left"
80
+ keyval_trans[Gdk::Keyval::KEY_Right] = "right"
81
+ keyval_trans[Gdk::Keyval::KEY_Down] = "down"
82
+ keyval_trans[Gdk::Keyval::KEY_Up] = "up"
83
+ keyval_trans[Gdk::Keyval::KEY_space] = "space"
84
+
85
+ keyval_trans[Gdk::Keyval::KEY_Shift_L] = "shift"
86
+ keyval_trans[Gdk::Keyval::KEY_Shift_R] = "shift"
87
+ keyval_trans[Gdk::Keyval::KEY_Tab] = "tab"
88
+
89
+ key_trans = {}
90
+ key_trans["\e"] = "esc"
91
+ tk = keyval_trans[event.keyval]
92
+ key_name = tk if !tk.nil?
93
+
94
+ key_str_parts = []
95
+ key_str_parts << "ctrl" if event.state.control_mask? and key_name != "ctrl"
96
+ key_str_parts << "alt" if event.state.mod1_mask? and key_name != "alt"
97
+
98
+ key_str_parts << key_name
99
+ key_str = key_str_parts.join("-")
100
+ keynfo = { :key_str => key_str, :key_name => key_name, :keyval => event.keyval }
101
+ puts keynfo.inspect
102
+ # $kbd.match_key_conf(key_str, nil, :key_press)
103
+ # puts "key_str=#{key_str} key_"
104
+
105
+ if key_str != "" # or prefixed_key_str != ""
106
+ if sig == :key_release_event and event.keyval == @last_keyval
107
+ $kbd.match_key_conf(key_str + "!", nil, :key_release)
108
+ @last_event = [event, :key_release]
109
+ elsif sig == :key_press_event
110
+ $kbd.match_key_conf(key_str, nil, :key_press)
111
+ @last_event = [event, key_str, :key_press]
112
+ end
113
+ @last_keyval = event.keyval #TODO: outside if?
114
+ end
115
+
116
+ handle_deltas
117
+
118
+ # set_focus(5)
119
+ # false
120
+
121
+ end
122
+
123
+ def pos_to_coord(i)
124
+ b = buffer
125
+ iter = b.get_iter_at(:offset => i)
126
+ iterxy = get_iter_location(iter)
127
+ winw = parent_window.width
128
+ view_width = visible_rect.width
129
+ gutter_width = winw - view_width
130
+
131
+ x = iterxy.x + gutter_width
132
+ y = iterxy.y
133
+
134
+ # buffer_to_window_coords(Gtk::TextWindowType::TEXT, iterxy.x, iterxy.y).inspect
135
+ # puts buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
136
+ (x, y) = buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y)
137
+ # Ripl.start :binding => binding
138
+
139
+ return [x, y]
140
+ end
141
+
142
+ def handle_deltas()
143
+ any_change = false
144
+ while d = buf.deltas.shift
145
+ any_change = true
146
+ pos = d[0]
147
+ op = d[1]
148
+ num = d[2]
149
+ txt = d[3]
150
+ if op == DELETE
151
+ startiter = buffer.get_iter_at(:offset => pos)
152
+ enditer = buffer.get_iter_at(:offset => pos + num)
153
+ buffer.delete(startiter, enditer)
154
+ elsif op == INSERT
155
+ startiter = buffer.get_iter_at(:offset => pos)
156
+ buffer.insert(startiter, txt)
157
+ end
158
+ end
159
+ if any_change
160
+ gui_set_cursor_pos($buffer.id, $buffer.pos) #TODO: only when necessary
161
+ end
162
+
163
+ # sanity_check #TODO
164
+ end
165
+
166
+ def sanity_check()
167
+ a = buffer.text
168
+ b = buf.to_s
169
+ # puts "===================="
170
+ # puts a.lines[0..10].join()
171
+ # puts "===================="
172
+ # puts b.lines[0..10].join()
173
+ # puts "===================="
174
+ if a == b
175
+ puts "Buffers match"
176
+ else
177
+ puts "ERROR: Buffer's don't match."
178
+ end
179
+ end
180
+
181
+ def set_cursor_pos(pos)
182
+ # return
183
+ itr = buffer.get_iter_at(:offset => pos)
184
+ itr2 = buffer.get_iter_at(:offset => pos + 1)
185
+ buffer.place_cursor(itr)
186
+
187
+ # $view.signal_emit("extend-selection", Gtk::MovementStep.new(:PAGES), -1, false)
188
+
189
+ within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
190
+ use_align = false
191
+ xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
192
+ yalign = 0.5
193
+
194
+ if @curpos_mark.nil?
195
+ @curpos_mark = buffer.create_mark("cursor", itr, false)
196
+ else
197
+ buffer.move_mark(@curpos_mark, itr)
198
+ end
199
+ scroll_to_mark(@curpos_mark, within_margin, use_align, xalign, yalign)
200
+ $idle_scroll_to_mark = true
201
+ ensure_cursor_visible
202
+
203
+ # scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
204
+
205
+ # $view.signal_emit("extend-selection", Gtk::TextExtendSelection.new, itr,itr,itr2)
206
+ # Ripl.start :binding => binding
207
+ draw_cursor
208
+
209
+ return true
210
+ end
211
+
212
+ def cursor_visible_idle_func
213
+ puts "cursor_visible_idle_func"
214
+ # From https://picheta.me/articles/2013/08/gtk-plus--a-method-to-guarantee-scrolling.html
215
+ # vr = visible_rect
216
+
217
+ # b = $view.buffer
218
+ # iter = buffer.get_iter_at(:offset => buffer.cursor_position)
219
+ # iterxy = get_iter_location(iter)
220
+
221
+ sleep(0.01)
222
+ # intr = iterxy.intersect(vr)
223
+ if is_cursor_visible == false
224
+ # set_cursor_pos(buffer.cursor_position)
225
+
226
+ itr = buffer.get_iter_at(:offset => buffer.cursor_position)
227
+
228
+ within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
229
+ use_align = false
230
+ xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
231
+ yalign = 0.5
232
+
233
+ scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
234
+
235
+ # return true # Call this func again
236
+ else
237
+ return false # Don't call this idle func again
238
+ end
239
+ end
240
+
241
+ def is_cursor_visible
242
+ vr = visible_rect
243
+ iter = buffer.get_iter_at(:offset => buffer.cursor_position)
244
+ iterxy = get_iter_location(iter)
245
+ iterxy.width = 1 if iterxy.width == 0
246
+ iterxy.height = 1 if iterxy.height == 0
247
+
248
+ intr = iterxy.intersect(vr)
249
+ if intr.nil?
250
+ puts iterxy.inspect
251
+ puts vr.inspect
252
+ # Ripl.start :binding => binding
253
+
254
+ # exit!
255
+ return false
256
+ else
257
+ return true
258
+ end
259
+ end
260
+
261
+ def ensure_cursor_visible
262
+ if is_cursor_visible == false
263
+ Thread.new {
264
+ sleep 0.01
265
+ GLib::Idle.add(proc { cursor_visible_idle_func })
266
+ }
267
+ end
268
+ end
269
+
270
+ def draw_cursor
271
+ if is_command_mode
272
+ itr = buffer.get_iter_at(:offset => buf.pos)
273
+ itr2 = buffer.get_iter_at(:offset => buf.pos + 1)
274
+ $view.buffer.select_range(itr, itr2)
275
+ elsif buf.visual_mode?
276
+ puts "VISUAL MODE"
277
+ (_start, _end) = buf.get_visual_mode_range2
278
+ puts "#{_start}, #{_end}"
279
+ itr = buffer.get_iter_at(:offset => _start)
280
+ itr2 = buffer.get_iter_at(:offset => _end + 1)
281
+ $view.buffer.select_range(itr, itr2)
282
+ else # Insert mode
283
+ itr = buffer.get_iter_at(:offset => buf.pos)
284
+ $view.buffer.select_range(itr, itr)
285
+ puts "INSERT MODE"
286
+ end
287
+ end
288
+
289
+ # def quit
290
+ # destroy
291
+ # true
292
+ # end
293
+ end
294
+
@@ -1,4 +1,3 @@
1
-
2
1
  def e_move_forward_char
3
2
  buf.move(FORWARD_CHAR)
4
3
  end
@@ -29,249 +28,127 @@ 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
+ reg_act(:easy_jump, proc { EasyJump.start }, "Easy jump")
32
+ reg_act(:savedebug, "savedebug", "Save debug info", { :group => :debug })
33
+ reg_act(:open_file_dialog, "open_file_dialog", "Open file", { :group => :file })
34
+ reg_act(:create_new_file, "create_new_file", "Create new file", { :group => :file })
35
+ reg_act(:backup_all_buffers, proc{backup_all_buffers}, "Backup all buffers", { :group => :file })
36
+ reg_act(:e_move_forward_char, "e_move_forward_char", "", { :group => :move })
37
+ reg_act(:e_move_backward_char, "e_move_backward_char", "", { :group => :move })
38
+ reg_act(:history_switch_backwards, "history_switch_backwards", "", { :group => :file })
39
+ reg_act(:history_switch_forwards, "history_switch_forwards", "", { :group => :file })
40
+ reg_act(:center_on_current_line, "center_on_current_line", "", { :group => :view })
41
+ reg_act(:run_last_macro, proc { $macro.run_last_macro }, "Run last recorded or executed macro", { :group => :macro })
59
42
  reg_act(:jump_to_next_edit, "jump_to_next_edit", "")
60
43
  reg_act(:jump_to_last_edit, proc { buf.jump_to_last_edit }, "")
61
-
62
-
63
44
  reg_act(:jump_to_random, proc { buf.jump_to_random_pos }, "")
64
- bindkey "C , j r", :jump_to_random
65
-
66
- reg_act(:insert_new_line, proc { buf.insert_new_line()}, "")
67
- bindkey "I enter", :insert_new_line
68
-
45
+ reg_act(:insert_new_line, proc { buf.insert_new_line() }, "")
69
46
  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
47
  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
48
  # reg_act(:encrypt_file, proc{buf.set_encrypted},"Set current file to encrypt on save")
76
49
  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
50
  reg_act(:set_unencrypted, proc { buf.set_unencrypted }, "Set current file to save unencrypted")
80
- bindkey "C , ; u", :set_unencrypted #TODO: better binding
81
-
82
- reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
83
-
51
+ reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
84
52
  reg_act(:close_current_buffer, proc { bufs.close_current_buffer(true) }, "Close current buffer")
85
- bindkey "C , c b", :close_current_buffer
86
-
87
53
  reg_act(:comment_selection, proc { buf.comment_selection }, "")
88
- bindkey "V ctrl-c", :comment_selection
89
-
90
54
  reg_act(:delete_char_forward, proc { buf.delete(CURRENT_CHAR_FORWARD) }, "Delete char forward")
91
- bindkey "C x", :delete_char_forward
92
-
93
55
  reg_act(:load_theme, proc { load_theme }, "Load theme")
94
- bindkey "C , , l t", :load_theme
95
-
96
56
  reg_act(:gui_file_finder, proc { vma.FileFinder.start_gui }, "Fuzzy file finder")
97
- bindkey "C , f", :gui_file_finder
98
-
99
-
100
57
  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
58
  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
59
  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
60
  reg_act(:set_style_link, proc { buf.style_transform(:link) }, "Set text as link")
112
- bindkey "V , t l", :set_style_link
113
-
114
61
  reg_act(:V_join_lines, proc { vma.buf.convert_selected_text(:joinlines) }, "Join lines")
115
- bindkey "V J", :V_join_lines
116
-
117
-
118
62
  reg_act(:clear_formats, proc { buf.style_transform(:clear) }, "Clear style formats")
119
- bindkey "V , t c", :clear_formats
120
-
121
63
  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
64
  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
65
  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
66
  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
67
  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
68
  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
69
  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
70
  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
71
  reg_act(:gui_select_buffer, proc { $kbd.set_mode("S"); gui_select_buffer }, "Select buffer")
144
- bindkey "C , b", :gui_select_buffer
145
-
146
72
  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
73
  reg_act :minibuffer_end, proc { minibuffer_end }
151
- bindkey "M enter", :minibuffer_end
152
-
153
74
  reg_act(:invoke_replace, "invoke_replace", "")
154
75
  reg_act(:diff_buffer, "diff_buffer", "")
155
-
156
76
  # reg_act(:invoke_grep_search, proc{invoke_grep_search}, "")
157
77
  reg_act(:invoke_grep_search, proc { gui_grep }, "Grep current buffer")
158
-
159
-
160
78
  reg_act(:ack_search, proc { gui_ack }, "") #invoke_ack_search
161
- bindkey "C , a", :ack_search
162
-
163
79
  reg_act :update_file_index, proc { update_file_index }, "Update file index"
164
-
165
-
166
80
  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
81
  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
82
  reg_act :start_browse_mode, proc { $kbd.set_mode(:browse); $kbd.set_default_mode(:browse) }, "Start browse mode"
186
-
187
- reg_act :exit_browse_mode, proc { bufs.add_current_buf_to_history();$kbd.set_mode(:command); $kbd.set_default_mode(:command)
83
+ reg_act :exit_browse_mode, proc {
84
+ bufs.add_current_buf_to_history(); $kbd.set_mode(:command); $kbd.set_default_mode(:command)
188
85
  }, "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
86
 
87
+ reg_act :page_down, proc { page_down }
88
+ reg_act :page_up, proc { page_up }
89
+ reg_act :jump_to_start_of_buffer, proc { buf.jump(START_OF_BUFFER) }, "Jump to start of buffer"
90
+ reg_act :jump_to_end_of_buffer, proc { buf.jump(END_OF_BUFFER) }, "Jump to end of buffer"
214
91
  reg_act(:auto_indent_buffer, proc { buf.indent }, "Auto format buffer")
215
- bindkey "C , v", :auto_indent_buffer
216
- bindkey "C , , d", :savedebug
217
- bindkey "C , , u", :update_file_index
218
-
219
- bindkey "C , s a", "buf.save_as()"
220
-
221
-
222
-
223
92
  reg_act(:execute_current_line_in_terminal, proc { buf.execute_current_line_in_terminal }, "Execute current line in terminal")
224
-
225
93
  reg_act(:show_images, proc { hpt_scan_images() }, "Show images inserted with ⟦img:file.png⟧ syntax")
226
-
227
94
  reg_act(:delete_current_file, proc { bufs.delete_current_buffer() }, "Delete current file")
228
95
 
96
+ act_list = {
97
+ # File handling
98
+ :buf_save => { :proc => proc { buf.save },
99
+ :desc => "Save buffer", :group => :file },
229
100
 
230
- bindkey "C d d", [:delete_line, proc{buf.delete_line}, "Delete current line"]
231
- bindkey "C enter || C return", [:line_action,proc{buf.handle_line_action()}, "Line action"]
232
- bindkey "C p" , [:paste_after,proc{buf.paste(AFTER)},""] # TODO: implement as replace for visual mode
233
- bindkey "V d" , [:delete_selection,proc{buf.delete(SELECTION)},""]
101
+ :buf_save_as => { :proc => proc { buf.save_as },
102
+ :desc => "Save file as", :group => :file },
103
+ :buf_new => { :proc => proc { create_new_file() }, :desc => "Create a new file", :group => :file },
104
+ :buf_revert => { :proc => proc { buf.revert },
105
+ :desc => "Reload file from disk", :group => :file },
106
+ :buf_backup => { :proc => proc { buf.backup() }, :desc => "Backup current file", :group => :file },
234
107
 
108
+ :edit_redo => { :proc => proc { buf.redo },
109
+ :desc => "Redo edit", :group => :edit },
235
110
 
236
- # reg_act(:start_file_selector, proc { FileSelector.new.run; $kbd.set_mode(:file_exp) }, "File selector")
237
- # bindkey "C , j f", :start_file_selector
238
- # bindkey "C , f", :start_file_selector
111
+ :edit_undo => { :proc => proc { buf.undo },
112
+ :desc => "Undo edit", :group => :edit },
239
113
 
240
- # $kbd.add_minor_mode('fexp', :file_exp, :command)
114
+ :find_in_buffer => { :proc => proc { invoke_search },
115
+ :desc => "Find", :group => :edit },
241
116
 
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
117
 
246
- # bindkey "C , j j", [:mode_file_exp, proc{$kbd.set_mode(:file_exp)}, "fexp"]
118
+ # { :proc => proc { },
119
+ # :desc => "", :group => : },
247
120
 
248
- #bindkey 'C z h', :history_switch_backwards
249
- #bindkey 'C z l', :history_switch_forwards
121
+ :search_actions => { :proc => proc { search_actions },
122
+ :desc => "Search actions", :group => :search },
250
123
 
124
+ :quit => { :proc => proc { _quit },
125
+ :desc => "Quit", :group => :app },
251
126
 
252
- #TODO: Change these evals into proc{}'s
253
- default_keys = {
127
+ }
254
128
 
255
- # File handling
256
- "C ctrl-s" => "buf.save",
257
- "C W" => "buf.save",
129
+ for k, v in act_list
130
+ reg_act(k, v[:proc], v[:desc])
131
+ end
132
+
133
+ act_list_todo = {
258
134
 
259
135
  # Buffer handling
260
- "C B" => "bufs.switch",
261
- "C tab" => "bufs.switch_to_last_buf",
136
+ # : => {proc => proc {bufs.switch}, :desc => "", :group => :},
137
+ :buf_switch_to_last => { :proc => proc { bufs.switch_to_last_buf },
138
+ :desc => "", :group => :file },
262
139
  # 'C , s'=> 'gui_select_buffer',
263
- "C , r v b" => "buf.revert",
264
- "C , c b" => "bufs.close_current_buffer",
140
+ :buf_revert => { :proc => proc { buf.revert },
141
+ :desc => "Reload/revert file from disk", :group => :file },
142
+ :buf_close => { :proc => proc { bufs.close_current_buffer },
143
+ :desc => "Close current file", :group => :file },
265
144
  #"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
145
 
271
146
 
272
147
  # MOVING
273
148
  # 'VC h' => 'buf.move(BACKWARD_CHAR)',
274
- "VC l" => "buf.move(FORWARD_CHAR)",
149
+ :m_forward_char => { :proc => proc { buf.move(FORWARD_CHAR) },
150
+ :desc => "Move cursor one char forward",
151
+ :group => :move },
275
152
  "VC j" => "buf.move(FORWARD_LINE)",
276
153
  "VC k" => "buf.move(BACKWARD_LINE)",
277
154
 
@@ -289,6 +166,9 @@ default_keys = {
289
166
  # 'C '=> 'buf.jump_word(BACKWARD,END)',#TODO
290
167
  "VC f <char>" => "buf.jump_to_next_instance_of_char(<char>)",
291
168
  "VC F <char>" => "buf.jump_to_next_instance_of_char(<char>,BACKWARD)",
169
+ "VC f space" => "buf.jump_to_next_instance_of_char(' ')",
170
+ "VC F space" => "buf.jump_to_next_instance_of_char(' ',BACKWARD)",
171
+
292
172
  "VC /[1-9]/" => "set_next_command_count(<char>)",
293
173
  # 'VC number=/[0-9]/+ g'=> 'jump_to_line(<number>)',
294
174
  # 'VC X=/[0-9]/+ * Y=/[0-9]/+ '=> 'x_times_y(<X>,<Y>)',
@@ -343,7 +223,6 @@ default_keys = {
343
223
  "C /[1-9]/" => "set_next_command_count(<char>)",
344
224
 
345
225
  # Command mode only:
346
- "C ctrl-r" => "buf.redo()", # TODO:???
347
226
  "C R" => "buf.redo()",
348
227
  "C v" => "buf.start_visual_mode",
349
228
  "C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
@@ -402,20 +281,19 @@ default_keys = {
402
281
  # Macros
403
282
  # (experimental, may not work correctly)
404
283
  # "C q a" => '$macro.start_recording("a")',
405
- "VC q <char>" => '$macro.start_recording(<char>)',
284
+ "VC q <char>" => "$macro.start_recording(<char>)",
406
285
  "VC q($macro.is_recording==true) " => "$macro.end_recording", # TODO
407
286
  # 'C q'=> '$macro.end_recording', #TODO
408
287
  "C q v" => "$macro.end_recording",
409
288
  # 'C v'=> '$macro.end_recording',
410
289
  # "C M" => '$macro.run_last_macro',
411
- "C @ <char>" => '$macro.run_macro(<char>)',
290
+ "C @ <char>" => "$macro.run_macro(<char>)",
412
291
  "C , m S" => '$macro.save_macro("a")',
413
- "C , m s" => '$macro.save',
292
+ "C , m s" => "$macro.save",
414
293
  "C , t r" => "run_tests()",
415
294
 
416
295
  "C ." => "repeat_last_action", # TODO
417
296
  "VC ;" => "repeat_last_find",
418
- "CV Q" => "_quit",
419
297
  "CV ctrl-q" => "_quit",
420
298
  "CV , R" => "restart_application",
421
299
  "I ctrl!" => "$kbd.set_mode(:command)",
@@ -435,11 +313,11 @@ default_keys = {
435
313
  "I alt-f" => "buf.jump_word(FORWARD,WORD_START)",
436
314
  "I alt-b" => "buf.jump_word(BACKWARD,WORD_START)",
437
315
 
438
- "I tab" => 'buf.insert_txt(" ")',
316
+ "I tab" => 'buf.insert_txt(" ")',
439
317
  "I space" => 'buf.insert_txt(" ")',
440
318
  # "I return" => 'buf.insert_new_line()',
441
319
  }
442
320
 
443
- default_keys.each { |key, value|
444
- bindkey(key, value)
445
- }
321
+ # default_keys.each { |key, value|
322
+ # bindkey(key, value)
323
+ # }