vimamsa 0.1.26 → 0.1.28

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 (229) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +93 -0
  3. data/.gitignore +4 -1
  4. data/Dockerfile +7 -4
  5. data/README.md +195 -99
  6. data/custom_example.rb +59 -17
  7. data/doc/TODO.md +678 -0
  8. data/doc/action_names_plan.md +442 -0
  9. data/doc/bundling_plan.md +570 -0
  10. data/doc/delta_syntax_plan.md +293 -0
  11. data/doc/demo_recording_plan.md +288 -0
  12. data/doc/design_goals.md +27 -0
  13. data/doc/intro_page_plan.md +266 -0
  14. data/doc/key_bindings_report_plan.md +213 -0
  15. data/doc/line_tree_plan.md +89 -0
  16. data/doc/missing_vim_bindings.md +61 -0
  17. data/doc/modules_settings_plan.md +433 -0
  18. data/doc/refactor_dedup_plan.md +117 -0
  19. data/doc/registries_plan.md +202 -0
  20. data/doc/startup_speed_plan.md +97 -0
  21. data/doc/treap_visualizer.html +585 -0
  22. data/doc/unused_code_plan.md +120 -0
  23. data/doc/vim_compatibility_plan.md +451 -0
  24. data/doc/vimlike_vim_conflicts.md +262 -0
  25. data/doc/vm_snapshots_plan.md +146 -0
  26. data/doc/wysiwyg_plan.md +231 -0
  27. data/exe/run_tests.rb +124 -3
  28. data/exe/vimamsa +68 -5
  29. data/fonts/OFL-Oxanium.txt +93 -0
  30. data/fonts/Oxanium[wght].ttf +0 -0
  31. data/help/intro.txt +30 -0
  32. data/help/vim_intro.txt +31 -0
  33. data/icon.png +0 -0
  34. data/img/demo.gif +0 -0
  35. data/img/demo.mp4 +0 -0
  36. data/lang/hyperplaintext.lang +7 -1
  37. data/lib/vimamsa/ack.rb +13 -1
  38. data/lib/vimamsa/actions.rb +385 -37
  39. data/lib/vimamsa/appimage_env.rb +35 -0
  40. data/lib/vimamsa/audio.rb +2 -5
  41. data/lib/vimamsa/bookmarks.rb +302 -0
  42. data/lib/vimamsa/buffer.rb +675 -118
  43. data/lib/vimamsa/buffer_changetext.rb +150 -68
  44. data/lib/vimamsa/buffer_cursor.rb +7 -0
  45. data/lib/vimamsa/buffer_list.rb +6 -2
  46. data/lib/vimamsa/buffer_manager.rb +10 -7
  47. data/lib/vimamsa/bundled_fonts.rb +32 -0
  48. data/lib/vimamsa/cli_help.rb +75 -0
  49. data/lib/vimamsa/clipboard.rb +9 -3
  50. data/lib/vimamsa/conf.rb +68 -3
  51. data/lib/vimamsa/constants.rb +3 -0
  52. data/lib/vimamsa/crash_handler.rb +149 -0
  53. data/lib/vimamsa/debug.rb +6 -3
  54. data/lib/vimamsa/demo_player.rb +458 -0
  55. data/lib/vimamsa/demo_recorder.rb +277 -0
  56. data/lib/vimamsa/desktop_install.rb +96 -0
  57. data/lib/vimamsa/diff_buffer.rb +40 -11
  58. data/lib/vimamsa/dot_repeat.rb +104 -0
  59. data/lib/vimamsa/easy_jump.rb +57 -3
  60. data/lib/vimamsa/editor.rb +327 -78
  61. data/lib/vimamsa/encrypt.rb +78 -29
  62. data/lib/vimamsa/file_finder.rb +4 -19
  63. data/lib/vimamsa/file_history.rb +4 -1
  64. data/lib/vimamsa/file_manager.rb +46 -31
  65. data/lib/vimamsa/fold.rb +226 -0
  66. data/lib/vimamsa/form_input.rb +388 -0
  67. data/lib/vimamsa/gui.rb +603 -119
  68. data/lib/vimamsa/gui_command_line.rb +247 -0
  69. data/lib/vimamsa/gui_dialog.rb +94 -42
  70. data/lib/vimamsa/gui_file_panel.rb +356 -25
  71. data/lib/vimamsa/gui_form_generator.rb +75 -40
  72. data/lib/vimamsa/gui_func_panel.rb +67 -22
  73. data/lib/vimamsa/gui_image.rb +3 -0
  74. data/lib/vimamsa/gui_key_hint.rb +165 -0
  75. data/lib/vimamsa/gui_keylog_panel.rb +408 -0
  76. data/lib/vimamsa/gui_menu.rb +84 -53
  77. data/lib/vimamsa/gui_select_window.rb +80 -75
  78. data/lib/vimamsa/gui_settings.rb +86 -41
  79. data/lib/vimamsa/gui_sourceview.rb +280 -92
  80. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  81. data/lib/vimamsa/gui_text.rb +63 -2
  82. data/lib/vimamsa/gui_theme.rb +615 -0
  83. data/lib/vimamsa/hook.rb +5 -0
  84. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  85. data/lib/vimamsa/intro_page.rb +368 -0
  86. data/lib/vimamsa/key_actions.rb +382 -193
  87. data/lib/vimamsa/key_binding_tree.rb +467 -273
  88. data/lib/vimamsa/key_bindings_notepad.rb +45 -0
  89. data/lib/vimamsa/key_bindings_report.rb +484 -0
  90. data/lib/vimamsa/key_bindings_vim.rb +104 -0
  91. data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
  92. data/lib/vimamsa/key_names.rb +80 -0
  93. data/lib/vimamsa/langservp.rb +271 -54
  94. data/lib/vimamsa/line_tree.rb +367 -0
  95. data/lib/vimamsa/macro.rb +23 -3
  96. data/lib/vimamsa/main.rb +14 -8
  97. data/lib/vimamsa/rbvma.rb +41 -1
  98. data/lib/vimamsa/registers.rb +125 -0
  99. data/lib/vimamsa/run_ruby.rb +64 -0
  100. data/lib/vimamsa/search.rb +3 -0
  101. data/lib/vimamsa/search_replace.rb +15 -14
  102. data/lib/vimamsa/string_util.rb +134 -40
  103. data/lib/vimamsa/terminal.rb +3 -0
  104. data/lib/vimamsa/test_framework.rb +28 -2
  105. data/lib/vimamsa/tests.rb +11 -8
  106. data/lib/vimamsa/text_objects.rb +310 -0
  107. data/lib/vimamsa/text_transforms.rb +18 -0
  108. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  109. data/lib/vimamsa/user_dirs.rb +83 -0
  110. data/lib/vimamsa/util.rb +46 -7
  111. data/lib/vimamsa/version.rb +1 -1
  112. data/lib/vimamsa/vim_core.rb +355 -0
  113. data/lib/vimamsa/vim_operators.rb +365 -0
  114. data/lib/vimamsa.rb +0 -1
  115. data/modules/calculator/calculator.rb +5 -5
  116. data/modules/color_highlight/color_highlight.rb +118 -0
  117. data/modules/color_highlight/color_highlight_info.rb +3 -0
  118. data/modules/dictation/dictation.rb +1054 -0
  119. data/modules/dictation/dictation_info.rb +3 -0
  120. data/modules/dictation/whisper_worker.py +273 -0
  121. data/modules/ollama/ollama.rb +107 -0
  122. data/modules/ollama/ollama_info.rb +3 -0
  123. data/modules/terminal/terminal.rb +5 -5
  124. data/modules/tts/tts.rb +119 -0
  125. data/modules/tts/tts_info.rb +3 -0
  126. data/run_e2e_vm.sh +28 -0
  127. data/run_tests_vm.rb +138 -0
  128. data/scripts/appimage/AppRun +54 -0
  129. data/scripts/appimage/Dockerfile +18 -0
  130. data/scripts/appimage/build.sh +19 -0
  131. data/scripts/appimage/build_in_container.sh +192 -0
  132. data/scripts/appimage/smoke_test.sh +27 -0
  133. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  134. data/scripts/demo/demo_files_steps.txt +52 -0
  135. data/scripts/demo/demo_steps.txt +67 -0
  136. data/scripts/demo/notes.txt +6 -0
  137. data/scripts/demo/record_demo.rb +156 -0
  138. data/scripts/demo/report.rb +7 -0
  139. data/scripts/demo/shapes.rb +29 -0
  140. data/scripts/demo/square/shapes.rb +29 -0
  141. data/scripts/demo/square/steps.txt +185 -0
  142. data/scripts/lib/perf_startup.rb +138 -0
  143. data/scripts/lib/script_helpers.rb +53 -0
  144. data/scripts/perf_compare.rb +34 -0
  145. data/scripts/profile_startup.rb +72 -0
  146. data/styles/134272-molokai.xml +3 -0
  147. data/styles/molokai_cyber.xml +48 -0
  148. data/styles/molokai_edit.xml +1 -0
  149. data/tests/support/virtual_keyboard.rb +254 -0
  150. data/tests/support/virtual_mic.rb +67 -0
  151. data/tests/test_ack.rb +22 -0
  152. data/tests/test_action_ids.rb +232 -0
  153. data/tests/test_auto_format.rb +122 -0
  154. data/tests/test_autocomplete.rb +211 -0
  155. data/tests/test_autosave.rb +145 -0
  156. data/tests/test_basic_editing.rb +46 -16
  157. data/tests/test_bookmarks.rb +206 -0
  158. data/tests/test_bracket_match.rb +88 -0
  159. data/tests/test_bundling.rb +92 -0
  160. data/tests/test_cli_help.rb +64 -0
  161. data/tests/test_color_highlight.rb +92 -0
  162. data/tests/test_command_line.rb +79 -0
  163. data/tests/test_command_line_file.rb +27 -0
  164. data/tests/test_context_menu_file.rb +147 -0
  165. data/tests/test_copy_paste.rb +106 -26
  166. data/tests/test_crash_handler.rb +39 -0
  167. data/tests/test_custom_two_phase.rb +92 -0
  168. data/tests/test_demo_player.rb +301 -0
  169. data/tests/test_demo_recorder.rb +202 -0
  170. data/tests/test_dialog_callback_errors.rb +44 -0
  171. data/tests/test_dictation.rb +294 -0
  172. data/tests/test_diff_buffer_name.rb +51 -0
  173. data/tests/test_dot_repeat.rb +88 -0
  174. data/tests/test_double_click.rb +41 -0
  175. data/tests/test_drag_selection.rb +125 -0
  176. data/tests/test_e2e_cmdline.rb +116 -0
  177. data/tests/test_e2e_dictation.rb +98 -0
  178. data/tests/test_e2e_replace_char.rb +58 -0
  179. data/tests/test_easy_jump.rb +93 -0
  180. data/tests/test_extract_file_links.rb +55 -0
  181. data/tests/test_file_format.rb +217 -0
  182. data/tests/test_file_manager.rb +72 -0
  183. data/tests/test_file_panel.rb +269 -0
  184. data/tests/test_flash.rb +78 -0
  185. data/tests/test_fold.rb +111 -0
  186. data/tests/test_font_refresh.rb +56 -0
  187. data/tests/test_form_input.rb +203 -0
  188. data/tests/test_func_panel.rb +68 -0
  189. data/tests/test_grep_apply.rb +46 -0
  190. data/tests/test_gtk_sync.rb +126 -0
  191. data/tests/test_hpt_highlight_visible.rb +75 -0
  192. data/tests/test_hpt_link_highlight.rb +82 -0
  193. data/tests/test_intro_page.rb +437 -0
  194. data/tests/test_jump_to_file.rb +41 -0
  195. data/tests/test_key_bindings.rb +208 -0
  196. data/tests/test_key_categories.rb +163 -0
  197. data/tests/test_keylog_panel.rb +261 -0
  198. data/tests/test_line_ends.rb +51 -0
  199. data/tests/test_line_tree.rb +86 -0
  200. data/tests/test_lsp_clangd.rb +281 -0
  201. data/tests/test_lsp_jump.rb +87 -0
  202. data/tests/test_lsp_position_encoding.rb +49 -0
  203. data/tests/test_lsp_symbols.rb +68 -0
  204. data/tests/test_macro.rb +137 -0
  205. data/tests/test_markdown_highlight.rb +57 -0
  206. data/tests/test_mode_badge.rb +41 -0
  207. data/tests/test_module_interface.rb +9 -9
  208. data/tests/test_notepad_bindings.rb +67 -0
  209. data/tests/test_perf_startup.rb +28 -0
  210. data/tests/test_popup_queue.rb +51 -0
  211. data/tests/test_random_edit.rb +109 -0
  212. data/tests/test_registers.rb +122 -0
  213. data/tests/test_revert.rb +127 -0
  214. data/tests/test_run_ruby.rb +77 -0
  215. data/tests/test_startup_file.rb +58 -0
  216. data/tests/test_status_area.rb +50 -0
  217. data/tests/test_text_objects.rb +163 -0
  218. data/tests/test_text_transforms.rb +341 -0
  219. data/tests/test_tmp_user_dir.rb +79 -0
  220. data/tests/test_tts.rb +68 -0
  221. data/tests/test_undo.rb +34 -34
  222. data/tests/test_user_dirs.rb +122 -0
  223. data/tests/test_vim_bindings.rb +353 -0
  224. data/tests/test_vim_conflicts.rb +100 -0
  225. data/tests/test_vim_operators.rb +116 -0
  226. data/tests/test_window_layout.rb +302 -0
  227. data/vimamsa.gemspec +3 -1
  228. data/vm_guest_run.sh +129 -0
  229. metadata +167 -10
