vimamsa 0.1.19 → 0.1.21

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.
@@ -40,8 +40,9 @@ class OneInputAction
40
40
  def initialize(main_window, title, field_label, button_title, callback, opt = {})
41
41
  @window = Gtk::Window.new()
42
42
  # @window.screen = main_window.screen
43
- # @window.title = title
44
43
  @window.title = ""
44
+ # @window.width_request = 800
45
+ # @window.hexpand = false
45
46
 
46
47
  frame = Gtk::Frame.new()
47
48
  # frame.margin = 20
@@ -49,15 +50,17 @@ class OneInputAction
49
50
 
50
51
  infolabel = Gtk::Label.new
51
52
  infolabel.markup = title
53
+ infolabel.wrap = true
54
+ infolabel.max_width_chars = 80
55
+
52
56
 
53
57
  vbox = Gtk::Box.new(:vertical, 8)
54
58
  vbox.margin = 10
55
59
  frame.set_child(vbox)
56
60
 
57
61
  hbox = Gtk::Box.new(:horizontal, 8)
58
- # @window.add(hbox)
59
- vbox.pack_end(infolabel, :expand => false, :fill => false, :padding => 0)
60
- vbox.pack_end(hbox, :expand => false, :fill => false, :padding => 0)
62
+ vbox.append(infolabel)
63
+ vbox.append(hbox)
61
64
 
62
65
  button = Gtk::Button.new(:label => button_title)
63
66
  cancel_button = Gtk::Button.new(:label => "Cancel")
@@ -95,10 +98,10 @@ class OneInputAction
95
98
  end
96
99
  end
97
100
 
98
- hbox.pack_end(label, :expand => false, :fill => false, :padding => 0)
99
- hbox.pack_end(@entry1, :expand => false, :fill => false, :padding => 0)
100
- hbox.pack_end(button, :expand => false, :fill => false, :padding => 0)
101
- hbox.pack_end(cancel_button, :expand => false, :fill => false, :padding => 0)
101
+ hbox.append(label)
102
+ hbox.append(@entry1)
103
+ hbox.append(button)
104
+ hbox.append(cancel_button)
102
105
  return
103
106
  end
104
107
 
@@ -49,9 +49,7 @@ class PopupFormGenerator
49
49
  if params.has_key?("title")
50
50
  infolabel = Gtk::Label.new
51
51
  infolabel.markup = params["title"]
52
- #TODO:gtk4
53
- # vbox.pack_start(infolabel, :expand => false, :fill => false, :padding => 0)
54
- vbox.pack_end(infolabel, :expand => false, :fill => false, :padding => 0)
52
+ vbox.append(infolabel)
55
53
  end
56
54
 
57
55
  hbox = Gtk::Box.new(:horizontal, 8)
@@ -61,7 +59,7 @@ class PopupFormGenerator
61
59
  for id, elem in params["inputs"]
62
60
  if elem[:type] == :button
63
61
  button = Gtk::Button.new(:label => elem[:label])
64
- hbox.pack_end(button, :expand => false, :fill => false, :padding => 0)
62
+ hbox.append(button)
65
63
  if elem[:default_focus] == true
66
64
  @default_button = button
67
65
  end
@@ -75,8 +73,8 @@ class PopupFormGenerator
75
73
  if elem.has_key?(:initial_text)
76
74
  entry.text = elem[:initial_text]
77
75
  end
78
- hbox.pack_end(label, :expand => false, :fill => false, :padding => 0)
79
- hbox.pack_end(entry, :expand => false, :fill => false, :padding => 0)
76
+ hbox.append(label)
77
+ hbox.append(entry)
80
78
  @vals[id] = entry
81
79
 
82
80
  press = Gtk::EventControllerKey.new
@@ -96,13 +94,13 @@ class PopupFormGenerator
96
94
  end
97
95
  end
98
96
 
99
- vbox.pack_end(hbox, :expand => false, :fill => false, :padding => 0)
97
+ vbox.append(hbox)
100
98
 
101
99
  cancel_button = Gtk::Button.new(:label => "Cancel")
102
100
  cancel_button.signal_connect "clicked" do
