vimamsa 0.1.27 → 0.1.29

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +17 -10
  3. data/Dockerfile +2 -2
  4. data/README.md +162 -90
  5. data/custom_example.rb +33 -15
  6. data/doc/TODO.md +334 -110
  7. data/doc/action_names_plan.md +442 -0
  8. data/doc/bundling_plan.md +2 -1
  9. data/doc/delta_syntax_plan.md +293 -0
  10. data/doc/demo_recording_plan.md +288 -0
  11. data/doc/design_goals.md +27 -0
  12. data/doc/intro_page_plan.md +266 -0
  13. data/doc/key_bindings_report_plan.md +45 -0
  14. data/doc/line_tree_plan.md +89 -0
  15. data/doc/missing_vim_bindings.md +34 -44
  16. data/doc/modules_settings_plan.md +1 -1
  17. data/doc/registries_plan.md +202 -0
  18. data/doc/startup_speed_plan.md +97 -0
  19. data/doc/test_commands.md +232 -0
  20. data/doc/treap_visualizer.html +585 -0
  21. data/doc/vim_compatibility_plan.md +186 -31
  22. data/doc/vimlike_vim_conflicts.md +236 -228
  23. data/doc/vm_snapshots_plan.md +4 -4
  24. data/doc/wysiwyg_plan.md +231 -0
  25. data/docker_cmd.sh +1 -1
  26. data/exe/run_tests.rb +85 -3
  27. data/exe/vimamsa +49 -6
  28. data/help/intro.txt +30 -0
  29. data/help/vim_intro.txt +31 -0
  30. data/img/demo.gif +0 -0
  31. data/img/demo.mp4 +0 -0
  32. data/lang/hyperplaintext.lang +1 -1
  33. data/lib/vimamsa/ack.rb +2 -0
  34. data/lib/vimamsa/actions.rb +381 -36
  35. data/lib/vimamsa/bookmarks.rb +8 -8
  36. data/lib/vimamsa/buffer.rb +84 -38
  37. data/lib/vimamsa/buffer_changetext.rb +58 -36
  38. data/lib/vimamsa/buffer_list.rb +2 -2
  39. data/lib/vimamsa/buffer_manager.rb +6 -6
  40. data/lib/vimamsa/cli_help.rb +75 -0
  41. data/lib/vimamsa/clipboard.rb +6 -3
  42. data/lib/vimamsa/conf.rb +9 -0
  43. data/lib/vimamsa/crash_handler.rb +2 -2
  44. data/lib/vimamsa/debug.rb +2 -2
  45. data/lib/vimamsa/demo_player.rb +494 -0
  46. data/lib/vimamsa/demo_recorder.rb +277 -0
  47. data/lib/vimamsa/diff_buffer.rb +1 -1
  48. data/lib/vimamsa/dot_repeat.rb +104 -0
  49. data/lib/vimamsa/easy_jump.rb +54 -3
  50. data/lib/vimamsa/editor.rb +136 -65
  51. data/lib/vimamsa/file_history.rb +1 -1
  52. data/lib/vimamsa/file_manager.rb +23 -23
  53. data/lib/vimamsa/form_input.rb +388 -0
  54. data/lib/vimamsa/gui.rb +89 -13
  55. data/lib/vimamsa/gui_command_line.rb +44 -5
  56. data/lib/vimamsa/gui_form_generator.rb +17 -6
  57. data/lib/vimamsa/gui_func_panel.rb +1 -1
  58. data/lib/vimamsa/gui_key_hint.rb +165 -0
  59. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  60. data/lib/vimamsa/gui_menu.rb +69 -50
  61. data/lib/vimamsa/gui_select_window.rb +77 -43
  62. data/lib/vimamsa/gui_settings.rb +9 -5
  63. data/lib/vimamsa/gui_sourceview.rb +28 -81
  64. data/lib/vimamsa/gui_theme.rb +11 -2
  65. data/lib/vimamsa/hook.rb +2 -0
  66. data/lib/vimamsa/intro_page.rb +367 -0
  67. data/lib/vimamsa/key_actions.rb +315 -225
  68. data/lib/vimamsa/key_binding_tree.rb +228 -61
  69. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  70. data/lib/vimamsa/key_bindings_report.rb +290 -67
  71. data/lib/vimamsa/key_bindings_vim.rb +43 -297
  72. data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
  73. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  74. data/lib/vimamsa/key_names.rb +80 -0
  75. data/lib/vimamsa/langservp.rb +62 -7
  76. data/lib/vimamsa/line_tree.rb +367 -0
  77. data/lib/vimamsa/macro.rb +20 -3
  78. data/lib/vimamsa/rbvma.rb +15 -0
  79. data/lib/vimamsa/registers.rb +125 -0
  80. data/lib/vimamsa/run_ruby.rb +64 -0
  81. data/lib/vimamsa/search_replace.rb +4 -4
  82. data/lib/vimamsa/string_util.rb +17 -3
  83. data/lib/vimamsa/tests.rb +8 -8
  84. data/lib/vimamsa/text_objects.rb +11 -54
  85. data/lib/vimamsa/text_transforms.rb +4 -0
  86. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  87. data/lib/vimamsa/user_dirs.rb +83 -0
  88. data/lib/vimamsa/version.rb +1 -1
  89. data/lib/vimamsa/vim_operators.rb +365 -0
  90. data/modules/calculator/calculator.rb +5 -5
  91. data/modules/color_highlight/color_highlight.rb +3 -3
  92. data/modules/dictation/dictation.rb +32 -32
  93. data/modules/ollama/ollama.rb +5 -5
  94. data/modules/terminal/terminal.rb +5 -5
  95. data/modules/tts/tts.rb +10 -10
  96. data/run_e2e_vm.sh +3 -3
  97. data/run_tests_vm.rb +163 -0
  98. data/scripts/appimage/AppRun +7 -0
  99. data/scripts/appimage/build_in_container.sh +11 -1
  100. data/scripts/appimage/smoke_test.sh +1 -1
  101. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  102. data/scripts/demo/demo_files_steps.txt +52 -0
  103. data/scripts/demo/demo_steps.txt +9 -1
  104. data/scripts/demo/notes.txt +6 -0
  105. data/scripts/demo/record_demo.rb +60 -81
  106. data/scripts/demo/report.rb +7 -0
  107. data/scripts/demo/shapes.rb +1 -0
  108. data/scripts/demo/square/shapes.rb +29 -0
  109. data/scripts/demo/square/steps.txt +185 -0
  110. data/scripts/lib/perf_startup.rb +138 -0
  111. data/scripts/lib/script_helpers.rb +53 -0
  112. data/scripts/perf_compare.rb +34 -0
  113. data/scripts/profile_startup.rb +72 -0
  114. data/tests/test_action_ids.rb +232 -0
  115. data/tests/test_auto_format.rb +2 -2
  116. data/tests/test_autocomplete.rb +1 -1
  117. data/tests/test_basic_editing.rb +18 -18
  118. data/tests/test_bookmarks.rb +6 -6
  119. data/tests/test_bracket_match.rb +3 -0
  120. data/tests/test_cli_help.rb +64 -0
  121. data/tests/test_color_highlight.rb +2 -2
  122. data/tests/test_command_line.rb +1 -1
  123. data/tests/test_context_menu_file.rb +18 -0
  124. data/tests/test_copy_paste.rb +33 -33
  125. data/tests/test_custom_two_phase.rb +1 -1
  126. data/tests/test_demo_player.rb +355 -0
  127. data/tests/test_demo_recorder.rb +202 -0
  128. data/tests/test_dictation.rb +16 -16
  129. data/tests/test_dot_repeat.rb +88 -0
  130. data/tests/test_easy_jump.rb +93 -0
  131. data/tests/test_extract_file_links.rb +3 -3
  132. data/tests/test_file_panel.rb +2 -2
  133. data/tests/test_flash.rb +1 -1
  134. data/tests/test_fold.rb +1 -1
  135. data/tests/test_form_input.rb +203 -0
  136. data/tests/test_func_panel.rb +2 -2
  137. data/tests/test_gtk_sync.rb +7 -7
  138. data/tests/test_intro_page.rb +437 -0
  139. data/tests/test_key_categories.rb +163 -0
  140. data/tests/test_keylog_panel.rb +163 -3
  141. data/tests/test_line_ends.rb +51 -0
  142. data/tests/test_line_tree.rb +86 -0
  143. data/tests/test_lsp_clangd.rb +2 -2
  144. data/tests/test_lsp_root.rb +43 -0
  145. data/tests/test_macro.rb +2 -2
  146. data/tests/test_module_interface.rb +9 -9
  147. data/tests/test_notepad_bindings.rb +5 -5
  148. data/tests/test_perf_startup.rb +28 -0
  149. data/tests/test_random_edit.rb +27 -27
  150. data/tests/test_registers.rb +131 -0
  151. data/tests/test_run_ruby.rb +77 -0
  152. data/tests/test_startup_file.rb +45 -4
  153. data/tests/test_text_objects.rb +1 -1
  154. data/tests/test_text_transforms.rb +12 -0
  155. data/tests/test_tmp_user_dir.rb +79 -0
  156. data/tests/test_tts.rb +10 -10
  157. data/tests/test_undo.rb +34 -34
  158. data/tests/test_user_dirs.rb +122 -0
  159. data/tests/test_vim_bindings.rb +107 -6
  160. data/tests/test_vim_conflicts.rb +41 -4
  161. data/tests/test_vim_operators.rb +116 -0
  162. data/tests/test_window_layout.rb +83 -0
  163. data/vimamsa.gemspec +1 -1
  164. data/vm_guest_run.sh +75 -28
  165. metadata +60 -4
  166. data/run_tests.rb +0 -89
  167. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,266 @@
