vimamsa 0.1.13 → 0.1.15

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/custom_example.rb +12 -0
  3. data/lib/vimamsa/ack.rb +3 -4
  4. data/lib/vimamsa/actions.rb +1 -2
  5. data/lib/vimamsa/audio.rb +25 -1
  6. data/lib/vimamsa/buffer.rb +116 -591
  7. data/lib/vimamsa/buffer_changetext.rb +272 -0
  8. data/lib/vimamsa/buffer_cursor.rb +303 -0
  9. data/lib/vimamsa/buffer_list.rb +137 -133
  10. data/lib/vimamsa/buffer_manager.rb +15 -15
  11. data/lib/vimamsa/clipboard.rb +36 -0
  12. data/lib/vimamsa/conf.rb +136 -5
  13. data/lib/vimamsa/constants.rb +0 -10
  14. data/lib/vimamsa/debug.rb +9 -8
  15. data/lib/vimamsa/editor.rb +57 -84
  16. data/lib/vimamsa/encrypt.rb +6 -11
  17. data/lib/vimamsa/file_history.rb +0 -8
  18. data/lib/vimamsa/file_manager.rb +142 -10
  19. data/lib/vimamsa/gui.rb +106 -85
  20. data/lib/vimamsa/gui_dialog.rb +113 -0
  21. data/lib/vimamsa/gui_menu.rb +5 -1
  22. data/lib/vimamsa/gui_sourceview.rb +46 -29
  23. data/lib/vimamsa/gui_sourceview_autocomplete.rb +141 -0
  24. data/lib/vimamsa/gui_text.rb +49 -0
  25. data/lib/vimamsa/hyper_plain_text.rb +19 -5
  26. data/lib/vimamsa/key_actions.rb +41 -202
  27. data/lib/vimamsa/key_binding_tree.rb +129 -41
  28. data/lib/vimamsa/key_bindings_vimlike.rb +58 -48
  29. data/lib/vimamsa/langservp.rb +23 -3
  30. data/lib/vimamsa/macro.rb +35 -25
  31. data/lib/vimamsa/main.rb +7 -10
  32. data/lib/vimamsa/rbvma.rb +13 -11
  33. data/lib/vimamsa/search.rb +1 -1
  34. data/lib/vimamsa/search_replace.rb +106 -160
  35. data/lib/vimamsa/terminal.rb +34 -0
  36. data/lib/vimamsa/tests.rb +122 -0
  37. data/lib/vimamsa/util.rb +43 -4
  38. data/lib/vimamsa/version.rb +1 -1
  39. data/vimamsa.gemspec +5 -2
  40. metadata +59 -9
  41. /data/lib/vimamsa/{form_generator.rb → gui_form_generator.rb} +0 -0
@@ -18,31 +18,18 @@
18
18
  # 'I ctrl-a'=> 'vma.buf.jump(BEGINNING_OF_LINE)',
19
19
  #
20
20
 
21
- $cnf = {} # TODO
22
-
23
- def conf(id)
24
- return $cnf[id]
25
- end
26
-
27
- def set_conf(id, val)
28
- $cnf[id] = val
29
- end
30
-
31
- def setcnf(id, val)
32
- set_conf(id, val)
33
- end
34
-
35
21
  setcnf :indent_based_on_last_line, true
36
22
  setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc", ".php", ".sh", ".m", ".gd", ".js"]
37
23
 
38
24
  class State
39
25
  attr_accessor :key_name, :eval_rule, :children, :action, :label, :major_modes, :level, :cursor_type
40
- attr_reader :cur_mode
26
+ attr_reader :cur_mode, :scope
41
27
 
42
- def initialize(key_name, eval_rule = "", ctype = :command)
28
+ def initialize(key_name, eval_rule = "", ctype = :command, scope: :buffer)
43
29
  @key_name = key_name
44
30
  @eval_rule = eval_rule
45
31
  @children = []
32
+ @scope = scope
46
33
  @major_modes = []
47
34
  @action = nil
48
35
  @level = 0
@@ -55,18 +42,21 @@ class State
55
42
  end
56
43
 
57
44
  class KeyBindingTree