103
101
  @window.destroy
104
102
  end
105
- hbox.pack_end(cancel_button, :expand => false, :fill => false, :padding => 0)
103
+ hbox.append(cancel_button)
106
104
  @cancel_button = cancel_button
107
105
  return
108
106
  end
@@ -1,6 +1,11 @@
1
1
  module Vimamsa
2
2
  class Menu
3
3
  def add_to_menu(_mpath, x)
4
+ # If no menu label provided, take from the action definition
5
+ if !x[:action].nil? and x[:label].nil?
6
+ x[:label] = vma.actions[x[:action]].method_name
7
+ end
8
+
4
9
  mpath = _mpath.split(".")
5
10
  curnfo = @nfo
6
11
  for y in mpath
@@ -31,9 +36,10 @@ module Vimamsa
31
36
  add_to_menu "Edit.Redo", { :label => "Redo edit", :action => :edit_redo }
32
37
  add_to_menu "Edit.SearchReplace", { :label => "Search and replace", :action => :gui_search_replace }
33
38
  add_to_menu "Edit.Find", { :label => "Find", :action => :find_in_buffer }
34
-
35
- add_to_menu "Edit.StartCompletion", { :label => "StartCompletion", :action => :start_autocomplete }
36
- add_to_menu "Edit.ShowCompletion", { :label => "ShowCompletion", :action => :show_autocomplete }
39
+
40
+ # add_to_menu "Edit.StartCompletion", { :label => "StartCompletion", :action => :start_autocomplete }
41
+ # add_to_menu "Edit.ShowCompletion", { :label => "ShowCompletion", :action => :show_autocomplete }
42
+ add_to_menu "Edit.CustomRb", { :action => :edit_customrb }
37
43
 
38
44
  add_to_menu "Actions.SearchForActions", { :label => "Search for Actions", :action => :search_actions }
39
45
 
@@ -46,13 +52,11 @@ module Vimamsa
46
52
  add_to_menu "Actions.experimental.EnableDebug", { :label => "Enable debug", :action => :enable_debug }
47
53
  add_to_menu "Actions.experimental.DisableDebug", { :label => "Disable debug", :action => :disable_debug }
48
54
  add_to_menu "Actions.experimental.ShowImages", { :label => "Show images ⟦img:path⟧", :action => :show_images }
49
-
55
+
50
56
  add_to_menu "Actions.debug.dumpkbd", { :label => "Dump kbd state", :action => :kbd_dump_state }
51
-
52
-
57
+
53
58
  add_to_menu "View.BufferManager", { :label => "Show open files", :action => :start_buf_manager }
54
59
  add_to_menu "View.TwoColumn", { :label => "Toggle two column mode", :action => :toggle_two_column }
55
-
56
60
 
57
61
  add_to_menu "Actions.EncryptFile", { :label => "Encrypt file", :action => :encrypt_file }
58
62
  add_to_menu "Help.KeyBindings", { :label => "Show key bindings", :action => :show_key_bindings }
@@ -89,7 +93,7 @@ module Vimamsa
89
93
  label_str = nfo[:label] + kbd_str
90
94
  actkey = nfo[:action].to_s
91
95
  menuitem = Gio::MenuItem.new(label_str, "app.#{actkey}")
92
-
96
+
93
97
  # This worked in GTK3:
94
98
  # But seems there is no way to access the Label object in GTK4
95
99
  # menuitem.children[0].set_markup(label_str)
@@ -110,7 +114,6 @@ module Vimamsa
110
114
  # menuitem.set_attribute_value("use-markup", true)
111
115
  # This might change in the future(?), but the string version still works in gtk-4.13.0 (gtk/gtkmenutrackeritem.c)
112
116
 
113
-
114
117
  if !nfo[:items].nil? and !nfo[:items].empty?
115
118
  for k2, item in nfo[:items]
116
119
  build_menu(item, menu)
@@ -118,7 +121,6 @@ module Vimamsa
118
121
  menuitem.submenu = menu
119
122
  end
120
123
  o = parent.append_item(menuitem)
121
-
122
124
  end
123
125
  end #end class
124
126
  end