@@ -0,0 +1,64 @@
1
+ require "open3"
2
+ require "tempfile"
3
+
4
+ module Vimamsa
5
+ # buf.run.ruby: runs the current file with Ruby and shows what it printed in
6
+ # a buffer. A separate process, not eval: a script can't hang, crash or
7
+ # change the editor, and it runs as it would from a terminal (its own
8
+ # __FILE__, require_relative, exit). Output and errors come in the order
9
+ # printed (stdout and stderr together), so a backtrace's file:line lines can
10
+ # be followed with enter. The file is saved first if it has changes; a buffer
11
+ # without a file runs from a temporary copy.
12
+
13
+ # The Ruby to run scripts with: `ruby` on the PATH (the user's, with their
14
+ # gems), else the editor's own
15
+ def script_ruby
16
+ ENV["PATH"].to_s.split(File::PATH_SEPARATOR).map { |d| File.join(d, "ruby") }
17
+ .find { |f| File.executable?(f) && !File.directory?(f) } || RbConfig.ruby
18
+ end
19
+
20
+ def run_buffer_as_ruby(b = vma.buf)
21
+ return message("No buffer to run") if b.nil?
22
+ tmp = nil
23
+ if b.fname
24
+ b.save if b.unsaved_changes?
25
+ path = b.fname
26
+ else
27
+ tmp = Tempfile.new(["vimamsa-run", ".rb"])
28
+ tmp.write(b.to_s)
29
+ tmp.close
30
+ path = tmp.path
31
+ end
32
+ dir = File.dirname(path)
33
+ name = b.fname ? File.basename(path) : b.title.to_s
34
+ message("Running #{name} with Ruby...")
35
+ t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
36
+ Thread.new {
37
+ begin
38
+ # stdout unbuffered (it is a pipe here), so output and errors come in
39
+ # the order printed; load keeps the script's __FILE__ and $0
40
+ out, st = Open3.capture2e(script_ruby, "-e", "STDOUT.sync = true; $0 = ARGV[0]; load ARGV.shift", path, chdir: dir)
41
+ rescue => e
42
+ out, st = "#{e.class}: #{e.message}\n", nil
43
+ end
44
+ secs = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0
45
+ tmp&.unlink
46
+ GLib::Idle.add {
47
+ show_ruby_output(b.fname || name, out, st, secs)
48
+ false
49
+ }
50
+ }
51
+ end
52
+
53
+ # The output in a buffer (the previous output of the same file is replaced)
54
+ def show_ruby_output(name, out, status, secs)
55
+ vma.buffers.list.select { |x| x.instance_variable_get(:@ruby_output_of) == name }
56
+ .each { |x| vma.buffers.close_buffer(x.id) }
57
+ code = status ? status.exitstatus : "-"
58
+ head = "# ruby #{name} (exit #{code}, #{format("%.2f", secs)} s)\n\n"
59
+ ob = create_new_buffer(head + (out.empty? ? "(no output)\n" : out), "ruby-output")
60
+ ob.instance_variable_set(:@ruby_output_of, name)
61
+ message(status&.success? ? "Ruby: done" : "Ruby: exit status #{code}")
62
+ ob
63
+ end
64
+ end # module Vimamsa
@@ -1,4 +1,6 @@
1
1
 