58
- attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action, :modifiers
59
- attr_reader :mode_root_state, :state_trail, :act_bindings
45
+ attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action, :modifiers, :next_command_count, :method_handles_repeat, :default_mode
46
+ attr_reader :mode_root_state, :state_trail, :act_bindings, :default_mode_stack
60
47
 
61
48
  def initialize()
49
+ @next_command_count = nil
62
50
  @modes = {}
63
51
  @root = State.new("ROOT")
64
52
  @cur_state = @root # used for building the tree
65
53
  @default_mode = nil
54
+ @default_mode_stack = []
66
55
  @mode_history = []
67
56
  @state_trail = []
68
57
  @last_action = nil
69
58
  @cur_action = nil
59
+ @method_handles_repeat = false
70
60
 
71
61
  @modifiers = { :ctrl => false, :shift => false, :alt => false } # TODO: create a queue
72
62
  @last_event = [nil, nil, nil, nil, nil]
@@ -76,18 +66,62 @@ class KeyBindingTree
76
66
  @act_bindings = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
77
67
  end
78
68
 
79
- def set_default_mode(label)
69
+ def set_mode(label)
80
70
  @match_state = [@modes[label]] # used for matching input
81
71
  @mode_root_state = @modes[label]
72
+ # @default_mode = label
73
+ @default_mode_stack << label
74
+
75
+ __set_mode(label)
76
+ if !vma.buf.nil?
77
+ # vma.buf.mode_stack = @default_mode_stack.clone
78
+ end
79
+ end
80
+
81
+ def set_default_mode(label)
82
+ @match_state = [@modes[label]]
83
+ @mode_root_state = @modes[label]
82
84
  @default_mode = label
85
+ set_mode_stack [label]
86
+ end
87
+
88
+ def set_mode_stack(ms)
89
+ debug "set_mode_stack(#{ms})", 2
90
+ show_caller if cnf.debug? # TODO: remove
91
+ @default_mode_stack = ms
92
+ label = @default_mode_stack[-1]
93
+ @match_state = [@modes[label]]
94
+ @mode_root_state = @modes[label]
95
+ end
96
+
97
+ def dump_state
98
+ debug "dump_state", 2
99
+ pp ["@default_mode_stack", @default_mode_stack]
100
+ pp ["@default_mode", @default_mode]
101
+ pp ["vma.buf.mode_stack", vma.buf.mode_stack]
102
+ pp ["scope", self.get_scope]
103
+ # pp ["@mode_root_state", @mode_root_state]
104
+ # pp ["@match_state", @match_state]
83
105
  end
84
106
 
85
107
  def set_mode_to_default()
86
- set_mode(@default_mode)
108
+ # set_mode(@default_mode)
109
+ set_mode_stack [@default_mode_stack[0]]
110
+ __set_mode(@default_mode_stack[0])
87
111
  end
88
112
 
89
- def add_mode(id, label, cursortype = :command, name: nil)
90
- mode = State.new(id, "", cursortype)
113
+ def to_previous_mode()
114
+ debug "to_previous_mode",2
115
+ pp @default_mode_stack
116
+ if @default_mode_stack.size > 1
117
+ @default_mode_stack.pop
118
+ end
119
+ pp @default_mode_stack
120
+ __set_mode(@default_mode_stack[-1])
121
+ end
122
+
123
+ def add_mode(id, label, cursortype = :command, name: nil, scope: :buffer)
124
+ mode = State.new(id, "", cursortype, scope: scope)
91
125
  mode.level = 1
92
126
  @modes[label] = mode
93
127
  @root.children << mode
@@ -100,6 +134,10 @@ class KeyBindingTree
100
134
  def add_minor_mode(id, label, major_mode_label)
101
135
  mode = State.new(id)
102
136
  @modes[label] = mode
137
+ if @root.nil?
138
+ show_caller
139
+ Ripl.start :binding => binding
140
+ end
103
141
  @root.children << mode
104
142
  mode.major_modes << major_mode_label
105
143
  end
@@ -161,7 +199,8 @@ class KeyBindingTree
161
199
  vma.gui.statnfo.markup = "<span weight='ultrabold'>#{st}</span>"
162
200
  end
163
201
 