@@ -154,7 +154,9 @@ class SelectUpdateWindow
154
154
  sw = Gtk::ScrolledWindow.new(nil, nil)
155
155
  # sw.shadow_type = :etched_in #TODO:gtk4
156
156
  sw.set_policy(:never, :automatic)
157
- vbox.pack_end(sw, :expand => true, :fill => true, :padding => 0)
157
+ vbox.append(sw)
158
+ sw.vexpand = true
159
+ sw.hexpand = true
158
160
 
159
161
  # sw.add(treeview) #TODO:gtk4
160
162
  sw.set_child(treeview)
@@ -104,9 +104,18 @@ class VSourceView < GtkSource::View
104
104
  # Sometimes a GestureClick EventController appears from somewhere
105
105
  # not initiated from this file.
106
106
 
107
- # if ctr.class == Gtk::EventControllerKey or ctr.class == Gtk::GestureClick
108
- if ctr != @click
109
- # to_remove << ctr if ctr.class != Gtk::GestureDrag
107
+ # TODO: Check which of these are needed:
108
+ # puts ctr.class
109
+ # Gtk::DropTarget
110
+ # Gtk::EventControllerFocus
111
+ # Gtk::EventControllerKey
112
+ # Gtk::EventControllerMotion
113
+ # Gtk::EventControllerScroll
114
+ # Gtk::GestureClick
115
+ # Gtk::GestureDrag
116
+ # Gtk::ShortcutController
117
+
118
+ if ctr != @click and [Gtk::DropControllerMotion, Gtk::DropTarget, Gtk::GestureDrag, Gtk::GestureClick, Gtk::EventControllerKey].include?(ctr.class)
110
119
  to_remove << ctr
111
120
  end
112
121
  }
@@ -119,6 +128,20 @@ class VSourceView < GtkSource::View
119
128
  end
120
129
  end
121
130
 
131
+ def focus_out()
132
+ set_cursor_color(:inactive)
133
+
134
+ # This does not seem to work: (TODO:why?)
135
+ # self.cursor_visible = false
136
+ end
137
+
138
+ def focus_in()
139
+ set_cursor_color(@ctype)
140
+ self.cursor_visible = false
141
+ self.cursor_visible = true
142
+ self.grab_focus
143
+ end
144
+
122
145
  def register_signals()
123
146
  check_controllers
124
147
 
@@ -317,7 +340,7 @@ class VSourceView < GtkSource::View
317
340
  end
318
341
  debug $view.visible_rect.inspect
319
342
 
320
- debug "key event"
343
+ debug "key event" + [keyval, @last_keyval, keyname, sig].to_s
321
344
  # debug event
322
345
 
323
346
  # key_name = event.string
@@ -338,6 +361,7 @@ class VSourceView < GtkSource::View
338
361
  keyval_trans[Gdk::Keyval::KEY_KP_Enter] = "enter"
339
362
  keyval_trans[Gdk::Keyval::KEY_Alt_L] = "alt"
340
363
  keyval_trans[Gdk::Keyval::KEY_Alt_R] = "alt"
364
+ keyval_trans[Gdk::Keyval::KEY_Caps_Lock] = "caps"
341
365
 
342
366
  keyval_trans[Gdk::Keyval::KEY_BackSpace] = "backspace"
343
367
  keyval_trans[Gdk::Keyval::KEY_KP_Page_Down] = "pagedown"
@@ -368,6 +392,15 @@ class VSourceView < GtkSource::View
368
392
  key_str_parts << "super" if vma.kbd.modifiers[:super]
369
393
  key_str_parts << keyname
370
394
 
395
+ # After remapping capslock to control in gnome-tweak tool,
396
+ # if pressing and immediately releasing the capslock (control) key,
397
+ # we get first "caps" on keydown and ctrl-"caps" on keyup (keyval 65509, Gdk::Keyval::KEY_Caps_Lock)
398
+ # If mapping capslock to ctrl in hardware, we get keyval 65507 (Gdk::Keyval::KEY_Control_L) instead
399
+ if key_str_parts[0] == "ctrl" and key_str_parts[1] == "caps"
400
+ # Replace ctrl-caps with ctrl
401
+ key_str_parts.delete_at(1)
402
+ end
403
+
371
404
  if key_str_parts[0] == key_str_parts[1]