2
+ module Vimamsa
3
+
2
4
  def execute_search(input_str)
3
5
  $search = Search.new
4
6
  eval_str="execute_search(#{input_str.dump})"
@@ -95,3 +97,4 @@ class Search
95
97
  end
96
98
 
97
99
 
100
+ end # module Vimamsa
@@ -1,4 +1,6 @@
1
1
 
2
+ module Vimamsa
3
+
2
4
  class FileSelector
3
5
  def initialize()
4
6
  @buf = nil
@@ -67,26 +69,24 @@ class Grep
67
69
  def self.init()
68
70
  vma.kbd.add_minor_mode("grep", :grep, :command)
69
71
 
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
72
  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 {
73
+ reg_act("grep.buf", proc { Grep.new.run }, "Grep current buffer")
74
+ reg_act("grep.refresh", proc {
83
75
  if vma.buf.module.class == Grep
84
76
  vma.buf.module.refresh
85
77
  end
86
78
  }, "Refresh current Grep buffer")
87
79
 
88
- bindkey "C , g", :grep_buffer
89
- bindkey "grep ctrl-r", :grep_refresh
80
+ bindkey "C , g", "grep.buf"
81
+ bindkey "grep ctrl-r", "grep.refresh"
82
+ end
83
+
84
+ # Called by Buffer#save. Saving a grep buffer writes the edited lines back to
85
+ # the original buffer. Returns false to fall back to a normal save.
86
+ def on_save()
87
+ return false if !cnf.experimental?
88
+ apply_changes
89
+ return true
90
90
  end
91
91
 
92
92
  def apply_changes()
@@ -233,3 +233,4 @@ def buf_replace_string(instr)
233
233
  end
234
234
  buf_replace(a[0], a[1])
235
235
  end
236
+ end # module Vimamsa
@@ -1,56 +1,150 @@
1
- def flip_true_false(str)
2
- str.gsub(/\b(true|false)\b/i) do |match|
3
- if match.match?(/\Atrue\z/i)
4
- replacement = "false"
5
- else
6
- replacement = "true"
1
+ module Vimamsa
2
+ def flip_term(str)
3
+ y = str.downcase
4
+ replacements = [
5
+ %w[true false],
6
+ %w[left right],
7
+ %w[begin end],
8
+ %w[spring summer autumn winter],
9
+ ("a".."z").to_a,
10
+ %w[january february march april may june july august september october november december],
11
+ %w[jan feb mar apr may jun jul aug sep oct nov dec],
12
+ %w[monday tuesday wednesday thursday friday saturday sunday],
13
+ %w[mon tue wed thu fri sat sun],
14
+ %w[zero one two three four five six seven eight nine ten],
15
+ %w[north east south west],
16
+ %w[am pm],
17
+ %w[todo doing done],
18
+ %w[yes no],
19
+ %w[on off],
20
+ %w[enabled disabled],
21
+ %w[enable disable],
22
+ %w[active inactive],
23
+ %w[open closed],
24
+ %w[public private],
25
+ %w[visible hidden],
26
+ %w[show hide],
27
+ %w[up down],
28
+ %w[top bottom],
29
+ %w[first last],
30
+ %w[next previous],
31
+ %w[before after],
32
+ %w[min max],
33
+ %w[minimum maximum],
34
+ %w[increase decrease],
35
+ %w[push pop],
36
+ %w[add remove],
37
+ %w[include exclude],
38
+ %w[read write],
39
+ %w[input output],
40
+ %w[source target],
41
+ %w[start stop],
42
+ # %w[start finish],
43
+ %w[create destroy],
44
+ %w[connect disconnect],
45
+ %w[attach detach],
46
+ %w[lock unlock],
47
+ %w[valid invalid],
48
+ %w[success failure],
49
+ %w[pass fail],
50
+ %w[positive negative],
51
+ %w[gain loss],
52
+ %w[ascending descending],
53
+ %w[horizontal vertical],
54
+ %w[portrait landscape],
55
+ %w[absolute relative],
56
+ %w[local remote],
57
+ %w[client server],
58
+ %w[request response],
59
+ %w[parent child],
60
+ %w[head tail],
61
+ %w[prefix suffix],
62
+ %w[foreground background],
63
+ %w[light dark],
64
+ %w[black white],
65
+ ]
66
+
67
+ rep = nil
68
+ for x in replacements
69
+ i = x.find_index(y)
70
+ if i
71
+ i = (i + 1) % x.size
72
+ rep = x[i]
73
+ rep = preserve_case(str, rep)
74
+ return rep
75
+ end
7
76
  end
77
+ flip_numbered_term(str)
78
+ end
79
+
80
+ def flip_numbered_term(str)
81
+ return nil unless str =~ /\A(.*?)(\d+)\z/
82
+
83
+ prefix = Regexp.last_match(1)
84
+ number = Regexp.last_match(2)
8
85
 
9
- # preserve casing style
10
- if match == match.upcase
86
+ next_number = number.to_i + 1
87
+
88
+ # Preserve zero padding: item001 -> item002
89
+ "#{prefix}#{next_number.to_s.rjust(number.length, "0")}"
90
+ end
91
+
92
+ def preserve_case(original, replacement)
93
+ if original == original.upcase
11
94
  replacement.upcase
12
- elsif match[0] == match[0].upcase
95
+ elsif original[0] == original[0]&.upcase
13
96
  replacement.capitalize
14
97
  else
15
98
  replacement.downcase
16
99
  end
17
100
  end
18
- end
19
101
 
20
- def to_camel_case(str)
21
- words = str.split(/\W+/) # Split the input string into words
22
- camel_case_words = words.map.with_index do |word, index|
23
- index == 0 ? word.downcase : word.capitalize
102
+ def to_camel_case(str)
103
+ words = str.split(/\W+/) # Split the input string into words
104
+ camel_case_words = words.map.with_index do |word, index|
105
+ index == 0 ? word.downcase : word.capitalize
106
+ end
107
+ camel_case_words.join
24
108
  end
25
- camel_case_words.join
26
- end
27
109
 
28
- # Get all indexes for start of matching regexp
29
- def scan_indexes(txt, regex)
30
- # indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) + 1 }
31
- indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) }
32
- return indexes
33
- end
34
-
35
- def is_path(s)
36
- m = s.match(/(~[a-z]*)?\/.*\//)
37
- if m != nil
38
- return true
110
+ # Get all (character) indexes for start of matching regexp.
111
+ # MatchData#begin counts characters from the start of the string on every
112
+ # call when the text is not ASCII-only, which made this O(n^2): 13 s for the
113
+ # line ends of a 5.5 MB file with one "ä". Instead count only the characters
114
+ # between consecutive matches, using byte offsets.
115
+ def scan_indexes(txt, regex)
116
+ if txt.ascii_only?
117
+ return txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) }
118
+ end
119
+ indexes = []
120
+ bpos = 0
121
+ cpos = 0
122
+ txt.scan(regex) do
123
+ b = Regexp.last_match.byteoffset(0)[0]
124
+ cpos += txt.byteslice(bpos, b - bpos).size
125
+ bpos = b
126
+ indexes << cpos
127
+ end
128
+ return indexes
39
129
  end
