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,202 @@
|
|
|
1
|
+
# Plan: registries for definitions that modules and custom.rb can change
|
|
2
|
+
|
|
3
|
+
TODO: not started. Act next on step 1 of "Implementation order".
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
Several definition tables are Ruby constants, so nothing loaded later can change
|
|
8
|
+
them. A module can't add a key binding category, a setting to an existing
|
|
9
|
+
Settings section, or a context menu item. `custom.rb` can't rename or remove a
|
|
10
|
+
built-in one. When a module needs something like this today, it gets a special
|
|
11
|
+
case in core code: `all_settings_defs` (`gui_settings.rb`) builds the "Modules"
|
|
12
|
+
section, and `key_binding_category` (`key_bindings_report.rb`) makes the
|
|
13
|
+
automatic `module:<name>` category.
|
|
14
|
+
|
|
15
|
+
What a module adds must also go away when it is disabled. Today every module
|
|
16
|
+
does that cleanup by hand in `<name>_disable` (color_highlight, tts, ollama,
|
|
17
|
+
terminal, calculator, dictation), with `unbindkey` / `unreg_act` calls that have
|
|
18
|
+
to match its init code.
|
|
19
|
+
|
|
20
|
+
## Which tables
|
|
21
|
+
|
|
22
|
+
Tables that something might reasonably want to change after they're defined:
|
|
23
|
+
|
|
24
|
+
| Kind | Table | File |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| list | `KEY_CATEGORIES` | `key_bindings_report.rb` |
|
|
27
|
+
| list | `BASIC_ACTIONS` | `key_bindings_report.rb` |
|
|
28
|
+
| list | `SETTINGS_DEFS` (sections and the settings in each) | `gui_settings.rb` |
|
|
29
|
+
| list | `CONTEXT_MENU_ITEMS`, `CONTEXT_MENU_ITEMS_SELECTION` | `gui_sourceview.rb` |
|
|
30
|
+
| map | `ACTION_NS_CATEGORY`, `KEY_WORD_CATEGORY`, `KEY_MODE_CATEGORY` | `key_bindings_report.rb` |
|
|
31
|
+
| map | `KEY_CONDITIONS`, `KEY_MODE_NAMES` | `key_bindings_report.rb` |
|
|
32
|
+
| map | `SHEBANG_LANGS` | `buffer.rb` |
|
|
33
|
+
| map | `MARKUP_OVERLAY_STYLES` | `gui_settings.rb` |
|
|
34
|
+
| map | `ACTION_ALIASES` | `actions.rb` |
|
|
35
|
+
|
|
36
|
+
Borderline, decide when they come up: `TEXT_OBJECT_BRACKETS`,
|
|
37
|
+
`THEME_COLOR_DEFAULTS` / `CYBER_COLOR_DEFAULTS`, `VIM_BINDINGS`.
|
|
38
|
+
`GUESS_ENCODING_ORDER` is a user choice and belongs in `cnf`.
|
|
39
|
+
|
|
40
|
+
These stay constants. They are fixed facts, not definitions: `VOWELS`,
|
|
41
|
+
`CONSONANTS`, the LSP kind numbers (`COMPLETION_KINDS`, `FUNCTION_KINDS`,
|
|
42
|
+
`CLASS_KINDS`), `LSP_LANG`, `VIM_CONFLICT_WHY`, `DEMO_FILES`, the GUI size
|
|
43
|
+
defaults.
|
|
44
|
+
|
|
45
|
+
## Design
|
|
46
|
+
|
|
47
|
+
### 1. `Registry`: ordered entries by id
|
|
48
|
+
|
|
49
|
+
A new `lib/vimamsa/registry.rb` (add it to `rbvma.rb`). One class serves both
|
|
50
|
+
lists and maps: entries are kept in insertion order and keyed by id, and each
|
|
51
|
+
entry has a value plus the owner that added it.
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
r = vma.registry(:key_categories)
|
|
55
|
+
|
|
56
|
+
# one entry
|
|
57
|
+
r.add("ai", "AI assistant")
|
|
58
|
+
|
|
59
|
+
# several entries in one call: an Array of [id, value] pairs or a Hash
|
|
60
|
+
r.add([["ai", "AI assistant"], ["speech", "Speech"]])
|
|
61
|
+
vma.registry(:action_ns_category).add("ollama" => "ai", "tts" => "speech")
|
|
62
|
+
|
|
63
|
+
# entries whose value is a Hash of fields (settings, context menu)
|
|
64
|
+
vma.registry(:settings).add([:ollama, :model], section: "modules", label: "Model", type: :string)
|
|
65
|
+
vma.registry(:settings).add([
|
|
66
|
+
[[:ollama, :model], { section: "modules", label: "Model", type: :string }],
|
|
67
|
+
[[:ollama, :url], { section: "modules", label: "Server URL", type: :string }],
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
r.remove("ai") # also: r.remove(["ai", "speech"])
|
|
71
|
+
r.replace("ai", "AI") # change the value and keep the position
|
|
72
|
+
r["ai"] # value, or nil
|
|
73
|
+
r.include?("ai")
|
|
74
|
+
r.each { |id, value| ... } # in order
|
|
75
|
+
r.ids, r.values, r.to_h
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Rules:
|
|
79
|
+
|
|
80
|
+
- `add` with an existing id is an error that names both owners, so two modules
|
|
81
|
+
don't overwrite each other without noticing. To change an entry on purpose,
|
|
82
|
+
use `replace`, or `remove` and then `add`.
|
|
83
|
+
- A batch `add` checks every entry before adding any of them: either the whole
|
|
84
|
+
batch goes in or nothing does.
|
|
85
|
+
- There are no ordering rules (`after:`/`before:`). Entries keep the order they
|
|
86
|
+
were added in, so built-in entries come first and those from modules and
|
|
87
|
+
custom.rb follow. Where position matters, a module reuses an existing entry
|
|
88
|
+
instead (e.g. puts its bindings in the `code` category) rather than adding
|
|
89
|
+
one.
|
|
90
|
+
- Values are stored as given; the registry doesn't copy or freeze them.
|
|
91
|
+
|
|
92
|
+
### 2. Built-ins use the same API
|
|
93
|
+
|
|
94
|
+
Each table keeps its literal data in the file where it's defined, as the
|
|
95
|
+
initial entries:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
define_registry(:key_categories, [
|
|
99
|
+
["motion", "Moving the cursor"],
|
|
100
|
+
["search", "Searching and jumping"],
|
|
101
|
+
...
|
|
102
|
+
])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`define_registry` creates the registry with owner `"core"`. Built-in entries
|
|
106
|
+
aren't special, so custom.rb can `replace` or `remove` them. Code that read the
|
|
107
|
+
constant reads the registry. During the conversion the constant can stay as an
|
|
108
|
+
alias (`KEY_CATEGORIES = ...` replaced by a method) only where outside code
|
|
109
|
+
might use it; the codebase itself is switched over in the same step.
|
|
110
|
+
|
|
111
|
+
`SETTINGS_DEFS` becomes two registries: `:settings_sections` (id → label) and
|
|
112
|
+
`:settings` (key → fields including `section:`). A module can then add a
|
|
113
|
+
setting to an existing section such as Font, not only to "Modules", and the
|
|
114
|
+
special case in `all_settings_defs` goes away: the module loader registers each
|
|
115
|
+
module's enable switch.
|
|
116
|
+
|
|
117
|
+
### 3. Owners, so disabling a module undoes it
|
|
118
|
+
|
|
119
|
+
Every `add` records the current owner, set the same way as
|
|
120
|
+
`KeyBindingTree#with_keywords`:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
with_owner("module:ollama") { ollama_init } # done by the module loader
|
|
124
|
+
remove_owned("module:ollama") # done by the loader on disable
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- The loader already wraps module init (startup and Settings) and the three
|
|
128
|
+
places custom.rb runs in `with_keywords`; the same places set the owner
|
|
129
|
+
(`"module:<name>"`, `"custom"`). Outside them the owner is `"core"`.
|
|
130
|
+
- `remove_owned` removes that owner's entries from every registry, so modules
|
|
131
|
+
write no cleanup for registry entries.
|
|
132
|
+
- Later (step 6) `reg_act` and `bindkey` record the owner too, and
|
|
133
|
+
`remove_owned` also unregisters the actions and unbinds the keys. Then most
|
|
134
|
+
`<name>_disable` functions become unnecessary; a module keeps one only for
|
|
135
|
+
cleanup the registries don't know about (stopping a thread, closing a
|
|
136
|
+
window).
|
|
137
|
+
- `r.owner(id)` returns who added an entry, for error messages and debugging.
|
|
138
|
+
|
|
139
|
+
### 4. Change listeners for consumers that cache
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
vma.registry(:context_menu).on_change { |reg| ... }
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
runs after any `add`, `replace` or `remove` (once per batch call). Needed
|
|
146
|
+
where something is built once:
|
|
147
|
+
|
|
148
|
+
- the context menu creates its `Gio::SimpleAction`s in `init_context_menu`,
|
|
149
|
+
at startup;
|
|
150
|
+
- the Settings dialog builds its widgets when it opens, so it only needs to
|
|
151
|
+
rebuild if it's open.
|
|
152
|
+
|
|
153
|
+
The key bindings page reads the registries each time it's shown and needs no
|
|
154
|
+
listener.
|
|
155
|
+
|
|
156
|
+
### 5. `cnf` stays separate
|
|
157
|
+
|
|
158
|
+
`cnf` holds the values the user chooses; registries hold what exists to choose
|
|
159
|
+
from. A setting's definition (label, type, range, section) goes in the
|
|
160
|
+
`:settings` registry, and its value stays in `cnf`.
|
|
161
|
+
|
|
162
|
+
### 6. Discoverability
|
|
163
|
+
|
|
164
|
+
- `vma.registries` lists the registry names, so the command line can show
|
|
165
|
+
them (`:vma.registries`), and `vma.registry(:x).to_h` shows the contents.
|
|
166
|
+
- An unknown name in `vma.registry(:x)` is an error with a did-you-mean
|
|
167
|
+
suggestion (as for action ids), not a new empty registry, so a typo doesn't
|
|
168
|
+
fail silently. Registries are created only by `define_registry`.
|
|
169
|
+
- `custom_example.rb` gets a short example: rename a key binding category,
|
|
170
|
+
add a context menu item.
|
|
171
|
+
|
|
172
|
+
## Implementation order
|
|
173
|
+
|
|
174
|
+
1. `Registry`, `define_registry`, `vma.registry`, `with_owner` /
|
|
175
|
+
`remove_owned`, `on_change`, with single and batch `add`/`remove`.
|
|
176
|
+
Unit-style tests in `tests/test_registry.rb`: order, duplicate-id error with
|
|
177
|
+
owners, all-or-nothing batch, owner removal, listener called once per
|
|
178
|
+
batch, unknown-name error.
|
|
179
|
+
2. Convert the key bindings page tables (`KEY_CATEGORIES`, `BASIC_ACTIONS`,
|
|
180
|
+
`ACTION_NS_CATEGORY`, `KEY_WORD_CATEGORY`, `KEY_MODE_CATEGORY`,
|
|
181
|
+
`KEY_CONDITIONS`, `KEY_MODE_NAMES`). They are new and used in one file. The
|
|
182
|
+
module loader sets the owner around module init and custom.rb. Test: a
|
|
183
|
+
module-owned category appears on the page and disappears after
|
|
184
|
+
`remove_owned`. `test_every_binding_has_a_category` keeps passing.
|
|
185
|
+
3. Context menu (`CONTEXT_MENU_ITEMS`, `CONTEXT_MENU_ITEMS_SELECTION`), with
|
|
186
|
+
an `on_change` listener that creates the missing Gio actions. Test: an item
|
|
187
|
+
added after startup shows up in the menu and runs its action.
|
|
188
|
+
4. `SETTINGS_DEFS` → `:settings_sections` + `:settings`; module enable
|
|
189
|
+
switches registered by the loader; `all_settings_defs` reads the
|
|
190
|
+
registries. Test: a module setting in an existing section is shown and
|
|
191
|
+
saved.
|
|
192
|
+
5. `SHEBANG_LANGS`, `MARKUP_OVERLAY_STYLES`, `ACTION_ALIASES`.
|
|
193
|
+
6. Owner tags on `reg_act` and `bindkey`; `remove_owned` unregisters and
|
|
194
|
+
unbinds them; remove the parts of `<name>_disable` that become
|
|
195
|
+
unnecessary. Test per module: enable, disable, and no actions, bindings or
|
|
196
|
+
registry entries of that module remain.
|
|
197
|
+
|
|
198
|
+
Run the full suite in the test VM after each step (`./run_tests_vm.rb`).
|
|
199
|
+
|
|
200
|
+
## DONE
|
|
201
|
+
|
|
202
|
+
(nothing yet)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Plan: faster startup
|
|
2
|
+
|
|
3
|
+
TODO: not started. Act next on step 1 of "Implementation order".
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
Investigated 2026-11-21. Measured on the development machine, not the test VM: the VM
|
|
8
|
+
was at its login screen. The editor reached its first idle after about 2.6–3.0 s:
|
|
9
|
+
about 1.9 s loading code and about 0.9 s building the window and running `Editor#start`.
|
|
10
|
+
"Saves" below is the fastest of 5 runs, compared with the same version without the
|
|
11
|
+
change (`scripts/lib/perf_startup.rb`).
|
|
12
|
+
|
|
13
|
+
Tools:
|
|
14
|
+
- `ruby -r ./scripts/profile_startup.rb exe/vimamsa [file]` prints, at exit, the slow
|
|
15
|
+
requires and the slow calls of vimamsa's own methods, as trees with start offsets
|
|
16
|
+
and inclusive times. Method tracing starts once the code is loaded, so method times
|
|
17
|
+
are a bit too high.
|
|
18
|
+
- `./run_tests_vm.rb perf_startup [ref=REF] [runs=N]` compares startup time with
|
|
19
|
+
another commit. Use it to confirm each step.
|
|
20
|
+
|
|
21
|
+
## Where the time goes
|
|
22
|
+
|
|
23
|
+
| Part | Time |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `require "colors"` (the red-colors gem, required by cairo) | 0.6–0.8 s |
|
|
26
|
+
| The GTK typelibs (gdk4, gio2, pango, gsk4, gtk4, gtksourceview5) | ≈0.9 s |
|
|
27
|
+
| Other Ruby requires (listen, openssl, vimamsa's own files) | ≈0.3 s |
|
|
28
|
+
| `@window.show` (first realize, renderer setup) | ≈0.2 s |
|
|
29
|
+
| Key bindings (`bind_vim_bindings`: `bind_template`, `vim_keys_taken?`) | 0.13–0.2 s |
|
|
30
|
+
| Opening the file (`gui_set_file_lang` 72 ms) | ≈0.11 s |
|
|
31
|
+
| GC: 27 runs (7 major), mostly marking the GObject wrappers | ≈0.3 s in total |
|
|
32
|
+
|
|
33
|
+
### What red-colors is
|
|
34
|
+
|
|
35
|
+
A color library from the Red Data Tools project. It has color models (RGB, HSL, HUSL,
|
|
36
|
+
XYZ, xyY, xterm256) with conversions, CSS/X11 color names, and the matplotlib and
|
|
37
|
+
seaborn colormaps (viridis, plasma, ...). When it is loaded,
|
|
38
|
+
`colors/colormap_data.rb` builds every colormap and a reversed copy of each:
|
|
39
|
+
thousands of `Colors::RGB` objects, many from Rationals. That is the slow part.
|
|
40
|
+
|
|
41
|
+
cairo loads it in `cairo/color.rb` only for `Cairo::Color.parse`, to turn a color
|
|
42
|
+
*name* into RGB. Hex strings and arrays don't need it. Vimamsa uses no colormaps.
|
|
43
|
+
|
|
44
|
+
## Changes
|
|
45
|
+
|
|
46
|
+
### Worth doing
|
|
47
|
+
|
|
48
|
+
1. **Load red-colors only when it is used.** A shim `colors.rb` (e.g.
|
|
49
|
+
`lib/vimamsa/lazy/colors.rb`) does
|
|
50
|
+
`Object.autoload(:Colors, File.join(Gem::Specification.find_by_name("red-colors").full_gem_path, "lib/colors.rb"))`.
|
|
51
|
+
Put its dir first on `$LOAD_PATH` only around `require "gtk4"` in `rbvma.rb`, so
|
|
52
|
+
cairo's `require "colors"` gets the shim. If the gem spec can't be found (e.g. the
|
|
53
|
+
AppImage), skip the shim and load normally. Checked: `Cairo::Color.parse("red")`
|
|
54
|
+
and `"#ff0000"` still work. **Saves ≈0.5 s** (3.00 → 2.49 s).
|
|
55
|
+
2. **GC off during startup.** `GC.disable` at the top of `exe/vimamsa`, and
|
|
56
|
+
`GC.enable` in the first idle after `Editor#start`. Peak memory is about 80 MB
|
|
57
|
+
higher until then. **Saves ≈0.24 s.** A larger initial heap
|
|
58
|
+
(`RUBY_GC_HEAP_*_INIT_SLOTS`) saved ≈0.1 s, but it must be set before Ruby
|
|
59
|
+
starts.
|
|
60
|
+
3. **Load openssl only when it is needed.** `buffer.rb:5` requires `openssl` but
|
|
61
|
+
doesn't use it. `encrypt.rb` needs it only when a file is actually encrypted or
|
|
62
|
+
decrypted: require it inside those methods. Saves ≈0.05 s.
|
|
63
|
+
4. **Remove `sleep(0.03)` in `Editor#start`** (`editor.rb:191`). Saves 0.03 s.
|
|
64
|
+
5. **Start the `listen` file listener after the window is up** (an idle after
|
|
65
|
+
startup), or replace it with a GLib file monitor (`Gio::File#monitor_directory`).
|
|
66
|
+
Requiring it loads rb-inotify and ffi. Saves ≈0.08–0.15 s.
|
|
67
|
+
6. **Reuse one `GtkSource::LanguageManager`.** `gui_set_file_lang` (`gui.rb:142`)
|
|
68
|
+
creates a new one on every call, which rescans the language files (72 ms). This
|
|
69
|
+
saves time for each extra file opened at startup and for every later file open.
|
|
70
|
+
7. **Generate the style scheme once.** `load_vimamsa_scheme` and
|
|
71
|
+
`gui_apply_color_mode` run for each buffer and again in `gui_refresh_colors`:
|
|
72
|
+
three times at startup. Saves ≈0.04 s.
|
|
73
|
+
|
|
74
|
+
### Possible, smaller or with trade-offs
|
|
75
|
+
|
|
76
|
+
- Optimize binding the key templates (`bind_template`, `vim_keys_taken?`): 0.1–0.2 s.
|
|
77
|
+
- Cache compiled Ruby code (as bootsnap does): compiling vimamsa's files takes ≈0.09 s
|
|
78
|
+
and loading them from binary ≈0.015 s, so at most ≈0.1 s. It adds complexity.
|
|
79
|
+
- `GSK_RENDERER=cairo` starts ≈0.18 s faster, but drawing is likely slower. Don't
|
|
80
|
+
make it the default.
|
|
81
|
+
|
|
82
|
+
### Not worth it
|
|
83
|
+
|
|
84
|
+
- YJIT (`--yjit`): ≈0.35 s slower.
|
|
85
|
+
- `GSK_RENDERER=gl` / `vulkan`: 0.1–0.4 s slower than the default (ngl).
|
|
86
|
+
- The rest (the GTK typelibs and the first draw) can't be avoided from Ruby.
|
|
87
|
+
|
|
88
|
+
## Implementation order
|
|
89
|
+
|
|
90
|
+
1. Items 1–4. Confirm the gain with `./run_tests_vm.rb perf_startup ref=HEAD`, and
|
|
91
|
+
run the full suite in the VM.
|
|
92
|
+
2. Items 5–7.
|
|
93
|
+
3. Optionally, the key template binding.
|
|
94
|
+
|
|
95
|
+
## DONE
|
|
96
|
+
|
|
97
|
+
(nothing yet)
|