vimamsa 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,6 +28,8 @@ def is_visual_mode()
28
28
  return 0
29
29
  end
30
30
 
31
+ reg_act(:command_to_buf, proc { command_to_buf }, "Execute command, output to buffer")
32
+
31
33
  reg_act(:lsp_debug, proc { vma.buf.lsp_get_def }, "LSP get definition")
32
34
  reg_act(:lsp_jump_to_definition, proc { vma.buf.lsp_jump_to_def }, "LSP jump to definition")
33
35
 
@@ -38,8 +40,6 @@ reg_act(:easy_jump, proc { EasyJump.start }, "Easy jump")
38
40
  reg_act(:gui_ensure_cursor_visible, proc { vma.gui.view.ensure_cursor_visible }, "Scroll to current cursor position")
39
41
  reg_act(:gui_refresh_cursor, proc { vma.buf.refresh_cursor }, "Refresh cursor")
40
42
 
41
-
42
-
43
43
  reg_act(:savedebug, "savedebug", "Save debug info", { :group => :debug })
44
44
  reg_act(:open_file_dialog, "open_file_dialog", "Open file", { :group => :file })
45
45
  reg_act(:create_new_file, "create_new_file", "Create new file", { :group => :file })
@@ -62,7 +62,7 @@ reg_act(:put_file_ref_to_clipboard, proc { buf.put_file_ref_to_clipboard }, "Put
62
62
  reg_act(:encrypt_file, proc { encrypt_cur_buffer }, "Set current file to encrypt on save")
63
63
  reg_act(:set_unencrypted, proc { buf.set_unencrypted }, "Set current file to save unencrypted")
64
64
  reg_act(:set_executable, proc { buf.set_executable }, "Set current file permissions to executable")
65
- reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
65
+ # reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
66
66
  reg_act(:close_current_buffer, proc { bufs.close_current_buffer(true) }, "Close current buffer")
67
67
  reg_act(:comment_selection, proc { buf.comment_selection }, "")
68
68
  reg_act(:delete_char_forward, proc { buf.delete(CURRENT_CHAR_FORWARD) }, "Delete char forward", { :group => [:edit, :basic] })
@@ -94,15 +94,23 @@ reg_act :update_file_index, proc { FileFinder.update_index }, "Update file index
94
94
  reg_act :delete_to_word_end, proc { buf.delete2(:to_word_end) }, "Delete to file end", { :group => [:edit, :basic] }
95
95
  reg_act :delete_to_next_word_start, proc { buf.delete2(:to_next_word) }, "Delete to start of next word", { :group => [:edit, :basic] }
96
96
  reg_act :delete_to_line_start, proc { buf.delete2(:to_line_start) }, "Delete to line start", { :group => [:edit, :basic] }
97
- reg_act :start_browse_mode, proc { $kbd.set_mode(:browse); $kbd.set_default_mode(:browse) }, "Start browse mode"
97
+
98
+ reg_act :start_browse_mode, proc {
99
+ vma.kbd.set_mode(:browse)
100
+ bufs.reset_navigation
101
+ }, "Start browse mode"
102
+ reg_act :kbd_dump_state, proc { vma.kbd.dump_state }, "Dump keyboard tree state"
103
+
98
104
  reg_act :exit_browse_mode, proc {
99
- bufs.add_current_buf_to_history;
100
- vma.kbd.set_mode_stack([vma.buf.default_mode])
101
- vma.kbd.set_mode_to_default
105
+ bufs.add_current_buf_to_history
106
+ # Load previously saved buffer specific mode stack
107
+ buf.restore_kbd_mode
102
108
  }, "Exit browse mode"
103
109
 
104
- reg_act :page_down, proc { page_down }, "Page down", :group => [:move, :basic]
105
- reg_act :page_up, proc { page_up }, "Page up", :group => [:move, :basic]
110
+ # reg_act :page_down, proc { page_down }, "Page down", :group => [:move, :basic]
111
+ reg_act :page_down, proc { vma.gui.page_down }, "Page down", :group => [:move, :basic]
112
+
113
+ reg_act :page_up, proc { vma.gui.page_up }, "Page up", :group => [:move, :basic]
106
114
  reg_act :jump_to_start_of_buffer, proc { buf.jump(START_OF_BUFFER) }, "Jump to start of buffer"
107
115
  reg_act :jump_to_end_of_buffer, proc { buf.jump(END_OF_BUFFER) }, "Jump to end of buffer"
108
116
  reg_act(:auto_indent_buffer, proc { buf.indent }, "Auto format buffer")
@@ -164,7 +172,7 @@ act_list = {
164
172
  :toggle_active_window => { :proc => proc { vma.gui.toggle_active_window },
165
173
  :desc => "Toggle active window", :group => :search },
166
174
 
167
- :toggle_two_column => { :proc => proc { vma.gui.set_two_column },
175
+ :toggle_two_column => { :proc => proc { vma.gui.toggle_two_column },
168
176
  :desc => "Set two column mode", :group => :search },
169
177
 
170
178
  :content_search => { :proc => proc { FileContentSearch.start_gui },
@@ -179,6 +187,17 @@ act_list = {
179
187
  :debug_buf_hex => { :proc => proc { puts "SHA256: " + (Digest::SHA2.hexdigest vma.buf.to_s) },
180
188
  :desc => "Output SHA256 hex digest of curent buffer" },
181
189
 
190
+ :start_autocomplete => { :proc => proc { vma.buf.view.start_autocomplete },
191
+ :desc => "Start autocomplete" },
192
+
193
+ :show_autocomplete => { :proc => proc {
194
+ # vma.buf.view.signal_emit("show-completion")
195
+ # vma.buf.view.show_completion
196
+ vma.buf.view.show_completions
197
+ },
198
+ :desc => "Show autocomplete" },
199
+
200
+
182
201
  }
183
202
 
184
203
  for k, v in act_list
@@ -23,12 +23,13 @@ setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc",
23
23
 
24
24
  class State
25
25
  attr_accessor :key_name, :eval_rule, :children, :action, :label, :major_modes, :level, :cursor_type
26
- attr_reader :cur_mode
26
+ attr_reader :cur_mode, :scope
27
27
 
28
- def initialize(key_name, eval_rule = "", ctype = :command)
28
+ def initialize(key_name, eval_rule = "", ctype = :command, scope: :buffer)
29
29
  @key_name = key_name
30
30
  @eval_rule = eval_rule
31
31
  @children = []
32
+ @scope = scope
32
33
  @major_modes = []
33
34
  @action = nil
34
35
  @level = 0
@@ -41,7 +42,7 @@ class State
41
42
  end
42
43
 
43
44
  class KeyBindingTree
44
- attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action, :modifiers, :next_command_count, :method_handles_repeat
45
+ attr_accessor :C, :I, :cur_state, :root, :match_state, :last_action, :cur_action, :modifiers, :next_command_count, :method_handles_repeat, :default_mode
45
46
  attr_reader :mode_root_state, :state_trail, :act_bindings, :default_mode_stack
46
47
 
47
48
  def initialize()
@@ -65,34 +66,62 @@ class KeyBindingTree
65
66
  @act_bindings = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
66
67
  end
67
68
 
68
- def set_default_mode(label)
69
+ def set_mode(label)
69
70
  @match_state = [@modes[label]] # used for matching input
70
71
  @mode_root_state = @modes[label]
71
- @default_mode = label
72
+ # @default_mode = label
72
73
  @default_mode_stack << label
74
+
75
+ __set_mode(label)
73
76
  if !vma.buf.nil?
74
77
  # vma.buf.mode_stack = @default_mode_stack.clone
75
78
  end
76
79
  end
77
80
 
81
+ def set_default_mode(label)
82
+ @match_state = [@modes[label]]
83
+ @mode_root_state = @modes[label]
84
+ @default_mode = label
85
+ set_mode_stack [label]
86
+ end
87
+
78
88
  def set_mode_stack(ms)
89
+ debug "set_mode_stack(#{ms})", 2
90
+ show_caller if cnf.debug? # TODO: remove
79
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]
80
105
  end
81
106
 
82
107
  def set_mode_to_default()
83
108
  # set_mode(@default_mode)
84
- set_mode(@default_mode_stack[-1])
109
+ set_mode_stack [@default_mode_stack[0]]
110
+ __set_mode(@default_mode_stack[0])
85
111
  end
86
112
 
87
113
  def to_previous_mode()
114
+ debug "to_previous_mode",2
115
+ pp @default_mode_stack
88
116
  if @default_mode_stack.size > 1
89
117
  @default_mode_stack.pop
90
118
  end
91
- set_mode_to_default()
119
+ pp @default_mode_stack
120
+ __set_mode(@default_mode_stack[-1])
92
121
  end
93
122
 
94
- def add_mode(id, label, cursortype = :command, name: nil)
95
- mode = State.new(id, "", cursortype)
123
+ def add_mode(id, label, cursortype = :command, name: nil, scope: :buffer)
124
+ mode = State.new(id, "", cursortype, scope: scope)
96
125
  mode.level = 1
97
126
  @modes[label] = mode
98
127
  @root.children << mode
@@ -105,6 +134,10 @@ class KeyBindingTree
105
134
  def add_minor_mode(id, label, major_mode_label)
106
135
  mode = State.new(id)
107
136
  @modes[label] = mode
137
+ if @root.nil?
138
+ show_caller
139
+ Ripl.start :binding => binding
140
+ end
108
141
  @root.children << mode
109
142
  mode.major_modes << major_mode_label
110
143
  end
@@ -166,7 +199,8 @@ class KeyBindingTree
166
199
  vma.gui.statnfo.markup = "<span weight='ultrabold'>#{st}</span>"
167
200
  end
168
201
 
169
- def set_mode(label)
202
+ def __set_mode(label)
203
+ debug "__set_mode(#{label})"
170
204
  @mode_history << @mode_root_state
171
205
 
172
206
  # Check if label in form :label
@@ -183,11 +217,19 @@ class KeyBindingTree
183
217
  end
184
218
  @cur_mode = label
185
219
 
220
+ if self.get_scope != :editor and !vma.buf.nil?
221
+ vma.buf.mode_stack = @default_mode_stack.clone
222
+ end
223
+
186
224
  if !vma.gui.view.nil?
187
225
  vma.gui.view.draw_cursor() #TODO: handle outside this class
188
226
  end
189
227
  end
190
228
 
229
+ def get_scope
230
+ @mode_root_state.scope
231
+ end
232
+
191
233
  def cur_mode_str()
192
234
  return @mode_root_state.key_name
193
235
  end
@@ -410,6 +452,8 @@ class KeyBindingTree
410
452
 
411
453
  def bindkey(key, action)
412
454
  if key.class != Array
455
+ # Handle syntax like :
456
+ # "X esc || X ctrl!" => "vma.kbd.to_previous_mode",
413
457
  key = key.split("||")
414
458
  end
415
459
 
@@ -440,10 +484,19 @@ class KeyBindingTree
440
484
  end
441
485
 
442
486
  m = key.match(/^(\S+)\s(\S.*)$/)
487
+ # Match/split e.g. "VC , , s" to "VC" and ", , s"
443
488
  if m
444
489
  modetmp = m[1]
445
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
446
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.
447
500
  modes = [modetmp] if modetmp.match(/^\p{Ll}+$/) # Lowercase
448
501
  keydef = m[2]
449
502
  else
@@ -456,7 +509,15 @@ class KeyBindingTree
456
509
  }
457
510
  end
458
511
 
512
+ # Binds a keyboard key combination to an action,
513
+ # for a given keyboard mode like insert ("I") or command ("C")
459
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
+
460
521
  set_state(mode_id, "") # TODO: check is ok?
461
522
  start_state = @cur_state
462
523
 
@@ -464,23 +525,32 @@ class KeyBindingTree
464
525
 
465
526
  prev_state = nil
466
527
  s1 = start_state
467
- k_arr.each { |i|
528
+
529
+ k_arr.each_with_index { |k, idx|
468
530
  # check if key has rules for context like q has in
469
531
  # "C q(cntx.recording_macro==true)"
470
- match = /(.+)\((.*)\)/.match(i)
532
+ last_item = false
533
+ if k_arr.size - 1 == idx
534
+ last_item = true
535
+ end
536
+ match = /(.+)\((.*)\)/.match(k)
471
537
  eval_rule = ""
472
538
  if match
473
539
  key_name = match[1]
474
540
  eval_rule = match[2]
475
541
  else
476
- key_name = i
542
+ key_name = k
477
543
  end
478
544
 
479
545
  prev_state = s1
480
546
  # Create a new state for key if it doesn't exist
481
547
  s1 = find_state(key_name, eval_rule)
482
- if s1 == nil
548
+ if s1 == nil or last_item
483
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
484
554
  s1 = new_state
485
555
  @cur_state.children << new_state
486
556
  end
@@ -4,10 +4,10 @@ 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
6
  vma.kbd.add_minor_mode("audio", :audio, :command)
7
- vma.kbd.add_mode("B", :browse, :command)
7
+ vma.kbd.add_mode("B", :browse, :command, scope: :editor)
8
8
  vma.kbd.add_mode("X", :replace, :command, name: "Replace")
9
9
  vma.kbd.set_default_mode(:command)
10
- vma.kbd.set_mode(:command)
10
+ vma.kbd.__set_mode(:command) #TODO:needed?
11
11
  # vma.kbd.show_state_trail
12
12
 
13
13
 
@@ -17,7 +17,6 @@ bindkey "VC s", :easy_jump
17
17
  bindkey "VC , m f", [:find_macro_gui, proc { vma.macro.find_macro_gui }, "Find named macro"]
18
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
@@ -58,7 +57,7 @@ bindkey "audio f || audio right", [:audio_forward, proc { Audio.seek_forward },
58
57
  bindkey "audio left", [:audio_backward, proc { Audio.seek_forward(-5.0) }, "Seek backward in audio stream"]
59
58
 
60
59
  bindkey "audio space", :audio_stop
61
- bindkey "audio q || audio esc", "vma.kbd.set_mode_to_default"
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
@@ -79,8 +78,9 @@ bindkey "B z", "center_on_current_line();call_action(:exit_browse_mode)"
79
78
  bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
80
79
  bindkey "B s", :page_up
81
80
  bindkey "B d", :page_down
82
- bindkey "B s", :page_up
83
- 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
+
84
84
  bindkey "B i", :jump_to_start_of_buffer
85
85
  bindkey "B o", :jump_to_end_of_buffer
86
86
  bindkey "B c", :close_current_buffer
@@ -105,7 +105,7 @@ 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,
@@ -117,11 +117,22 @@ default_keys = {
117
117
  # MOVING
118
118
  # 'VC h' => 'buf.move(BACKWARD_CHAR)',
119
119
  "VC l" => "buf.move(FORWARD_CHAR)",
120
- "VC j" => "buf.move(FORWARD_LINE)",
121
- "VC k" => "buf.move(BACKWARD_LINE)",
120
+ # "VC j" => "buf.move(FORWARD_LINE)",
121
+ # "VC k" => "buf.move(BACKWARD_LINE)",
122
+
123
+ "VC pagedown" => :page_down,
124
+ "VC pageup" => :page_up,
122
125
 
123
- "VC pagedown" => "page_down",
124
- "VC pageup" => "page_up",
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,
125
136
 
126
137
  "VCIX left" => "buf.move(BACKWARD_CHAR)",
127
138
  "VCIX right" => "buf.move(FORWARD_CHAR)",
@@ -172,6 +183,7 @@ default_keys = {
172
183
  "C , d b" => "debug_print_buffer",
173
184
  "C , d c" => "debug_dump_clipboard",
174
185
  "C , d d" => "debug_dump_deltas",
186
+ "C , d m" => :kbd_dump_state,
175
187
 
176
188
  "VC O" => "buf.jump(END_OF_LINE)",
177
189
  "VC $" => "buf.jump(END_OF_LINE)",
@@ -189,7 +201,6 @@ default_keys = {
189
201
 
190
202
  # Command mode only:
191
203
  "C ctrl-r" => "buf.redo()", # TODO:???
192
- "C R" => "buf.redo()",
193
204
  "C v" => "buf.start_visual_mode",
194
205
  "C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
195
206
  "C space <char>" => "buf.insert_txt(<char>)",
@@ -246,16 +257,13 @@ default_keys = {
246
257
  'CV \' <char>' => "buf.jump_to_mark(<char>)",
247
258
  # "CV ''" =>'jump_to_mark(NEXT_MARK)', #TODO
248
259
 
249
- # Switch to other mode
260
+ # Switch to another mode
250
261
  "C i" => "vma.kbd.set_mode(:insert)",
251
262
  "C R" => "vma.kbd.set_mode(:replace)",
252
263
  "C ctrl!" => "vma.kbd.set_mode(:insert)",
253
- "C ctrl!" => "vma.kbd.set_mode(:insert)",
254
264
 
255
-
256
- # "R esc || R ctrl!" => "vma.kbd.set_mode(:command)",
257
- "X esc" => "vma.kbd.set_mode(:command)",
258
- "X ctrl!" => "vma.kbd.set_mode(:command)",
265
+ # Replace mode
266
+ "X esc || X ctrl!" => "vma.kbd.to_previous_mode",
259
267
  "X <char>" => "buf.replace_with_char(<char>);buf.move(FORWARD_CHAR)",
260
268
 
261
269
  # Macros
@@ -280,7 +288,7 @@ default_keys = {
280
288
  # "I ctrl!" => "vma.kbd.to_previous_mode",
281
289
  "C shift!" => "buf.save",
282
290
  "I <char>" => "buf.insert_txt(<char>)",
283
- "I esc || I ctrl!" => "vma.kbd.set_mode_to_default",
291
+ "I esc || I ctrl!" => "vma.kbd.to_previous_mode",
284
292
 
285
293
  "I ctrl-d" => "buf.delete2(:to_word_end)",
286
294
 
@@ -294,8 +302,10 @@ default_keys = {
294
302
  "IX alt-f" => "buf.jump_word(FORWARD,WORD_START)",
295
303
  "IX alt-b" => "buf.jump_word(BACKWARD,WORD_START)",
296
304
 
297
- "I tab" => 'buf.insert_tab',
298
- "I shift-tab" => 'buf.unindent',
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
 
data/lib/vimamsa/main.rb CHANGED
@@ -32,6 +32,10 @@ def buf()
32
32
  return vma.buf
33
33
  end
34
34
 
35
+ def hook
36
+ return vma.hook
37
+ end
38
+
35
39
  def bufs()
36
40
  return vma.buffers
37
41
  end
data/lib/vimamsa/rbvma.rb CHANGED
@@ -32,6 +32,7 @@ require "vimamsa/gui_menu"
32
32
  require "vimamsa/gui_dialog"
33
33
  require "vimamsa/gui_select_window"
34
34
  require "vimamsa/gui_sourceview"
35
+ require "vimamsa/gui_sourceview_autocomplete"
35
36
  require "vimamsa/gui_image"
36
37
  require "vimamsa/hyper_plain_text"
37
38
 
@@ -39,6 +40,7 @@ require "vimamsa/ack"
39
40
  require "vimamsa/buffer"
40
41
  require "vimamsa/buffer_cursor"
41
42
  require "vimamsa/buffer_changetext"
43
+ # require "vimamsa/buffer_list"
42
44
  require "vimamsa/buffer_list"
43
45
  require "vimamsa/buffer_manager"
44
46
  require "vimamsa/constants"
@@ -1,9 +1,3 @@
1
- class Grep
2
- attr_accessor :history
3
-
4
- def initialize()
5
- end
6
- end
7
1
 
8
2
  class FileSelector
9
3
  def initialize()
@@ -85,9 +79,14 @@ class Grep
85
79
  end
86
80
  vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
87
81
  reg_act(:grep_buffer, proc { Grep.new.run }, "Grep current buffer")
82
+ reg_act(:grep_refresh, proc {
83
+ if vma.buf.module.class == Grep
84
+ vma.buf.module.refresh
85
+ end
86
+ }, "Refresh current Grep buffer")
88
87
 
89
88
  bindkey "C , g", :grep_buffer
90
-
89
+ bindkey "grep ctrl-r", :grep_refresh
91
90
  end
92
91
 
93
92
  def apply_changes()
@@ -114,45 +113,54 @@ class Grep
114
113
  @line_to_id = {}
115
114
  end
116
115
 
117
- def callback(search_str, b = nil)
118
- debug "grep_cur_buffer(search_str)"
119
- lines = vma.buf.split("\n")
120
- r = Regexp.new(Regexp.escape(search_str), Regexp::IGNORECASE)
121
- fpath = ""
122
- fpath = vma.buf.pathname.expand_path.to_s + ":" if vma.buf.pathname
123
- res_str = ""
116
+ def refresh
117
+ set_buf_contents
118
+ end
119
+
120
+ def set_buf_contents()
121
+ lines = @orig_buf.split("\n")
124
122
 
125
- hlparts = []
126
123
  @grep_matches = []
124
+
125
+ res_str = ""
127
126
  lines.each_with_index { |l, i|
128
- if r.match(l)
127
+ if @r.match(l)
129
128
  res_str << "#{i + 1}:"
130
129
  # ind = scan_indexes(l, r)
131
130
  res_str << "#{l}\n"
132
131
  @grep_matches << i + 1 # Lines start from index 1
133
132
  end
134
133
  }
135
- $grep_bufid = vma.buffers.current_buf
134
+
135
+ @buf.set_content(res_str)
136
+
137
+ Gui.highlight_match(@buf, @search_str, color: cnf.match.highlight.color!)
138
+ end
139
+
140
+ def callback(search_str, b = nil)
141
+ debug "grep_cur_buffer(search_str)"
142
+ @r = Regexp.new(Regexp.escape(search_str), Regexp::IGNORECASE)
143
+ fpath = ""
144
+ fpath = vma.buf.pathname.expand_path.to_s + ":" if vma.buf.pathname
145
+
146
+ @search_str = search_str
136
147
  @orig_buf = vma.buf
137
- b = create_new_buffer(res_str, "grep")
138
- vbuf = vma.gui.view.buffer
148
+ @buf = create_new_buffer("", "grep")
139
149
 
140
- Gui.highlight_match(b, search_str, color: cnf.match.highlight.color!)
141
- b.default_mode = :grep
142
- b.module = self
150
+ @buf.default_mode = :grep
151
+ @buf.module = self
143
152
 
144
- vma.kbd.set_mode(:grep) #TODO: allow to work with other keybindings also
145
- vma.kbd.set_default_mode(:grep)
146
- b.line_action_handler = proc { |lineno|
153
+ vma.kbd.set_mode(:grep)
154
+ @buf.line_action_handler = proc { |lineno|
147
155
  debug "GREP HANDLER:#{lineno}"
148
156
  jumpto = @grep_matches[lineno]
149
157
  if jumpto.class == Integer
150
- # vma.buffers.set_current_buffer($grep_bufid, update_history = true)
151
- # buf.jump_to_line(jumpto)
152
158
  vma.buffers.set_current_buffer_by_id(@orig_buf.id)
153
159
  @orig_buf.jump_to_line(jumpto)
154
160
  end
155
161
  }
162
+
163
+ set_buf_contents
156
164
  end
157
165
 
158
166
  def run()
@@ -1,3 +1,4 @@
1
+
1
2
  def exec_in_terminal(cmd, autoclose = false)
2
3
  # debug "CMD:#{cmd}"
3
4
 
@@ -19,4 +20,15 @@ def exec_in_terminal(cmd, autoclose = false)
19
20
  fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" }
20
21
  end
21
22
 
23
+ def command_to_buf_callback(cmd)
24
+ require "open3"
25
+ stdout, stderr, status = Open3.capture3(cmd)
26
+ b = create_new_buffer(stdout, cmd)
27
+ end
28
+
22
29
 
30
+ load "terminal_extra.rb" if File.exist?("terminal_extra.rb")
31
+ def command_to_buf
32
+ callback = method("command_to_buf_callback")
33
+ gui_one_input_action("Execute command in shell, output to buffer", "Command:", "Execute", callback)
34
+ end
data/lib/vimamsa/util.rb CHANGED
@@ -23,8 +23,17 @@ def file_is_text_file(fpath)
23
23
  debug "file_is_text_file(#{fpath})"
24
24
  fpath = File.expand_path(fpath)
25
25
  return false if !File.exist?(fpath)
26
+ return false if !File.file?(fpath)
27
+
28
+ if File.size(fpath) < 1000e3 #smaler than 1MB
29
+ str = IO.read(fpath)
30
+ str.force_encoding("UTF-8")
31
+ debug "Small file with valid utf-8"
32
+ return true if str.valid_encoding?
33
+ end
34
+
35
+ #TODO: not sure if needed
26
36
  r = exec_cmd("file", fpath)
27
- debug "DEBUG:#{r}"
28
37
  return true if r.match(/UTF-8.*text/)
29
38
  return true if r.match(/ASCII.*text/)
30
39
  return false
@@ -101,7 +110,7 @@ class HSafe
101
110
  hh = @h
102
111
  while !b.empty?
103
112
  x = b.pop
104
- puts "x=#{x}"
113
+ debug "x=#{x}"
105
114
  pp b
106
115
  ok = false
107
116
  if hh.class == Hash or hh.class == Array
@@ -1,3 +1,3 @@
1
1
  module Vimamsa
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
data/vimamsa.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib","ext"]
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 2.4.21"
24
- spec.add_development_dependency "rake", "~> 13.0"
24
+ spec.add_development_dependency "rake", "~> 13.1.0"
25
25
 
26
26
  spec.add_runtime_dependency 'rufo', '~> 0.16.2'
27
27
 
@@ -29,7 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency 'ripl-multi_line', '~> 0.3.1'
30
30
  spec.add_runtime_dependency 'gdk4', '~> 4.2.0'
31
31
  spec.add_runtime_dependency 'gtk4', '~> 4.2.0'
32
- spec.add_runtime_dependency 'rake', '~> 13.1.0'
32
+ spec.add_runtime_dependency 'rambling-trie', '~> 2.3.1'
33
+
33
34
  spec.add_runtime_dependency 'differ', '~> 0.1.2'
34
35
  spec.add_runtime_dependency 'gtksourceview5', '~> 4.2.0'
35
36
  spec.add_runtime_dependency 'parallel', '~> 1.14' #TODO: update?