372
405
  # We don't want "ctrl-ctrl" or "alt-alt"
373
406
  # TODO:There should be a better way to do this
@@ -400,8 +433,8 @@ class VSourceView < GtkSource::View
400
433
  $kbd.match_key_conf(key_str, nil, :key_press)
401
434
  @last_event = [keynfo, key_str, :key_press]
402
435
  end
403
- @last_keyval = keyval #TODO: outside if?
404
436
  end
437
+ @last_keyval = keyval
405
438
 
406
439
  handle_deltas
407
440
 
@@ -581,34 +614,28 @@ class VSourceView < GtkSource::View
581
614
  end
582
615
 
583
616
  def draw_cursor
584
- # if @tt.nil?
585
- # @tt = buffer.create_tag("font_tag")
586
- # @tt.font = "Arial"
587
- # end
617
+ sv = vma.gui.active_window[:sw].child
618
+ return if sv.nil?
619
+ if sv != self # if we are not the current buffer
620
+ sv.draw_cursor
621
+ return
622
+ end
588
623
 
589
- sv = vma.gui.sw.child
590
- return if sv.nil? #TODO: should not happen?
591
624
  mode = vma.kbd.get_mode
592
625
  ctype = vma.kbd.get_cursor_type
593
626
  ctype = :visual if vma.buf.selection_active?
594
627
 
595
- vma.gui.remove_overlay_cursor
596
628
  if [:command, :replace, :browse].include?(ctype)
597
629
  set_cursor_color(ctype)
598
630
 
599
- sv.overwrite = true
600
- # sv.cursor_visible = true
601
- # sv.reset_cursor_blink
602
-
603
- # (Via trial and error) This combination is needed to make cursor visible:
604
- sv.cursor_visible = false
605
- sv.cursor_visible = true
606
-
607
- # sv.reset_cursor_blink
608
- Gtk::Settings.default.gtk_cursor_blink = false
609
- # Gtk::Settings.default.gtk_cursor_blink_time = 8000
610
- # vma.gui.sw.child.toggle_cursor_visible
611
- # vma.gui.sw.child.cursor_visible = true
631
+ if !self.overwrite?
632
+ self.overwrite = true
633
+
634
+ # (Via trial and error) This combination is needed to make cursor visible:
635
+ # TODO: determine why "self.cursor_visible = true" is not enough
636
+ self.cursor_visible = false
637
+ self.cursor_visible = true
638
+ end
612
639
  elsif ctype == :visual
613
640
  set_cursor_color(ctype)
614
641
  # debug "VISUAL MODE"
@@ -620,12 +647,11 @@ class VSourceView < GtkSource::View
620
647
  buffer.select_range(itr, itr2)
621
648
  elsif ctype == :insert
622
649
  set_cursor_color(ctype)
623
- sv.overwrite = false
624
- # sv.cursor_visible = false
625
- # sv.cursor_visible = true
650
+ self.overwrite = false
626
651
  debug "INSERT MODE"
627
652
  else # TODO
628
653
  end
654
+
629
655
  if [:insert, :command, :replace, :browse].include?(ctype)
630
656
  # Place cursor where it already is
631
657
  # Without this hack, the cursor doesn't always get drawn
@@ -633,5 +659,13 @@ class VSourceView < GtkSource::View
633
659
  itr = buffer.get_iter_at(:offset => pos)
634
660
  buffer.place_cursor(itr)
635
661
  end
636
- end
662
+
663
+ # Sometimes we lose focus and the cursor vanishes because of that
664
+ # TODO: determine why&when
665
+ if !self.has_focus?
666
+ self.grab_focus
667
+ self.cursor_visible = false
668
+ self.cursor_visible = true
669
+ end
670
+ end #end draw_cursor
637
671
  end
