vimamsa 0.1.13 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/vimamsa/macro.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  def gui_find_macro_update_callback(search_str = "")
2
2
  debug "gui_find_macro_update_callback: #{search_str}"
3
- heystack = $macro.named_macros
3
+ heystack = vma.macro.named_macros
4
4
  return [] if heystack.empty?
5
5
  $macro_search_list = []
6
6
  files = heystack.keys.sort.collect { |x| [x, 0] }
@@ -15,11 +15,11 @@ end
15
15
  def gui_find_macro_select_callback(search_str, idx)
16
16
  debug "gui_find_macro_select_callback"
17
17
  selected = $macro_search_list[idx]
18
- m = $macro.named_macros[selected[0]].clone
18
+ m = vma.macro.named_macros[selected[0]].clone
19
19
  debug "SELECTED MACRO:#{selected}, #{m}"
20
- id = $macro.last_macro
21
- $macro.recorded_macros[id] = m
22
- $macro.run_macro(id)
20
+ id = vma.macro.last_macro
21
+ vma.macro.recorded_macros[id] = m
22
+ vma.macro.run_macro(id)
23
23
  end
24
24
 
25
25
  class Macro
@@ -52,7 +52,7 @@ class Macro
52
52
  end
53
53
 
54
54
  def find_macro_gui()
55
- l = $macro.named_macros.keys.sort.collect { |x| [x, 0] }
55
+ l = vma.macro.named_macros.keys.sort.collect { |x| [x, 0] }
56
56
  $macro_search_list = l
57
57
  $select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
58
58
 
@@ -116,36 +116,46 @@ class Macro
116
116
  run_macro(@last_macro)
117
117
  end
118
118
 
119
- def run_macro(name)
120
- if $macro.is_recording == true
121
- message("Can't run a macro that runs a macro (recursion risk)")
122
- return false
123
- end
124
- message("Start running macro [#{name}]")
125
- if @recorded_macros.has_key?(name)
126
- @last_macro = name
127
- end
128
- acts = @recorded_macros[name]
119
+ # Run the provided list of actions
120
+ def run_actions(acts)
121
+ isok = true
129
122
  if acts.kind_of?(Array) and acts.any?
130
123
  @running_macro = true
131
- set_last_command({ method: $macro.method("run_macro"), params: [name] })
132
- #
124
+ # TODO:needed?
125
+ # set_last_command({ method: vma.macro.method("run_macro"), params: [name] })
133
126
  for a in acts
134
127
  ret = exec_action(a)
135
- debug ret
136
128
  if ret == false
137
- message("Error while running macro")
138
- Ripl.start :binding => binding
139
-
129
+ error "Error while running macro"
130
+ isok=false
140
131
  break
141
132
  end
142
133
  end
143
- # eval_str = m.join(";")
144
- # debug(eval_str)
145
- # eval(eval_str)
146
134
  end
147
135
  @running_macro = false
148
136
  buf.set_pos(buf.pos)
137
+ # TODO: Should be a better way to trigger this. Sometimes need to wait for GTK to process things before updating the cursor.
138
+ run_as_idle proc { vma.buf.refresh_cursor; vma.buf.refresh_cursor }, delay: 0.15
139
+ return isok
140
+ end
141
+
142
+ def run_macro(name)
143
+ if vma.macro.is_recording == true
144
+ message("Can't run a macro that runs a macro (recursion risk)")
145
+ return false
146
+ end
147
+ message("Start running macro [#{name}]")
148
+ if @recorded_macros.has_key?(name)
149
+ @last_macro = name
150
+ end
151
+ acts = @recorded_macros[name]
152
+ return run_actions(acts)
153
+ end
154
+
155
+ def dump_last_macro()
156
+ puts "======MACRO START======="
157
+ puts @recorded_macros[@last_macro].inspect
158
+ puts "======MACRO END========="
149
159
  end
150
160
 
151
161
  def save_macro(name)
data/lib/vimamsa/main.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #scriptdir=File.expand_path(File.dirname(__FILE__))
2
2
  $:.unshift File.dirname(__FILE__) + "/lib"
3
3
 
4
- # require 'benchmark/ips'
4
+ #/home/samsam/Drive/code/vimamsa/git/lib/vimamsa/lib/vimamsa/main.rb require 'benchmark/ips'
5
5
 