40
- return false
41
- end
42
130
 
43
-
44
- def sanitize_input(str)
45
- if str.encoding != Encoding::UTF_8
46
- str = text.encode(Encoding::UTF_8)
131
+ def is_path(s)
132
+ m = s.match(/(~[a-z]*)?\/.*\//)
133
+ if m != nil
134
+ return true
135
+ end
136
+ return false
47
137
  end
48
- str.gsub!(/\r\n/, "\n")
49
- return str
50
- end
51
-
52
- def is_url(s)
53
- return s.match(/(https?|file):\/\/.*/) != nil
54
- end
55
138
 
139
+ def sanitize_input(str)
140
+ if str.encoding != Encoding::UTF_8
141
+ str = text.encode(Encoding::UTF_8)
142
+ end
143
+ str.gsub!(/\r\n/, "\n")
144
+ return str
145
+ end
56
146
 
147
+ def is_url(s)
148
+ return s.match(/(https?|file):\/\/.*/) != nil
149
+ end
150
+ end # module Vimamsa
@@ -1,4 +1,6 @@
1
1
 
2
+ module Vimamsa
3
+
2
4
  def exec_in_terminal(cmd, autoclose = false)
3
5
  # debug "CMD:#{cmd}"
4
6
 
@@ -32,3 +34,4 @@ def command_to_buf
32
34
  callback = method("command_to_buf_callback")
33
35
  gui_one_input_action("Execute command in shell, output to buffer", "Command:", "Execute", callback)
34
36
  end
37
+ end # module Vimamsa
@@ -1,3 +1,5 @@
1
+
2
+ module Vimamsa
1
3
  # VmaTest — integration test base class
2
4
  #
3
5
  # Tests run inside the live GTK app (headless or normal) after vma.start.
@@ -15,15 +17,17 @@
15
17
  # Run one class: run_vma_tests(MyTests)
16
18
 
17
19
  class VmaTestFailure < StandardError; end
20
+ class VmaTestSkip < StandardError; end
18
21
 
19
22
  class VmaTest
20
- attr_reader :failures, :passes
23
+ attr_reader :failures, :passes, :skips
21
24
 
22
25
  # Subclasses define test_* methods.
23
26
  # Each receives a fresh buffer and the kbd in :command mode.
24
27
  def run_all
25
28
  @passes = 0
26
29
  @failures = []
30
+ @skips = []
27
31
  test_methods = self.class.instance_methods(false)
28
32
  .select { |m| m.to_s.start_with?("test_") }
29
33
  .sort
@@ -34,6 +38,9 @@ class VmaTest
34
38
  send(m)
35
39
  @passes += 1
36
40
  puts " PASS #{self.class}##{m}"
41
+ rescue VmaTestSkip => e
42
+ @skips << "#{self.class}##{m}: #{e.message}"
43
+ puts " SKIP #{self.class}##{m}: #{e.message}"
37
44
  rescue VmaTestFailure => e
38
45
  @failures << "#{self.class}##{m}: #{e.message}"
39
46
  puts " FAIL #{self.class}##{m}: #{e.message}"
@@ -53,6 +60,13 @@ class VmaTest
53
60
  drain_idle
54
61
  end
55
62
 
63
+ # Execute one action without draining the GLib main loop.
64
+ # Use in tight loops; call drain_idle manually at a suitable interval.
65
+ def act_fast(action)
66
+ exec_action(action)
67
+ drain_idle
68
+ end
69
+
56
70
  # Simulate a space-separated key sequence in the current mode.
57
71
  # E.g.: keys("i h e l l o esc")
58
72
  # Special tokens: ctrl-x, alt-x, shift-X, esc, enter, backspace, tab, space
@@ -95,6 +109,13 @@ class VmaTest
95
109
  raise VmaTestFailure, msg unless cond
96
110
  end
97
111
 
112
+ # Skip the current test (reported as SKIP, not a failure). Use for tests
113
+ # that are unreliable in the current environment (e.g. clipboard/idle timing
114
+ # under headless GTK).
115
+ def skip(msg = "")
116
+ raise VmaTestSkip, msg
117
+ end
118
+
98
119
  private
99
120
 
100
121
  def _setup_test
@@ -119,6 +140,7 @@ def run_vma_tests(*classes)
119
140
 
120
141
  total_pass = 0
121
142
  total_fail = []
143
+ total_skip = []
122
144
 
123
145
  classes.each do |klass|
124
146
  puts "\n#{klass}"
@@ -126,12 +148,16 @@ def run_vma_tests(*classes)
126
148
  t.run_all
127
149
  total_pass += t.passes
128
150
  total_fail.concat(t.failures)
151
+ total_skip.concat(t.skips || [])
129
152
  end
130
153
 
131
154
  puts "\n#{"=" * 50}"
132
- puts "Results: #{total_pass} passed, #{total_fail.size} failed"
155
+ skip_note = total_skip.empty? ? "" : ", #{total_skip.size} skipped"
156
+ puts "Results: #{total_pass} passed, #{total_fail.size} failed#{skip_note}"
133
157
  total_fail.each { |f| puts " FAIL: #{f}" }
158
+ total_skip.each { |s| puts " SKIP: #{s}" }
134
159
  puts "=" * 50
135
160
 
136
161
  total_fail.empty?
137
162
  end
163
+ end # module Vimamsa
data/lib/vimamsa/tests.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require "digest"
2
2
 
3
+ module Vimamsa
4
+
3
5
  def run_tests()
4
- # DelayExecutioner.exec(id: :run_tests, wait: 0.7, callable: proc { run_tests_0 })
6
+ # DelayExecutioner.exec(id: "debug.tests", wait: 0.7, callable: proc { run_tests_0 })
5
7
 
6
8
  # Reload class
7
9
  # if Object.constants.include?(:EditorTests)
@@ -67,7 +69,7 @@ class EditorTests
67
69
  ['buf.replace_with_char("-")', "zzzz\n"],
68
70
  'buf.insert_txt("\n")',
69
71
  ['buf.insert_txt("yy")', "zzzz\nyy\n"],
70
- :e_move_backward_char, :e_move_backward_char,
72
+ "move.char.prev", "move.char.prev",
71
73
  ['buf.insert_txt("0")', "zzzz\n0yy\n"],
72
74
  "buf.jump(START_OF_BUFFER)",
73
75
  ['buf.replace_with_char("1")', "1zzz\n0yy\n"]]