164
- def set_mode(label)
202
+ def __set_mode(label)
203
+ debug "__set_mode(#{label})"
165
204
  @mode_history << @mode_root_state
166
205
 
167
206
  # Check if label in form :label
@@ -178,13 +217,19 @@ class KeyBindingTree
178
217
  end
179
218
  @cur_mode = label
180
219
 
220
+ if self.get_scope != :editor and !vma.buf.nil?
221
+ vma.buf.mode_stack = @default_mode_stack.clone
222
+ end
223
+
181
224
  if !vma.gui.view.nil?
182
225
  vma.gui.view.draw_cursor() #TODO: handle outside this class
183
-
184
- # Ripl.start :binding => binding
185
226
  end
186
227
  end
187
228
 
229
+ def get_scope
230
+ @mode_root_state.scope
231
+ end
232
+
188
233
  def cur_mode_str()
189
234
  return @mode_root_state.key_name
190
235
  end
@@ -220,6 +265,7 @@ class KeyBindingTree
220
265
 
221
266
  # Print key bindings to show as documentation or for debugging
222
267
  def to_s()
268
+ # return self.class.to_s
223
269
  s = ""
224
270
  # @cur_state = @root
225
271
  stack = [[@root, ""]]
@@ -284,9 +330,21 @@ class KeyBindingTree
284
330
  act_s = cstate.action.to_s if cstate.action != nil
285
331
  children << " #{cstate.to_s} #{act_s}\n"
286
332
  end
333
+ if !@next_command_count.nil?
334
+ s_trail << " #{@next_command_count}"
335
+ end
287
336
  return [s_trail, children]
288
337
  end
289
338
 
339
+ def set_next_command_count(num)
340
+ if @next_command_count != nil
341
+ @next_command_count = @next_command_count * 10 + num.to_i
342
+ else
343
+ @next_command_count = num.to_i
344
+ end
345
+ debug("NEXT COMMAND COUNT: #{@next_command_count}")
346
+ end
347
+
290
348
  # Modifies state of key binding tree (move to new state) based on received event
291
349
  # Checks child nodes of current state if they match received event
292
350
  # if yes, change state to child
@@ -354,7 +412,7 @@ class KeyBindingTree
354
412
  if event_type == :key_press and c != "shift"
355
413
  # TODO:include other modifiers in addition to shift?
356
414
  set_state_to_root
357
- printf(", BACK TO ROOT") if $debug
415
+ printf(", BACK TO ROOT") if cnf.debug?
358
416
  end
359
417
 
360
418
  if event_type == :key_release and c == "shift!"
@@ -362,10 +420,10 @@ class KeyBindingTree
362
420
  # only on key release when no other key has been pressed
363
421
  # after said modifier key (shift).
364
422
  set_state_to_root
365
- printf(", BACK TO ROOT") if $debug
423
+ printf(", BACK TO ROOT") if cnf.debug?
366
424
  end
367
425
 
368
- printf("\n") if $debug
426
+ printf("\n") if cnf.debug?
369
427
  else
370
428
 
371
429
  # Don't execute action if one of the states has children
@@ -394,6 +452,8 @@ class KeyBindingTree
394
452
 
395
453
  def bindkey(key, action)
396
454
  if key.class != Array
455
+ # Handle syntax like :
456
+ # "X esc || X ctrl!" => "vma.kbd.to_previous_mode",
397
457
  key = key.split("||")
398
458
  end
399
459
 
@@ -424,10 +484,19 @@ class KeyBindingTree
424
484
  end
425
485
 
426
486
  m = key.match(/^(\S+)\s(\S.*)$/)
487
+ # Match/split e.g. "VC , , s" to "VC" and ", , s"
427
488
  if m
428
489
  modetmp = m[1]
429
490
  debug [key, modetmp, m].inspect
491
+
492
+ # If all of first word are uppercase, e.g. in
493
+ # "VCIX left" => "buf.move(BACKWARD_CHAR)",
494
+ # interpret as each char representing a mode
430
495
  modes = modetmp.split("") if modetmp.match(/^\p{Lu}+$/) # Uppercase
496
+
497
+ # If all of first word is down case, like in:
498
+ # bindkey "audio space", :audio_stop
499
+ # interpret as whole word representing a mode.
431
500
  modes = [modetmp] if modetmp.match(/^\p{Ll}+$/) # Lowercase