6
6
  # load "vendor/ver/lib/ver/vendor/textpow.rb"
7
7
  # load "vendor/ver/lib/ver/syntax/detector.rb"
@@ -19,26 +19,23 @@ end
19
19
  Encoding.default_external = Encoding::UTF_8
20
20
  Encoding.default_internal = Encoding::UTF_8
21
21
 
22
- # Globals
22
+ # Globals (TODO:refactor)
23
23
  $command_history = []
24
- $clipboard = []
25
- $register = Hash.new("")
26
- $cnf = {}
27
24
  $errors = []
28
25
 
29
- $cur_register = "a"
30
26
  $debuginfo = {}
31
27
 
32
- $jump_sequence = []
33
-
34
- $debug = false
35
- $experimental = false
28
+ cnf.debug = false
36
29
 
37
30
  # Return currently active buffer
38
31
  def buf()
39
32
  return vma.buf
40
33
  end
41
34
 
35
+ def hook
36
+ return vma.hook
37
+ end
38
+
42
39
  def bufs()
43
40
  return vma.buffers
44
41
  end
data/lib/vimamsa/rbvma.rb CHANGED
@@ -12,29 +12,40 @@ require "ripl/multi_line"
12
12
  require "shellwords"
13
13
  require "cgi"
14
14
  require "uri"
15
+ require "vimamsa/conf"
15
16
  require "vimamsa/util"
16
17
  # exit!
17
18
  require "vimamsa/main"
18
- require "vimamsa/form_generator"
19
+ require "vimamsa/terminal"
19
20
 
20
21
  require "vimamsa/actions"
21
22
  require "vimamsa/key_binding_tree"
22
23
  require "vimamsa/key_actions"
23
24
 
25
+ require "vimamsa/clipboard"
26
+
24
27
  # Graphical stuff:
25
28
  require "vimamsa/gui"
29
+ require "vimamsa/gui_form_generator"
30
+ require "vimamsa/gui_text"
26
31
  require "vimamsa/gui_menu"
32
+ require "vimamsa/gui_dialog"
27
33
  require "vimamsa/gui_select_window"
28
34
  require "vimamsa/gui_sourceview"
35
+ require "vimamsa/gui_sourceview_autocomplete"
29
36
  require "vimamsa/gui_image"
30
37
  require "vimamsa/hyper_plain_text"
31
38
 
32
39
  require "vimamsa/ack"
33
40
  require "vimamsa/buffer"
41
+ require "vimamsa/buffer_cursor"
42
+ require "vimamsa/buffer_changetext"
43
+ # require "vimamsa/buffer_list"
34
44
  require "vimamsa/buffer_list"
35
45
  require "vimamsa/buffer_manager"
36
46
  require "vimamsa/constants"
37
47
  require "vimamsa/debug"
48
+ require "vimamsa/tests"
38
49
  require "vimamsa/easy_jump"
39
50
  require "vimamsa/encrypt"
40
51
  require "vimamsa/file_finder"
@@ -43,7 +54,6 @@ require "vimamsa/hook"
43
54
  require "vimamsa/macro"
44
55
  require "vimamsa/search"
45
56
  require "vimamsa/search_replace"
46
- require "vimamsa/conf"
47
57
  # load "vendor/ver/lib/ver/vendor/textpow.rb"
48
58
  # load "vendor/ver/lib/ver/syntax/detector.rb"
49
59
  # load "vendor/ver/config/detect.rb"
@@ -52,15 +62,7 @@ def unimplemented
52
62
  debug "unimplemented"
53
63
  end
54
64
 
55
-
56
- $debug = false
57
-
58
- def scan_indexes(txt, regex)
59
- # indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) + 1 }
60
- indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) }
61
- return indexes
62
- end
63
-
65
+ cnf.debug = false
64
66
  $update_cursor = false
65
67
 
66
68
 
@@ -2,7 +2,7 @@
2
2
  def execute_search(input_str)
3
3
  $search = Search.new
4
4
  eval_str="execute_search(#{input_str.dump})"
5
- $macro.overwrite_current_action(eval_str)
5
+ vma.macro.overwrite_current_action(eval_str)
6
6
  return $search.set(input_str, "simple", vma.buf)