@@ -33,6 +33,8 @@ reg_act(:command_to_buf, proc { command_to_buf }, "Execute command, output to bu
33
33
  reg_act(:lsp_debug, proc { vma.buf.lsp_get_def }, "LSP get definition")
34
34
  reg_act(:lsp_jump_to_definition, proc { vma.buf.lsp_jump_to_def }, "LSP jump to definition")
35
35
 
36
+ reg_act(:eval_buf, proc { vma.buf.eval_whole_buf }, "Eval whole current buffer as ruby code (DANGEROUS)")
37
+
36
38
  reg_act(:enable_debug, proc { cnf.debug = true }, "Enable debug")
37
39
  reg_act(:disable_debug, proc { cnf.debug = false }, "Disable debug")
38
40
 
@@ -46,8 +48,9 @@ reg_act(:create_new_file, "create_new_file", "Create new file", { :group => :fil
46
48
  reg_act(:backup_all_buffers, proc { backup_all_buffers }, "Backup all buffers", { :group => :file })
47
49
  reg_act(:e_move_forward_char, "e_move_forward_char", "", { :group => [:move, :basic] })
48
50
  reg_act(:e_move_backward_char, "e_move_backward_char", "", { :group => [:move, :basic] })
49
- reg_act(:history_switch_backwards, "history_switch_backwards", "", { :group => :file })
50
- reg_act(:history_switch_forwards, "history_switch_forwards", "", { :group => :file })
51
+ # reg_act(:history_switch_backwards, proc{bufs.history_switch_backwards}, "", { :group => :file })
52
+ reg_act(:history_switch_backwards, proc{bufs.history_switch(-1)}, "", { :group => :file })
53
+ reg_act(:history_switch_forwards, proc{bufs.history_switch(+1)}, "", { :group => :file })
51
54
  reg_act(:center_on_current_line, "center_on_current_line", "", { :group => :view })
52
55
  reg_act(:run_last_macro, proc { vma.macro.run_last_macro }, "Run last recorded or executed macro", { :group => :macro })
53
56
  reg_act(:jump_to_next_edit, "jump_to_next_edit", "")
@@ -169,11 +172,14 @@ act_list = {
169
172
  :search_actions => { :proc => proc { vma.actions.gui_search },
170
173
  :desc => "Search actions", :group => :search },
171
174
 
175
+ :edit_customrb => { :proc => proc { jump_to_file("~/.config/vimamsa/custom.rb") },
176
+ :desc => "Customize (edit custom.rb)", :group => :search },
177
+
172
178
  :toggle_active_window => { :proc => proc { vma.gui.toggle_active_window },
173
- :desc => "Toggle active window", :group => :search },
179
+ :desc => "Switch active column in two column mode", :group => :search },
174
180
 
175
181
  :toggle_two_column => { :proc => proc { vma.gui.toggle_two_column },
176
- :desc => "Set two column mode", :group => :search },
182
+ :desc => "Toggle two column mode", :group => :search },
177
183
 
178
184
  :content_search => { :proc => proc { FileContentSearch.start_gui },
179
185
  :desc => "Search content of files", :group => :search },
@@ -188,15 +194,14 @@ act_list = {
188
194
  :desc => "Output SHA256 hex digest of curent buffer" },
189
195
 
190
196
  :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
-
197
+ :desc => "Start autocomplete" },
198
+
199
+ :show_autocomplete => { :proc => proc {
200
+ # vma.buf.view.signal_emit("show-completion")
201
+ # vma.buf.view.show_completion
202
+ vma.buf.view.show_completions
203
+ },
204
+ :desc => "Show autocomplete" },
200
205
 
201
206
  }
202
207
 
@@ -18,8 +18,6 @@
18
18
  # 'I ctrl-a'=> 'vma.buf.jump(BEGINNING_OF_LINE)',
19
19
  #
20
20
 
21
- setcnf :indent_based_on_last_line, true
22
- setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc", ".php", ".sh", ".m", ".gd", ".js"]
23
21
 
24
22
  class State
25
23
  attr_accessor :key_name, :eval_rule, :children, :action, :label, :major_modes, :level, :cursor_type
@@ -634,11 +632,12 @@ end
634
632
 
635
633
  # Try to clear modifiers when program loses focus
636
634
  # e.g. after alt-tab
