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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +17 -10
- data/Dockerfile +2 -2
- data/README.md +162 -90
- data/custom_example.rb +33 -15
- data/doc/TODO.md +334 -110
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +2 -1
- 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 +45 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +34 -44
- data/doc/modules_settings_plan.md +1 -1
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/test_commands.md +232 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/vim_compatibility_plan.md +186 -31
- data/doc/vimlike_vim_conflicts.md +236 -228
- data/doc/vm_snapshots_plan.md +4 -4
- data/doc/wysiwyg_plan.md +231 -0
- data/docker_cmd.sh +1 -1
- data/exe/run_tests.rb +85 -3
- data/exe/vimamsa +49 -6
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +1 -1
- data/lib/vimamsa/ack.rb +2 -0
- data/lib/vimamsa/actions.rb +381 -36
- data/lib/vimamsa/bookmarks.rb +8 -8
- data/lib/vimamsa/buffer.rb +84 -38
- data/lib/vimamsa/buffer_changetext.rb +58 -36
- data/lib/vimamsa/buffer_list.rb +2 -2
- data/lib/vimamsa/buffer_manager.rb +6 -6
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +6 -3
- data/lib/vimamsa/conf.rb +9 -0
- data/lib/vimamsa/crash_handler.rb +2 -2
- data/lib/vimamsa/debug.rb +2 -2
- data/lib/vimamsa/demo_player.rb +494 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/diff_buffer.rb +1 -1
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +54 -3
- data/lib/vimamsa/editor.rb +136 -65
- data/lib/vimamsa/file_history.rb +1 -1
- data/lib/vimamsa/file_manager.rb +23 -23
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +89 -13
- data/lib/vimamsa/gui_command_line.rb +44 -5
- data/lib/vimamsa/gui_form_generator.rb +17 -6
- data/lib/vimamsa/gui_func_panel.rb +1 -1
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +164 -2
- data/lib/vimamsa/gui_menu.rb +69 -50
- data/lib/vimamsa/gui_select_window.rb +77 -43
- data/lib/vimamsa/gui_settings.rb +9 -5
- data/lib/vimamsa/gui_sourceview.rb +28 -81
- data/lib/vimamsa/gui_theme.rb +11 -2
- data/lib/vimamsa/hook.rb +2 -0
- data/lib/vimamsa/intro_page.rb +367 -0
- data/lib/vimamsa/key_actions.rb +315 -225
- data/lib/vimamsa/key_binding_tree.rb +228 -61
- data/lib/vimamsa/key_bindings_notepad.rb +18 -16
- data/lib/vimamsa/key_bindings_report.rb +290 -67
- data/lib/vimamsa/key_bindings_vim.rb +43 -297
- data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +62 -7
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +20 -3
- data/lib/vimamsa/rbvma.rb +15 -0
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search_replace.rb +4 -4
- data/lib/vimamsa/string_util.rb +17 -3
- data/lib/vimamsa/tests.rb +8 -8
- data/lib/vimamsa/text_objects.rb +11 -54
- data/lib/vimamsa/text_transforms.rb +4 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +3 -3
- data/modules/dictation/dictation.rb +32 -32
- data/modules/ollama/ollama.rb +5 -5
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +10 -10
- data/run_e2e_vm.sh +3 -3
- data/run_tests_vm.rb +163 -0
- data/scripts/appimage/AppRun +7 -0
- data/scripts/appimage/build_in_container.sh +11 -1
- data/scripts/appimage/smoke_test.sh +1 -1
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +9 -1
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +60 -81
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +1 -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/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +2 -2
- data/tests/test_autocomplete.rb +1 -1
- data/tests/test_basic_editing.rb +18 -18
- data/tests/test_bookmarks.rb +6 -6
- data/tests/test_bracket_match.rb +3 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +2 -2
- data/tests/test_command_line.rb +1 -1
- data/tests/test_context_menu_file.rb +18 -0
- data/tests/test_copy_paste.rb +33 -33
- data/tests/test_custom_two_phase.rb +1 -1
- data/tests/test_demo_player.rb +355 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dictation.rb +16 -16
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +3 -3
- data/tests/test_file_panel.rb +2 -2
- data/tests/test_flash.rb +1 -1
- data/tests/test_fold.rb +1 -1
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +2 -2
- data/tests/test_gtk_sync.rb +7 -7
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +163 -3
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +2 -2
- data/tests/test_lsp_root.rb +43 -0
- data/tests/test_macro.rb +2 -2
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +5 -5
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_random_edit.rb +27 -27
- data/tests/test_registers.rb +131 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +45 -4
- data/tests/test_text_objects.rb +1 -1
- data/tests/test_text_transforms.rb +12 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +10 -10
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +107 -6
- data/tests/test_vim_conflicts.rb +41 -4
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +83 -0
- data/vimamsa.gemspec +1 -1
- data/vm_guest_run.sh +75 -28
- metadata +60 -4
- data/run_tests.rb +0 -89
- data/run_tests_vm.sh +0 -130
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Config dir and data dir (user_dirs.rb): the XDG defaults, --user-dir
|
|
2
|
+
# keeping both in one dir, which files go where, and the one-time move of
|
|
3
|
+
# the files of older versions
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
|
|
6
|
+
class TestUserDirs < VmaTest
|
|
7
|
+
REPO = File.expand_path("..", __dir__)
|
|
8
|
+
|
|
9
|
+
def with_env(vars)
|
|
10
|
+
old = vars.keys.to_h { |k| [k, ENV[k]] }
|
|
11
|
+
vars.each { |k, v| ENV[k] = v }
|
|
12
|
+
yield
|
|
13
|
+
ensure
|
|
14
|
+
old.each { |k, v| ENV[k] = v }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_xdg_defaults
|
|
18
|
+
with_env("XDG_CONFIG_HOME" => nil, "XDG_DATA_HOME" => nil) {
|
|
19
|
+
assert_eq File.expand_path("~/.config/vimamsa"), UserDirs.default_config_dir
|
|
20
|
+
assert_eq File.expand_path("~/.local/share/vimamsa"), UserDirs.default_data_dir
|
|
21
|
+
assert_eq File.expand_path("~/.local/share/vimamsa"), UserDirs.data_dir_for("~/.config/vimamsa")
|
|
22
|
+
}
|
|
23
|
+
with_env("XDG_CONFIG_HOME" => "/tmp/xc", "XDG_DATA_HOME" => "/tmp/xd") {
|
|
24
|
+
assert_eq "/tmp/xc/vimamsa", UserDirs.default_config_dir
|
|
25
|
+
assert_eq "/tmp/xd/vimamsa", UserDirs.data_dir_for("/tmp/xc/vimamsa")
|
|
26
|
+
}
|
|
27
|
+
# --user-dir: data in the same dir
|
|
28
|
+
assert_eq "/tmp/somedir", UserDirs.data_dir_for("/tmp/somedir")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The test run uses its own user dir, and data goes there too
|
|
32
|
+
def test_test_run_isolated
|
|
33
|
+
assert !UserDirs.default_config_dir?(vma_user_dir)
|
|
34
|
+
assert_eq File.expand_path(vma_user_dir), File.expand_path(vma_data_dir)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# With separate dirs, generated files go to the data dir and the user's
|
|
38
|
+
# files to the config dir
|
|
39
|
+
def test_files_go_to_their_dirs
|
|
40
|
+
Dir.mktmpdir { |d|
|
|
41
|
+
old = $vma_data_dir
|
|
42
|
+
$vma_data_dir = d
|
|
43
|
+
begin
|
|
44
|
+
vma.marshal_save("file_index", [])
|
|
45
|
+
assert File.exist?(File.join(d, "file_index")), "file_index not in the data dir"
|
|
46
|
+
assert_eq File.join(d, "file_history"), vma.var_file_path("file_history")
|
|
47
|
+
assert_eq get_dot_path("bookmarks"), vma.var_file_path("bookmarks")
|
|
48
|
+
assert_eq get_dot_path("named_macros"), vma.var_file_path("named_macros")
|
|
49
|
+
vma.save_session
|
|
50
|
+
assert File.exist?(File.join(d, "session.txt")), "session not in the data dir"
|
|
51
|
+
assert_eq File.join(d, "crash"), Vimamsa::CrashHandler.crash_dir
|
|
52
|
+
f = File.join(d, "afile.txt")
|
|
53
|
+
File.write(f, "x\n")
|
|
54
|
+
jump_to_file(f)
|
|
55
|
+
b = vma.buf
|
|
56
|
+
assert_eq f, b.fname
|
|
57
|
+
b.backup # written on a thread
|
|
58
|
+
t = Time.now
|
|
59
|
+
sleep 0.02 while Dir[File.join(d, "backup", "*afile.txt_*")].empty? && Time.now - t < 2
|
|
60
|
+
assert Dir[File.join(d, "backup", "*afile.txt_*")].any?, "backup not in the data dir"
|
|
61
|
+
vma.buffers.close_buffer(b.id)
|
|
62
|
+
ensure
|
|
63
|
+
$vma_data_dir = old
|
|
64
|
+
end
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# No code uses fixed paths (~/.vimamsa, ~/.config/vimamsa): they would
|
|
69
|
+
# skip --user-dir, and the tests would touch the real user's files.
|
|
70
|
+
# user_dirs.rb names the old places, to move their files.
|
|
71
|
+
def test_no_fixed_user_paths
|
|
72
|
+
files = Dir[File.join(REPO, "{lib,modules}/**/*.rb")] + [File.join(REPO, "exe/vimamsa")]
|
|
73
|
+
files -= [File.join(REPO, "lib/vimamsa/user_dirs.rb")]
|
|
74
|
+
bad = files.flat_map { |f|
|
|
75
|
+
File.readlines(f).each_with_index.map { |l, i|
|
|
76
|
+
next if l.strip.start_with?("#")
|
|
77
|
+
"#{f.sub(REPO + "/", "")}:#{i + 1}: #{l.strip}" if l =~ %r{["']~/\.(vimamsa|config/vimamsa|config/\.vimamsa)}
|
|
78
|
+
}.compact
|
|
79
|
+
}
|
|
80
|
+
assert bad.empty?, "fixed user paths:\n#{bad.join("\n")}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_migrate
|
|
84
|
+
Dir.mktmpdir { |t|
|
|
85
|
+
conf, data = File.join(t, "conf"), File.join(t, "data")
|
|
86
|
+
legacy, lmacro = File.join(t, "legacy"), File.join(t, "lmacro")
|
|
87
|
+
w = ->(path, txt = "x") { FileUtils.mkdir_p(File.dirname(path)); File.write(path, txt) }
|
|
88
|
+
w.(File.join(conf, "session.txt"), "s")
|
|
89
|
+
w.(File.join(conf, "file_history"))
|
|
90
|
+
w.(File.join(conf, "bookmarks"))
|
|
91
|
+
w.(File.join(conf, "settings.rb"))
|
|
92
|
+
w.(File.join(conf, "backup", "a_1"))
|
|
93
|
+
w.(File.join(conf, "crash", "stderr.log"), "old log")
|
|
94
|
+
FileUtils.mkdir_p(File.join(conf, "listen"))
|
|
95
|
+
w.(File.join(data, "crash", "stderr.log"), "new log") # written at start, before the move
|
|
96
|
+
w.(File.join(legacy, "cmd_history.txt"), ":e x")
|
|
97
|
+
w.(File.join(legacy, "backup", "c_1"))
|
|
98
|
+
w.(File.join(legacy, "backup", "a_1"), "older a")
|
|
99
|
+
w.(File.join(legacy, "file_history"), "older")
|
|
100
|
+
w.(File.join(lmacro, "macro_q.rb"), "macro")
|
|
101
|
+
moved = UserDirs.migrate(config_dir: conf, data_dir: data, legacy_dir: legacy, legacy_macro_dir: lmacro)
|
|
102
|
+
%w[session.txt file_history cmd_history.txt backup/a_1 backup/c_1].each { |n|
|
|
103
|
+
assert File.exist?(File.join(data, n)), "#{n} not moved"
|
|
104
|
+
}
|
|
105
|
+
assert_eq "s", File.read(File.join(data, "session.txt"))
|
|
106
|
+
assert_eq "x", File.read(File.join(data, "backup", "a_1")), "the config dir's backup wins"
|
|
107
|
+
assert_eq "older a", File.read(File.join(legacy, "backup", "a_1")), "a file in both places left as it was"
|
|
108
|
+
assert_eq "new log", File.read(File.join(data, "crash", "stderr.log"))
|
|
109
|
+
assert File.exist?(File.join(conf, "crash", "stderr.log")), "the old log is kept"
|
|
110
|
+
assert File.exist?(File.join(legacy, "file_history")), "older copies in ~/.vimamsa stay"
|
|
111
|
+
assert File.exist?(File.join(conf, "settings.rb")) && File.exist?(File.join(conf, "bookmarks")), "config files moved"
|
|
112
|
+
assert File.exist?(File.join(conf, "macro_q.rb")), "saved macro not moved to the config dir"
|
|
113
|
+
assert !File.exist?(File.join(conf, "listen")), "empty old listen dir left"
|
|
114
|
+
assert !File.exist?(File.join(conf, "session.txt"))
|
|
115
|
+
assert moved.include?([File.join(conf, "session.txt"), File.join(data, "session.txt")])
|
|
116
|
+
# once: a second run moves nothing
|
|
117
|
+
assert_eq [], UserDirs.migrate(config_dir: conf, data_dir: data, legacy_dir: legacy, legacy_macro_dir: lmacro)
|
|
118
|
+
# one dir (--user-dir): nothing moves
|
|
119
|
+
assert_eq [], UserDirs.migrate(config_dir: conf, data_dir: conf, legacy_dir: legacy, legacy_macro_dir: lmacro)
|
|
120
|
+
}
|
|
121
|
+
end
|
|
122
|
+
end
|
data/tests/test_vim_bindings.rb
CHANGED
|
@@ -86,6 +86,107 @@ class TestVimBindings < VmaTest
|
|
|
86
86
|
assert_matches_vim("foo bar\n", "wgUUx") # cursor to line start
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
+
# The operator + motion layer (vim_operators.rb): every operator with
|
|
90
|
+
# every motion, counts in both places
|
|
91
|
+
def test_operator_counts
|
|
92
|
+
assert_matches_vim("a b c d e f g\n", "d2w")
|
|
93
|
+
assert_matches_vim("a b c d e f g\n", "2dw")
|
|
94
|
+
assert_matches_vim("a b c d e f g\n", "2d2w")
|
|
95
|
+
assert_matches_vim("a\nb\nc\nd\ne\n", "d2j")
|
|
96
|
+
assert_matches_vim("a\nb\nc\nd\ne\n", "3dd")
|
|
97
|
+
assert_matches_vim("a\nb\nc\n", "5dd") # more lines than left: no-op
|
|
98
|
+
assert_matches_vim("a\nb\nc\n", "j2dd")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_operator_word_motions
|
|
102
|
+
assert_matches_vim("foo.bar baz\n", "dW")
|
|
103
|
+
assert_matches_vim("foo.bar baz\n", "dE")
|
|
104
|
+
assert_matches_vim("foo bar.baz\n", "$dB")
|
|
105
|
+
assert_matches_vim("foo bar baz\n", "wwdb")
|
|
106
|
+
assert_matches_vim("foo bar\nbaz\n", "wdw") # last word: not joined
|
|
107
|
+
assert_matches_vim("foo bar\nbaz qux\n", "wd2w")
|
|
108
|
+
assert_matches_vim("foo\n\nbar\n", "dw")
|
|
109
|
+
assert_matches_vim("foo bar\n", "jdb")
|
|
110
|
+
assert_matches_vim("x\n foo\nbar\n", "jjdb")
|
|
111
|
+
assert_matches_vim("foo bar baz\n", "llcwX\e") # cw inside a word
|
|
112
|
+
assert_matches_vim("foo bar baz\n", "lllcwX\e") # cw on a blank
|
|
113
|
+
assert_matches_vim("a bc d\n", "c2wX\e")
|
|
114
|
+
assert_matches_vim("foo bar\n", "yeP")
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def test_operator_line_motions
|
|
118
|
+
assert_matches_vim("x\n abc def\n", "jwd0")
|
|
119
|
+
assert_matches_vim("x\n abc def\n", "j$d^")
|
|
120
|
+
assert_matches_vim("abc def\n", "wd$")
|
|
121
|
+
assert_matches_vim("abc\ndef\nghi\n", "d2$")
|
|
122
|
+
assert_matches_vim("abcdef\n", "$dh")
|
|
123
|
+
assert_matches_vim("abcdef\n", "$dl")
|
|
124
|
+
assert_matches_vim("abcdef\n", "d3l")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_operator_find_till
|
|
128
|
+
assert_matches_vim("foo bar baz\n", "dtb")
|
|
129
|
+
assert_matches_vim("foo bar baz\n", "d2fa")
|
|
130
|
+
assert_matches_vim("foo bar baz\n", "$dTo")
|
|
131
|
+
assert_matches_vim("foo bar baz\n", "$dF ")
|
|
132
|
+
assert_matches_vim("foo bar baz\n", "dt ")
|
|
133
|
+
assert_matches_vim("foo bar baz\n", "cfrX\e")
|
|
134
|
+
assert_matches_vim("foo bar baz\n", "gUfr")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def test_operator_linewise_motions
|
|
138
|
+
assert_matches_vim("a\nb\nc\nd\n", "jdk")
|
|
139
|
+
assert_matches_vim("a\nb\nc\nd\n", "jdG")
|
|
140
|
+
assert_matches_vim("a\nb\nc\nd\n", "jjdgg")
|
|
141
|
+
assert_matches_vim("a\nb\nc\nd\n", "d3G")
|
|
142
|
+
assert_matches_vim("a\nb\nc\n", "yjGp")
|
|
143
|
+
assert_matches_vim("a\nb\nc\n", "jcjX\e")
|
|
144
|
+
assert_matches_vim("a\nb\nc\n", "Gdj") # can't move: no-op
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_indent_operators
|
|
148
|
+
assert_matches_vim("a\nb\nc\n", ">>")
|
|
149
|
+
assert_matches_vim("a\nb\nc\n", "3>>")
|
|
150
|
+
assert_matches_vim("a\n\nc\n", ">j")
|
|
151
|
+
assert_matches_vim("a\n\nc\n", ">2j") # empty lines stay empty
|
|
152
|
+
assert_matches_vim("\ta\n\tb\n", "<j")
|
|
153
|
+
assert_matches_vim(" a\nb\n", "<<")
|
|
154
|
+
assert_matches_vim("a b\nc\n", ">w") # > always works on lines
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_operator_text_objects_and_case
|
|
158
|
+
assert_matches_vim("foo (bar baz) x\n", "fbd2w")
|
|
159
|
+
assert_matches_vim("foo (bar baz) x\n", "fb>i(")
|
|
160
|
+
assert_matches_vim("foo bar\nbaz\n", "g~j")
|
|
161
|
+
assert_matches_vim("foo bar\n", "gUiw")
|
|
162
|
+
assert_matches_vim("Foo Bar\n", "gu$")
|
|
163
|
+
assert_matches_vim("foo bar\n", "wgUb")
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_plain_motions_from_the_layer
|
|
167
|
+
assert_matches_vim("foo.bar baz\n", "Wix\e")
|
|
168
|
+
assert_matches_vim("foo.bar baz\n", "Eix\e")
|
|
169
|
+
assert_matches_vim("foo bar.baz\n", "$Bix\e")
|
|
170
|
+
assert_matches_vim("foo bar baz\n", "tzix\e")
|
|
171
|
+
assert_matches_vim("foo bar baz\n", "$Tfix\e")
|
|
172
|
+
assert_matches_vim("abc\n", "$ix\e") # $ on the last character
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# "." repeats the last change (dot_repeat.rb)
|
|
176
|
+
def test_dot_repeat
|
|
177
|
+
assert_matches_vim("a b c d e\n", "dw.")
|
|
178
|
+
assert_matches_vim("a b c d e\n", "dw2.")
|
|
179
|
+
assert_matches_vim("one two three\n", "cwfoo\ew.")
|
|
180
|
+
assert_matches_vim("ab\n", "ixy\e0.") # (vim's esc also moves left; vimamsa's doesn't)
|
|
181
|
+
assert_matches_vim("abcd\n", "x..")
|
|
182
|
+
assert_matches_vim("1\n2\n3\n4\n", "dd.")
|
|
183
|
+
assert_matches_vim("a\nb\n", ">>j.")
|
|
184
|
+
assert_matches_vim("a\nb\n", "A!\ej.")
|
|
185
|
+
assert_matches_vim("a\nb\n", "ox\ej.")
|
|
186
|
+
assert_matches_vim("foo bar\n", "gUiww.")
|
|
187
|
+
assert_matches_vim("a b c\n", "dwlu.") # undo doesn't replace the change
|
|
188
|
+
end
|
|
189
|
+
|
|
89
190
|
def test_join
|
|
90
191
|
assert_matches_vim("aa\nbb\n", "J")
|
|
91
192
|
end
|
|
@@ -155,30 +256,30 @@ class TestVimBindings < VmaTest
|
|
|
155
256
|
|
|
156
257
|
def test_zz_dispatch
|
|
157
258
|
keys "z z"
|
|
158
|
-
assert_eq
|
|
259
|
+
assert_eq "view.center", vma.kbd.cur_action
|
|
159
260
|
end
|
|
160
261
|
|
|
161
262
|
def test_ctrl_o_binding
|
|
162
|
-
assert_eq "ctrl-o", vma.kbd.act_bindings["C"][
|
|
263
|
+
assert_eq "ctrl-o", vma.kbd.act_bindings["C"]["jump.edit.prev"]
|
|
163
264
|
end
|
|
164
265
|
|
|
165
266
|
def test_backtick_jumps_to_mark
|
|
166
267
|
act 'buf.insert_txt("one\ntwo\nthree\n")'
|
|
167
|
-
act
|
|
268
|
+
act "move.buf.start"
|
|
168
269
|
keys "j m a G ` a"
|
|
169
270
|
assert_eq 1, vma.buf.lpos
|
|
170
271
|
end
|
|
171
272
|
|
|
172
273
|
def test_ctrl_a_increments
|
|
173
274
|
act 'buf.insert_txt("a 41 b")'
|
|
174
|
-
act
|
|
275
|
+
act "move.buf.start"
|
|
175
276
|
keys "w ctrl-a"
|
|
176
277
|
assert_buf "a 42 b\n"
|
|
177
278
|
end
|
|
178
279
|
|
|
179
280
|
def test_visual_case_ops
|
|
180
281
|
act 'buf.insert_txt("abc def")'
|
|
181
|
-
act
|
|
282
|
+
act "move.buf.start"
|
|
182
283
|
keys "v e U"
|
|
183
284
|
assert_buf "ABC def\n"
|
|
184
285
|
end
|
|
@@ -215,7 +316,7 @@ class TestVimBindings < VmaTest
|
|
|
215
316
|
# last line, so jump to line 1 first.
|
|
216
317
|
mode = NVIM == "nvim" ? ["--headless"] : ["-E", "-s", "-c", "1"]
|
|
217
318
|
ok = system(NVIM, *mode, "-u", "NONE", "-i", "NONE", "-n",
|
|
218
|
-
"-c", "set noautoindent nosmartindent",
|
|
319
|
+
"-c", "set noautoindent nosmartindent sw=4 ts=4",
|
|
219
320
|
"-c", "normal! #{nkeys}",
|
|
220
321
|
"-c", "wq!", f.path,
|
|
221
322
|
out: File::NULL, err: File::NULL)
|
data/tests/test_vim_conflicts.rb
CHANGED
|
@@ -29,14 +29,14 @@ class TestVimConflicts < VmaTest
|
|
|
29
29
|
r = row("C", "s") # vim substitute, vimlike easy_jump
|
|
30
30
|
assert_eq [:conflict, :same_keys], [r[:status], r[:why]]
|
|
31
31
|
r = row("C", "c c") # vimlike has no c operator
|
|
32
|
-
assert_eq :
|
|
33
|
-
assert_eq :
|
|
32
|
+
assert_eq :added, r[:status] # so it comes from VIM_BINDINGS
|
|
33
|
+
assert_eq :added, row("C", "d i <char>")[:status] # text objects from the shared templates
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def test_shorter_and_prefix_conflicts
|
|
37
37
|
kbd = KeyBindingTree.new(actions: ActionList.new)
|
|
38
38
|
kbd.add_mode("C", :command)
|
|
39
|
-
kbd.bindkey("C z",
|
|
39
|
+
kbd.bindkey("C z", "mode.browse")
|
|
40
40
|
kbd.bindkey("C , x", :foo)
|
|
41
41
|
kbd.bindkey("C q <char>", :rec)
|
|
42
42
|
st = ->(keys) { vim_binding_status(kbd, "C", keys.split, :vim_action) }
|
|
@@ -46,6 +46,43 @@ class TestVimConflicts < VmaTest
|
|
|
46
46
|
assert_eq :missing, st.("t <char>")[:status]
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
# Everything vimlike could take from the shared table, it took
|
|
50
|
+
def test_nothing_left_missing
|
|
51
|
+
missing = rows.select { |r| r[:status] == :missing }
|
|
52
|
+
assert missing.empty?, missing.map { |r| "#{r[:mode]} #{r[:keys].join(" ")}" }.inspect
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# The live vimlike tree (the one the tests run with) has the added
|
|
56
|
+
# bindings, and they behave as in vim
|
|
57
|
+
def test_added_bindings_work_in_vimlike
|
|
58
|
+
assert vma.kbd.vim_added.include?(["C", ["c", "w"]]), "c w not added"
|
|
59
|
+
buf.set_content("foo bar baz\n")
|
|
60
|
+
buf.set_pos(4)
|
|
61
|
+
keys("D")
|
|
62
|
+
assert_buf "foo \n"
|
|
63
|
+
assert_mode :command
|
|
64
|
+
|
|
65
|
+
buf.set_content("foo bar\n")
|
|
66
|
+
buf.set_pos(0)
|
|
67
|
+
keys("c w x esc")
|
|
68
|
+
assert_buf "x bar\n"
|
|
69
|
+
assert_mode :command
|
|
70
|
+
|
|
71
|
+
buf.set_content(" foo\nbar\n")
|
|
72
|
+
buf.set_pos(3)
|
|
73
|
+
keys("S y esc")
|
|
74
|
+
assert_buf "y\nbar\n"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Conflicting vim bindings are not loaded: vimlike's own action stays
|
|
78
|
+
def test_vimlike_keeps_its_own_bindings
|
|
79
|
+
st = vim_binding_status(vma.kbd, "C", ["s"], "edit.change.char")
|
|
80
|
+
assert_eq [:conflict, :same_keys], st.values_at(:status, :why)
|
|
81
|
+
assert !vma.kbd.vim_added.include?(["C", ["s"]])
|
|
82
|
+
# Adding C ctrl-f ("move.page.next") doesn't change the key the menu shows
|
|
83
|
+
assert_eq "pagedown", vma.kbd.act_bindings["C"]["move.page.next"]
|
|
84
|
+
end
|
|
85
|
+
|
|
49
86
|
def test_loading_schemes_leaves_editor_alone
|
|
50
87
|
kbd, acts = vma.kbd, vma.actions
|
|
51
88
|
color = cnf.mode.command.cursor.background!
|
|
@@ -55,7 +92,7 @@ class TestVimConflicts < VmaTest
|
|
|
55
92
|
assert vma.kbd.equal?(kbd), "vma.kbd replaced"
|
|
56
93
|
assert vma.actions.equal?(acts), "vma.actions replaced"
|
|
57
94
|
assert_eq "#123456", cnf.mode.command.cursor.background!
|
|
58
|
-
assert vma.actions.include?(
|
|
95
|
+
assert vma.actions.include?("help.keys")
|
|
59
96
|
ensure
|
|
60
97
|
cnf.mode.command.cursor.background = color
|
|
61
98
|
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# The operator + motion layer in the vimlike keymap (vim_operators.rb,
|
|
2
|
+
# doc/vim_compatibility_plan.md step 1). Vimlike gets every combination of
|
|
3
|
+
# the shared templates whose keys it doesn't use itself.
|
|
4
|
+
#
|
|
5
|
+
# CASES: [text with "|" at the cursor, vim keys, expected text, expected
|
|
6
|
+
# cursor offset]. The expected values come from vim 9.1 (vim -Nu NONE);
|
|
7
|
+
# test_cases_match_real_vim checks them again when vim is installed. The
|
|
8
|
+
# vim keymap has its own oracle tests in test_vim_bindings.rb.
|
|
9
|
+
require "tmpdir"
|
|
10
|
+
|
|
11
|
+
class TestVimOperators < VmaTest
|
|
12
|
+
CASES = [
|
|
13
|
+
["foo b|ar baz", "cwX\e", "foo bX baz\n", 5],
|
|
14
|
+
["foo bar| baz", "cwX\e", "foo barXbaz\n", 7],
|
|
15
|
+
["one two three four", "d3w", "four\n", 0],
|
|
16
|
+
["one two three four", "2d2w", "\n", 0],
|
|
17
|
+
["foo bar", "gUtr", "FOO BAr\n", 0],
|
|
18
|
+
["a.b c", "dW", "c\n", 0],
|
|
19
|
+
["a\nb|\nc", ">>", "a\n\tb\nc\n", 3],
|
|
20
|
+
["a\nb|\nc", ">j", "a\n\tb\n\tc\n", 3],
|
|
21
|
+
["\ta\n\tb", "<j", "a\nb\n", 0],
|
|
22
|
+
["a\nb|\nc\nd", "c2jX\e", "a\nX\n", 2],
|
|
23
|
+
["one two", "wcbX\e", "Xtwo\n", 0],
|
|
24
|
+
["x (a b) y", "fa>i(", "\tx (a b) y\n", 1],
|
|
25
|
+
["ab cd", "c$X\e", "X\n", 0],
|
|
26
|
+
["foo bar", "cOX\e", "X\n", 0], # vimlike's O motion (line end) after an operator
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
def inserts?(keys)
|
|
30
|
+
keys.include?("\e")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def vma_keys(keys)
|
|
34
|
+
keys.chars.map { |ch| { "\e" => "esc", " " => "space" }.fetch(ch, ch) }.join(" ")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# [text before the cursor, from the cursor]; no "|" = cursor at the start
|
|
38
|
+
def split_case(text)
|
|
39
|
+
text.include?("|") ? text.split("|", 2) : ["", text]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def run_case(text, keys)
|
|
43
|
+
pre, rest = split_case(text)
|
|
44
|
+
s = pre + rest
|
|
45
|
+
s += "\n" unless s.end_with?("\n")
|
|
46
|
+
pos = pre.size
|
|
47
|
+
b = vma.buf
|
|
48
|
+
b.set_content(s)
|
|
49
|
+
b.set_pos(pos)
|
|
50
|
+
vma.kbd.set_mode(:command)
|
|
51
|
+
keys(vma_keys(keys))
|
|
52
|
+
[b.to_s, b.pos]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_cases
|
|
56
|
+
# > and < indent with a tab, as vim -u NONE (other tests change these)
|
|
57
|
+
saved = [cnf.tab.width!, cnf.tab.to_spaces_default?]
|
|
58
|
+
cnf.tab.width = 4
|
|
59
|
+
cnf.tab.to_spaces_default = false
|
|
60
|
+
fails = []
|
|
61
|
+
CASES.each { |text, keys, want, want_pos|
|
|
62
|
+
got, got_pos = run_case(text, keys)
|
|
63
|
+
ok = got == want && (inserts?(keys) || got_pos == want_pos)
|
|
64
|
+
fails << "#{text.inspect} #{keys.inspect}: got #{got.inspect} pos #{got_pos}, vim #{want.inspect} pos #{want_pos}" if !ok
|
|
65
|
+
vma.kbd.set_mode(:command)
|
|
66
|
+
}
|
|
67
|
+
assert fails.empty?, "#{fails.size} of #{CASES.size} cases differ from vim:\n " + fails.join("\n ")
|
|
68
|
+
ensure
|
|
69
|
+
cnf.tab.width, cnf.tab.to_spaces_default = saved if saved
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# vimlike's own bindings win over the templates
|
|
73
|
+
def test_vimlike_bindings_kept
|
|
74
|
+
assert_eq "edit.delete.word.end", vma.kbd.find_state_by_path("C d e").action
|
|
75
|
+
assert_eq "op.motion", vma.kbd.find_state_by_path("C c w").action
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# A motion added after the keymap loaded works with every operator
|
|
79
|
+
def test_key_set_add
|
|
80
|
+
vma.kbd.key_set_add(:motion, "Q" => :line_end)
|
|
81
|
+
vma.buf.set_content("abc def\n")
|
|
82
|
+
vma.buf.set_pos(0)
|
|
83
|
+
keys("g U Q")
|
|
84
|
+
assert_buf "ABC DEF\n"
|
|
85
|
+
ensure
|
|
86
|
+
vma.kbd.key_sets[:motion].delete("Q")
|
|
87
|
+
vma.kbd.bindings.select { |b| b[:args] && b[:keys].last == "Q" }.each { |b|
|
|
88
|
+
unbindkey("#{b[:mode]} #{b[:keys].join(" ")}")
|
|
89
|
+
}
|
|
90
|
+
assert vma.kbd.bindings.none? { |b| b[:args] && b[:keys].last == "Q" }, "Q bindings left"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def vim_result(text, keys)
|
|
94
|
+
pre, rest = split_case(text)
|
|
95
|
+
Dir.mktmpdir { |d|
|
|
96
|
+
f = "#{d}/f.txt"
|
|
97
|
+
File.write(f, pre + rest + (rest.end_with?("\n") ? "" : "\n"))
|
|
98
|
+
k = keys.gsub("\\", "\\\\\\\\").gsub('"', '\\"').gsub("\e", "\\<Esc>")
|
|
99
|
+
system("vim", "-Nu", "NONE", "-i", "NONE", "-es", "-c", "go #{pre.bytesize + 1}",
|
|
100
|
+
"-c", "exe \"norm! #{k}\"",
|
|
101
|
+
"-c", "call writefile([line2byte(line('.'))+col('.')-2], '#{d}/p')", "-c", "wq", f)
|
|
102
|
+
[File.read(f), File.read("#{d}/p").to_i]
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_cases_match_real_vim
|
|
107
|
+
skip "vim not installed" unless system("command -v vim >/dev/null 2>&1")
|
|
108
|
+
fails = CASES.reject { |text, keys, want, want_pos|
|
|
109
|
+
next true if keys.include?("O") # vimlike-only motion
|
|
110
|
+
got, got_pos = vim_result(text, keys)
|
|
111
|
+
got == want && (inserts?(keys) || got_pos == want_pos)
|
|
112
|
+
}
|
|
113
|
+
assert fails.empty?, "expected values out of date for this vim: " +
|
|
114
|
+
fails.map { |c| [c[0], c[1], vim_result(c[0], c[1])] }.inspect
|
|
115
|
+
end
|
|
116
|
+
end
|
data/tests/test_window_layout.rb
CHANGED
|
@@ -174,6 +174,7 @@ class TestWindowLayout < VmaTest
|
|
|
174
174
|
# first starts with the default size, maximizes, shows two columns and the
|
|
175
175
|
# file panel, and quits; the second reports what it restored.
|
|
176
176
|
def test_restored_after_restart
|
|
177
|
+
skip "needs a window manager to maximize (--headless has none)" if ENV["VMA_HEADLESS"]
|
|
177
178
|
skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
|
|
178
179
|
Dir.mktmpdir { |dir|
|
|
179
180
|
ud = "#{dir}/ud"
|
|
@@ -216,4 +217,86 @@ class TestWindowLayout < VmaTest
|
|
|
216
217
|
"second start: #{second.inspect}\nsaved: #{Marshal.load(File.binread("#{ud}/#{VMAgui::LAYOUT_FILE}")).inspect}"
|
|
217
218
|
}
|
|
218
219
|
end
|
|
220
|
+
|
|
221
|
+
# custom.rb for a real startup: after 3 s, run the Ruby code in steps (a
|
|
222
|
+
# list of [delay ms, code] run one after another), then write the window
|
|
223
|
+
# layout to dir/name and quit
|
|
224
|
+
def layout_custom_rb(dir, name, steps = [])
|
|
225
|
+
chain = steps.reverse.inject("File.binwrite(#{"#{dir}/#{name}".inspect}, Marshal.dump(vma.gui.window_layout))\n" \
|
|
226
|
+
"GLib::Timeout.add(1000) { vma.shutdown; false }") { |inner, (ms, code)|
|
|
227
|
+
"#{code}\nGLib::Timeout.add(#{ms}) {\n#{inner}\nfalse }"
|
|
228
|
+
}
|
|
229
|
+
"def hook_custom_after_init\n GLib::Timeout.add(3000) {\n#{chain}\nfalse }\nend\n"
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Maximize (full display), then make the window somewhat narrower, keeping
|
|
233
|
+
# the full height (like dragging its side edge), and quit: the next starts
|
|
234
|
+
# get that size back, not the maximized one, and starting and quitting
|
|
235
|
+
# doesn't change it.
|
|
236
|
+
def test_resized_after_maximize_restored
|
|
237
|
+
skip "needs a window manager to maximize (--headless has none)" if ENV["VMA_HEADLESS"]
|
|
238
|
+
skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
|
|
239
|
+
Dir.mktmpdir { |dir|
|
|
240
|
+
ud = "#{dir}/ud"
|
|
241
|
+
Dir.mkdir(ud)
|
|
242
|
+
mw, mh = gui.monitor_size(gui.layout_monitor)
|
|
243
|
+
# Each step waits (up to 8 s) for the window manager to really
|
|
244
|
+
# maximize or unmaximize: with animations, or on a busy machine, that
|
|
245
|
+
# can take a while
|
|
246
|
+
File.write("#{ud}/custom.rb", <<~RUBY)
|
|
247
|
+
def hook_custom_after_init
|
|
248
|
+
win = vma.gui.window
|
|
249
|
+
save = ->(name) { File.binwrite(#{dir.inspect} + "/" + name, Marshal.dump(vma.gui.window_layout)) }
|
|
250
|
+
wait = ->(cond, done) {
|
|
251
|
+
t0 = Time.now
|
|
252
|
+
GLib::Timeout.add(100) { (cond.() || Time.now - t0 > 8) ? (done.(); false) : true }
|
|
253
|
+
}
|
|
254
|
+
GLib::Timeout.add(3000) {
|
|
255
|
+
win.maximize
|
|
256
|
+
wait.(-> { win.maximized? }, -> {
|
|
257
|
+
GLib::Timeout.add(500) { # let the maximized size settle
|
|
258
|
+
save.("max")
|
|
259
|
+
w, h = win.width, win.height
|
|
260
|
+
win.unmaximize
|
|
261
|
+
wait.(-> { !win.maximized? }, -> {
|
|
262
|
+
win.set_default_size((w * 0.85).to_i, h)
|
|
263
|
+
GLib::Timeout.add(1500) {
|
|
264
|
+
save.("run1")
|
|
265
|
+
GLib::Timeout.add(1000) { vma.shutdown; false }
|
|
266
|
+
false
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
false
|
|
270
|
+
}
|
|
271
|
+
})
|
|
272
|
+
false
|
|
273
|
+
}
|
|
274
|
+
end
|
|
275
|
+
RUBY
|
|
276
|
+
run_editor(ud)
|
|
277
|
+
max = Marshal.load(File.binread("#{dir}/max"))
|
|
278
|
+
assert_eq true, max[:maximized], "the window manager didn't maximize the window within 8 s: #{max.inspect}"
|
|
279
|
+
maxw = max[:win_width]
|
|
280
|
+
first = Marshal.load(File.binread("#{dir}/run1"))
|
|
281
|
+
assert_eq false, first[:maximized], "still maximized after unmaximize: #{first.inspect}"
|
|
282
|
+
fw, fh = first.values_at(:width, :height)
|
|
283
|
+
w = (maxw * 0.85).to_i
|
|
284
|
+
# The window manager may adjust it a little, but it must be narrower
|
|
285
|
+
# than the maximized window
|
|
286
|
+
assert fw < maxw && (fw - w).abs <= 50, "resized width #{fw}, asked #{w}, maximized #{maxw}, monitor #{mw}x#{mh}"
|
|
287
|
+
|
|
288
|
+
File.write("#{ud}/custom.rb", layout_custom_rb(dir, "run2"))
|
|
289
|
+
run_editor(ud)
|
|
290
|
+
second = Marshal.load(File.binread("#{dir}/run2"))
|
|
291
|
+
saved = Marshal.load(File.binread("#{ud}/#{VMAgui::LAYOUT_FILE}")).inspect
|
|
292
|
+
assert_eq [false, fw, fh], second.values_at(:maximized, :width, :height),
|
|
293
|
+
"second start: #{second.inspect}\nsaved: #{saved}"
|
|
294
|
+
|
|
295
|
+
File.write("#{ud}/custom.rb", layout_custom_rb(dir, "run3"))
|
|
296
|
+
run_editor(ud)
|
|
297
|
+
third = Marshal.load(File.binread("#{dir}/run3"))
|
|
298
|
+
assert_eq [false, fw, fh], third.values_at(:maximized, :width, :height),
|
|
299
|
+
"third start (after a plain start and stop): #{third.inspect}"
|
|
300
|
+
}
|
|
301
|
+
end
|
|
219
302
|
end
|
data/vimamsa.gemspec
CHANGED
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
spec.bindir = "exe"
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
23
|
spec.require_paths = ["lib","ext"]
|
|
24
|
-
spec.required_ruby_version = ">= 3.
|
|
24
|
+
spec.required_ruby_version = ">= 3.2"
|
|
25
25
|
|
|
26
26
|
spec.add_development_dependency "bundler", ">= 2.4"
|
|
27
27
|
spec.add_development_dependency "rake", "~> 13.1.0"
|