432
501
  keydef = m[2]
433
502
  else
@@ -440,7 +509,15 @@ class KeyBindingTree
440
509
  }
441
510
  end
442
511
 
512
+ # Binds a keyboard key combination to an action,
513
+ # for a given keyboard mode like insert ("I") or command ("C")
443
514
  def mode_bind_key(mode_id, keydef, action)
515
+ # debug "mode_bind_key #{mode_id.inspect}, #{keydef.inspect}, #{action.inspect}", 2
516
+ # Example:
517
+ # bindkey "C , f", :gui_file_finder
518
+ # mode_id = "C", keydef = ", f"
519
+ # and action = :gui_file_finder
520
+
444
521
  set_state(mode_id, "") # TODO: check is ok?
445
522
  start_state = @cur_state
446
523
 
@@ -448,23 +525,32 @@ class KeyBindingTree
448
525
 
449
526
  prev_state = nil
450
527
  s1 = start_state
451
- k_arr.each { |i|
528
+
529
+ k_arr.each_with_index { |k, idx|
452
530
  # check if key has rules for context like q has in
453
531
  # "C q(cntx.recording_macro==true)"
454
- match = /(.+)\((.*)\)/.match(i)
532
+ last_item = false
533
+ if k_arr.size - 1 == idx
534
+ last_item = true
535
+ end
536
+ match = /(.+)\((.*)\)/.match(k)
455
537
  eval_rule = ""
456
538
  if match
457
539
  key_name = match[1]
458
540
  eval_rule = match[2]
459
541
  else
460
- key_name = i
542
+ key_name = k
461
543
  end
462
544
 
463
545
  prev_state = s1
464
546
  # Create a new state for key if it doesn't exist
465
547
  s1 = find_state(key_name, eval_rule)
466
- if s1 == nil
548
+ if s1 == nil or last_item
467
549
  new_state = State.new(key_name, eval_rule)
550
+ if last_item
551
+ # Override existing key definition
552
+ @cur_state.children.delete(s1)
553
+ end
468
554
  s1 = new_state
469
555
  @cur_state.children << new_state
470
556
  end
@@ -481,11 +567,10 @@ class KeyBindingTree
481
567
 
482
568
  def handle_key_bindigs_action(action, c)
483
569
  $acth << action
484
- $method_handles_repeat = false #TODO:??
570
+ @method_handles_repeat = false #TODO:??
485
571
  n = 1
486
- if $next_command_count and !(action.class == String and action.include?("set_next_command_count"))
487
- n = $next_command_count
488
- # $next_command_count = nil
572
+ if @next_command_count and !(action.class == String and action.include?("set_next_command_count"))
573
+ n = @next_command_count
489
574
  debug("COUNT command #{n} times")
490
575
  end
491
576
 
@@ -493,15 +578,18 @@ class KeyBindingTree
493
578
  n.times do
494
579
  ret = exec_action(action)
495
580
 
496
- if $macro.is_recording and ret != false
497
- $macro.record_action(action)
581
+ if vma.macro.is_recording and ret != false
582
+ debug "RECORD ACTION:#{action}", 2
583
+ vma.macro.record_action(action)
498
584
  end
499
- break if $method_handles_repeat
585
+ break if @method_handles_repeat
500
586
  # Some methods have specific implementation for repeat,
501
587
  # like '5yy' => copy next five lines. (copy_line())
502
588
  # By default the same command is just repeated n times
503
589
  # like '20j' => go to next line 20 times.
590
+ # But methods can also handle the number input themselves if vma.kbd.method_handles_repeat=true is set,
504
591
  end
592
+ # run_as_idle proc { vma.buf.refresh_cursor; vma.buf.refresh_cursor }, delay: 0.05
505
593
  rescue SyntaxError
506
594
  message("SYNTAX ERROR with eval cmd #{action}: " + $!.to_s)
507
595
  # rescue NoMethodError
@@ -521,8 +609,8 @@ class KeyBindingTree
521
609
  end
522
610
  end
523
611
 
524
- if action.class == String and !action.include?("set_next_command_count")
525
- $next_command_count = nil
612
+ if !(action.class == String and action.include?("set_next_command_count"))
613
+ @next_command_count = nil
526
614
  end
527
615
  end
528
616
  end
@@ -3,21 +3,20 @@ vma.kbd.add_mode("I", :insert, :insert)
3
3
  vma.kbd.add_mode("V", :visual, :visual)
4
4
  vma.kbd.add_mode("M", :minibuffer) #TODO: needed?
5
5
  vma.kbd.add_mode("R", :readchar)
6
- # vma.kbd.add_mode("audio", :audio, :command)
7
6
  vma.kbd.add_minor_mode("audio", :audio, :command)
8
- vma.kbd.add_mode("B", :browse, :command)
7
+ vma.kbd.add_mode("B", :browse, :command, scope: :editor)
9
8
  vma.kbd.add_mode("X", :replace, :command, name: "Replace")
10
9
  vma.kbd.set_default_mode(:command)
11
- vma.kbd.set_mode(:command)
12
- vma.kbd.show_state_trail
10
+ vma.kbd.__set_mode(:command) #TODO:needed?
11
+ # vma.kbd.show_state_trail
12
+
13
13
 
14
14
  bindkey ["VCB M", "B m"], :run_last_macro
15
15
 
16
16
  bindkey "VC s", :easy_jump
17
- bindkey "VC , m f", [:find_macro_gui, proc { $macro.find_macro_gui }, "Find named macro"]
18
- bindkey "C , m n", [:gui_name_macro, proc { $macro.gui_name_macro }, "Name last macro"]
17
+ bindkey "VC , m f", [:find_macro_gui, proc { vma.macro.find_macro_gui }, "Find named macro"]
18
+ bindkey "C , m n", [:gui_name_macro, proc { vma.macro.gui_name_macro }, "Name last macro"]
19
19
  bindkey "C , j r", :jump_to_random
20
- bindkey "I enter", :insert_new_line
21
20
  bindkey "C , ; s k", :show_key_bindings #TODO: better binding
22
21
  bindkey "C , , c b", :put_file_path_to_clipboard #TODO: better binding or remove?
23
22
  bindkey "C , , e", :encrypt_file #TODO: better binding
@@ -52,13 +51,13 @@ bindkey "C , w", :toggle_active_window
52
51
  bindkey "C , , w", :toggle_two_column
53
52
 
54
53
  bindkey "C , u s", :audio_stop
55
- bindkey "C m a", "vma.kbd.set_mode(:audio)"
54
+ bindkey "C , m a", "vma.kbd.set_mode(:audio)"
56
55
  bindkey "audio s", :audio_stop
57
- bindkey "audio space", :audio_stop
58
- bindkey "audio q || audio esc", "vma.kbd.set_mode_to_default"
59
-
60
-
56
+ bindkey "audio f || audio right", [:audio_forward, proc { Audio.seek_forward }, "Seek forward in audio stream"]
57
+ bindkey "audio left", [:audio_backward, proc { Audio.seek_forward(-5.0) }, "Seek backward in audio stream"]
61
58
 
59
+ bindkey "audio space", :audio_stop
60
+ bindkey "audio q || audio esc", "vma.kbd.to_previous_mode"
62
61
 
63
62
  # bindkey "C , f o", :open_file_dialog
64
63
  bindkey "CI ctrl-o", :open_file_dialog
@@ -72,14 +71,16 @@ bindkey "VC h", :e_move_backward_char
72
71
  bindkey "C , , .", :backup_all_buffers
73
72
  bindkey "C z ", :start_browse_mode
74
73
  bindkey "B h", :history_switch_backwards
74
+ # bindkey "B h", [:browse_file_backwards, proc { vma.kbd.to_previous_mode; call_action(:history_switch_backwards); }, "Browse previous file"]
75
75
  bindkey "B l", :history_switch_forwards
76
76
  #bindkey 'B z', :center_on_current_line
77
77
  bindkey "B z", "center_on_current_line();call_action(:exit_browse_mode)"
78
78
  bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
79
79
  bindkey "B s", :page_up
80
80
  bindkey "B d", :page_down
81
- bindkey "B s", :page_up
82
- bindkey "B d", :page_down
81
+ bindkey "B r", proc { vma.gui.page_down(multip:0.25)}
82
+ bindkey "B e", proc { vma.gui.page_up(multip:0.25)}
83
+
83
84
  bindkey "B i", :jump_to_start_of_buffer
84
85
  bindkey "B o", :jump_to_end_of_buffer
85
86
  bindkey "B c", :close_current_buffer
@@ -87,7 +88,6 @@ bindkey "B ;", "buf.jump_to_last_edit"
87
88
  bindkey "B q", :jump_to_last_edit
88
89
  bindkey "B w", :jump_to_next_edit
89
90
  # bindkey "C , d", :diff_buffer
90
- bindkey "C , g", :invoke_grep_search
91
91
  #bindkey 'C , g', proc{invoke_grep_search}
92
92
  bindkey "C , v", :auto_indent_buffer
93
93
  bindkey "C , , d", :savedebug
@@ -105,12 +105,11 @@ default_keys = {
105
105
  "C ctrl-s" => :buf_save,
106
106
 
107
107
  # Buffer handling
108
- "C B" => "bufs.switch",
108
+ # "C B" => "bufs.switch",
109
109
  "C tab" => "bufs.switch_to_last_buf",
110
110
  # 'C , s'=> 'gui_select_buffer',
111
111
  "C , r v b" => :buf_revert,
112
112
  "C , c b" => "bufs.close_current_buffer",
113
- #"C , b" => 'vma.kbd.set_mode("S");gui_select_buffer',
114
113
  "C , n b" => :buf_new,
115
114
  # "C , , ." => "backup_all_buffers()",
116
115
  "VC , , s" => :search_actions,
@@ -118,11 +117,22 @@ default_keys = {
118
117
  # MOVING
119
118
  # 'VC h' => 'buf.move(BACKWARD_CHAR)',
120
119
  "VC l" => "buf.move(FORWARD_CHAR)",
121
- "VC j" => "buf.move(FORWARD_LINE)",
122
- "VC k" => "buf.move(BACKWARD_LINE)",
120
+ # "VC j" => "buf.move(FORWARD_LINE)",
121
+ # "VC k" => "buf.move(BACKWARD_LINE)",
123
122
 
124
- "VC pagedown" => "page_down",
125
- "VC pageup" => "page_up",
123
+ "VC pagedown" => :page_down,
124
+ "VC pageup" => :page_up,
125
+
126
+ "I down(vma.buf.view.autocp_active)" => "vma.buf.view.autocp_select_next",
127
+ "I tab(vma.buf.view.autocp_active)" => "vma.buf.view.autocp_select_next",
128
+ "I up(vma.buf.view.autocp_active)" => "vma.buf.view.autocp_select_previous",
129
+ "I shift-tab(vma.buf.view.autocp_active)" => "vma.buf.view.autocp_select_previous",
130
+ "I enter(vma.buf.view.autocp_active)" => "vma.buf.view.autocp_select",
131
+
132
+ "I tab" => 'buf.insert_tab',
133
+ "I shift-tab" => 'buf.unindent',
134
+
135
+ "I enter" => :insert_new_line,
126
136
 
127
137
  "VCIX left" => "buf.move(BACKWARD_CHAR)",
128
138
  "VCIX right" => "buf.move(FORWARD_CHAR)",
@@ -138,16 +148,16 @@ default_keys = {
138
148
  "VC f space" => "buf.jump_to_next_instance_of_char(' ')",
139
149
  "VC F space" => "buf.jump_to_next_instance_of_char(' ',BACKWARD)",
140
150
 
141
- "VC /[1-9]/" => "set_next_command_count(<char>)",
151
+ "VC /[1-9]/" => "vma.kbd.set_next_command_count(<char>)",
142
152
  # 'VC number=/[0-9]/+ g'=> 'jump_to_line(<number>)',
143
153
  # 'VC X=/[0-9]/+ * Y=/[0-9]/+ '=> 'x_times_y(<X>,<Y>)',
144
- "VC ^" => "buf.jump(BEGINNING_OF_LINE)",
145
- "VC G($next_command_count!=nil)" => "buf.jump_to_line()",
146
- "VC 0($next_command_count!=nil)" => "set_next_command_count(<char>)",
147
- "VC 0($next_command_count==nil)" => "buf.jump(BEGINNING_OF_LINE)",
154
+ "VC G(vma.kbd.next_command_count!=nil)" => "buf.jump_to_line()",
155
+ "VC 0(vma.kbd.next_command_count!=nil)" => "set_next_command_count(<char>)",
156
+ "VC 0(vma.kbd.next_command_count==nil)" => "buf.jump(BEGINNING_OF_LINE)",
148
157
  # 'C 0'=> 'buf.jump(BEGINNING_OF_LINE)',
149
158
  "VC g g" => "buf.jump(START_OF_BUFFER)",
150
159
  "VC g ;" => "buf.jump_to_last_edit",
160
+ "VC ^" => "buf.jump(BEGINNING_OF_LINE)",
151
161
  "VC G" => "buf.jump(END_OF_BUFFER)",
152
162
  # 'VC z z' => 'center_on_current_line',
153
163
  "VC *" => "buf.jump_to_next_instance_of_word",
@@ -173,6 +183,7 @@ default_keys = {
173
183
  "C , d b" => "debug_print_buffer",
174
184
  "C , d c" => "debug_dump_clipboard",
175
185
  "C , d d" => "debug_dump_deltas",
186
+ "C , d m" => :kbd_dump_state,
176
187
 
177
188
  "VC O" => "buf.jump(END_OF_LINE)",
178
189
  "VC $" => "buf.jump(END_OF_LINE)",
@@ -186,11 +197,10 @@ default_keys = {
186
197
  "C u" => "buf.undo()",
187
198
 
188
199
  "C ^" => "buf.jump(BEGINNING_OF_LINE)",
189
- "C /[1-9]/" => "set_next_command_count(<char>)",
200
+ # "C /[1-9]/" => "vma.kbd.set_next_command_count(<char>)",
190
201
 
191
202
  # Command mode only:
192
203
  "C ctrl-r" => "buf.redo()", # TODO:???
193
- "C R" => "buf.redo()",
194
204
  "C v" => "buf.start_visual_mode",
195
205
  "C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
196
206
  "C space <char>" => "buf.insert_txt(<char>)",
@@ -213,7 +223,7 @@ default_keys = {
213
223
  "C r <char>" => "buf.replace_with_char(<char>)", # TODO
214
224
  "C , l b" => "load_buffer_list",
215
225
  "C , l l" => "save_buffer_list",
216
- "C , r <char>" => "set_register(<char>)", # TODO
226
+ "C , r <char>" => "vma.set_register(<char>)", # TODO
217
227
  "C , p <char>" => "buf.paste(BEFORE,<char>)", # TODO
218
228
 
219
229
  "C ctrl-c" => "buf.comment_line()",
@@ -247,30 +257,27 @@ default_keys = {
247
257
  'CV \' <char>' => "buf.jump_to_mark(<char>)",
248
258
  # "CV ''" =>'jump_to_mark(NEXT_MARK)', #TODO
249
259
 
250
- # Switch to other mode
260
+ # Switch to another mode
251
261
  "C i" => "vma.kbd.set_mode(:insert)",
252
262
  "C R" => "vma.kbd.set_mode(:replace)",
253
263
  "C ctrl!" => "vma.kbd.set_mode(:insert)",
254
- "C ctrl!" => "vma.kbd.set_mode(:insert)",
255
264
 
256
-
257
- # "R esc || R ctrl!" => "vma.kbd.set_mode(:command)",
258
- "X esc" => "vma.kbd.set_mode(:command)",
259
- "X ctrl!" => "vma.kbd.set_mode(:command)",
265
+ # Replace mode
266
+ "X esc || X ctrl!" => "vma.kbd.to_previous_mode",
260
267
  "X <char>" => "buf.replace_with_char(<char>);buf.move(FORWARD_CHAR)",
261
268
 
262
269
  # Macros
263
270
  # (experimental, may not work correctly)
264
- # "C q a" => '$macro.start_recording("a")',
265
- "VC q <char>" => "$macro.start_recording(<char>)",
266
- "VC q($macro.is_recording==true) " => "$macro.end_recording", # TODO
267
- # 'C q'=> '$macro.end_recording', #TODO
268
- "C q v" => "$macro.end_recording",
269
- # 'C v'=> '$macro.end_recording',
270
- # "C M" => '$macro.run_last_macro',
271
- "C @ <char>" => "$macro.run_macro(<char>)",
272
- "C , m S" => '$macro.save_macro("a")',
273
- "C , m s" => "$macro.save",
271
+ # "C q a" => 'vma.macro.start_recording("a")',
272
+ "VC q <char>" => "vma.macro.start_recording(<char>)",
273
+ "VC q(vma.macro.is_recording==true) " => "$macro.end_recording", # TODO
274
+ # 'C q'=> 'vma.macro.end_recording', #TODO
275
+ "C q v" => "vma.macro.end_recording",
276
+ # 'C v'=> 'vma.macro.end_recording',
277
+ # "C M" => 'vma.macro.run_last_macro',
278
+ "C @ <char>" => "vma.macro.run_macro(<char>)",
279
+ "C , m S" => 'vma.macro.save_macro("a")',
280
+ "C , m s" => "vma.macro.save",
274
281
  "C , t r" => "run_tests()",
275
282
 
276
283
  # "C ." => "repeat_last_action", # TODO
@@ -278,10 +285,10 @@ default_keys = {
278
285
  # "CV Q" => :quit,
279
286
  "CV ctrl-q" => :quit,
280
287
  "CV , R" => "restart_application",
281
- "I ctrl!" => "vma.kbd.set_mode(:command)",
288
+ # "I ctrl!" => "vma.kbd.to_previous_mode",
282
289
  "C shift!" => "buf.save",
283
290
  "I <char>" => "buf.insert_txt(<char>)",
284
- "I esc" => "vma.kbd.set_mode(:command)",
291
+ "I esc || I ctrl!" => "vma.kbd.to_previous_mode",
285
292
 
286
293
  "I ctrl-d" => "buf.delete2(:to_word_end)",
287
294
 
@@ -295,7 +302,10 @@ default_keys = {
295
302
  "IX alt-f" => "buf.jump_word(FORWARD,WORD_START)",
296
303
  "IX alt-b" => "buf.jump_word(BACKWARD,WORD_START)",
297
304
 
298
- "I tab" => 'buf.insert_txt(" ")',
305
+ "I ctrl-h" => :show_autocomplete,
306
+ "I ctrl-j" => "vma.buf.view.hide_completions",
307
+
308
+
299
309
  "I space" => 'buf.insert_txt(" ")',
300
310
  # "I return" => 'buf.insert_new_line()',
301
311
  }
@@ -19,13 +19,31 @@ class LangSrv
19
19
 
20
20
  def initialize(lang)
21
21
  @error = true
22
- clsp = conf(:custom_lsp)
23
22
 
24
23
  # Use LSP server specified by user if available
25
24
  @lang = lang
26
- lspconf = clsp[lang]
25
+
26
+ lspconf = nil
27
+ ret = cnf.lsp.server?.find { |k, v| v[:languages].include?(@lang) }
28
+ lspconf = ret[1] unless ret.nil?
29
+
27
30
  if !lspconf.nil?
28
- @io = IO.popen(lspconf[:command], "r+")
31
+ error = false
32
+ begin
33
+ @io = IO.popen(lspconf[:command], "r+")
34
+ rescue Errno::ENOENT => e
35
+ pp e
36
+ error = true
37
+ rescue StandardError => e
38
+ debug "StandardError @io = IO.popen(lspconf[:command] ...", 2
39
+ pp e
40
+ error = true
41
+ end
42
+ if error or @io.nil?
43
+ message("Could not start lsp server #{lspconf[:name]}")
44
+ error = true
45
+ return nil
46
+ end
29
47
  else
30
48
  return nil
31
49
  end
@@ -37,6 +55,8 @@ class LangSrv
37
55
  for c in conf(:workspace_folders)
38
56
  wf << LSP::Interface::WorkspaceFolder.new(uri: c[:uri], name: c[:name])
39
57
  end
58
+ debug "WORKSPACE FOLDERS", 2
59
+ debug wf.inspect, 2
40
60
 
41
61
  pid = Process.pid
42
62