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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +93 -0
- data/.gitignore +4 -1
- data/Dockerfile +7 -4
- data/README.md +195 -99
- data/custom_example.rb +59 -17
- data/doc/TODO.md +678 -0
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +570 -0
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +213 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +61 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +451 -0
- data/doc/vimlike_vim_conflicts.md +262 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +124 -3
- data/exe/vimamsa +68 -5
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +7 -1
- data/lib/vimamsa/ack.rb +13 -1
- data/lib/vimamsa/actions.rb +385 -37
- data/lib/vimamsa/appimage_env.rb +35 -0
- data/lib/vimamsa/audio.rb +2 -5
- data/lib/vimamsa/bookmarks.rb +302 -0
- data/lib/vimamsa/buffer.rb +675 -118
- data/lib/vimamsa/buffer_changetext.rb +150 -68
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +6 -2
- data/lib/vimamsa/buffer_manager.rb +10 -7
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +9 -3
- data/lib/vimamsa/conf.rb +68 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +6 -3
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +40 -11
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +57 -3
- data/lib/vimamsa/editor.rb +327 -78
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +4 -1
- data/lib/vimamsa/file_manager.rb +46 -31
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +603 -119
- data/lib/vimamsa/gui_command_line.rb +247 -0
- data/lib/vimamsa/gui_dialog.rb +94 -42
- data/lib/vimamsa/gui_file_panel.rb +356 -25
- data/lib/vimamsa/gui_form_generator.rb +75 -40
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +408 -0
- data/lib/vimamsa/gui_menu.rb +84 -53
- data/lib/vimamsa/gui_select_window.rb +80 -75
- data/lib/vimamsa/gui_settings.rb +86 -41
- data/lib/vimamsa/gui_sourceview.rb +280 -92
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +615 -0
- data/lib/vimamsa/hook.rb +5 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +382 -193
- data/lib/vimamsa/key_binding_tree.rb +467 -273
- data/lib/vimamsa/key_bindings_notepad.rb +45 -0
- data/lib/vimamsa/key_bindings_report.rb +484 -0
- data/lib/vimamsa/key_bindings_vim.rb +104 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +23 -3
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +41 -1
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +15 -14
- data/lib/vimamsa/string_util.rb +134 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +11 -8
- data/lib/vimamsa/text_objects.rb +310 -0
- data/lib/vimamsa/text_transforms.rb +18 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/lib/vimamsa.rb +0 -1
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +118 -0
- data/modules/color_highlight/color_highlight_info.rb +3 -0
- data/modules/dictation/dictation.rb +1054 -0
- data/modules/dictation/dictation_info.rb +3 -0
- data/modules/dictation/whisper_worker.py +273 -0
- data/modules/ollama/ollama.rb +107 -0
- data/modules/ollama/ollama_info.rb +3 -0
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.rb +138 -0
- data/scripts/appimage/AppRun +54 -0
- data/scripts/appimage/Dockerfile +18 -0
- data/scripts/appimage/build.sh +19 -0
- data/scripts/appimage/build_in_container.sh +192 -0
- data/scripts/appimage/smoke_test.sh +27 -0
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +67 -0
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +156 -0
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +29 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/styles/134272-molokai.xml +3 -0
- data/styles/molokai_cyber.xml +48 -0
- data/styles/molokai_edit.xml +1 -0
- data/tests/support/virtual_keyboard.rb +254 -0
- data/tests/support/virtual_mic.rb +67 -0
- data/tests/test_ack.rb +22 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +122 -0
- data/tests/test_autocomplete.rb +211 -0
- data/tests/test_autosave.rb +145 -0
- data/tests/test_basic_editing.rb +46 -16
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +88 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +92 -0
- data/tests/test_command_line.rb +79 -0
- data/tests/test_command_line_file.rb +27 -0
- data/tests/test_context_menu_file.rb +147 -0
- data/tests/test_copy_paste.rb +106 -26
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dialog_callback_errors.rb +44 -0
- data/tests/test_dictation.rb +294 -0
- data/tests/test_diff_buffer_name.rb +51 -0
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_double_click.rb +41 -0
- data/tests/test_drag_selection.rb +125 -0
- data/tests/test_e2e_cmdline.rb +116 -0
- data/tests/test_e2e_dictation.rb +98 -0
- data/tests/test_e2e_replace_char.rb +58 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +55 -0
- data/tests/test_file_format.rb +217 -0
- data/tests/test_file_manager.rb +72 -0
- data/tests/test_file_panel.rb +269 -0
- data/tests/test_flash.rb +78 -0
- data/tests/test_fold.rb +111 -0
- data/tests/test_font_refresh.rb +56 -0
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +68 -0
- data/tests/test_grep_apply.rb +46 -0
- data/tests/test_gtk_sync.rb +126 -0
- data/tests/test_hpt_highlight_visible.rb +75 -0
- data/tests/test_hpt_link_highlight.rb +82 -0
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +261 -0
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +281 -0
- data/tests/test_lsp_jump.rb +87 -0
- data/tests/test_lsp_position_encoding.rb +49 -0
- data/tests/test_lsp_symbols.rb +68 -0
- data/tests/test_macro.rb +137 -0
- data/tests/test_markdown_highlight.rb +57 -0
- data/tests/test_mode_badge.rb +41 -0
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_registers.rb +122 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +58 -0
- data/tests/test_status_area.rb +50 -0
- data/tests/test_text_objects.rb +163 -0
- data/tests/test_text_transforms.rb +341 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +353 -0
- data/tests/test_vim_conflicts.rb +100 -0
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +302 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +129 -0
- metadata +167 -10
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
# Modules page: move module toggles out of Preferences into Settings ▸ Modules
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
Module toggles currently live on the **Modules** tab of Settings ▸ Preferences. They're
|
|
6
|
+
built by `all_settings_defs` (`gui_settings.rb`), which scans `modules/*/` and calls
|
|
7
|
+
`<name>_info` for each. Each toggle is just a label with a switch. The user doesn't learn
|
|
8
|
+
what the module does or what it needs installed, so they can enable TTS or dictation and
|
|
9
|
+
get only a runtime error like "TTS: need 'piper' and 'aplay' on PATH".
|
|
10
|
+
|
|
11
|
+
Goal:
|
|
12
|
+
1. A separate **Settings ▸ Modules...** menu item with its own dialog. The Modules tab
|
|
13
|
+
is removed from Preferences.
|
|
14
|
+
2. Each module shows **what it does** and **what the user has to do** to make it work
|
|
15
|
+
(apt/pip installs, model downloads, a running service).
|
|
16
|
+
3. **Experimental modules** (Embedded Terminal, Scientific Calculator) go in their own
|
|
17
|
+
section, apart from the stable ones.
|
|
18
|
+
|
|
19
|
+
## Current state (verified)
|
|
20
|
+
|
|
21
|
+
- `lib/vimamsa/gui_settings.rb`
|
|
22
|
+
- `all_settings_defs` returns `SETTINGS_DEFS` plus a generated `"Modules"` section
|
|
23
|
+
(keys `[:modules, <name>, :enabled]`, `:no_restart` taken from info).
|
|
24
|
+
- `SettingsDialog#activate_no_restart_modules` loads the module and calls
|
|
25
|
+
`<name>_init` / `<name>_disable` when a switch changes with `no_restart: true`.
|
|
26
|
+
- `modules/<name>/<name>_info.rb` only returns `{ name:, no_restart: }`. All 6 modules
|
|
27
|
+
are `no_restart: true`.
|
|
28
|
+
- Startup loading: `editor.rb:229-243` (stays as it is).
|
|
29
|
+
- `gui_menu.rb:46` `Settings.Preferences` → `:show_settings` (`key_actions.rb:33`).
|
|
30
|
+
- There is already a top-level **Modules** menu (`Menu#add_module_action`) that holds
|
|
31
|
+
module *actions* such as "Insert Calculator". It is separate from this work but has
|
|
32
|
+
the same name (see open question 1).
|
|
33
|
+
- Tests that depend on the Modules section being inside `all_settings_defs`:
|
|
34
|
+
- `tests/test_module_interface.rb:79-97` (3 tests)
|
|
35
|
+
- `tests/test_color_highlight.rb:86-91` (`test_setting_exposed`)
|
|
36
|
+
- `tests/test_tts.rb`, `tests/test_dictation.rb` check `_info` structure (still valid,
|
|
37
|
+
will be extended).
|
|
38
|
+
|
|
39
|
+
## Design
|
|
40
|
+
|
|
41
|
+
### 1. Extend the `<name>_info` contract
|
|
42
|
+
|
|
43
|
+
The new keys are optional, so modules without them still work:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
def tts_info
|
|
47
|
+
{
|
|
48
|
+
name: "Text to Speech",
|
|
49
|
+
no_restart: true,
|
|
50
|
+
experimental: false,
|
|
51
|
+
description: "Reads the selection or current line aloud using Piper neural TTS.",
|
|
52
|
+
requirements: [
|
|
53
|
+
{ text: "Piper TTS engine", cmd: "pip install piper-tts", check: proc { which("piper") } },
|
|
54
|
+
{ text: "aplay (ALSA utils)", cmd: "sudo apt install alsa-utils", check: proc { which("aplay") } },
|
|
55
|
+
{ text: "A Piper voice in ~/piper-voices (default en_GB-alan-medium)",
|
|
56
|
+
check: proc { Dir.exist?(File.expand_path(cnf.tts.data_dir! || "~/piper-voices")) } },
|
|
57
|
+
],
|
|
58
|
+
usage: "Key bindings: … (filled in from the module's add_keys)",
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- `description`: one or two sentences.
|
|
64
|
+
- `requirements`: an array of `{ text:, cmd: (optional), check: (optional proc → bool) }`.
|
|
65
|
+
An empty or missing array is displayed as "No extra setup needed".
|
|
66
|
+
- `check` lets the dialog mark each requirement ✓ found / ✗ missing. Checks must be
|
|
67
|
+
cheap (`which`, `File.exist?`, at most a fast `require` probe). No network calls.
|
|
68
|
+
Ollama is the exception: it's reported as "not checked" rather than pinging the port
|
|
69
|
+
while the dialog opens.
|
|
70
|
+
- `experimental: true` puts the module in the Experimental section.
|
|
71
|
+
|
|
72
|
+
### 2. Per-module content and concrete setup actions
|
|
73
|
+
|
|
74
|
+
This section is the text that goes into each `_info.rb` and onto the dialog. It also
|
|
75
|
+
lists the **in-app setup actions**: buttons on a module's card that do a setup step for
|
|
76
|
+
the user, so they don't have to look it up.
|
|
77
|
+
|
|
78
|
+
The dialog supports three kinds of action:
|
|
79
|
+
- **copy**: copy a shell command to the clipboard, for anything that needs `sudo` or a
|
|
80
|
+
long download. Nothing privileged ever runs from inside the editor.
|
|
81
|
+
- **run**: run a command that needs no `sudo` in the external terminal
|
|
82
|
+
(`exec_in_terminal`), so the user sees its progress and output. One example is
|
|
83
|
+
`ollama pull`.
|
|
84
|
+
- **config**: write a `cnf.*` value, for example a detected path.
|
|
85
|
+
|
|
86
|
+
So in `_info`, a requirement or action entry can look like
|
|
87
|
+
`{ text:, cmd:, kind: :copy | :run | :config, check: }`.
|
|
88
|
+
|
|
89
|
+
Ubuntu 23.04+ blocks a system-wide `pip install` (PEP 668). Python dependencies
|
|
90
|
+
therefore get a vimamsa-owned venv at `~/.local/share/vimamsa/venv`, and the dialog's **run**
|
|
91
|
+
action creates it. This affects dictation and TTS.
|
|
92
|
+
|
|
93
|
+
Exact package names and commands below are best-effort. Verify them on the clean
|
|
94
|
+
test VM (`$VM_NAME`) while implementing (see the last implementation step).
|
|
95
|
+
|
|
96
|
+
#### Configuration info on the module page
|
|
97
|
+
|
|
98
|
+
Each module's card also lists its **settings**, meaning the `cnf.*` keys a user can set
|
|
99
|
+
in `~/.vimamsa/custom.rb` (or `settings.rb`). For now that information lives only in
|
|
100
|
+
the comments at the top of the source files, such as `dictation.rb:24-41` and
|
|
101
|
+
`tts.rb:15-17`.
|
|
102
|
+
|
|
103
|
+
- New `_info` key `config:`, an array of
|
|
104
|
+
`{ key: "dictation.model", default: "large-v3", desc: "faster-whisper model (tiny…large-v3)" }`.
|
|
105
|
+
The module's own code still applies the defaults (`cnf.x! || default`). `default:`
|
|
106
|
+
is there for display only.
|
|
107
|
+
- The card has a collapsible **"Settings (custom.rb)"** section (`Gtk::Expander`,
|
|
108
|
+
collapsed by default). It's a small grid with one row per key: `cnf.<key>` in
|
|
109
|
+
monospace, then the current value (`cnf_get`, shown dim when unset, with
|
|
110
|
+
"(default: …)"), then the description.
|
|
111
|
+
- Below the grid:
|
|
112
|
+
- **Copy snippet** puts a ready-to-paste block on the clipboard, one
|
|
113
|
+
`# cnf.<key> = <default> # <desc>` line per setting.
|
|
114
|
+
- **Open custom.rb** reuses the existing `:edit_customrb` action and closes the
|
|
115
|
+
dialog.
|
|
116
|
+
- The values are read-only on the page. Editing them in the dialog is a possible
|
|
117
|
+
follow-up. Read-only avoids a second, half-complete settings editor, and custom.rb
|
|
118
|
+
remains the single place where these values are written.
|
|
119
|
+
- The header comments in each module file are kept short. They point to `_info` as the
|
|
120
|
+
canonical list, so the two don't drift apart.
|
|
121
|
+
- Test: every `cnf.<module>.*` key read in a module's `.rb` (grep for
|
|
122
|
+
`cnf\.<name>\.[a-z_]+`) is listed in its `config:`. This catches undocumented
|
|
123
|
+
settings.
|
|
124
|
+
|
|
125
|
+
Settings per module, taken from the code:
|
|
126
|
+
|
|
127
|
+
| Module | Settings (`cnf.` prefix) |
|
|
128
|
+
|---|---|
|
|
129
|
+
| dictation | `dictation.python` ("python3"), `.worker` (bundled whisper_worker.py), `.model` ("large-v3"), `.language` ("en"), `.device` ("auto"), `.compute_type` ("float16"), `.normalize` (true), `.initial_prompt` (none), `.chunk_secs` (4), `.idle_timeout` (300), `.startup_timeout` (600), `.source` ("autoaudiosrc") |
|
|
130
|
+
| ollama | `ollama.model` ("qwen3.5:0.8b"), `.host` ("localhost"), `.port` (11434), `.timeout` (60), `.multi_temperature` (1.2) |
|
|
131
|
+
| tts | `tts.voice` ("en_GB-alan-medium"), `.data_dir` ("~/piper-voices"), `.rate` (taken from the voice's .json, else 22050), plus the new `.piper` path |
|
|
132
|
+
| color_highlight, calculator, terminal | none apart from the enable switch |
|
|
133
|
+
| ack (extracted) | `default_search_extensions` (shared with the search form). Rename it to `ack.extensions`, keeping the old key as a fallback. |
|
|
134
|
+
| auto_format (extracted) | `auto_format.formatters`, a hash `filetype → {cmd:, mode: :stdout/:inplace, ext:, ignore_exit_code:}`. The card shows the configured formatters, and the snippet includes the rubocop example from `conf.rb:190`. |
|
|
135
|
+
| audio (extracted) | none today |
|
|
136
|
+
| lsp (extracted) | `lsp.server.<name> = {name:, command:, type:, languages:}`, `workspace_folders`, `autocomplete.lsp.enabled`, `autocomplete.lsp.debounce`. The snippet is the solargraph/ruby-lsp/clangd block from `custom_example.rb:89-99`. |
|
|
137
|
+
|
|
138
|
+
#### Stable modules
|
|
139
|
+
|
|
140
|
+
**color_highlight — Hex Color Highlight** (default: on)
|
|
141
|
+
- Does: paints `#RGB` / `#RRGGBB` / `#RRGGBBAA` codes in any file with their own color.
|
|
142
|
+
- Requires: nothing. Toggle: `C , ; h c`.
|
|
143
|
+
|
|
144
|
+
**dictation — Voice Dictation**
|
|
145
|
+
- Does: records from the microphone. faster-whisper transcribes the audio and the text
|
|
146
|
+
is inserted at the cursor. A quick draft appears while recording and the final pass
|
|
147
|
+
replaces it.
|
|
148
|
+
- Requires and checks:
|
|
149
|
+
- ffmpeg: `sudo apt install ffmpeg` (copy). Check: `which("ffmpeg")`.
|
|
150
|
+
- GStreamer mic source: `sudo apt install gstreamer1.0-plugins-good gstreamer1.0-pulseaudio`
|
|
151
|
+
(copy). Check: `Gst::ElementFactory.find("autoaudiosrc")`.
|
|
152
|
+
- faster-whisper: **run**
|
|
153
|
+
`python3 -m venv ~/.local/share/vimamsa/venv && ~/.local/share/vimamsa/venv/bin/pip install faster-whisper`,
|
|
154
|
+
then **config** `cnf.dictation.python = "~/.local/share/vimamsa/venv/bin/python"`.
|
|
155
|
+
Check: `<python> -c "import faster_whisper"`. Run this check only when the user
|
|
156
|
+
presses "Check", because it takes about 1 s.
|
|
157
|
+
- Notes on the card:
|
|
158
|
+
- The first use downloads the model (default `large-v3`, about 3 GB).
|
|
159
|
+
- Without an NVIDIA GPU, use a smaller model. A "CPU mode" **config** button sets
|
|
160
|
+
`cnf.dictation.device = "cpu"`, `compute_type = "int8"` and `model = "small"`.
|
|
161
|
+
|
|
162
|
+
**ollama — Ollama**
|
|
163
|
+
- Does: rewrites or improves the selected text with a local LLM. `V , o i` makes one
|
|
164
|
+
rewrite; `V , o N i` makes N alternatives.
|
|
165
|
+
- Requires and checks:
|
|
166
|
+
- Ollama: `curl -fsSL https://ollama.com/install.sh | sh` (copy). Check: `which("ollama")`.
|
|
167
|
+
- The model: **run** `ollama pull qwen3.5:0.8b`, or whatever `cnf.ollama.model` is set to.
|
|
168
|
+
- The server running: a "Test connection" button does a short GET of `/api/tags` on
|
|
169
|
+
`cnf.ollama.host:port`, with a 1 s timeout, only when pressed.
|
|
170
|
+
|
|
171
|
+
**tts — Text to Speech**
|
|
172
|
+
- Does: reads the selection or current line aloud using a Piper neural voice.
|
|
173
|
+
- Requires and checks:
|
|
174
|
+
- piper: **run** `python3 -m venv ~/.local/share/vimamsa/venv && ~/.local/share/vimamsa/venv/bin/pip install piper-tts`,
|
|
175
|
+
then **config** to point the module at `~/.local/share/vimamsa/venv/bin/piper`. This needs a new
|
|
176
|
+
`cnf.tts.piper` setting, because today the module looks for `piper` on PATH.
|
|
177
|
+
Check: the binary exists.
|
|
178
|
+
- aplay: `sudo apt install alsa-utils` (copy). Check: `which("aplay")`.
|
|
179
|
+
- A voice: **run**
|
|
180
|
+
`~/.local/share/vimamsa/venv/bin/python -m piper.download_voices en_GB-alan-medium --data-dir ~/piper-voices`.
|
|
181
|
+
Check: `<data_dir>/<voice>.onnx` exists.
|
|
182
|
+
|
|
183
|
+
#### Experimental modules
|
|
184
|
+
|
|
185
|
+
**terminal — Embedded Terminal (VTE)**
|
|
186
|
+
- Does: embeds an interactive shell widget inside a buffer.
|
|
187
|
+
- Requires: the VTE GTK4 introspection data, `sudo apt install gir1.2-vte-3.91` (copy).
|
|
188
|
+
The `vte4` gem is already a runtime dependency in the gemspec.
|
|
189
|
+
Check: `require "vte4"` inside `begin/rescue LoadError`.
|
|
190
|
+
|
|
191
|
+
**calculator — Scientific Calculator**
|
|
192
|
+
- Does: inserts an inline calculator widget at the cursor (Modules ▸ Insert Calculator).
|
|
193
|
+
↩ inserts the result.
|
|
194
|
+
- Requires: nothing.
|
|
195
|
+
|
|
196
|
+
For the modules extracted in section 7 below, the entries are listed there.
|
|
197
|
+
|
|
198
|
+
During implementation, read each module's header comment and `_init` to get the exact
|
|
199
|
+
bindings, actions and `cnf.*` settings. Copy them into `usage:` instead of guessing.
|
|
200
|
+
|
|
201
|
+
### 3. Shared module helpers (`gui_settings.rb`, or a new `lib/vimamsa/modules_info.rb`)
|
|
202
|
+
|
|
203
|
+
Pull the scanning code out of `all_settings_defs`:
|
|
204
|
+
|
|
205
|
+
- `module_infos` → array of `{ dir:, id: "tts", info: {...}, key: [:modules, :tts, :enabled] }`,
|
|
206
|
+
sorted by name, with defaults filled in (`name` from the directory name,
|
|
207
|
+
`no_restart: false`, `experimental: false`, `requirements: []`).
|
|
208
|
+
- `module_set_enabled(id, enabled, was_enabled)`: the load + `_init` / `_disable` logic
|
|
209
|
+
moved out of `SettingsDialog#activate_no_restart_modules`, so the new dialog can use
|
|
210
|
+
it (and the tests can call it directly).
|
|
211
|
+
- `all_settings_defs` → returns only `SETTINGS_DEFS`. It can be inlined or kept as an
|
|
212
|
+
alias. Keeping it is less churn for the two tests that use it for non-module keys
|
|
213
|
+
(`test_autocomplete.rb:194`).
|
|
214
|
+
|
|
215
|
+
If a new file is created, add `require "vimamsa/modules_info"` to `rbvma.rb`.
|
|
216
|
+
|
|
217
|
+
### 4. New `ModulesDialog` (`lib/vimamsa/gui_modules.rb`, required in `rbvma.rb`)
|
|
218
|
+
|
|
219
|
+
- `make_modal_window("Modules")` with a vertical box inside a `Gtk::ScrolledWindow`
|
|
220
|
+
(6+ cards won't fit otherwise). Default size about 600×600.
|
|
221
|
+
- Two headings: **Modules** and **Experimental modules**. Under the experimental
|
|
222
|
+
heading, a short dim note: "May be unstable or incomplete."
|
|
223
|
+
- One card per module (`Gtk::Frame`, using the existing `margin=` monkeypatch):
|
|
224
|
+
- Row 1: bold name + `Gtk::Switch` aligned right (+ "(requires restart)" if
|
|
225
|
+
`!no_restart`).
|
|
226
|
+
- Description label (`wrap = true`, `xalign = 0`).
|
|
227
|
+
- "Requires:" list with one line per requirement: ✓/✗ marker, text, and the command
|
|
228
|
+
in monospace, `selectable = true` so it can be copied. Optionally a small "Copy"
|
|
229
|
+
button that puts `cmd` on the clipboard through the existing clipboard helper.
|
|
230
|
+
With no requirements: "No extra setup needed."
|
|
231
|
+
- `usage` line, dim, if present.
|
|
232
|
+
- Buttons: Cancel / Save, as in Preferences. On Save: `cnf_set` each switch, run
|
|
233
|
+
`save_settings_to_file`, then `module_set_enabled` for every switch that changed.
|
|
234
|
+
The modal style and Save behavior match Preferences.
|
|
235
|
+
- When a module is switched on and its checks report something missing, it's still
|
|
236
|
+
enabled, and a `message("TTS enabled — missing: piper")` explains what's missing.
|
|
237
|
+
This doesn't block anything.
|
|
238
|
+
- `on_submit_escape(@window, escape: …)` as in `SettingsDialog`.
|
|
239
|
+
|
|
240
|
+
### 5. Wiring
|
|
241
|
+
|
|
242
|
+
- `key_actions.rb`: `reg_act(:show_modules, proc { show_modules_dialog }, "Show modules")`.
|
|
243
|
+
- `gui_menu.rb`: `add_to_menu "Settings.Modules", { :label => "Modules...", :action => :show_modules }`
|
|
244
|
+
directly below Preferences.
|
|
245
|
+
- `SettingsDialog`: remove `activate_no_restart_modules` and the `:no_restart` /
|
|
246
|
+
`:prev_value` code that only existed for the module tab.
|
|
247
|
+
- Update the comments that point to the old place: `modules/calculator/calculator.rb:3`
|
|
248
|
+
("Preferences → Modules"), `modules/color_highlight/color_highlight.rb:7`, and any
|
|
249
|
+
others found by `grep -rn "Modules" modules lib README.md`.
|
|
250
|
+
|
|
251
|
+
### 6. Tests
|
|
252
|
+
|
|
253
|
+
Update:
|
|
254
|
+
- `test_module_interface.rb`: switch the 3 `all_settings_defs` tests to `module_infos`.
|
|
255
|
+
Add an assertion that `all_settings_defs` no longer contains a `"Modules"` section.
|
|
256
|
+
- `test_color_highlight.rb#test_setting_exposed`: check `module_infos` instead.
|
|
257
|
+
|
|
258
|
+
Add (`tests/test_modules_dialog.rb`):
|
|
259
|
+
- Every module's info has a non-empty `:description`, and `:requirements` is an Array.
|
|
260
|
+
- `calculator` and `terminal` are `experimental: true`; the others are not.
|
|
261
|
+
- `ModulesDialog.new` builds without error and produces one switch per module, split
|
|
262
|
+
into the two sections.
|
|
263
|
+
- Toggling calculator on in the dialog and pressing Save registers `:insert_calculator`;
|
|
264
|
+
toggling it off unregisters it. This replaces the coverage the old
|
|
265
|
+
`activate_no_restart_modules` path had.
|
|
266
|
+
- `:show_modules` is registered and in the Settings menu.
|
|
267
|
+
|
|
268
|
+
Run the full suite in the test VM (`./run_tests_vm.rb`, VM from `$VM_NAME`), not just the touched files.
|
|
269
|
+
|
|
270
|
+
### 7. Core features to turn into modules
|
|
271
|
+
|
|
272
|
+
I surveyed `lib/vimamsa/*` for features that call external programs, pull in an
|
|
273
|
+
optional gem/library, or are already behind an on/off flag. Each candidate gets a
|
|
274
|
+
verdict below.
|
|
275
|
+
|
|
276
|
+
**General rules for an extraction:**
|
|
277
|
+
- Move the code to `modules/<name>/<name>.rb` and drop its `require` from `rbvma.rb` /
|
|
278
|
+
`editor.rb`.
|
|
279
|
+
- Add `<name>_info.rb`.
|
|
280
|
+
- Move its `reg_act`s, bindings and menu entries into `<name>_init`, and undo them in
|
|
281
|
+
`<name>_disable`.
|
|
282
|
+
- Bindings for all three schemes (vimlike, vim, notepad) move into `_init`. The init
|
|
283
|
+
code checks `cnf.keybindings.scheme` if they differ.
|
|
284
|
+
- **Keep current behavior by default.** Features that are on today get
|
|
285
|
+
`cnf.modules.<name>.enabled = true` in `conf.rb`, the same way color_highlight does.
|
|
286
|
+
- Old flags (`cnf.audio.enabled`, `cnf.lsp.enabled`) are mapped to the new key once,
|
|
287
|
+
after custom.rb phase 1, so existing user configs keep working.
|
|
288
|
+
|
|
289
|
+
#### Extract (recommended)
|
|
290
|
+
|
|
291
|
+
**A. ack — Content Search (ack)**
|
|
292
|
+
- Code: `ack.rb` (204 lines, `FileContentSearch` + `Ack`), `:ack_search` in
|
|
293
|
+
`key_actions.rb:124,151` (registered twice, so one copy can go), `C , a` in
|
|
294
|
+
`key_bindings_vimlike.rb:336`, and the commented-out menu entry `gui_menu.rb:89`.
|
|
295
|
+
- Why: hard dependency on the external `ack` binary. Today, with ack missing, the search
|
|
296
|
+
just returns nothing. Self-contained, with one entry point.
|
|
297
|
+
- Default: on. Stable.
|
|
298
|
+
- Does: searches file contents (`C , a`) in the project directory, that is, the nearest
|
|
299
|
+
parent directory containing `.git` / `.vma_project`. Results are grouped by folder
|
|
300
|
+
and you can jump to them.
|
|
301
|
+
- Requires:
|
|
302
|
+
- `sudo apt install ack` (copy). The package is `ack` on current Ubuntu; `ack-grep` is
|
|
303
|
+
the old name, and README.md:59 needs fixing.
|
|
304
|
+
- Check: `which("ack")`.
|
|
305
|
+
- Tests: `tests/test_ack.rb` loads or enables the module in setup.
|
|
306
|
+
- Effort: small. This makes it the pilot extraction that proves out the pattern.
|
|
307
|
+
|
|
308
|
+
**B. auto_format — Auto Format**
|
|
309
|
+
- Code: `Buffer#auto_format` (`buffer_changetext.rb:42-88`), which already has a
|
|
310
|
+
`# TODO: rename ot auto-format. separate module?` comment, plus
|
|
311
|
+
`cnf.auto_format.formatters` (`conf.rb:190-197`), `:auto_indent_buffer`
|
|
312
|
+
(`key_actions.rb:208`) and `C , v`.
|
|
313
|
+
- Why: every formatter is an external program, and the feature is self-contained.
|
|
314
|
+
- Default: on. Stable.
|
|
315
|
+
- Does: reformats the whole buffer with the formatter set for its file type (`C , v`).
|
|
316
|
+
- Requires: one entry for each formatter configured in `cnf.auto_format.formatters`,
|
|
317
|
+
generated from the first word of its `cmd`:
|
|
318
|
+
- clang-format (C, C++, JavaScript): `sudo apt install clang-format` (copy).
|
|
319
|
+
Check: `which`.
|
|
320
|
+
- rufo (Ruby): `gem install rufo` (copy, no sudo needed for a user gem dir).
|
|
321
|
+
Check: `which`.
|
|
322
|
+
- `Buffer#auto_format` stays as a thin method that calls the module, or `:auto_indent_buffer`
|
|
323
|
+
calls a module function directly. Pick whichever keeps `tests/test_auto_format.rb`
|
|
324
|
+
unchanged.
|
|
325
|
+
- Effort: small.
|
|
326
|
+
|
|
327
|
+
**C. audio — Audio Playback**
|
|
328
|
+
- Code: `audio.rb` (GStreamer `Audio` class), loaded by `editor.rb:218-220` behind
|
|
329
|
+
`cnf.audio.enabled`. Used by `⟦audio:path⟧` links in `hyper_plain_text.rb:31` and by
|
|
330
|
+
the `audio` minor mode plus bindings in `key_bindings_vimlike.rb:8,412,430-438` and
|
|
331
|
+
`key_bindings_vim.rb:22,346-350`. The vim file's comment already calls it "the audio
|
|
332
|
+
module".
|
|
333
|
+
- Why: it's already opt-in, already described as a module, and needs GStreamer codecs.
|
|
334
|
+
- Default: off. Stable.
|
|
335
|
+
- Does: plays audio files linked from text as `⟦audio:file.mp3⟧`. Audio mode
|
|
336
|
+
(`C , m a`): `f`/`←` seek, `space`/`s` stop.
|
|
337
|
+
- Requires:
|
|
338
|
+
- `sudo apt install gstreamer1.0-plugins-good gstreamer1.0-libav` for mp3 and other
|
|
339
|
+
codecs (copy).
|
|
340
|
+
- Check: `Gst::ElementFactory.find("playbin")`.
|
|
341
|
+
- Migration: map `cnf.audio.enabled` to `cnf.modules.audio.enabled`.
|
|
342
|
+
- `hyper_plain_text.rb` needs a guard: `defined?(Audio)` / `respond_to?`. A hook would be
|
|
343
|
+
cleaner (see color_highlight's `:view_*` hooks).
|
|
344
|
+
- Effort: small to medium, because of the minor-mode bindings.
|
|
345
|
+
|
|
346
|
+
**D. lsp — Language Server (LSP)**
|
|
347
|
+
- Code:
|
|
348
|
+
- `langservp.rb` (564 lines) and `gui_func_panel.rb` (172).
|
|
349
|
+
- Startup in `editor.rb:222-227`.
|
|
350
|
+
- LSP calls spread through `buffer.rb`, `gui_sourceview.rb` and
|
|
351
|
+
`gui_sourceview_autocomplete.rb`.
|
|
352
|
+
- Menu entries `View.FuncPanel` / `Actions.LspRestart`.
|
|
353
|
+
- Setup through `cnf.lsp.server.*` in custom.rb (`custom_example.rb:89-99`).
|
|
354
|
+
- Why: it's the biggest optional feature, already off by default, and needs external
|
|
355
|
+
servers. Setup is also the hardest part for users today: they must find and uncomment
|
|
356
|
+
config in custom.rb.
|
|
357
|
+
- Default: off. Stable.
|
|
358
|
+
- Does: jump to definition, a symbol/function panel and completion candidates, using a
|
|
359
|
+
language server for each language.
|
|
360
|
+
- Requires, one entry per known server:
|
|
361
|
+
- Ruby, solargraph: `gem install solargraph` (copy). Check: `which("solargraph")`.
|
|
362
|
+
- Ruby, ruby-lsp, as an alternative: `gem install ruby-lsp`.
|
|
363
|
+
- C/C++, clangd: `sudo apt install clangd` (copy). Check: `which("clangd")`.
|
|
364
|
+
The card also notes that clangd needs `compile_commands.json` or
|
|
365
|
+
`compile_flags.txt` in the project.
|
|
366
|
+
- Concrete simplification, **config**: built-in default `cnf.lsp.server` presets. When a
|
|
367
|
+
language has no server configured, `lsp_init` uses the first one found on PATH
|
|
368
|
+
(solargraph, ruby-lsp, clangd). Enabling the module then just works, with no
|
|
369
|
+
custom.rb edit. The card shows which server was picked for each language.
|
|
370
|
+
- Risk: the buffer, sourceview and autocomplete code calls into LSP directly. Those call
|
|
371
|
+
sites need nil-safe guards or hooks first. This one is a **refactor**, not a move.
|
|
372
|
+
- Migration: map `cnf.lsp.enabled` to `cnf.modules.lsp.enabled`. Keep the LSP tests
|
|
373
|
+
(`test_lsp_*.rb`) enabling it explicitly.
|
|
374
|
+
- Effort: large. Do it last, as its own commit series.
|
|
375
|
+
|
|
376
|
+
#### Keep in core (not worth a module)
|
|
377
|
+
|
|
378
|
+
- **Encryption** (`encrypt.rb`): no external deps (stdlib `openssl`). It's built into the
|
|
379
|
+
file open/save path (`editor.rb:648,717`, `buffer.rb:2008`). If it were disabled,
|
|
380
|
+
encrypted files would open as unreadable data and might be saved over. It has to stay
|
|
381
|
+
in core.
|
|
382
|
+
- **Diff / git diff** (`diff_buffer.rb`): needs only `diff`/`git`, which are almost
|
|
383
|
+
always installed and already checked with `if_cmd_exists`. Keep it. The card text
|
|
384
|
+
could still list it under core features, which is optional.
|
|
385
|
+
- **Grep lines** (`search_replace.rb`, `Grep`): pure Ruby, core navigation. This is a
|
|
386
|
+
different feature from ack.
|
|
387
|
+
- **Run line in external terminal** (`terminal.rb#exec_in_terminal`): small. Its only
|
|
388
|
+
problem is the hardcoded `gnome-terminal`. Leave it in core and add a
|
|
389
|
+
`cnf.terminal.command` setting (out of scope here; noted as a follow-up). It must not
|
|
390
|
+
be mixed up with the embedded VTE `terminal` module.
|
|
391
|
+
- **Image display** (`gui_image.rb`), **xdg-open**, **desktop_install**: no optional
|
|
392
|
+
deps, or deps that are always present.
|
|
393
|
+
- `xclip` (`buffer_changetext.rb:104`): it belongs to a workaround that's commented out
|
|
394
|
+
and never called. Nothing to do.
|
|
395
|
+
|
|
396
|
+
#### Resulting module list
|
|
397
|
+
|
|
398
|
+
- **Stable:** ack (on), auto_format (on), color_highlight (on), audio, dictation, lsp,
|
|
399
|
+
ollama, tts.
|
|
400
|
+
- **Experimental:** terminal, calculator.
|
|
401
|
+
|
|
402
|
+
## Implementation order
|
|
403
|
+
|
|
404
|
+
1. `module_infos` + `module_set_enabled`, and remove the Modules tab from Preferences.
|
|
405
|
+
Update the existing tests. Suite green.
|
|
406
|
+
2. Extend the 6 existing `_info.rb` files with description / requirements /
|
|
407
|
+
experimental / usage / config.
|
|
408
|
+
3. `ModulesDialog`, menu item, action, and copy/run/config setup buttons and checks.
|
|
409
|
+
4. Extract **ack** (pilot), then **auto_format**, then **audio**: one commit each, full
|
|
410
|
+
suite after each.
|
|
411
|
+
5. Shared `~/.local/share/vimamsa/venv` setup and the `cnf.tts.piper` setting.
|
|
412
|
+
6. Fix README.md "optional features" so it points to Settings ▸ Modules (and `ack`, not
|
|
413
|
+
`ack-grep`).
|
|
414
|
+
7. On a fresh snapshot of the test VM, follow every card's steps literally. Fix any command
|
|
415
|
+
that's wrong.
|
|
416
|
+
8. **LSP** extraction plus presets, as a separate follow-up series.
|
|
417
|
+
|
|
418
|
+
## Open questions
|
|
419
|
+
|
|
420
|
+
1. **Naming clash**: the top-level **Modules** menu (module actions like "Insert
|
|
421
|
+
Calculator") and the new Settings ▸ Modules page. Keep both as they are (proposed),
|
|
422
|
+
or rename the top-level menu to something like "Tools"?
|
|
423
|
+
2. Should experimental modules be hidden or disabled unless the existing
|
|
424
|
+
`cnf.experimental` ("Enable experimental features") is on? Proposed: no. They're
|
|
425
|
+
always visible in their own section, and `cnf.experimental` stays as it is.
|
|
426
|
+
3. Apply switches immediately (no Save button) instead of Save/Cancel? Proposed:
|
|
427
|
+
Save/Cancel, to match Preferences.
|
|
428
|
+
4. Should the **run** setup actions (venv + pip install, `ollama pull`, voice download)
|
|
429
|
+
be offered at all, or should every action be copy-only? Proposed: offer them. They
|
|
430
|
+
need no sudo and run visibly in a terminal.
|
|
431
|
+
5. Should LSP be extracted now, or is it enough to add server auto-detection presets
|
|
432
|
+
and leave it in core? Proposed: presets first (that's what helps users most),
|
|
433
|
+
extraction later.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Deduplication refactor: reduce source size by removing repeated code
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
Goal: find repeated source code that can be refactored to shrink the codebase.
|
|
6
|
+
Findings come from a mechanical duplicate-block scan plus a file-by-file sweep of the
|
|
7
|
+
GUI and core layers; every item below was verified by reading both copies. Total
|
|
8
|
+
realistic reduction: **~250–300 lines** (of ~15k in lib/). Ordered in tiers from
|
|
9
|
+
zero-risk deletions to the larger structural extraction, so it can be cut short at any
|
|
10
|
+
tier boundary. Each tier is committed separately and verified with the test suite
|
|
11
|
+
(`ruby exe/run_tests.rb --headless`), plus the binding-scheme tests for Tier 5.
|
|
12
|
+
|
|
13
|
+
## Tier 1 — dead / duplicate code, pure deletion (~80 lines)
|
|
14
|
+
|
|
15
|
+
1. **Duplicate `Clipboard` class** — `editor.rb:483-505` re-defines `Clipboard#set/#get`
|
|
16
|
+
identically to `clipboard.rb` (the live, fuller copy with `[]`/`<<`, required at
|
|
17
|
+
rbvma.rb:37). Delete the editor.rb copy.
|
|
18
|
+
2. **Dead body of `KeyBindingTree#to_s`** — `key_binding_tree.rb:416-458`: line 417 is
|
|
19
|
+
`return self.class.to_s`, making the remaining ~40 lines unreachable — and they are
|
|
20
|
+
a verbatim copy of the traversal in the method above (`394-413`). Delete the dead
|
|
21
|
+
body, keep the one-line return.
|
|
22
|
+
3. **Unreachable fuzzy-filter tail** — `file_finder.rb:167-179`: verbatim copy of
|
|
23
|
+
`FileHistory.fuzzy_filter` (`file_history.rb:63-77`) sitting after an unconditional
|
|
24
|
+
`return` inside `filter_files`. Delete.
|
|
25
|
+
4. **Dead wrapper `open_existing_file`** — `editor.rb:677-679` is a pass-through to
|
|
26
|
+
`open_new_file`. Delete and update callers (`grep -rn open_existing_file lib tests`;
|
|
27
|
+
includes `gui_command_line.rb`).
|
|
28
|
+
|
|
29
|
+
## Tier 2 — route through helpers that already exist (~15 lines)
|
|
30
|
+
|
|
31
|
+
5. **`get_repeat_num` not reused** — `buffer_changetext.rb:343-348` (`delete_line`) and
|
|
32
|
+
`buffer.rb:1473-1478` (`copy_line`) inline the exact body of the existing
|
|
33
|
+
`get_repeat_num` (`buffer.rb:757`). Replace both blocks with the call.
|
|
34
|
+
6. **Margins set line-by-line** — `gui_form_generator.rb:34-37, 45-48` expand 4-line
|
|
35
|
+
margin blocks although `Gtk::Box#margin=` / `Gtk::Frame#margin=` monkeypatches exist
|
|
36
|
+
(`gui_dialog.rb:14-32`). Replace with `frame.margin = 8` etc.
|
|
37
|
+
|
|
38
|
+
## Tier 3 — small single-file helper extractions (~50 lines)
|
|
39
|
+
|
|
40
|
+
7. **Visual-selection transform envelope** — `buffer.rb`: `transform_selection` (1403),
|
|
41
|
+
`convert_selected_text` (1428), `style_transform` (1439), `set_line_style` (1453)
|
|
42
|
+
all repeat `return if !@visual_mode; r = get_visual_mode_range; txt = self[r]; …;
|
|
43
|
+
replace_range(r, txt); end_visual_mode`. Extract
|
|
44
|
+
`transform_visual_selection { |txt| ... }`; also share the style-marker wrapping
|
|
45
|
+
(`⦁`/`❙`/clear-gsub) used by the last two.
|
|
46
|
+
8. **Indent/unindent shared range math** — `buffer.rb:330-362`: both methods repeat the
|
|
47
|
+
6-line visual-line-range setup + `replace_range` + selection restore. Extract
|
|
48
|
+
`transform_selected_lines { |line| ... }`; each method becomes ~3 lines.
|
|
49
|
+
9. **LSP documentSymbol request scaffolding** — `langservp.rb`: `document_functions`
|
|
50
|
+
(336) and `document_functions_grouped` (360) share ~12 lines of
|
|
51
|
+
ensure_open/params/write/wait/validate. Extract private
|
|
52
|
+
`request_document_symbols(fpath)` returning the symbols array or nil.
|
|
53
|
+
10. **Git-root lookup** — `diff_buffer.rb:153` and `:182` duplicate the
|
|
54
|
+
`dir = …; git_root = \`git -C … rev-parse --show-toplevel\`` block. Extract
|
|
55
|
+
`buffer_git_root` helper.
|
|
56
|
+
|
|
57
|
+
## Tier 4 — GUI cross-file widget helpers (~90 lines)
|
|
58
|
+
|
|
59
|
+
Helpers live next to the existing ones in `gui_dialog.rb` (`set_margin_all`,
|
|
60
|
+
margin monkeypatches) as module-level Vimamsa functions.
|
|
61
|
+
|
|
62
|
+
11. **TreeView + ScrolledWindow scaffolding** — `gui_file_panel.rb:8-48`,
|
|
63
|
+
`gui_func_panel.rb:12-40`, `gui_settings.rb:194-210` build the same
|
|
64
|
+
TreeStore/TreeView (headers off, single-click, one ellipsized expanding text
|
|
65
|
+
column) inside a `ScrolledWindow(:never,:automatic)`, plus structurally identical
|
|
66
|
+
`row-activated` handlers. Extract e.g.
|
|
67
|
+
`build_list_tree(store, ellipsize:, text_col:) { |iter| … }` returning
|
|
68
|
+
`[tree, scrolled_window]`. (~30–40 lines)
|
|
69
|
+
12. **Modal popup boilerplate** — `gui_dialog.rb:43-48`, `gui_form_generator.rb:17-31`,
|
|
70
|
+
`gui_settings.rb:90-93`, `gui_select_window.rb:46-52` all do
|
|
71
|
+
`Gtk::Window.new; set_transient_for($vmag.window); modal = true; title = …`, and
|
|
72
|
+
three have identical `run` (show-or-destroy). Extract `make_modal_window(title)`
|
|
73
|
+
factory + share `run`. (~20–25 lines)
|
|
74
|
+
13. **Return/Escape CAPTURE key controller** — `gui_dialog.rb:90-108`,
|
|
75
|
+
`gui_form_generator.rb:84-97`, `gui_settings.rb:151-161`,
|
|
76
|
+
`gui_select_window.rb:104-148` wire the same EventControllerKey with
|
|
77
|
+
Return→submit / Escape→destroy. Extract
|
|
78
|
+
`on_submit_escape(widget, submit:, escape:) { |keyval| … }` with an optional block
|
|
79
|
+
for extra keys (select_window's Up/Down/Delete). (~20 lines)
|
|
80
|
+
14. **Panel show/hide/toggle in gui.rb** — `gui.rb:1148-1245`: file/func panel pairs
|
|
81
|
+
build the same Paned wrapper and near-identical hide logic; toggle/refresh/init
|
|
82
|
+
trios differ only in the ivar. Extract `make_side_pane(widget, pos)` and collapse
|
|
83
|
+
the trios data-driven. (~15–20 lines)
|
|
84
|
+
|
|
85
|
+
## Tier 5 — shared key-binding definitions (~80–110 lines, most careful)
|
|
86
|
+
|
|
87
|
+
15. **`key_bindings_vim.rb` ⇄ `key_bindings_vimlike.rb`** share byte-identical blocks:
|
|
88
|
+
mode/minor-mode setup + cursor colors (vimlike:3-24 / vim:17-35), the
|
|
89
|
+
`_insert_move`/`insert_select_move`/`insert_move` helper methods (19 lines each),
|
|
90
|
+
insert-mode arrow/selection bindings, `f`/`F` char-find + count + BOL/EOL entries,
|
|
91
|
+
marks, READCHAR + macro-record entries, the entire Browse-mode block
|
|
92
|
+
(vimlike:310-324 / vim:323-337), and the audio minor-mode bindkeys.
|
|
93
|
+
Extract into a new `lib/vimamsa/key_bindings_common.rb` (add to rbvma.rb per
|
|
94
|
+
convention — or `require`d by both scheme files directly, like
|
|
95
|
+
key_bindings_notepad.rb already requires vimlike). Both scheme files keep only
|
|
96
|
+
scheme-specific content. Binding semantics must stay identical: later
|
|
97
|
+
`bindkey`/`add_keys` override earlier ones, so common content loads first in each
|
|
98
|
+
scheme file.
|
|
99
|
+
|
|
100
|
+
## Verification
|
|
101
|
+
|
|
102
|
+
- After each tier: `ruby exe/run_tests.rb --headless` (full suite, ~150 tests).
|
|
103
|
+
- Tier 1 item 4: re-run `test_command_line` + `test_jump_to_file`.
|
|
104
|
+
- Tier 4: `test_func_panel`, `test_keylog_panel`, `test_file_manager`, plus a manual
|
|
105
|
+
smoke test of one dialog (search) and the select window (file finder) in a real run.
|
|
106
|
+
- Tier 5: additionally `ruby exe/run_tests.rb tests/test_vim_bindings.rb` and
|
|
107
|
+
`tests/test_notepad_bindings.rb` (excluded from the default suite; the vim one
|
|
108
|
+
replays sequences against a real-vim oracle) and `tests/test_key_bindings.rb`.
|
|
109
|
+
- Final: line-count before/after (`wc -l lib/vimamsa/*.rb`), E2E cmdline test focused,
|
|
110
|
+
one commit per tier.
|
|
111
|
+
|
|
112
|
+
## Explicitly not doing (checked, already fine or not worth it)
|
|
113
|
+
|
|
114
|
+
- Marshal save/load, file-read/run-cmd error handling, forward/backward cursor
|
|
115
|
+
methods: already centralized (`editor.rb:320`, `util.rb:283/108`, direction params).
|
|
116
|
+
- CSS-provider one-liners and `GLib::Idle.add { message(…) }` wrappers: savings too
|
|
117
|
+
small relative to churn.
|