@@ -78,8 +80,8 @@ class EditorTests
78
80
  'buf.insert_txt("\n")',
79
81
  ['buf.insert_txt("yy")', "abcdef\nyy\n"],
80
82
  "buf.jump(START_OF_BUFFER)",
81
- :delete_char_forward,
82
- [:delete_char_forward, "cdef\nyy\n"],
83
+ "edit.delete.char",
84
+ ["edit.delete.char", "cdef\nyy\n"],
83
85
  "buf.jump(END_OF_LINE)",
84
86
  "buf.delete(BACKWARD_CHAR)",
85
87
  ["buf.delete(BACKWARD_CHAR)", "cd\nyy\n"]]
@@ -87,13 +89,13 @@ class EditorTests
87
89
 
88
90
  def test_create_close_buf
89
91
  ['buf.insert_txt("abcdef")',
90
- [:buf_new,"\n"],
92
+ ["buf.new","\n"],
91
93
  'buf.insert_txt("a")',
92
94
  'buf.insert_txt("b")',
93
95
  'buf.insert_txt("c")',
94
96
  'buf.insert_txt("d")',
95
97
  ['buf.insert_txt("e")',"abcde\n"],
96
- [:close_current_buffer, "abcdef\n"]]
98
+ ["buf.close", "abcdef\n"]]
97
99
  end
