vimamsa 0.1.27 → 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 (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,365 @@
1
+ module Vimamsa
2
+ # Vim operators and motions (doc/vim_compatibility_plan.md, step 1).
3
+ #
4
+ # The keys are key sets (KeyBindingTree#define_key_set), combined by templates
5
+ # in VIM_BINDINGS ("C <op> <motion>", ...), so every operator works with every
6
+ # motion and text object. This file has the data (VIM_KEY_SETS), what each
7
+ # motion and operator means (VIM_MOTIONS, VIM_OPERATORS), and the Buffer
8
+ # methods that compute motion targets and apply operators to a range.
9
+ #
10
+ # Vim rules followed (vim :help exclusive, :help cw, :help dw):
11
+ # - A motion is charwise or linewise, and a charwise motion is inclusive (its
12
+ # target character is included: e, f, t, $) or exclusive (w, b, h, l, 0, ^).
13
+ # - An exclusive motion that ends in column 0 of a later line ends at the end
14
+ # of the line before instead. If it started at or before the first non-blank
15
+ # of its line, it becomes linewise.
16
+ # - With an operator, w stops at the end of the line of the last word moved
17
+ # over (dw on the last word of a line doesn't join lines).
18
+ # - cw on a non-blank works like ce.
19
+ # - Counts before the operator and before the motion multiply (2d3w).
20
+
21
+ # Motion id => properties. desc is used on the key bindings page.
22
+ VIM_MOTIONS = {
23
+ char_left: { desc: "character left" },
24
+ char_right: { desc: "character right" },
25
+ line_down: { desc: "line down", linewise: true },
26
+ line_up: { desc: "line up", linewise: true },
27
+ word_next: { desc: "next word start" },
28
+ word_prev: { desc: "previous word start" },
29
+ word_end: { desc: "word end", inclusive: true },
30
+ bigword_next: { desc: "next WORD start" },
31
+ bigword_prev: { desc: "previous WORD start" },
32
+ bigword_end: { desc: "WORD end", inclusive: true },
33
+ line_start: { desc: "line start" },
34
+ line_first_char: { desc: "first non-blank" },
35
+ line_end: { desc: "line end", inclusive: true },
36
+ buf_start: { desc: "first line (<count>: that line)", linewise: true },
37
+ buf_end: { desc: "last line (<count>: that line)", linewise: true },
38
+ find_char: { desc: "to <char>", inclusive: true },
39
+ till_char: { desc: "till <char>", inclusive: true },
40
+ find_char_back: { desc: "back to <char>" },
41
+ till_char_back: { desc: "back till <char>" },
42
+ mark_line: { desc: "line of mark <char>", linewise: true },
43
+ mark: { desc: "mark <char>" },
44
+ }
45
+
46
+ # Operator id => description
47
+ VIM_OPERATORS = {
48
+ delete: "delete", change: "change", yank: "copy",
49
+ upcase: "uppercase", downcase: "lowercase", swapcase: "swap case",
50
+ indent: "indent", unindent: "unindent",
51
+ }
52
+
53
+ VIM_TEXTOBJ_DESC = { inner: "inside", around: "around" }
54
+
55
+ # The key sets of the vim keymap. vimlike uses the same sets, plus its own
56
+ # additions (key_set_add before bind_vim_bindings), and gets each
57
+ # combination whose keys it doesn't use for something else.
58
+ VIM_KEY_SETS = {
59
+ op: {
60
+ "d" => :delete, "c" => :change, "y" => :yank,
61
+ "g U" => :upcase, "g u" => :downcase, "g ~" => :swapcase,
62
+ ">" => :indent, "<" => :unindent,
63
+ },
64
+ motion: {
65
+ "h" => :char_left, "l" => :char_right, "j" => :line_down, "k" => :line_up,
66
+ "w" => :word_next, "b" => :word_prev, "e" => :word_end,
67
+ "W" => :bigword_next, "B" => :bigword_prev, "E" => :bigword_end,
68
+ "0" => :line_start, "^" => :line_first_char, "$" => :line_end,
69
+ "g g" => :buf_start, "G" => :buf_end,
70
+ "f <char>" => :find_char, "t <char>" => :till_char,
71
+ "F <char>" => :find_char_back, "T <char>" => :till_char_back,
72
+ "f space" => { id: :find_char, char: " " }, "t space" => { id: :till_char, char: " " },
73
+ "F space" => { id: :find_char_back, char: " " }, "T space" => { id: :till_char_back, char: " " },
74
+ "' <char>" => :mark_line, "` <char>" => :mark,
75
+ },
76
+ # The object is the typed <char>: w W s p " ' ` ( ) b [ ] { } B < > t
77
+ textobj: { "i <char>" => :inner, "a <char>" => :around },
78
+ }
79
+
80
+ # Text for a key set value on the key bindings page
81
+ def key_set_value_desc(set, value)
82
+ case set
83
+ when :op then VIM_OPERATORS[value]
84
+ when :motion then VIM_MOTIONS.dig(value, :desc)
85
+ when :textobj then VIM_TEXTOBJ_DESC[value]
86
+ end || value.to_s
87
+ end
88
+
89
+ class Buffer < String
90
+ # The position motion moves to from pos, or nil if it can't move.
91
+ # count: the typed count, nil if none.
92
+ def vim_motion_target(motion, count, char, pos = @pos)
93
+ n = count || 1
94
+ ls, le = tobj_line_bounds(pos)
95
+ case motion
96
+ when :char_left
97
+ return nil if pos <= ls
98
+ [pos - n, ls].max
99
+ when :char_right
100
+ return nil if pos >= le
101
+ [pos + n, le].min
102
+ when :line_down, :line_up
103
+ l = get_line_pos(pos) + (motion == :line_down ? n : -n)
104
+ return nil if l < 0 || l >= @line_ends.size
105
+ r = line_range(l, 1)
106
+ [r.begin + (pos - ls), r.end].min
107
+ when :word_next, :bigword_next
108
+ big = motion == :bigword_next
109
+ t = pos
110
+ n.times { t = vm_word_next(t, big) }
111
+ t == pos ? nil : t
112
+ when :word_end, :bigword_end
113
+ t = pos
114
+ n.times { t = vm_word_end(t, motion == :bigword_end) || (return nil) }
115
+ t
116
+ when :word_prev, :bigword_prev
117
+ t = pos
118
+ n.times { t = vm_word_prev(t, motion == :bigword_prev) || (return nil) }
119
+ t
120
+ when :line_start then ls
121
+ when :line_first_char then vm_first_non_blank(ls)
122
+ when :line_end
123
+ l = [get_line_pos(pos) + n - 1, @line_ends.size - 1].min
124
+ r = line_range(l, 1)
125
+ r.end > r.begin ? r.end - 1 : r.begin
126
+ when :buf_start, :buf_end
127
+ l = count ? count - 1 : (motion == :buf_start ? 0 : @line_ends.size - 1)
128
+ l = l.clamp(0, @line_ends.size - 1)
129
+ vm_first_non_blank(line_range(l, 1).begin)
130
+ when :find_char, :till_char
131
+ return nil if char.nil?
132
+ t = pos
133
+ n.times { t = index(char, t + 1); return nil if t.nil? || t >= le }
134
+ motion == :till_char ? t - 1 : t
135
+ when :find_char_back, :till_char_back
136
+ return nil if char.nil? || pos == 0
137
+ t = pos
138
+ n.times { t = t > 0 ? rindex(char, t - 1) : nil; return nil if t.nil? || t < ls }
139
+ motion == :till_char_back ? t + 1 : t
140
+ when :mark_line, :mark
141
+ t = @marks[char]
142
+ return nil if t.nil?
143
+ t = [t, size - 1].min
144
+ motion == :mark_line ? vm_first_non_blank(tobj_line_bounds(t)[0]) : t
145
+ end
146
+ end
147
+
148
+ # Plain cursor movement and Visual mode extension (the selection follows
149
+ # the cursor)
150
+ def vim_motion_move(motion, count, char)
151
+ t = vim_motion_target(motion, count, char)
152
+ return false if t.nil?
153
+ tobj_set_normal_pos(t)
154
+ true
155
+ end
156
+
157
+ # d w, c e, y $, g U f x, > j, ...
158
+ def vim_operator_motion(op, motion, count, char)
159
+ m = VIM_MOTIONS[motion]
160
+ return false if m.nil?
161
+ p = @pos
162
+ linewise = m[:linewise] || false
163
+ inclusive = m[:inclusive] || false
164
+ word = [:word_next, :bigword_next].include?(motion)
165
+ if op == :change && word && !" \t\n".include?(self[p].to_s)
166
+ # cw = ce: change to the end of the word, not including the blanks after
167
+ big = motion == :bigword_next
168
+ t = p
169
+ k = count || 1
170
+ k -= 1 if vm_word_end_at?(p, big)
171
+ k.times { t = vm_word_end(t, big) || t }
172
+ inclusive = true
173
+ else
174
+ t = vim_motion_target(motion, count, char, p)
175
+ end
176
+ return false if t.nil?
177
+
178
+ s, e = [p, t].minmax
179
+ if !linewise
180
+ e += 1 if inclusive && self[e] != "\n"
181
+ if word && !inclusive && t > p && get_line_pos(t) > get_line_pos(p) &&
182
+ self[tobj_line_bounds(t)[0]...t].match?(/\A[ \t]*\z/)
183
+ # dw on the last word of a line: stop at the end of that line
184
+ e = [tobj_line_bounds(t)[0] - 1, s].max
185
+ elsif !inclusive && e > s && e < size && (e == 0 || self[e - 1] == "\n") &&
186
+ get_line_pos(e) > get_line_pos(s)
187
+ e -= 1 # end of the line before (its "\n" is not included)
188
+ # (e is now that line's "\n", so the linewise range below ends there)
189
+ linewise = true if s <= vm_first_non_blank(tobj_line_bounds(s)[0])
190
+ end
191
+ end
192
+ # A charwise delete over several lines that starts in the indent and ends
193
+ # at the end of a line deletes whole lines (vim op_delete): d2$ from col 0
194
+ if !linewise && op == :delete && e > s && get_line_pos([e - 1, s].max) > get_line_pos(s)
195
+ le = tobj_line_bounds(e - 1)[1]
196
+ if self[e...le].to_s.match?(/\A[ \t]*\z/) && s <= vm_first_non_blank(tobj_line_bounds(s)[0])
197
+ linewise = true
198
+ end
199
+ end
200
+ # > and < always work on whole lines
201
+ linewise = true if [:indent, :unindent].include?(op)
202
+ if linewise
203
+ s = tobj_line_bounds(s)[0]
204
+ e = tobj_line_bounds(e)[1] + 1
205
+ end
206
+ return false if e <= s
207
+ vim_apply_operator(op, s, e, linewise, from: p)
208
+ end
209
+
210
+ # d d, c c, y y, > >, g U U: count lines from the current one. Like vim,
211
+ # nothing happens when there are fewer lines left than the count.
212
+ def vim_operator_lines(op, count)
213
+ l = get_line_pos(@pos)
214
+ l2 = l + (count || 1) - 1
215
+ return false if l2 >= @line_ends.size
216
+ s = line_range(l, 1).begin
217
+ e = line_range(l2, 1).end + 1
218
+ vim_apply_operator(op, s, e, true, from: @pos)
219
+ end
220
+
221
+ # Apply op to [s, e) (e exclusive). from: the cursor before the command.
222
+ # Shared with the text objects (text_object_op).
223
+ def vim_apply_operator(op, s, e, linewise, from: @pos)
224
+ e = [e, size].min
225
+ case op
226
+ when :yank
227
+ vma.clipboard.set(self[s...e], linewise: linewise) if e > s
228
+ # The cursor goes to the start of the text, but a linewise yank that
229
+ # starts on the cursor line doesn't move it (y j, y y)
230
+ if !(linewise && tobj_line_bounds(from)[0] == s)
231
+ linewise ? tobj_set_line_pos(s) : set_pos(s)
232
+ end
233
+ when :delete
234
+ return false if e <= s
235
+ txt = self[s...e]
236
+ ds, de = s, e - 1
237
+ # The buffer's final "\n" can't be deleted: for the last lines, take
238
+ # the newline before them instead (vim dap / dd on the last line).
239
+ ds, de = s - 1, e - 2 if linewise && e >= size && s > 0
240
+ Gui.flash_range(self, ds..de) do
241
+ delete_range(ds, de, register: false)
242
+ vma.clipboard.set(txt, linewise: linewise, kind: :delete)
243
+ linewise ? tobj_set_line_pos(ds) : tobj_set_normal_pos(s)
244
+ end
245
+ when :change
246
+ vma.clipboard.set(self[s...e], linewise: linewise, kind: :delete) if e > s
247
+ # Linewise (cc, cip, multi-line ci{): leave an empty line to type on
248
+ if linewise && e >= size && e - 1 > s
249
+ delete_range(s, e - 2, register: false) # the final "\n" stays as that line
250
+ else
251
+ delete_range(s, e - 1, register: false) if e > s
252
+ insert_txt_at("\n", s) if linewise
253
+ end
254
+ set_pos(s)
255
+ vma.kbd.set_mode(:insert)
256
+ when :upcase, :downcase, :swapcase
257
+ return false if e <= s
258
+ old = self[s...e]
259
+ txt = transform_text(old.dup, op)
260
+ replace_range(s..(e - 1), txt) if txt != old
261
+ set_pos(s)
262
+ when :indent, :unindent
263
+ ls = tobj_line_bounds(s)[0]
264
+ le = tobj_line_bounds([e - 1, s].max)[1]
265
+ old = self[ls..le]
266
+ tw = cnf.tab.width!
267
+ new = old.lines.map { |line|
268
+ if op == :indent
269
+ line == "\n" ? line : vm_indent_pad + line
270
+ else
271
+ line.sub(/\A(\t| {1,#{tw}})/, "")
272
+ end
273
+ }.join
274
+ replace_range(ls..le, new) if new != old
275
+ tobj_set_line_pos(ls)
276
+ else
277
+ return false
278
+ end
279
+ true
280
+ end
281
+
282
+ private
283
+
284
+ def vm_indent_pad
285
+ convert = cnf.tab.to_spaces_default?
286
+ convert = true if cnf.tab.to_spaces_languages?.include?(@lang)
287
+ convert = false if cnf.tab.to_spaces_not_languages?.include?(@lang)
288
+ convert ? " " * cnf.tab.width! : "\t"
289
+ end
290
+
291
+ def vm_first_non_blank(ls)
292
+ p = ls
293
+ p += 1 while p < size - 1 && " \t".include?(self[p])
294
+ p
295
+ end
296
+
297
+ # Character class for word motions: 0 blank or newline, 1 punctuation,
298
+ # 2 word character. For WORDs (big) every non-blank is 1.
299
+ def vm_cls(p, big)
300
+ ch = self[p]
301
+ return 0 if ch.nil? || ch == " " || ch == "\t" || ch == "\n"
302
+ return 1 if big
303
+ ch.match?(/[\p{L}\p{N}_]/) ? 2 : 1
304
+ end
305
+
306
+ # w: start of the next word. An empty line counts as a word; at the end of
307
+ # the buffer, the final "\n".
308
+ def vm_word_next(p, big)
309
+ last = size - 1
310
+ if self[p] != "\n"
311
+ c = vm_cls(p, big)
312
+ p += 1 while p < last && c != 0 && vm_cls(p, big) == c
313
+ p += 1 while p < last && " \t".include?(self[p])
314
+ return p if self[p] != "\n" || p >= last
315
+ end
316
+ loop {
317
+ p += 1
318
+ return last if p >= last
319
+ return p if self[p] == "\n" # empty line
320
+ p += 1 while p < last && " \t".include?(self[p])
321
+ return p if self[p] != "\n"
322
+ }
323
+ end
324
+
325
+ # e: end of the word (the next one when already at an end), or nil
326
+ def vm_word_end(p, big)
327
+ last = size - 1
328
+ p += 1
329
+ p += 1 while p < last && vm_cls(p, big) == 0
330
+ return nil if p >= last
331
+ c = vm_cls(p, big)
332
+ p += 1 while p + 1 < last && vm_cls(p + 1, big) == c
333
+ p
334
+ end
335
+
336
+ def vm_word_end_at?(p, big)
337
+ c = vm_cls(p, big)
338
+ c != 0 && vm_cls(p + 1, big) != c
339
+ end
340
+
341
+ # b: start of the previous word (an empty line counts), or nil at the start
342
+ def vm_word_prev(p, big)
343
+ return nil if p == 0
344
+ p -= 1
345
+ loop {
346
+ ch = self[p]
347
+ break if p == 0
348
+ if ch == " " || ch == "\t"
349
+ p -= 1
350
+ elsif ch == "\n"
351
+ return p if self[p - 1] == "\n" # empty line
352
+ p -= 1
353
+ else
354
+ break
355
+ end
356
+ }
357
+ c = vm_cls(p, big)
358
+ return p if c == 0
359
+ p -= 1 while p > 0 && vm_cls(p - 1, big) == c
360
+ p
361
+ end
362
+
363
+ public
364
+ end
365
+ end # module Vimamsa
@@ -3,7 +3,7 @@
3
3
  # Enable this module in Preferences → Modules → "Scientific Calculator".
4
4
  #
5
5
  # Usage (once enabled):
6
- # :insert_calculator action — inserts the widget at the cursor position
6
+ # "calculator.insert" action — inserts the widget at the cursor position
7
7
  #
8
8
  # The widget occupies a single U+FFFC (object replacement) character in the
9
9
  # Ruby buffer, keeping GTK/Ruby buffer offsets aligned.
@@ -308,11 +308,11 @@ def insert_calculator_in_buffer
308
308
  end
309
309
 
310
310
  def calculator_init
311
- reg_act(:insert_calculator, proc { insert_calculator_in_buffer }, "Insert scientific calculator widget at cursor")
312
- vma.gui.menu.add_module_action(:insert_calculator, "Insert Calculator")
311
+ reg_act("calculator.insert", proc { insert_calculator_in_buffer }, "Insert scientific calculator widget at cursor")
312
+ vma.gui.menu.add_module_action("calculator.insert", "Insert Calculator")
313
313
  end
314
314
 
315
315
  def calculator_disable
316
- unreg_act(:insert_calculator)
317
- vma.gui.menu.remove_module_action(:insert_calculator)
316
+ unreg_act("calculator.insert")
317
+ vma.gui.menu.remove_module_action("calculator.insert")
318
318
  end
@@ -87,13 +87,13 @@ def color_highlight_on_text_changed(_view = nil)
87
87
  end
88
88
 
89
89
  def color_highlight_init
90
- reg_act(:toggle_highlight_colors, proc {
90
+ reg_act("color_highlight.toggle", proc {
91
91
  en = cnf.modules.color_highlight.enabled? == false
92
92
  cnf.modules.color_highlight.enabled = en
93
93
  color_highlight_rehighlight_all
94
94
  message("Color code highlighting: #{en ? "ON" : "OFF"}")
95
95
  }, "Toggle hex color code highlighting on/off")
96
- add_keys "color_highlight", { "C , ; h c" => :toggle_highlight_colors }
96
+ add_keys "color_highlight", { "C , ; h c" => "color_highlight.toggle" }
97
97
 
98
98
  # Register the view hooks once. The guard survives module reloads (a global
99
99
  # set only here persists across `load`), so a no_restart re-enable never
@@ -109,7 +109,7 @@ end
109
109
 
110
110
  def color_highlight_disable
111
111
  unbindkey "C , ; h c"
112
- unreg_act(:toggle_highlight_colors)
112
+ unreg_act("color_highlight.toggle")
113
113
  # cnf.modules.color_highlight.enabled is already false here, so this wipes the
114
114
  # swatches. The registered hooks stay but no-op via that gate.
115
115
  color_highlight_rehighlight_all
@@ -21,7 +21,7 @@ require "json"
21
21
  # inserted span is tracked by position, so concurrent edits would misplace the
22
22
  # final replacement.
23
23
  #
24
- # Configuration (set in ~/.vimamsa/settings.rb via cnf, all optional):
24
+ # Configuration (set in ~/.config/vimamsa/settings.rb via cnf, all optional):
25
25
  # cnf.dictation.python python interpreter (default "python3")
26
26
  # cnf.dictation.worker worker script path (default bundled whisper_worker.py)
27
27
  # cnf.dictation.model faster-whisper model (default "large-v3")
@@ -634,7 +634,7 @@ class VmaDictationSession
634
634
  return
635
635
  end
636
636
  final = res[:text].to_s
637
- @buf.delete_range(@dict_start, @dict_start + @dict_len - 1) if @dict_len > 0
637
+ @buf.delete_range(@dict_start, @dict_start + @dict_len - 1, register: false) if @dict_len > 0
638
638
  @dict_len = 0
639
639
 
640
640
  if final.empty?
@@ -676,7 +676,7 @@ end
676
676
  # ── Saved prompts ───────────────────────────────────────────────────────────────
677
677
 
678
678
  def vma_dict_prompts_path
679
- get_dot_path("dictation_prompts.json")
679
+ get_data_path("dictation_prompts.json")
680
680
  end
681
681
 
682
682
  def vma_dict_load_prompts
@@ -996,38 +996,38 @@ end
996
996
  def dictation_init
997
997
  $vma_dict_prompts = vma_dict_load_prompts
998
998
  vma_dict_restore_model
999
- reg_act(:dictation_select_model, proc { vma_dictation_model_dialog },
999
+ reg_act("dictation.select_model", proc { vma_dictation_model_dialog },
1000
1000
  "Voice dictation: choose speech model")
1001
- reg_act(:dictation_toggle, proc { dictation_toggle },
1001
+ reg_act("dictation.toggle", proc { dictation_toggle },
1002
1002
  "Voice dictation: start/stop (fast, last prompt)")
1003
- reg_act(:dictation_toggle_dialog, proc { dictation_toggle_dialog },
1003
+ reg_act("dictation.toggle_dialog", proc { dictation_toggle_dialog },
1004
1004
  "Voice dictation: start/stop (choose prompt)")
1005
- reg_act(:dictation_release_vram, proc { dictation_release_vram },
1005
+ reg_act("dictation.release_vram", proc { dictation_release_vram },
1006
1006
  "Voice dictation: unload model to free VRAM")
1007
- reg_act(:dictation_enter_mode, proc { dictation_enter_mode },
1007
+ reg_act("dictation.enter_mode", proc { dictation_enter_mode },
1008
1008
  "Voice dictation: start + enter dictation mode (exit if in it)")
1009
- reg_act(:dictation_toggle_stay, proc { dictation_toggle_stay },
1009
+ reg_act("dictation.toggle_stay", proc { dictation_toggle_stay },
1010
1010
  "Dictation mode: toggle listening (stay in mode)")
1011
- reg_act(:dictation_newline, proc { dictation_newline },
1011
+ reg_act("dictation.newline", proc { dictation_newline },
1012
1012
  "Dictation mode: new line")
1013
- reg_act(:dictation_exit_mode, proc { dictation_exit_mode },
1013
+ reg_act("dictation.exit_mode", proc { dictation_exit_mode },
1014
1014
  "Dictation mode: exit")
1015
1015
 
1016
1016
  # A dedicated dictation input mode that inherits command mode (like `audio`),
1017
1017
  # so unoverridden command chords stay available while dictating.
1018
1018
  vma.kbd.add_minor_mode("dictation", :dictation, :command)
1019
1019
  add_keys "dictation", {
1020
- "C , k" => :dictation_enter_mode, # start + enter dictation mode
1021
- "C , ; k" => :dictation_toggle_dialog, # plain toggle (choose prompt), no mode
1022
- "dictation space" => :dictation_toggle_stay,
1023
- "dictation enter || dictation return" => :dictation_newline,
1024
- "dictation esc || dictation ctrl! || dictation , k" => :dictation_exit_mode,
1020
+ "C , k" => "dictation.enter_mode", # start + enter dictation mode
1021
+ "C , ; k" => "dictation.toggle_dialog", # plain toggle (choose prompt), no mode
1022
+ "dictation space" => "dictation.toggle_stay",
1023
+ "dictation enter || dictation return" => "dictation.newline",
1024
+ "dictation esc || dictation ctrl! || dictation , k" => "dictation.exit_mode",
1025
1025
  }
1026
1026
  # Same action as `, k`, so the menu shows that binding
1027
- vma.gui.menu.add_module_action(:dictation_enter_mode, "Start/Stop Dictation")
1028
- vma.gui.menu.add_module_action(:dictation_toggle_dialog, "Start Dictation (choose prompt)")
1029
- vma.gui.menu.add_module_action(:dictation_release_vram, "Release Dictation VRAM")
1030
- vma.gui.menu.add_module_action(:dictation_select_model, "Select Dictation Model…")
1027
+ vma.gui.menu.add_module_action("dictation.enter_mode", "Start/Stop Dictation")
1028
+ vma.gui.menu.add_module_action("dictation.toggle_dialog", "Start Dictation (choose prompt)")
1029
+ vma.gui.menu.add_module_action("dictation.release_vram", "Release Dictation VRAM")
1030
+ vma.gui.menu.add_module_action("dictation.select_model", "Select Dictation Model…")
1031
1031
  end
1032
1032
 
1033
1033
  def dictation_disable
@@ -1036,19 +1036,19 @@ def dictation_disable
1036
1036
  # The module is going away; don't leave a stale indicator behind. (stop above
1037
1037
  # only queues the finalize that would normally clear it.)
1038
1038
  vma.gui&.set_status_indicator(VmaDictationSession::STATUS_KEY, nil)
1039
- unreg_act(:dictation_toggle)
1040
- unreg_act(:dictation_toggle_dialog)
1041
- unreg_act(:dictation_release_vram)
1042
- unreg_act(:dictation_enter_mode)
1043
- unreg_act(:dictation_toggle_stay)
1044
- unreg_act(:dictation_newline)
1045
- unreg_act(:dictation_exit_mode)
1046
- unreg_act(:dictation_select_model)
1039
+ unreg_act("dictation.toggle")
1040
+ unreg_act("dictation.toggle_dialog")
1041
+ unreg_act("dictation.release_vram")
1042
+ unreg_act("dictation.enter_mode")
1043
+ unreg_act("dictation.toggle_stay")
1044
+ unreg_act("dictation.newline")
1045
+ unreg_act("dictation.exit_mode")
1046
+ unreg_act("dictation.select_model")
1047
1047
  unbindkey "C , k"
1048
1048
  unbindkey "C , ; k"
1049
1049
  unbindkey "dictation", include_child_nodes: true
1050
- vma.gui.menu.remove_module_action(:dictation_enter_mode)
1051
- vma.gui.menu.remove_module_action(:dictation_toggle_dialog)
1052
- vma.gui.menu.remove_module_action(:dictation_release_vram)
1053
- vma.gui.menu.remove_module_action(:dictation_select_model)
1050
+ vma.gui.menu.remove_module_action("dictation.enter_mode")
1051
+ vma.gui.menu.remove_module_action("dictation.toggle_dialog")
1052
+ vma.gui.menu.remove_module_action("dictation.release_vram")
1053
+ vma.gui.menu.remove_module_action("dictation.select_model")
1054
1054
  end
@@ -87,21 +87,21 @@ rescue => e
87
87
  end
88
88
 
89
89
  def ollama_init
90
- reg_act(:ollama_improve_selection,
90
+ reg_act("ollama.improve_selection",
91
91
  proc { ollama_improve_selection },
92
92
  "Ollama: improve selected text")
93
- reg_act(:ollama_improve_selection_multi,
93
+ reg_act("ollama.improve_selection_multi",
94
94
  proc { ollama_improve_selection_multi },
95
95
  "Ollama: generate N improved variants below paragraph")
96
96
 
97
- bindings = { "V , o i" => :ollama_improve_selection }
97
+ bindings = { "V , o i" => "ollama.improve_selection" }
98
98
  (1..9).each { |n| bindings["V , o #{n} i"] = "ollama_improve_selection_multi(#{n})" }
99
99
  add_keys "ollama", bindings
100
100
  end
101
101
 
102
102
  def ollama_disable
103
- unreg_act(:ollama_improve_selection)
104
- unreg_act(:ollama_improve_selection_multi)
103
+ unreg_act("ollama.improve_selection")
104
+ unreg_act("ollama.improve_selection_multi")
105
105
  unbindkey "V , o i"
106
106
  (1..9).each { |n| unbindkey "V , o #{n} i" }
107
107
  end
@@ -129,12 +129,12 @@ end
129
129
 
130
130
  def terminal_init
131
131
  require "vte4"
132
- reg_act(:insert_terminal, proc { insert_terminal_in_buffer }, "Insert embedded terminal at cursor")
133
- # add_keys "terminal", { "C , t" => :insert_terminal }
134
- vma.gui.menu.add_module_action(:insert_terminal, "Insert Terminal")
132
+ reg_act("terminal.insert", proc { insert_terminal_in_buffer }, "Insert embedded terminal at cursor")
133
+ # add_keys "terminal", { "C , t" => "terminal.insert" }
134
+ vma.gui.menu.add_module_action("terminal.insert", "Insert Terminal")
135
135
  end
136
136
 
137
137
  def terminal_disable
138
- unreg_act(:insert_terminal)
139
- vma.gui.menu.remove_module_action(:insert_terminal)
138
+ unreg_act("terminal.insert")
139
+ vma.gui.menu.remove_module_action("terminal.insert")
140
140
  end
data/modules/tts/tts.rb CHANGED
@@ -11,7 +11,7 @@ require "json"
11
11
  # V , s speak the current selection
12
12
  # C , q stop speaking
13
13
  #
14
- # Configuration (set in ~/.vimamsa/settings.rb via cnf, all optional):
14
+ # Configuration (set in ~/.config/vimamsa/settings.rb via cnf, all optional):
15
15
  # cnf.tts.voice Piper voice name (default "en_GB-alan-medium")
16
16
  # cnf.tts.data_dir voices directory (default "~/piper-voices")
17
17
  # cnf.tts.rate sample rate (Hz) (default: from <voice>.onnx.json, else 22050)
@@ -101,19 +101,19 @@ def tts_stop
101
101
  end
102
102
 
103
103
  def tts_init
104
- reg_act(:tts_speak_selection, proc { tts_speak_selection }, "Speak selected text")
105
- reg_act(:tts_stop, proc { tts_stop }, "Stop speaking")
106
- add_keys "tts", { "V , s" => :tts_speak_selection, "C , q" => :tts_stop }
107
- vma.gui.menu.add_module_action(:tts_speak_selection, "Speak Selection")
108
- vma.gui.menu.add_module_action(:tts_stop, "Stop Speaking")
104
+ reg_act("tts.speak_selection", proc { tts_speak_selection }, "Speak selected text")
105
+ reg_act("tts.stop", proc { tts_stop }, "Stop speaking")
106
+ add_keys "tts", { "V , s" => "tts.speak_selection", "C , q" => "tts.stop" }
107
+ vma.gui.menu.add_module_action("tts.speak_selection", "Speak Selection")
108
+ vma.gui.menu.add_module_action("tts.stop", "Stop Speaking")
109
109
  end
110
110
 
111
111
  def tts_disable
112
112
  $vma_tts&.stop
113
- unreg_act(:tts_speak_selection)
114
- unreg_act(:tts_stop)
113
+ unreg_act("tts.speak_selection")
114
+ unreg_act("tts.stop")
115
115
  unbindkey "V , s"
116
116
  unbindkey "C , q"
117
- vma.gui.menu.remove_module_action(:tts_speak_selection)
118
- vma.gui.menu.remove_module_action(:tts_stop)
117
+ vma.gui.menu.remove_module_action("tts.speak_selection")
118
+ vma.gui.menu.remove_module_action("tts.stop")
119
119
  end
data/run_e2e_vm.sh CHANGED
@@ -8,11 +8,11 @@
8
8
  # VM's desktop once. Every test in the run then finds it already focused.
9
9
  #
10
10
  # The heavy lifting (sync, provision, uinput/Wayland setup) is shared with
11
- # run_tests_vm.sh; this wrapper just restricts the run to the E2E file and turns
11
+ # run_tests_vm.rb; this wrapper just restricts the run to the E2E file and turns
12
12
  # on the interactive focus wait.
13
13
  #
14
14
  # Usage:
15
- # (VM_NAME, VM_USER and VM_PASS exported, as for run_tests_vm.sh)
15
+ # (VM_NAME, VM_USER and VM_PASS exported, as for run_tests_vm.rb)
16
16
  # ./run_e2e_vm.sh
17
17
  # ./run_e2e_vm.sh e2e_cmdline # explicit filter
18
18
  set -euo pipefail
@@ -25,4 +25,4 @@ echo ">> When you see the '[E2E] Click the vimamsa window…' prompt, click that
25
25
  echo ">> window once to focus it; the tests then type into it via uinput."
26
26
 
27
27
  # Default to the cmdline E2E file; forward any explicit filter args instead.
28
- exec "$HERE/run_tests_vm.sh" "${@:-e2e_cmdline}"
28
+ exec "$HERE/run_tests_vm.rb" "${@:-e2e_cmdline}"