637
- def focus_out
638
- debug "RB Clear modifiers"
639
- $kbd.clear_modifiers()
640
- end
641
-
642
- def handle_key_event(event)
643
- $kbd.handle_key_event(event)
644
- end
635
+ # TODO
636
+ # def focus_out
637
+ # debug "RB Clear modifiers"
638
+ # $kbd.clear_modifiers()
639
+ # end
640
+
641
+ # def handle_key_event(event)
642
+ # $kbd.handle_key_event(event)
643
+ # end
@@ -18,6 +18,7 @@ cnf.mode.visual.cursor.background = "#bc6040"
18
18
  cnf.mode.replace.cursor.background = "#fc0331"
19
19
  cnf.mode.browse.cursor.background = "#f803fc"
20
20
  cnf.mode.insert.cursor.background = "#ffffff"
21
+ cnf.mode.inactive.cursor.background = "#777777"
21
22
 
22
23
  def _insert_move(op)
23
24
  if op == :pagedown
@@ -100,9 +101,7 @@ bindkey "VC h", :e_move_backward_char
100
101
  bindkey "C , , .", :backup_all_buffers
101
102
  bindkey "C z ", :start_browse_mode
102
103
  bindkey "B h", :history_switch_backwards
103
- # bindkey "B h", [:browse_file_backwards, proc { vma.kbd.to_previous_mode; call_action(:history_switch_backwards); }, "Browse previous file"]
104
104
  bindkey "B l", :history_switch_forwards
105
- #bindkey 'B z', :center_on_current_line
106
105
  bindkey "B z", "center_on_current_line();call_action(:exit_browse_mode)"
107
106
  bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
108
107
  bindkey "B s", :page_up
@@ -128,6 +127,7 @@ bindkey "C p", [:paste_after, proc { buf.paste(AFTER) }, ""] # TODO: implement a
128
127
  bindkey "V d", [:delete_selection, proc { buf.delete(SELECTION) }, ""]
129
128
  bindkey "V a d", [:delete_append_selection, proc { buf.delete(SELECTION, :append) }, "Delete and append selection"]
130
129
 