1
+ # Plan: introduction page for first-time users
2
+
3
+ Done (2026-11-21, `6448bb9`). See DONE.
4
+
5
+ ## Context
6
+
7
+ A new user starts with an empty buffer and no hint of where to begin. The demos
8
+ (basic editing, easy jump, switching files) show the editor well, but they're three
9
+ levels deep in the menu (Help ▸ Demos ▸ …), so most people won't find them. The key
10
+ bindings page is complete but long.
11
+
12
+ An introduction page opens automatically on the first start and is always available
13
+ as Help ▸ Introduction. It's a short text page with buttons that start the
14
+ recommended demos and open the other help pages.
15
+
16
+ ## What exists to build on
17
+
18
+ - **Hyperplaintext** (`lang/hyperplaintext.lang`, `hyper_plain_text.rb`): `❙title❙`,
19
+ `◼ heading`, `⦁key⦁`, and links `⟦file⟧` / `⟦help:keybindings⟧`, which open with
20
+ enter or the context menu (`Buffer#handle_word`, `wtype == :help`,
21
+ `gui_sourceview.rb` `ctx_open_link`). The key bindings page and `demo.txt` use it.
22
+ - **Widgets embedded in the text:** the image code (`buffer.rb`, the
23
+ `create_child_anchor` / `add_child_at_anchor` calls) puts GTK widgets into the
24
+ text. Buttons can work the same way. (Audio widgets use this too, but audio is
25
+ experimental: the intro page doesn't use or mention it.)
26
+ - **Demos:** `DemoPlayer.toggle(name)`, the actions `help.demo`,
27
+ `help.demo.easyjump` and `help.demo.files`, and `DemoPlayer::DEMOS`.
28
+ - **Bindings generated from the live tree:** `key_bindings_page` uses `BASIC_ACTIONS`
29
+ and `vma.kbd.bindings`, so the keys it shows are right for the current scheme.
30
+ - **Vim differences:** `doc/vimlike_vim_conflicts.md` and the `help.vim_conflicts`
31
+ page list every key that differs, and `doc/missing_vim_bindings.md` lists what is
32
+ missing. Both are complete but long; the intro page links to a short summary (see
33
+ "For Vim users").
34
+ - **First run:** `Editor#start` already creates `custom.rb` from `custom_example.rb`
35
+ when it doesn't exist.
36
+
37
+ ## Design
38
+
39
+ ### Format: a hyperplaintext page in a read-only buffer, with buttons
40
+
41
+ The page is a template, `intro.txt` (next to `demo.txt`, shipped in the gem). It
42
+ opens in a buffer named `intro` with the hyperplaintext language, like the key
43
+ bindings page. Reasons:
44
+
45
+ - It's an ordinary editor buffer, so the reader is already using the editor: moving
46
+ around and searching work, and so does the key log.
47
+ - Every button is also a link, so it can be reached with the keyboard. Put the
48
+ cursor on it and press enter. The mouse works too.
49
+ - It's easy to edit: the text is a file, not GTK code.
50
+
51
+ A separate dialog was rejected: demos play in the main window, and a dialog would
52
+ have to close or get in the way.
53
+
54
+ ### New link kind: `⟦run:<action>|<label>⟧`
55
+
56
+ - `Buffer#handle_word` gets a `:run` type next to `:help`; enter on the link runs the
57
+ action with `call_action`.
58
+ - **Only actions in an allowlist run:** `help.*`, `app.demo`, `settings.*` (decide
59
+ the exact list). Any `.txt` file can contain this syntax, so opening a downloaded
60
+ file must not be able to run arbitrary actions. Outside the list, the link only
61
+ shows a message.
62
+ - **Buttons:** on a help page, each `⟦run:…⟧` link is shown as a `Gtk::Button`
63
+ with the label after `|`, in place of the link's text. The text stays in the
64
+ buffer but is hidden by an invisible GTK tag. The button is at a child anchor
65
+ that takes the place of a space the page adds before the link (before, because
66
+ GTK doesn't draw a widget that follows invisible text). Clicking the button runs
67
+ the action. In a buffer that can be edited, the link text is shown instead of
68
+ the button while the cursor is on its line. In a read-only one (the help pages)
69
+ the button is always shown; a cursor on the hidden text moves onto the button,
70
+ and enter there runs the link.
71
+ - `⟦help:…⟧` gets more targets: `keybindings` (exists), `vim_conflicts`, `intro`,
72
+ `vim_intro`.
73
+
74
+ ### Keys in the text come from the bindings
75
+
76
+ The template says `{key:mode.insert}`, `{key:buf.save}` and so on. When the page is
77
+ opened, these are replaced with the bound keys from `vma.kbd.bindings` (the first
78
+ binding in Command mode, formatted as on the key bindings page, in `⦁…⦁`). The page
79
+ stays right when bindings change or with the notepad scheme. An action that has no
80
+ binding shows its menu path or the `:` command instead. A test checks that every
81
+ `{key:…}` in the template resolves.
82
+
83
+ ### Content (keep it to about one screen)
84
+
85
+ ```
86
+ ❙Welcome to Vimamsa❙
87
+ A Vim-inspired text editor. This page: Help ▸ Introduction.
88
+
89
+ ◼ Modes
90
+ Command mode: keys move and edit (badge at the bottom right shows the mode).
91
+ Insert mode: keys type text. Enter it with {key:mode.insert}, leave it with {key:mode.prev}.
92
+ Visual mode: select text, {key:mode.visual}.
93
+
94
+ ◼ Watch a demo (each plays in its own buffer; the key log on the right
95
+ shows every key and what it did)
96
+ ⟦run:help.demo|▶ Basic editing⟧ moving, editing, undo ~1 min
97
+ ⟦run:help.demo.easyjump|▶ Easy jump⟧ jump anywhere on screen ~40 s
98
+ ⟦run:help.demo.files|▶ Switching files⟧ file finder, buffer history ~40 s
99
+
100
+ ◼ The essentials
101
+ Open file {key:file.open} File finder {key:file.finder} Save {key:buf.save}
102
+ Search {key:search.buf} Undo {key:undo.last} Command line {key:mode.cmdline}
103
+
104
+ ◼ Coming from Vim?
105
+ ⟦help:vim_intro⟧ the main differences, in one screen
106
+
107
+ ◼ Learn more
108
+ ⟦help:keybindings⟧ all key bindings
109
+ ⟦run:app.demo|Install demo files⟧ text and images to try
110
+ Customize: ⟦~/.config/vimamsa/custom.rb⟧ (Ruby, loaded at startup)
111
+
112
+ ⟦run:help.intro.toggle_startup|Don't show at startup⟧
113
+ ```
114
+
115
+ The demo lengths are measured, not guessed: `DemoPlayer` can sum the waits and
116
+ delays of a steps file. They could be generated like the keys (`{demo_len:basic}`).
117
+
118
+ ### For Vim users: a one-screen summary
119
+
120
+ A second short page, `vim_intro.txt`, opened by `⟦help:vim_intro⟧` on the intro
121
+ page. It lists the differences a Vim user hits in the first minutes, and ends with
122
+ links to the full lists. Its keys use `{key:…}` too, so it stays right when the
123
+ bindings change. Content, from what the code does now (2026-11-21):
124
+
125
+ - **`:` is very limited.** It understands only `:w`, `:q`, `:wq`, `:e <file>`, `:<line
126
+ number>`, `:!<shell command>` (output into a buffer) and `:reg`. Anything else is
127
+ run as Ruby, so there is no `:s///`, `:g`, `:set`, `:%`, ranges or `:help`. Search
128
+ and replace has its own commands (`{key:search.buf}`, the Search menu), and settings
129
+ are in Settings.
130
+ - **ctrl alone switches modes.** Press and release ctrl with no other key in between:
131
+ in Command mode it enters Insert mode, and in Insert and Visual mode it leaves
132
+ them. `esc` works
133
+ too, but it doesn't move the cursor one character left as Vim's does.
134
+ - **Some keys do other things:**
135
+
136
+ | Key | Vim | Vimlike |
137
+ |---|---|---|
138
+ | `s` | change a character | easy jump |
139
+ | `C` | change to end of line | grep in files |
140
+ | `O` | open a line above | end of line |
141
+ | `X` | delete a character back | new line below |
142
+ | `space` | right | prefix: `space <char>` inserts a character |
143
+ | `tab` | jump forward | switch to the last buffer |
144
+ | `z` | prefix (`zz`, `zt`) | Browse mode |
145
+ | `ctrl-o` | jump back | open a file |
146
+ | Insert `ctrl-n` / `ctrl-p` | completion | line down / up |
147
+ | Insert `ctrl-c` | leave Insert mode | copy |
148
+
149
+ `,` starts many of vimlike's own commands (see the key bindings page).
150
+ - **Not there yet:** line-wise and block visual (`V`, `ctrl-v`); `ge`, `{` / `}`,
151
+ `%`; `=` and `gq`; `ctrl-e` / `ctrl-y`; `gv` and `gi`.
152
+ - **The same as Vim:** operators with motions and text objects (`d c y gU gu g~ >
153
+ <`, `dw`, `ci(`, `yap` …), counts, registers (`"a`–`"z`, `"+`), `.`, macros
154
+ (`q` / `@`), marks.
155
+ - **Prefer Vim's keys?** Settings ▸ Keybinding scheme ▸ `vim` (restart needed).
156
+ - Links: ⟦help:vim_conflicts⟧ (every key that differs, generated) and the list of
157
+ missing Vim bindings.
158
+
159
+ The table is short on purpose: it doesn't try to list all 42 conflicts. A test
160
+ checks each row against the live bindings (e.g. that `s` runs `jump.easy` in
161
+ vimlike), so the page can't drift from the keymap unnoticed. Rows could be
162
+ generated from `vim_binding_conflicts` with a hand-picked list of keys, but then
163
+ someone still has to write each description.
164
+
165
+ ### When it is shown
166
+
167
+ - **`--intro`** on the command line shows the page at start whatever the setting,
168
+ the user dir or other arguments say, and doesn't change the setting. It's for
169
+ trying the page and for tests: `ruby exe/vimamsa --intro`, or with a fresh
170
+ `--user-dir` to see a real first start.
171
+ - Shown on start when `cnf.intro.show_on_startup` is true. It defaults to true and
172
+ is set to false after the page has been shown once, so normally the page appears
173
+ only on the first start.
174
+ - The setting is in Settings ▸ Behavior, and the page's last button changes it.
175
+ - **Not shown** when:
176
+ - files or dirs are given on the command line;
177
+ - a session is being restored;
178
+ - in test mode (`vma_test_mode?`, as for `check_session_restore`);
179
+ - `cnf.startup_file` is set.
180
+
181
+ In those cases the user already knows what they want.
182
+ - **Always available:**
183
+ - Help ▸ Introduction, the first item in the Help menu;
184
+ - the action `help.intro` (no key binding: the menu is enough);
185
+ - `:intro` on the command line.
186
+ - The intro buffer is read-only and isn't saved in the session or file history.
187
+ Opening it again switches to the existing buffer.
188
+
189
+ ### Demos started from the page
190
+
191
+ - A demo stops when another buffer is opened. When it was started from the intro
192
+ page, stopping it or letting it finish returns to the page (`DemoPlayer` remembers
193
+ the buffer it was started from), so the next demo is one click away.
194
+ - Demos keep looping until stopped (current behaviour). The demo controls (pause,
195
+ speed, ✕) are already shown above the key log.
196
+
197
+ ### Switching demos while one plays
198
+
199
+ While a demo plays, the demo controls above the key log
200
+ (`gui_keylog_panel.rb`, `show_demo_controls`) also list the demos, so the user can
201
+ go to another one without the menu or the intro page:
202
+
203
+ - A dropdown (`Gtk::DropDown`) next to the pause and speed buttons, with the demo
204
+ titles from `DemoPlayer::DEMOS` and the current one selected. Choosing another
205
+ demo calls `DemoPlayer.toggle(name)`, which stops the playing one and starts the
206
+ new one, keeping the speed setting. Optionally add "Next ▸", which starts the next
207
+ demo in the list.
208
+ - For this, each demo in `DemoPlayer::DEMOS` gets a `title:` ("Basic editing") and a
209
+ one-line `desc:`. The Help ▸ Demos menu, the intro page and the dropdown all use
210
+ them, so a new demo needs adding in one place only.
211
+ - The key log is cleared when the demo changes, as at the start of a round.
212
+ - Test: start the basic demo, choose "Easy jump" in the dropdown; the easy jump
213
+ demo runs, the basic one stopped, and the dropdown shows "Easy jump".
214
+
215
+ ## Implementation order
216
+
217
+ 1. `⟦run:action|label⟧` links: parsing in `handle_word` and the context menu, the
218
+ allowlist, and the new `⟦help:…⟧` targets. Tests: an allowed action runs, a
219
+ disallowed one doesn't and shows a message.
220
+ 2. `intro.txt`, `{key:…}` substitution, the `help.intro` action, the Help menu item,
221
+ `:intro`, and a read-only buffer kept out of the session. Tests: every `{key:…}`
222
+ resolves in vimlike and notepad, and opening the page twice keeps one buffer.
223
+ 3. Buttons at child anchors for `⟦run:…⟧` links. Test: clicking the button
224
+ (`signal_emit("clicked")`) starts the demo.
225
+ 4. Show on first start (`cnf.intro.show_on_startup`, the conditions above), plus the
226
+ Settings checkbox. Test: shown with a fresh user dir, not with a file argument,
227
+ not the second time.
228
+ 5. Return to the intro page after a demo started from it.
229
+ 6. `title:` / `desc:` in `DemoPlayer::DEMOS`, and the demo dropdown in the demo
230
+ controls.
231
+ 7. `vim_intro.txt` and `⟦help:vim_intro⟧`, with the test that checks its table
232
+ against the live bindings.
233
+ 8. Update the README (mention Help ▸ Introduction and `--intro`) and
234
+ `custom_example.rb`.
235
+
236
+ `--intro` comes with step 2, so every later step can be tried with
237
+ `ruby exe/vimamsa --intro`.
238
+
239
+ Run the suite in the test VM after each step (`./run_tests_vm.rb`).
240
+
241
+ ## Later
242
+
243
+ - No guided exercises on the intro page: it stays text plus demos. A separate step
244
+ by step tutorial may come later. The intro page would then link to it, and the
245
+ `⟦run:…⟧` links and buttons can be reused there.
246
+
247
+ ## DONE
248
+
249
+ - 2026-11-21, `6448bb9`. All the steps:
250
+ - `lib/vimamsa/intro_page.rb`, plus `help/intro.txt` and `help/vim_intro.txt`.
251
+ - `⟦run:…⟧` links with an allowlist (`help.*`, `app.demo`), and inline buttons.
252
+ - `{key:…}`, `{demos}` and `{vim_key_table}` placeholders.
253
+ - Read-only help buffers (`Buffer#read_only`, refused in `add_delta`).
254
+ - Help ▸ Introduction and Help ▸ Vimamsa for Vim users; `:intro`; `--intro`.
255
+ - `cnf.intro.show_on_startup` (Settings ▸ Behavior; set false once shown at
256
+ start).
257
+ - `DEMOS` `title:` / `desc:` / `action:` (used by the menu, the page and the
258
+ dropdown), and `DemoPlayer.duration`.
259
+ - The demo dropdown above the key log (on its own row, so the panel keeps its
260
+ width); switching keeps the speed.
261
+ - Back to the page after a demo started from it.
262
+ - README and `custom_example.rb`.
263
+ - Tests: `tests/test_intro_page.rb` (19). Full suite in the VM: 500 passed.
264
+ - Buttons are only added to help pages. A ⟦run:…⟧ link in an ordinary file
265
+ works with the keyboard and the context menu, but gets no button: that would
266
+ need a placeholder char in the file, as images do.
@@ -1,5 +1,8 @@
1
1
  # Plan: better organized "Show key bindings" page
2
2
 
3
+ TODO: act next on step 4 of "Implementation order" (text-object renderer and
4
+ `<char>`/`<num>` templates). Steps 1-3 are done (see DONE at the end).
5
+
3
6
  ## Context
4
7
 
5
8
  Help ▸ Show key bindings (`show_key_bindings`, `lib/vimamsa/key_bindings_report.rb:18`)
@@ -166,3 +169,45 @@ One ordered list in `key_bindings_report.rb` (or a small `key_categories.rb`):
166
169
  in parallel; until then the column shows the raw action.
167
170
 
168
171
  Run the full suite in the VM after each step.
172
+
173
+ ## DONE
174
+
175
+ - **Steps 1-2: binding records and categories** (2026-11-21, commit "feat: key
176
+ bindings page grouped by category"). `KeyBindingTree#bindings` returns
177
+ `{ mode:, keys:, action:, keywords:, desc: }` records in definition order,
178
+ including actions on nodes that also have longer bindings; `get_by_keywords`
179
+ is built on it. `desc` now also covers dotted action ids (since the renames
180
+ the page showed raw ids) and shows procs as `proc (file.rb:line)`.
181
+ Categories (`KEY_CATEGORIES` in `key_bindings_report.rb`, the table above
182
+ plus `app`, `help`, `custom` and `internal`): `key_binding_category` takes a
183
+ minor mode, then the namespace of a named action
184
+ (`doc/action_names_plan.md`), then a `cat:<id>` keyword, the
185
+ `module:<name>` / `custom` context, the major mode (`B`, `X`, `R`), and the
186
+ older section words (`vim motion`, `experimental`, ...). The context comes
187
+ from `KeyBindingTree#with_keywords`, wrapped around module inits (startup
188
+ and Settings) and the three places `custom.rb` runs. vimlike's `intro` and
189
+ `core` blocks are split into `cat:` groups (same bindings, same order within
190
+ each group, checked by script); the vim table gets `vim marks` and an
191
+ insert section. The page lists Basics (`intro`, as before), then the
192
+ categories in order; "Others" is gone. `tests/test_key_categories.rb`: every
193
+ binding of vimlike, vim and notepad has a category.
194
+ Left for later: Basics still uses the `intro` keyword (`BASIC_ACTIONS` is
195
+ step 3); the conflict report still uses its own traversal
196
+ (`kbd_leaf_bindings`).
197
+ - **Step 3: page layout** (2026-11-21). `key_bindings_page` builds the text,
198
+ `key_bindings_section` one section: rows in definition order
199
+ (`State#seq`, set by `bindkey`; `KeyBindingTree#bindings` is sorted by it),
200
+ the same keys and description in several modes merged into one row,
201
+ rows grouped by modes under `◼◼ Command, Visual` subheadings (ordered by
202
+ their first mode, then by which was defined first; none in minor-mode
203
+ sections), keys of a group with the same description merged (`y y / Y`),
204
+ keys and descriptions in aligned columns. Conditions are shown as text
205
+ through `KEY_CONDITIONS` (`(with a count)`), others as `(if <rule>)`. The
206
+ header names the scheme. Basics lists `BASIC_ACTIONS` with the keys the
207
+ active keymap binds them to in Command, Visual and Insert mode. Tests in
208
+ `tests/test_key_categories.rb` (`test_section_layout`, `test_page_layout`).
209
+ Not done: dimming the raw action after a description (hyperplaintext has
210
+ no dim style).
211
+ - **Step 5: descriptions** (2026-11-21): done through step 6 of
212
+ `doc/action_names_plan.md`, which made every Ruby-string binding a named
213
+ action with a description.
@@ -0,0 +1,89 @@
1
+ # Plan: line ends in a treap (`LineTree`)
2
+
3
+ ## Why
4
+
5
+ `Buffer#@line_ends` is a sorted Array of the positions of every `\n`. Lookups are
6
+ fast (`[i]`, `bsearch_index`), but every edit shifts all later entries in a Ruby
7
+ loop (`update_line_ends`, `buffer.rb`): 0.65 ms per edit at 10k lines and 6.3 ms at
8
+ 100k (measured 2026-11-21, see `doc/TODO.md`, "Performance"). A replace pays it
9
+ twice.
10
+
11
+ An implicit treap of lines makes edits and lookups O(log n) expected. Background
12
+ and an interactive walkthrough of the operations: the "Treap of Lines" artifact,
13
+ and the "tree structures" discussion in `doc/TODO.md`.
14
+
15
+ ## Design
16
+
17
+ `lib/vimamsa/line_tree.rb`, class `LineTree`.
18
+
19
+ - **One node per line**, in document order. Lines are ordered by position in the
20
+ tree; line numbers aren't stored.
21
+ - `len`: characters in the line, its `\n` included
22
+ - `prio`: random, and a parent's is higher than its children's (heap order)
23
+ - `cnt` and `sum`: lines and characters in the subtree
24
+ - **The last node is the text after the last `\n`** (usually empty, because buffers
25
+ end with `\n`). So every position, including the end of the text, belongs to a
26
+ node, and `size` (the number of newlines) is the node count minus 1.
27
+ - Core operations, as in the artifact: `split` and `merge` by line count, a descent by
28
+ line number or by character position, and an O(k) build from a list of lengths.
29
+
30
+ ### Array-compatible interface
31
+
32
+ `@line_ends` stays the name, and the tree answers the Array methods the code
33
+ uses. The about 75 call sites (`buffer.rb`, `buffer_cursor.rb`, `fold.rb`,
34
+ `vim_operators.rb`, `vim_core.rb`, `bookmarks.rb`, `gui_file_panel.rb`) then don't
35
+ change:
36
+
37
+ | Method | Meaning | Cost |
38
+ |---|---|---|
39
+ | `size` | number of `\n` | O(1) |
40
+ | `[i]` (negative `i` allowed) | position of the i-th `\n` | O(log n) |
41
+ | `bsearch_index { \|x\| … }` / `bsearch { … }` | find-minimum binary search over the `\n` positions, as `Array#bsearch` | O(log n), one descent |
42
+ | `to_a`, `==` | the plain Array, for tests and checks | O(n) |
43
+
44
+ Extra methods for later callers: `line_start(i)`, `line_len(i)`, `line_at(pos)` →
45
+ `[line, column]`, `total`.
46
+
47
+ ### Updates
48
+
49
+ `Buffer#update_line_ends(pos, changeamount, changestr)` calls
50
+ `@line_ends.insert(pos, text)` or `@line_ends.delete(pos, removed_text)`. Both
51
+ come from `run_delta`, which already knows the inserted or removed text.
52
+
53
+ - **Insert `text` at `pos`** (on line j, column c), where `text` has k newlines:
54
+ - **k = 0:** line j gets longer. Only the sums on its path change.
55
+ - **k > 0:**
56
+ - line j becomes `c + first piece + 1`
57
+ - the middle pieces become new lines
58
+ - the last piece plus the rest of line j becomes the last new line
59
+ - the k new lines are added with one split, an O(k) build and two merges
60
+ - **Delete `n` chars at `pos`**, where the removed text has m newlines:
61
+ - **m = 0:** line j gets shorter.
62
+ - **m > 0:** lines j … j + m become one line, of length `c + (len(j + m) − end column)`.
63
+ Lines j + 1 … j + m are removed with two splits and a merge.
64
+ - **A full rebuild** (`set_content`, `recalc_line_ends`) builds the tree from
65
+ `each_line` in O(n). There's no regex scan any more.
66
+
67
+ ## Tests
68
+
69
+ - **Random edits compared with a reference:** apply random inserts and deletes
70
+ (with and without newlines, at the start, middle and end, including non-ASCII
71
+ text) to a String and to a `LineTree`, and compare `to_a` with the newline
72
+ positions of the String after every step.
73
+ - **Invariants after each step:** heap order, and `cnt` / `sum` consistent.
74
+ - **Array interface:** `[]` with negative indexes, `bsearch_index` and `bsearch`
75
+ equal the Array versions for every position.
76
+ - **Buffer:** editing a buffer keeps `line_ends.to_a` equal to a fresh scan. The
77
+ existing suite covers the callers.
78
+ - **Performance:** 1000 single-character inserts in the middle of a 100k-line
79
+ buffer must be well below the old cost (about 6 ms each).
80
+
81
+ ## Order
82
+
83
+ 1. `LineTree` with unit tests (no Buffer changes).
84
+ 2. Buffer uses it: `set_content`, `update_line_ends`, `recalc_line_ends`,
85
+ `sanity_check_line_ends`. `require` in `rbvma.rb`. Full suite in the VM.
86
+ 3. Measure the edit cost at 100k lines, and record it in `doc/TODO.md`.
87
+ 4. Later: call sites that loop over all lines (`fold.rb`'s fold search) can walk
88
+ the tree in order instead of calling `[i]` per line. Per-line data (the
89
+ highlighter state, tokens) can move into the nodes when own highlighting comes.
@@ -11,42 +11,31 @@ This list comes from reading the binding files, not from testing in the editor.
11
11
  The generated [vimlike_vim_conflicts.md](vimlike_vim_conflicts.md) compares the two
12
12
  keymaps binding by binding.
13
13
 
14
- ## Root cause
15
-
16
- There is no general operator + motion system. Each combination (`d e`, `c w`, ...)
17
- is bound individually, so any combination nobody wrote out is missing.
18
-
19
- ## Case changes
20
-
21
- Done: `gUw`, `guw`, `g~w`, `gUU`, `guu`, `g~~` and `~` work in both keymaps, and
22
- `vimlike` also has Visual `U`, `u`, `~`. Still missing: counts (`2gUw`) and other
23
- motions or text objects after the operator (`gUe`, `gUiw`, ...), which need the
24
- operator-pending layer below.
25
-
26
- ## Operators: change, delete, yank
27
-
28
- - `vimlike` has no change operator at all: no `c w`, `c c`, `C`, `S`, `D` or `Y`.
29
- Its `C`, `s` and `S` are bound to other actions. The `vim` keymap has these.
30
- - Many combinations are missing in both, such as `d b`, `c b`, `y b`, `d t x`,
31
- `c f x`, `d G`, `d g g` and `d }`. `d j` and `d k` are missing in both keymaps
32
- (in `vimlike` they're commented-out TODOs).
33
- - A count after the operator (`d 3 w`, `y 2 y`, `d 2 f x`) works only for `d <num> e`
34
- in `vimlike`. A count before the command (`3 d w`) works, because the action is
35
- repeated.
36
- - Text objects are done in both keymaps (`lib/vimamsa/text_objects.rb`): `iw aw iW aW
37
- is as ip ap`, the quotes, the brackets and `it at`, after `d c y gU gu g~` and in
38
- Visual mode. Counts work for brackets and tags (`2di(`). Not done yet: a count after
39
- the operator (`d2i(`) and repeating `i(` in Visual mode to grow the selection.
40
- - Indenting from Command mode (`>>`, `<<`, `=`) is missing. Visual `>` and `<` exist
41
- only in the `vim` keymap.
42
-
43
- ## Motions
44
-
45
- - `t` / `T` (move to just before a character) and `,` (repeat `f` backwards).
46
- - `W` / `B` / `E` (move by whitespace-separated "WORD"), and `ge`.
47
- - `{` / `}` (paragraph), `(` / `)` (sentence) and `%` (matching bracket).
48
- - `H` / `M` / `L` (top, middle and bottom of the screen).
14
+ ## Operators and motions
15
+
16
+ Done (2026-11-21): the operator + motion layer (`lib/vimamsa/vim_operators.rb`,
17
+ step 1 of `doc/vim_compatibility_plan.md`). Every operator works with every motion and
18
+ text object, with counts before the operator and before the motion (`2d3w`):
19
+
20
+ - Operators: `d c y gU gu g~ > <`. Doubled, they act on lines: `dd cc yy gUU >>`.
21
+ - Motions: `h l j k w b e W B E 0 ^ $ gg G f t F T` (with a character or `space`),
22
+ `'x` and `` `x `` (marks). `cw` works like `ce`, and `dw` on the last word of a line
23
+ doesn't join lines, as in vim.
24
+ - Text objects: `iw aw iW aW is as ip ap`, the quotes, the brackets and `it at`.
25
+
26
+ The `vim` keymap has all of them. `vimlike` has every combination it doesn't use for
27
+ something else (see [vimlike_vim_conflicts.md](vimlike_vim_conflicts.md)). Its own
28
+ `d w`, `d e`, `d $`, `y e`, `g U w`, ... stay, so for those keys vimlike behaves as
29
+ before. `vimlike` also gets `W B E t T` as plain motions, and its own `O` (end of line)
30
+ works after every operator (`c O`, `g U O`).
31
+
32
+ Still missing:
33
+ - Operators `=` (reindent) and `gq` (format).
34
+ - Motions `ge`, `{` / `}` (paragraph), `(` / `)` (sentence), `%` (matching bracket),
35
+ `H` / `M` / `L` (top, middle and bottom of the screen), `,` (repeat `f` backwards),
36
+ `;` after `t` / `T`.
49
37
  - `#` (search backward for the word under the cursor).
38
+ - Repeating `i(` in Visual mode to grow the selection.
50
39
 
51
40
  ## Scrolling and jumps
52
41
 
@@ -60,12 +49,13 @@ operator-pending layer below.
60
49
 
61
50
  - Line-wise visual (`V`), block visual (`ctrl-v`) and `o` (swap selection ends) are
62
51
  missing. `vimlike` binds `V` and `ctrl-v` to other actions.
63
- - `ctrl-x` (decrement a number) is missing; `ctrl-a` exists only in the `vim` keymap.
64
- - `gJ` (join lines without adding a space) and named registers (`"a` etc.) are
65
- missing.
66
-
67
- ## Suggested approach
68
-
69
- A small generic operator-pending layer, where an operator (`d`, `c`, `y`, `gU`, `gu`,
70
- `g~`, `>`) waits for any motion or text object, would cover most of the case-change,
71
- operator and text-object gaps at once instead of adding dozens of separate bindings.
52
+ - `ctrl-x` (decrement a number) is missing; `ctrl-a` is in both keymaps.
53
+ - `gJ` (join lines without adding a space) is missing.
54
+ - `.` is done (2026-11-21, `lib/vimamsa/dot_repeat.rb`): it repeats the last change,
55
+ including the text typed after `c`, `i`, `o`, ..., with a new count if one is given,
56
+ as one undo step. Not for changes made in Visual mode.
57
+ - `esc` in Insert mode doesn't move the cursor one character left, as vim's does.
58
+ - Registers are done (2026-11-21, `lib/vimamsa/registers.rb`): `""`, `"0`, `"1`–`"9`,
59
+ `"-`, `"a`–`"z` (`"A` appends), `"+` / `"*` and `"_`, selected with `"x` before any
60
+ copy, delete or put. They remember whether the text was whole lines. Insert-mode
61
+ `ctrl-r x` is in the `vim` keymap only. `:reg` lists them.
@@ -265,7 +265,7 @@ Add (`tests/test_modules_dialog.rb`):
265
265
  `activate_no_restart_modules` path had.
266
266
  - `:show_modules` is registered and in the Settings menu.
267
267
 
268
- Run the full suite in the test VM (`./run_tests_vm.sh`, VM from `$VM_NAME`), not just the touched files.
268
+ Run the full suite in the test VM (`./run_tests_vm.rb`, VM from `$VM_NAME`), not just the touched files.
269
269
 
270
270
  ### 7. Core features to turn into modules
271
271