7
7
  end
8
8
 
@@ -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()
@@ -62,62 +56,117 @@ class FileSelector
62
56
  end
63
57
  end
64
58
 
65
- def gui_grep()
66
- callback = proc { |x| grep_cur_buffer(x) }
67
- # gui_one_input_action("Grep", "Search:", "grep", "grep_cur_buffer")
68
- gui_one_input_action("Grep", "Search:", "grep", callback)
69
- end
59
+ class Grep
60
+ attr_reader :buf
61
+ @@cur = nil # Current object of class
70
62
 
71
- def highlight_match(bf, str, color: "#aa0000ff")
72
- vbuf = bf.view.buffer
73
- r = Regexp.new(Regexp.escape(str), Regexp::IGNORECASE)
63
+ def self.cur()
64
+ return @@cur
65
+ end
74
66
 
75
- hlparts = []
67
+ def self.init()
68
+ vma.kbd.add_minor_mode("grep", :grep, :command)
69
+
70
+ if cnf.experimental?
71
+ bindkey "grep shift!", [:grep_apply_changes, proc {
72
+ if vma.buf.module.class == Grep
73
+ vma.buf.module.apply_changes
74
+ else
75
+ debug vma.buf.module, 2
76
+ message("ERROR")
77
+ end
78
+ }, "Write changes edited in grep buffer to the underlying file"]
79
+ end
80
+ vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
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")
76
87
 
77
- tt = vma.gui.view.buffer.create_tag("highlight_match_tag")
78
- tt.weight = 650
79
- tt.foreground = color
88
+ bindkey "C , g", :grep_buffer
89
+ bindkey "grep ctrl-r", :grep_refresh
90
+ end
80
91
 
81
- ind = scan_indexes(bf, r)
82
- ind.each { |x|
83
- itr = vbuf.get_iter_at(:offset => x)
84
- itr2 = vbuf.get_iter_at(:offset => x + str.size)
85
- vbuf.apply_tag(tt, itr, itr2)
86
- }
87
- end
92
+ def apply_changes()
93
+ b = @orig_buf
94
+ gb = vma.buf
95
+ changed = 0
96
+ gb.lines.each { |x|
97
+ if m = x.match(/(\d+):(.*)/m)
98
+ lineno = m[1].to_i
99
+ newl = m[2]
100
+ r = @orig_buf.line_range(lineno - 1, 1)
101
+ old = @orig_buf[r.first..r.last]
102
+ if old != newl
103
+ @orig_buf.replace_range(r, newl)
104
+ changed += 1
105
+ end
106
+ end
107
+ }
108
+ message("GREP: apply changes, #{changed} changed lines")
109
+ end
88
110
 
89
- def grep_cur_buffer(search_str, b = nil)
90
- debug "grep_cur_buffer(search_str)"
91
- lines = vma.buf.split("\n")
92
- r = Regexp.new(Regexp.escape(search_str), Regexp::IGNORECASE)
93
- fpath = ""
94
- fpath = vma.buf.pathname.expand_path.to_s + ":" if vma.buf.pathname
95
- res_str = ""
96
-
97
- hlparts = []
98
- $grep_matches = []
99
- lines.each_with_index { |l, i|
100
- if r.match(l)
101
- res_str << "#{i + 1}:"
102
- # ind = scan_indexes(l, r)
103
- res_str << "#{l}\n"
104
- $grep_matches << i + 1 # Lines start from index 1
105
- end
106
- }
107
- $grep_bufid = vma.buffers.current_buf
108
- b = create_new_buffer(res_str, "grep")
109
- vbuf = vma.gui.view.buffer
110
-
111
- highlight_match(b, search_str, color: "#10bd8e")
112
-
113
- b.line_action_handler = proc { |lineno|
114
- debug "GREP HANDLER:#{lineno}"
115
- jumpto = $grep_matches[lineno]
116
- if jumpto.class == Integer
117
- vma.buffers.set_current_buffer($grep_bufid, update_history = true)
118
- buf.jump_to_line(jumpto)
119
- end
120
- }
111
+ def initialize()
112
+ @buf = nil
113
+ @line_to_id = {}
114
+ end
115
+
116
+ def refresh
117
+ set_buf_contents
118
+ end
119
+
120
+ def set_buf_contents()
121
+ lines = @orig_buf.split("\n")
122
+
123
+ @grep_matches = []
124
+
125
+ res_str = ""
126
+ lines.each_with_index { |l, i|
127
+ if @r.match(l)
128
+ res_str << "#{i + 1}:"
129
+ # ind = scan_indexes(l, r)
130
+ res_str << "#{l}\n"
131
+ @grep_matches << i + 1 # Lines start from index 1
132
+ end
133
+ }
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
147
+ @orig_buf = vma.buf
148
+ @buf = create_new_buffer("", "grep")
149
+
150
+ @buf.default_mode = :grep
151
+ @buf.module = self
152
+
153
+ vma.kbd.set_mode(:grep)
154
+ @buf.line_action_handler = proc { |lineno|
155
+ debug "GREP HANDLER:#{lineno}"
156
+ jumpto = @grep_matches[lineno]
157
+ if jumpto.class == Integer
158
+ vma.buffers.set_current_buffer_by_id(@orig_buf.id)
159
+ @orig_buf.jump_to_line(jumpto)
160
+ end
161
+ }
162
+
163
+ set_buf_contents
164
+ end
165
+
166
+ def run()
167
+ callb = self.method("callback")
168
+ gui_one_input_action("Grep", "Search:", "grep", callb)
169
+ end
121
170
  end