130
+
131
131
  default_keys = {
132
132
 
133
133
  # File handling
@@ -267,6 +267,7 @@ default_keys = {
267
267
  "C d <num> e" => "delete_next_word",
268
268
  "C d ' <char>" => "buf.delete2(:to_mark,<char>)",
269
269
  "C r <char>" => "buf.replace_with_char(<char>)", # TODO
270
+ "C r space" => "buf.replace_with_char(' ')", # TODO
270
271
  "C , l b" => "load_buffer_list",
271
272
  "C , l l" => "save_buffer_list",
272
273
  "C , r <char>" => "vma.set_register(<char>)", # TODO
@@ -332,7 +333,7 @@ default_keys = {
332
333
  "CV ctrl-q" => :quit,
333
334
  "CV , R" => "restart_application",
334
335
  # "I ctrl!" => "vma.kbd.to_previous_mode",
335
- "C shift!" => "buf.save",
336
+ "C shift! s" => "buf.save",
336
337
  "I ctrl-s" => "buf.save",
337
338
  "I <char>" => "buf.insert_txt(<char>)",
338
339
  "I esc || I ctrl!" => "vma.kbd.to_previous_mode",
@@ -52,7 +52,7 @@ class LangSrv
52
52
  @id = 0
53
53
 
54
54
  wf = []
55
- for c in conf(:workspace_folders)
55
+ for c in cnf.workspace_folders!
56
56
  wf << LSP::Interface::WorkspaceFolder.new(uri: c[:uri], name: c[:name])
57
57
  end
58
58
  debug "WORKSPACE FOLDERS", 2
@@ -157,7 +157,6 @@ class LangSrv
157
157
  @writer.write(id: id, params: a, method: "textDocument/definition")
158
158
  r = wait_for_response(id)
159
159
  return nil if r.nil?
160
- # Ripl.start :binding => binding
161
160
  pp r
162
161
  line = HSafe.new(r)[:result][0][:range][:start][:line].val
163
162
  uri = HSafe.new(r)[:result][0][:uri].val
data/lib/vimamsa/macro.rb CHANGED
@@ -118,8 +118,10 @@ class Macro
118
118
 
119
119
  # Run the provided list of actions
120
120
  def run_actions(acts)
121
+ acts = [acts] if acts.class != Array
121
122
  isok = true
122
- if acts.kind_of?(Array) and acts.any?
123
+ # if acts.kind_of?(Array) and acts.any?
124
+ if acts.any?
123
125
  @running_macro = true
124
126
  # TODO:needed?
125
127
  # set_last_command({ method: vma.macro.method("run_macro"), params: [name] })
data/lib/vimamsa/tests.rb CHANGED
@@ -1,7 +1,19 @@
1
1
  require "digest"
2
2
 
3
3
  def run_tests()
4
- tests = ["test_paste_0", "test_delete_0"]
4
+ # DelayExecutioner.exec(id: :run_tests, wait: 0.7, callable: proc { run_tests_0 })
5
+
6
+ # Reload class
7
+ # if Object.constants.include?(:EditorTests)
8
+ # Object.send(:remove_const, :EditorTests)
9
+ # end
10
+ load __FILE__
11
+
12
+ run_edit_tests
13
+ end
14
+
15
+ def run_tests_0()
16
+ tests = ["test_write_0"]
5
17
  stats = []
6
18
  for t in tests
7
19
  r = eval(t)
@@ -16,7 +28,74 @@ def run_tests()
16
28
  puts "===================="
17
29
  end
18
30
 
19
- #
31
+ def run_edit_tests()
32
+ edt = EditorTests.new
33
+ tests = edt.methods.select { |x| x.match(/test_.*/) }.collect { |x| { :method => edt.method(x), :name => x } }
34
+ for t in tests
35
+ b = create_new_buffer(file_contents = "\n", prefix = "buf", setcurrent = true)
36
+
37
+ edits = t[:method].call
38
+ # next if t[:name] != :test_create_close_buf
39
+ errors = 0
40
+ edits.each_with_index do |x, i|
41
+ if x.class == Array
42
+ (act, target) = x
43
+
44
+ vma.macro.run_actions(act)
45
+ # bufc = b.to_s
46
+ bufc = vma.buf.to_s
47
+ if bufc != target
48
+ puts "ERROR[#{t[:name]}:#{i}] act=#{act.inspect} content=#{bufc.inspect} != #{target.inspect}"
49
+ errors += 1
50
+ end
51
+ else
52
+ vma.macro.run_actions(x)
53
+ end
54
+ end
55
+ if errors == 0
56
+ puts "TEST #{t[:name]} passed"
57
+ else
58
+ end
59
+ end
60
+ end
61
+
62
+ class EditorTests
63
+ def test_write
64
+ #[[action to run, expected buffer contents after], ...]
65
+ [['buf.insert_txt("zzzz")', "zzzz\n"],
66
+ # At end of file replace should not change anything
67
+ ['buf.replace_with_char("-")', "zzzz\n"],
68
+ 'buf.insert_txt("\n")',
69
+ ['buf.insert_txt("yy")', "zzzz\nyy\n"],
70
+ :e_move_backward_char, :e_move_backward_char,
71
+ ['buf.insert_txt("0")', "zzzz\n0yy\n"],
72
+ "buf.jump(START_OF_BUFFER)",
73
+ ['buf.replace_with_char("1")', "1zzz\n0yy\n"]]
74
+ end
75
+
76
+ def test_delete
77
+ [['buf.insert_txt("abcdef")', "abcdef\n"],
78
+ 'buf.insert_txt("\n")',
79
+ ['buf.insert_txt("yy")', "abcdef\nyy\n"],
80
+ "buf.jump(START_OF_BUFFER)",
81
+ :delete_char_forward,
82
+ [:delete_char_forward, "cdef\nyy\n"],
83
+ "buf.jump(END_OF_LINE)",
84
+ "buf.delete(BACKWARD_CHAR)",
85
+ ["buf.delete(BACKWARD_CHAR)", "cd\nyy\n"]]
86
+ end
87
+
88
+ def test_create_close_buf
89
+ ['buf.insert_txt("abcdef")',
90
+ [:buf_new,"\n"],
91
+ 'buf.insert_txt("a")',
92
+ 'buf.insert_txt("b")',
93
+ 'buf.insert_txt("c")',
94
+ 'buf.insert_txt("d")',
95
+ ['buf.insert_txt("e")',"abcde\n"],
96
+ [:close_current_buffer, "abcdef\n"]]
97
+ end
98
+ end
20
99
 
21
100
  def test_paste_0(runmacro = true)
22
101
  return
@@ -19,6 +19,8 @@ end
19
19
  Converter.new(lambda { |x| x.split("\n").collect { |x| r = x.strip }.select { |y| !y.empty? }.join(" ") + "\n" }, :lambda, :joinlines)
20
20
 
21
21
  Converter.new(lambda { |x| x.split("\n").sort.join("\n") }, :lambda, :sortlines)
22
+ Converter.new(lambda { |x| x.split("\n").reverse.join("\n") }, :lambda, :reverse_lines)
23
+
22
24
  Converter.new(lambda { |x| x.split(/\s+/).sort.join(" ") }, :lambda, :sortwords)
23
25
  Converter.new(lambda { |x| x.split("\n").collect { |b| b.scan(/(\d+(\.\d+)?)/).collect { |c| c[0] }.join(" ") }.join("\n") }, :lambda, :getnums_on_lines)
24
26
 
@@ -30,5 +32,8 @@ Converter.new(lambda { |x|
30
32
  x + "\n" + nums.join("+") + "=#{sum}"
31
33
  }, :lambda, :sum_of_numbers)
32
34
 
33
- c = Converter.new(lambda { |x| x.scan(/[\w\.]+@[\w\.]+/).join("\n") }, :lambda, :get_emails)
35
+ Converter.new(lambda { |x| x.scan(/[\w\.]+@[\w\.]+/).join("\n") }, :lambda, :get_emails)
36
+
37
+ # Eval selection as ruby code
38
+ Converter.new(lambda { |x| b = "eval failed"; begin; b = eval(x, TOPLEVEL_BINDING); rescue; end; "#{x}\n#{b}\n" }, :lambda, :eval)
34
39
 
data/lib/vimamsa/util.rb CHANGED
@@ -93,7 +93,7 @@ end
93
93
 
94
94
  # file --mime-type --mime-encoding
95
95
 
96
- # Run idle proc once
96
+ # Run idle proc once (return false)
97
97
  # Delay execution of proc until Gtk has fully processed the last calls.
98
98
  def run_as_idle(p, delay: 0.0)
99
99
  if p.class == Proc
@@ -141,6 +141,24 @@ def exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = ni
141
141
  return ret_str
142
142
  end
143
143
 
144
+ def pipe_to_external(program, text)
145
+ # Open a pipe to the external program
146
+ IO.popen(program, "r+") do |pipe|
147
+ # Send the text to the program
148
+ pipe.write(text)
149
+ pipe.close_write # Close the write end to signal EOF to the program
150
+ # Read and return the output from the program
151
+ output = pipe.read
152
+ return output
153
+ end
154
+ rescue Errno::ENOENT
155
+ puts "Error: The program '#{program}' was not found."
156
+ nil
157
+ rescue => e
158
+ puts "An error occurred: #{e.message}"
159
+ nil
160
+ end
161
+
144
162
  def mkdir_if_not_exists(_dirpath)
145
163
  dirpath = File.expand_path(_dirpath)
146
164
  Dir.mkdir(dirpath) unless File.exist?(dirpath)
@@ -1,3 +1,3 @@
1
1
  module Vimamsa
2
- VERSION = "0.1.19"
2
+ VERSION = "0.1.21"
3
3
  end
data/lib/vimamsa.rb CHANGED
@@ -2,6 +2,9 @@ require "vimamsa/version"
2
2
 
3
3
  require "vmaext"
4
4
 
5
+ $:.unshift File.expand_path(File.dirname(__FILE__)+"/../ext/stridx")
6
+ require "stridx"
7
+
5
8
  require "vimamsa/rbvma"
6
9
 
7
10
  module Vimamsa