98
100
  end
99
101
 
@@ -106,7 +108,7 @@ def test_paste_0(runmacro = true)
106
108
  b.insert_txt(LOREM_IPSUM)
107
109
  b.insert_txt(LOREM_IPSUM)
108
110
 
109
- 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)"]
111
+ macro = ["buf.jump(START_OF_BUFFER)", "buf.copy_line", "move.line.next", :paste_after, "move.line.prev", "move.line.prev", "buf.paste(BEFORE)", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "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, "move.line.next", "buf.jump(BEGINNING_OF_LINE)", "buf.copy_line", "move.line.next", "move.line.next", :paste_after, :paste_after, "move.line.next", "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)", "move.char.prev", "buf.copy_active_selection()", "move.line.next", "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)"]
110
112
 
111
113
  macro_r = true
112
114
  if runmacro
@@ -151,7 +153,7 @@ def macro_test(macro, correct_hex, runmacro = true)
151
153
  end
152
154
 
153
155
  def test_delete_0
154
- 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')"]
156
+ 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)", "move.char.prev", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "buf.delete(BACKWARD_CHAR)", "move.line.next", "move.char.prev", "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)", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "edit.delete.line", "move.line.next", "edit.delete.line", "move.line.next", "move.line.next", "edit.delete.line", "edit.delete.line", "move.line.next", "move.line.next", "vma.kbd.set_mode(:audio)", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "buf.delete2(:to_mark,'a')", "move.line.prev", "move.line.next", "move.line.next", "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')", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "move.line.next", "buf.delete2(:to_mark,'a')", "vma.kbd.set_mode(:audio)", "move.line.next", "move.line.next", "move.line.next", "buf.jump_to_mark('a')", "buf.jump_to_mark('a')", "move.line.prev", "move.line.prev", "move.line.prev", "move.line.prev", "buf.jump_to_mark('a')", "buf.jump_to_mark('a')", "buf.jump_to_mark('a')", "buf.jump_to_mark('a')"]
155
157
  return macro_test(macro, "71bc0421b47549267b327b69216ad8e042379625f99de1ba4faaa30d5042c22d")
156
158
  end
157
159
 
@@ -196,3 +198,4 @@ O frabjous day! Callooh! Callay!”
196
198
  All mimsy were the borogoves,
197
199
  And the mome raths outgrabe.
198
200
  "
201
+ end # module Vimamsa