122
171
 
123
172
  def gui_one_input_action(title, field_label, button_title, callback, opt = {})
@@ -184,106 +233,3 @@ def buf_replace_string(instr)
184
233
  end
185
234
  buf_replace(a[0], a[1])
186
235
  end
187
-
188
- module Gtk
189
- class Frame
190
- def margin=(a)
191
- self.margin_bottom = a
192
- self.margin_top = a
193
- self.margin_end = a
194
- self.margin_start = a
195
- end
196
- end
197
-
198
- class Box
199
- def margin=(a)
200
- self.margin_bottom = a
201
- self.margin_top = a
202
- self.margin_end = a
203
- self.margin_start = a
204
- end
205
- end
206
- end
207
-
208
- def set_margin_all(widget, m)
209
- widget.margin_bottom = m
210
- widget.margin_top = m
211
- widget.margin_end = m
212
- widget.margin_start = m
213
- end
214
-
215
- class OneInputAction
216
- def initialize(main_window, title, field_label, button_title, callback, opt = {})
217
- @window = Gtk::Window.new()
218
- # @window.screen = main_window.screen
219
- # @window.title = title
220
- @window.title = ""
221
-
222
- frame = Gtk::Frame.new()
223
- # frame.margin = 20
224
- @window.set_child(frame)
225
-
226
- infolabel = Gtk::Label.new
227
- infolabel.markup = title
228
-
229
- vbox = Gtk::Box.new(:vertical, 8)
230
- vbox.margin = 10
231
- frame.set_child(vbox)
232
-
233
- hbox = Gtk::Box.new(:horizontal, 8)
234
- # @window.add(hbox)
235
- vbox.pack_end(infolabel, :expand => false, :fill => false, :padding => 0)
236
- vbox.pack_end(hbox, :expand => false, :fill => false, :padding => 0)
237
-
238
- button = Gtk::Button.new(:label => button_title)
239
- cancel_button = Gtk::Button.new(:label => "Cancel")
240
-
241
- label = Gtk::Label.new(field_label)
242
-
243
- @entry1 = Gtk::Entry.new
244
-
245
- if opt[:hide]
246
- @entry1.visibility = false
247
- end
248
-
249
- button.signal_connect "clicked" do
250
- callback.call(@entry1.text)
251
- @window.destroy
252
- end
253
-
254
- cancel_button.signal_connect "clicked" do
255
- @window.destroy
256
- end
257
-
258
- press = Gtk::EventControllerKey.new
259
- press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
260
- @window.add_controller(press)
261
- press.signal_connect "key-pressed" do |gesture, keyval, keycode, y|
262
- if keyval == Gdk::Keyval::KEY_Return
263
- callback.call(@entry1.text)
264
- @window.destroy
265
- true
266
- elsif keyval == Gdk::Keyval::KEY_Escape
267
- @window.destroy
268
- true
269
- else
270
- false
271
- end
272
- end
273
-
274
- hbox.pack_end(label, :expand => false, :fill => false, :padding => 0)
275
- hbox.pack_end(@entry1, :expand => false, :fill => false, :padding => 0)
276
- hbox.pack_end(button, :expand => false, :fill => false, :padding => 0)
277
- hbox.pack_end(cancel_button, :expand => false, :fill => false, :padding => 0)
278
- return
279
- end
280
-
281
- def run
282
- if !@window.visible?
283
- @window.show
284
- else
285
- @window.destroy
286
- end
287
- @window
288
- end
289
- end
@@ -0,0 +1,34 @@
1
+
2
+ def exec_in_terminal(cmd, autoclose = false)
3
+ # debug "CMD:#{cmd}"
4
+
5
+ # global to prevent garbage collect unlink
6
+ $initf = Tempfile.new("bashinit")
7
+ # debug $initf.path
8
+ $initf.write(cmd)
9
+ if autoclose
10
+ $initf.write("\nsleep 10; exit;\n")
11
+ $initf.write("rm #{$initf.path}\n")
12
+ else
13
+ $initf.write("rm #{$initf.path}\n")
14
+ $initf.write("\nexec bash\n")
15
+ end
16
+ $initf.close
17
+ # PTY.spawn("gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash")
18
+ # fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" }
19
+ # Just another execution
20
+ fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" }
21
+ end
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
+
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
@@ -0,0 +1,122 @@
1
+ require "digest"
2
+
3
+ def run_tests()
4
+ tests = ["test_paste_0","test_delete_0"]
5
+ stats = []
6
+ for t in tests
7
+ r = eval(t)
8
+ if r == true
9
+ stats << "test #{t} OK"
10
+ else
11
+ stats << "test #{t} FAILED"
12
+ end
13
+ end
14
+ debug "TEST RESULTS:",2
15
+ puts stats.join("\n")
16
+ puts "===================="
17
+
18
+ end
19
+
20
+
21
+ #
22
+
23
+ def test_paste_0(runmacro = true)
24
+ b = create_new_buffer(file_contents = "\n", prefix = "buf", setcurrent = true)
25
+
26
+ b.insert_txt(JABBERWOCKY)
27
+ b.insert_txt(LOREM_IPSUM)
28
+ b.insert_txt(LOREM_IPSUM)
29
+
30
+ macro = ["buf.jump(START_OF_BUFFER)", "buf.copy_line", :forward_line, :paste_after, :backward_line, :backward_line, "buf.paste(BEFORE)", :forward_line, :forward_line, :forward_line, :forward_line, "buf.jump_word(FORWARD,WORD_START)", "buf.start_visual_mode", "buf.jump_word(FORWARD,WORD_END)", "buf.copy_active_selection()", "buf.move(FORWARD_CHAR)", "buf.paste(BEFORE)", "buf.jump_word(FORWARD,WORD_END)", :paste_after, :forward_line, "buf.jump(BEGINNING_OF_LINE)", "buf.copy_line", :forward_line, :forward_line, :paste_after, :paste_after, :forward_line, "buf.jump_word(FORWARD,WORD_START)", "buf.start_visual_mode", "buf.jump_word(FORWARD,WORD_END)", "buf.jump_word(FORWARD,WORD_END)", "buf.jump_word(FORWARD,WORD_END)", "buf.jump_word(FORWARD,WORD_END)", "buf.jump(END_OF_LINE)", :e_move_backward_char, "buf.copy_active_selection()", :forward_line, "buf.paste(BEFORE)", "buf.paste(BEFORE)", "buf.paste(BEFORE)", "buf.paste(BEFORE)", "buf.jump(END_OF_BUFFER)", "buf.jump(BEGINNING_OF_LINE)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.start_visual_mode", "buf.jump_word(FORWARD,WORD_END)", "buf.jump_word(FORWARD,WORD_END)", "buf.jump_word(FORWARD,WORD_END)", "buf.jump_word(FORWARD,WORD_END)", "buf.copy_active_selection()", "buf.jump(BEGINNING_OF_LINE)", "buf.paste(BEFORE)", "buf.paste(BEFORE)"]
31
+
32
+ macro_r = true
33
+ if runmacro
34
+ macro_r = vma.macro.run_actions(macro)
35
+ end
36
+
37
+ hex = Digest::SHA2.hexdigest b.to_s
38
+ conds = [hex == "705061f7bc6370b501b6d09615547530a103e2a659e20fb6915d17ae65f564fa",
39
+ macro_r == true]
40
+ # debug conds
41
+ debug hex
42
+
43
+ if conds.include?(false)
44
+ return false
45
+ else
46
+ return true
47
+ end
48
+ end
49
+
50
+ def macro_test(macro, correct_hex, runmacro=true)
51
+ b = create_new_buffer(file_contents = "\n", prefix = "buf", setcurrent = true)
52
+ b.insert_txt(JABBERWOCKY)
53
+ b.insert_txt(LOREM_IPSUM)
54
+ b.insert_txt(LOREM_IPSUM)
55
+
56
+ macro_r = true
57
+ if runmacro
58
+ macro_r = vma.macro.run_actions(macro)
59
+ end
60
+
61
+ hex = Digest::SHA2.hexdigest b.to_s
62
+ conds = [hex == correct_hex,
63
+ macro_r == true]
64
+ # debug conds
65
+ debug hex
66
+
67
+ if conds.include?(false)
68
+ return false
69
+ else
70
+ return true
71
+ end
72
+ end
73
+
74
+ def test_delete_0
75
+ macro = ["buf.jump(START_OF_BUFFER)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", :e_move_backward_char, "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", :forward_line, :e_move_backward_char, "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", "buf.delete(CURRENT_CHAR_FORWARD)", :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, :delete_line, :forward_line, :delete_line, :forward_line, :forward_line, :delete_line, :delete_line, :forward_line, :forward_line, "vma.kbd.set_mode(:audio)", :forward_line, :forward_line, :forward_line, :forward_line, "buf.delete2(:to_mark,'a')", :backward_line, :forward_line, :forward_line, "vma.kbd.set_mode(:audio)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.jump_word(FORWARD,WORD_START)", "buf.delete2(:to_mark,'a')", "buf.mark_current_position('b')", :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, :forward_line, "buf.delete2(:to_mark,'a')", "vma.kbd.set_mode(:audio)", :forward_line, :forward_line, :forward_line, "buf.jump_to_mark('a')", "buf.jump_to_mark('a')", :backward_line, :backward_line, :backward_line, :backward_line, "buf.jump_to_mark('a')", "buf.jump_to_mark('a')", "buf.jump_to_mark('a')", "buf.jump_to_mark('a')"]
76
+ return macro_test(macro, "71bc0421b47549267b327b69216ad8e042379625f99de1ba4faaa30d5042c22d")
77
+ end
78
+
79
+ LOREM_IPSUM = "
80
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
81
+
82
+ Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst."
83
+
84
+ JABBERWOCKY = "
85
+ ’Twas brillig, and the slithy toves
86
+ Did gyre and gimble in the wabe:
87
+ All mimsy were the borogoves,
88
+ And the mome raths outgrabe.
89
+
90
+ “Beware the Jabberwock, my son!
91
+ The jaws that bite, the claws that catch!
92
+ Beware the Jubjub bird, and shun
93
+ The frumious Bandersnatch!”
94
+
95
+ He took his vorpal sword in hand;
96
+ Long time the manxome foe he sought—
97
+ So rested he by the Tumtum tree
98
+ And stood awhile in thought.
99
+
100
+ And, as in uffish thought he stood,
101
+ The Jabberwock, with eyes of flame,
102
+ Came whiffling through the tulgey wood,
103
+ And burbled as it came!
104
+
105
+ One, two! One, two! And through and through
106
+ The vorpal blade went snicker-snack!
107
+ He left it dead, and with its head
108
+ He went galumphing back.
109
+
110
+ “And hast thou slain the Jabberwock?
111
+ Come to my arms, my beamish boy!
112
+ O frabjous day! Callooh! Callay!”
113
+ He chortled in his joy.
114
+
115
+ ’Twas brillig, and the slithy toves
116
+ Did gyre and gimble in the wabe:
117
+ All mimsy were the borogoves,
118
+ And the mome raths outgrabe.
119
+ "
120
+
121
+
122
+