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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# Operations that change the content of the buffer
|
|
2
4
|
# e.g. insert, delete
|
|
3
5
|
|
|
@@ -5,6 +7,10 @@ class Buffer < String
|
|
|
5
7
|
|
|
6
8
|
#TODO: change to apply=true as default
|
|
7
9
|
def add_delta(delta, apply = false, auto_update_cpos = false)
|
|
10
|
+
if @read_only
|
|
11
|
+
message("This page is read-only")
|
|
12
|
+
return
|
|
13
|
+
end
|
|
8
14
|
@t_modified = Time.now
|
|
9
15
|
return if !is_delta_ok(delta)
|
|
10
16
|
if delta[1] == DELETE
|
|
@@ -23,7 +29,8 @@ class Buffer < String
|
|
|
23
29
|
@deltas << delta
|
|
24
30
|
end
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
# cnf.undo.insert_one_step: no time-based steps inside an Insert session
|
|
33
|
+
unless @macro_group_active || (cnf.undo.insert_one_step? && vma.kbd&.get_mode == :insert)
|
|
27
34
|
if @last_delta_time && (Time.now - @last_delta_time) > cnf.undo.group_threshold!
|
|
28
35
|
new_undo_group
|
|
29
36
|
end
|
|
@@ -39,41 +46,51 @@ class Buffer < String
|
|
|
39
46
|
|
|
40
47
|
# TODO: rename ot auto-format. separate module?
|
|
41
48
|
# Indents whole buffer using external program
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
def auto_format()
|
|
50
|
+
ftype = get_file_type()
|
|
51
|
+
formatters = cnf.auto_format.formatters!
|
|
52
|
+
fmt = formatters&.fetch(ftype, nil)
|
|
53
|
+
if fmt.nil?
|
|
54
|
+
message("No auto-format handler for file of type: #{ftype}")
|
|
55
|
+
return
|
|
56
|
+
end
|
|
48
57
|
|
|
49
58
|
tmppos = @pos
|
|
50
|
-
|
|
51
59
|
message("Auto format #{@fname}")
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
ext = fmt[:ext] || ""
|
|
62
|
+
file = Tempfile.new(["vmaformat", ext])
|
|
63
|
+
file.write(self.to_s)
|
|
64
|
+
file.flush
|
|
65
|
+
|
|
66
|
+
cmd = fmt[:cmd] % { file: Shellwords.escape(file.path) }
|
|
67
|
+
debug cmd
|
|
68
|
+
|
|
69
|
+
ignore_exit = fmt[:ignore_exit_code]
|
|
70
|
+
bufc = nil
|
|
71
|
+
case fmt[:mode]
|
|
72
|
+
when :inplace
|
|
73
|
+
ok = system("bash", "-c", cmd)
|
|
74
|
+
bufc = IO.read(file.path) if ok || ignore_exit
|
|
75
|
+
when :stdout
|
|
76
|
+
outfile = Tempfile.new("vmaformat_out")
|
|
77
|
+
ok = system("bash", "-c", "#{cmd} > #{Shellwords.escape(outfile.path)}")
|
|
78
|
+
bufc = IO.read(outfile.path) if ok || ignore_exit
|
|
79
|
+
outfile.close; outfile.unlink
|
|
69
80
|
else
|
|
70
|
-
message("
|
|
81
|
+
message("Unknown auto-format mode: #{fmt[:mode]}")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
file.close; file.unlink
|
|
85
|
+
|
|
86
|
+
unless bufc
|
|
87
|
+
message("Auto-format command failed for #{ftype}")
|
|
71
88
|
return
|
|
72
89
|
end
|
|
90
|
+
|
|
73
91
|
self.update_content(bufc)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
infile.close; infile.unlink
|
|
92
|
+
@pos = tmppos.clamp(0, [self.size - 1, 0].max)
|
|
93
|
+
center_on_current_line
|
|
77
94
|
end
|
|
78
95
|
|
|
79
96
|
# Create a new line after current line and insert text on that line
|
|
@@ -83,12 +100,21 @@ class Buffer < String
|
|
|
83
100
|
set_pos(l.end + 1)
|
|
84
101
|
end
|
|
85
102
|
|
|
103
|
+
# Whether text is what the editor copied as whole lines (the unnamed
|
|
104
|
+
# register): text from other programs, read from the system clipboard, is
|
|
105
|
+
# put as characters. entry: the unnamed register when the paste started.
|
|
106
|
+
def register_linewise?(text, entry = vma.registers['"'])
|
|
107
|
+
!entry.nil? && entry.linewise && entry.text == text
|
|
108
|
+
end
|
|
109
|
+
|
|
86
110
|
# Workaround for https://github.com/ruby-gnome/ruby-gnome/issues/1609
|
|
87
111
|
def paste_start_xclip(at, register)
|
|
88
112
|
@clipboard_paste_running = true
|
|
113
|
+
ipos = @pos # capture insertion point before the async read
|
|
114
|
+
entry = vma.registers['"']
|
|
89
115
|
Thread.new {
|
|
90
116
|
text = `xclip -selection c -o`
|
|
91
|
-
GLib::Idle.add { paste_finish(text, at, register); false }
|
|
117
|
+
GLib::Idle.add { paste_finish(text, at, register, ipos: ipos, paste_lines: register_linewise?(text, entry)); false }
|
|
92
118
|
}
|
|
93
119
|
return nil
|
|
94
120
|
end
|
|
@@ -101,25 +127,38 @@ class Buffer < String
|
|
|
101
127
|
# return paste_start_xclip(at, register)
|
|
102
128
|
# end
|
|
103
129
|
|
|
130
|
+
# Capture the insertion point now: read_text_async returns immediately and
|
|
131
|
+
# the callback fires on a later main-loop turn, by which time the cursor
|
|
132
|
+
# may have moved (queued keystroke, mouse click, etc). Without this the
|
|
133
|
+
# paste would land at wherever the cursor happens to be when the clipboard
|
|
134
|
+
# data finally arrives.
|
|
135
|
+
ipos = @pos
|
|
136
|
+
entry = vma.registers['"']
|
|
137
|
+
|
|
104
138
|
clipboard = vma.gui.window.display.clipboard
|
|
105
139
|
clipboard.read_text_async do |_clipboard, result|
|
|
106
140
|
begin
|
|
107
|
-
text =
|
|
141
|
+
text = _clipboard.read_text_finish(result)
|
|
108
142
|
rescue Gio::IOError::NotSupported
|
|
109
143
|
debug Gio::IOError::NotSupported
|
|
110
144
|
else
|
|
111
|
-
paste_finish(text, at, register, overwrite: overwrite)
|
|
145
|
+
paste_finish(text, at, register, overwrite: overwrite, ipos: ipos, paste_lines: register_linewise?(text, entry))
|
|
112
146
|
end
|
|
113
147
|
end
|
|
114
148
|
return nil
|
|
115
149
|
end
|
|
116
150
|
|
|
117
|
-
|
|
151
|
+
# ipos/paste_lines: when given, the cursor position and whether to put
|
|
152
|
+
# whole lines, captured when the paste was started (see paste_start). nil
|
|
153
|
+
# means the live cursor, and whole lines if text is what the editor copied
|
|
154
|
+
# as lines (register_linewise?).
|
|
155
|
+
def paste_finish(text, at, register, overwrite: false, ipos: nil, paste_lines: nil)
|
|
118
156
|
debug "PASTE: #{text}"
|
|
119
157
|
|
|
120
|
-
|
|
121
|
-
if
|
|
122
|
-
|
|
158
|
+
@paste_lines = paste_lines.nil? ? register_linewise?(text) : paste_lines
|
|
159
|
+
if !ipos.nil?
|
|
160
|
+
# Clamp in case the buffer shrank during the async window.
|
|
161
|
+
set_pos(ipos.clamp(0, [size - 1, 0].max))
|
|
123
162
|
end
|
|
124
163
|
|
|
125
164
|
text = sanitize_input(text)
|
|
@@ -163,36 +202,51 @@ class Buffer < String
|
|
|
163
202
|
end
|
|
164
203
|
|
|
165
204
|
def paste_over(at = AFTER, register = nil)
|
|
166
|
-
|
|
167
|
-
text = vma.clipboard.get()
|
|
168
|
-
paste_finish(text, at, register, overwrite: true)
|
|
169
|
-
else
|
|
170
|
-
paste_start(at, register, overwrite: true)
|
|
171
|
-
end
|
|
172
|
-
return true
|
|
205
|
+
paste_register(at, register, overwrite: true)
|
|
173
206
|
end
|
|
174
207
|
|
|
175
208
|
def paste(at = AFTER, register = nil)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
209
|
+
paste_register(at, register)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Put a register (registers.rb): register (a name), else the one selected
|
|
213
|
+
# with "x, else the unnamed one. The unnamed register and "+ / "* read the
|
|
214
|
+
# system clipboard, so text copied in other programs is put too.
|
|
215
|
+
def paste_register(at, register = nil, overwrite: false)
|
|
216
|
+
reg = (register || vma.registers.take_pending || '"').to_s
|
|
217
|
+
if ['"', "+", "*"].include?(reg)
|
|
218
|
+
if vma.macro.running_macro
|
|
219
|
+
# Macros can't wait for the asynchronous read: use the editor's copy
|
|
220
|
+
paste_finish(vma.clipboard.get(), at, reg, overwrite: overwrite)
|
|
221
|
+
else
|
|
222
|
+
paste_start(at, reg, overwrite: overwrite)
|
|
223
|
+
end
|
|
182
224
|
else
|
|
183
|
-
|
|
184
|
-
|
|
225
|
+
e = vma.registers[reg]
|
|
226
|
+
if e.nil?
|
|
227
|
+
message("Register #{reg} is empty")
|
|
228
|
+
return false
|
|
229
|
+
end
|
|
230
|
+
paste_finish(e.text, at, reg, overwrite: overwrite, paste_lines: e.linewise)
|
|
185
231
|
end
|
|
186
232
|
return true
|
|
187
233
|
end
|
|
188
234
|
|
|
235
|
+
# Insert mode ctrl-r x: insert the text of register x at the cursor
|
|
236
|
+
def insert_register(name)
|
|
237
|
+
e = vma.registers[name]
|
|
238
|
+
return false if e.nil? || e.text.empty?
|
|
239
|
+
insert_txt(e.text)
|
|
240
|
+
true
|
|
241
|
+
end
|
|
242
|
+
|
|
189
243
|
def increment_current_word()
|
|
190
244
|
debug "increment_current_word", 2
|
|
191
245
|
p = @pos
|
|
192
246
|
return if !is_legal_pos(p)
|
|
193
247
|
(word, range) = get_word_in_pos(p, boundary: :word2)
|
|
194
|
-
if word
|
|
195
|
-
rep =
|
|
248
|
+
if x = flip_term(word)
|
|
249
|
+
rep = x
|
|
196
250
|
else
|
|
197
251
|
num = word.to_i
|
|
198
252
|
num += 1
|
|
@@ -214,26 +268,29 @@ class Buffer < String
|
|
|
214
268
|
end
|
|
215
269
|
|
|
216
270
|
def replace_range(range, text)
|
|
217
|
-
|
|
271
|
+
# add_delta restores the final "\n" of the buffer if the range deleted it
|
|
272
|
+
text = text.delete_suffix("\n") if range.last >= self.size - 1
|
|
273
|
+
delete_range(range.first, range.last, register: false)
|
|
218
274
|
insert_txt_at(text, range.begin)
|
|
219
275
|
end
|
|
220
276
|
|
|
221
277
|
def delete2(range_id, mark = nil)
|
|
222
|
-
@paste_lines = false
|
|
223
278
|
range = get_range(range_id, mark: mark)
|
|
224
279
|
return false if range == nil
|
|
225
280
|
debug "RANGE"
|
|
226
281
|
debug range.inspect
|
|
227
282
|
debug range.inspect
|
|
228
283
|
debug "------"
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
284
|
+
# Flash the range first so it is visible before the text is removed. When
|
|
285
|
+
# flashing is inactive (tests, config off) the block runs synchronously.
|
|
286
|
+
Gui.flash_range(self, range) do
|
|
287
|
+
delete_range(range.first, range.last)
|
|
288
|
+
set_pos([range.first, @pos].min)
|
|
289
|
+
end
|
|
232
290
|
return true
|
|
233
291
|
end
|
|
234
292
|
|
|
235
293
|
def delete(op, x = nil)
|
|
236
|
-
@paste_lines = false
|
|
237
294
|
# Delete selection
|
|
238
295
|
if op == SELECTION && visual_mode?
|
|
239
296
|
(startpos, endpos) = get_visual_mode_range2
|
|
@@ -267,9 +324,35 @@ class Buffer < String
|
|
|
267
324
|
#recalc_line_ends
|
|
268
325
|
calculate_line_and_column_pos
|
|
269
326
|
#need_redraw!
|
|
327
|
+
|
|
328
|
+
if vma.kbd&.get_mode == :insert
|
|
329
|
+
v = (self.view rescue nil)
|
|
330
|
+
v.autocp_on_delete if v.respond_to?(:autocp_on_delete)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Move the text in range (inclusive, like get_visual_mode_range) so that it
|
|
335
|
+
# starts at insertion point target of the current text, with the cursor at
|
|
336
|
+
# its new start. One undo step; the clipboard is left alone. Returns the
|
|
337
|
+
# moved text's new range, or nil when target is inside (or right after) the
|
|
338
|
+
# range, i.e. nothing would move.
|
|
339
|
+
def move_text(range, target)
|
|
340
|
+
s, e = range.begin, range.end
|
|
341
|
+
return nil if s > e or target.nil? or (target >= s and target <= e + 1)
|
|
342
|
+
txt = self[s..e]
|
|
343
|
+
new_undo_group
|
|
344
|
+
add_delta([s, DELETE, txt.size], true)
|
|
345
|
+
t = target > e ? target - txt.size : target
|
|
346
|
+
add_delta([t, INSERT, txt.size, txt], true)
|
|
347
|
+
new_undo_group
|
|
348
|
+
calculate_line_and_column_pos
|
|
349
|
+
set_pos(t)
|
|
350
|
+
return t..(t + txt.size - 1)
|
|
270
351
|
end
|
|
271
352
|
|
|
272
|
-
|
|
353
|
+
# Delete [startpos, endpos]. register: put the text in the registers and
|
|
354
|
+
# the clipboard (false for edits that only replace text, like a case change).
|
|
355
|
+
def delete_range(startpos, endpos, x = nil, register: true)
|
|
273
356
|
s = self[startpos..endpos]
|
|
274
357
|
if startpos > endpos or s == ""
|
|
275
358
|
return
|
|
@@ -278,7 +361,7 @@ class Buffer < String
|
|
|
278
361
|
debug "APPEND"
|
|
279
362
|
s += "\n" + vma.clipboard.get()
|
|
280
363
|
end
|
|
281
|
-
vma.clipboard.set(s)
|
|
364
|
+
vma.clipboard.set(s, kind: :delete) if register
|
|
282
365
|
add_delta([startpos, DELETE, (endpos - startpos + 1)], true)
|
|
283
366
|
#recalc_line_ends
|
|
284
367
|
calculate_line_and_column_pos
|
|
@@ -301,22 +384,20 @@ class Buffer < String
|
|
|
301
384
|
end
|
|
302
385
|
|
|
303
386
|
def delete_line()
|
|
304
|
-
|
|
305
|
-
num_lines = 1
|
|
306
|
-
if !vma.kbd.next_command_count.nil? and vma.kbd.next_command_count > 0
|
|
307
|
-
num_lines = vma.kbd.next_command_count
|
|
308
|
-
debug "copy num_lines:#{num_lines}"
|
|
309
|
-
end
|
|
387
|
+
num_lines = get_repeat_num()
|
|
310
388
|
lrange = line_range(@lpos, num_lines)
|
|
311
389
|
s = self[lrange]
|
|
312
390
|
add_delta([lrange.begin, DELETE, lrange.end - lrange.begin + 1], true)
|
|
313
|
-
vma.clipboard.set(s)
|
|
391
|
+
vma.clipboard.set(s, linewise: true, kind: :delete)
|
|
314
392
|
update_pos(lrange.begin)
|
|
315
|
-
@paste_lines = true
|
|
316
393
|
#recalc_line_ends
|
|
317
394
|
end
|
|
318
395
|
|
|
319
396
|
def insert_tab
|
|
397
|
+
if visual_mode?
|
|
398
|
+
indent_selection
|
|
399
|
+
return
|
|
400
|
+
end
|
|
320
401
|
convert = cnf.tab.to_spaces_default?
|
|
321
402
|
convert = true if cnf.tab.to_spaces_languages?.include?(@lang)
|
|
322
403
|
convert = false if cnf.tab.to_spaces_not_languages?.include?(@lang)
|
|
@@ -341,3 +422,4 @@ class Buffer < String
|
|
|
341
422
|
add_image(fname, imgpos)
|
|
342
423
|
end
|
|
343
424
|
end
|
|
425
|
+
end # module Vimamsa
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# Buffer operations related to cursor position, e.g. moving the cursor (backward, forward, next line etc.)
|
|
2
4
|
class Buffer < String
|
|
3
5
|
def line(lpos)
|
|
@@ -44,10 +46,14 @@ class Buffer < String
|
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
self.view.set_cursor_pos(pos)
|
|
49
|
+
self.view.autocp_check_pos(@pos) if self.view.respond_to?(:autocp_check_pos)
|
|
47
50
|
# gui_set_cursor_pos(@id, @pos)
|
|
48
51
|
calculate_line_and_column_pos
|
|
49
52
|
|
|
50
53
|
check_if_modified_outside
|
|
54
|
+
# Actions often end in set_pos; a false return would keep them out of
|
|
55
|
+
# macro recordings and abort macro playback.
|
|
56
|
+
return true
|
|
51
57
|
end
|
|
52
58
|
|
|
53
59
|
# Get the line number of character position
|
|
@@ -307,3 +313,4 @@ class Buffer < String
|
|
|
307
313
|
set_pos(new_pos)
|
|
308
314
|
end
|
|
309
315
|
end
|
|
316
|
+
end # module Vimamsa
|
data/lib/vimamsa/buffer_list.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
def save_buffer_list()
|
|
2
4
|
message("Save buffer list")
|
|
3
|
-
buffn =
|
|
5
|
+
buffn = get_data_path("buffers.txt")
|
|
4
6
|
f = File.open(buffn, "w")
|
|
5
7
|
bufstr = vma.buffers.list.collect { |buf| buf.fname }.inspect
|
|
6
8
|
f.write(bufstr)
|
|
@@ -9,7 +11,7 @@ end
|
|
|
9
11
|
|
|
10
12
|
def load_buffer_list()
|
|
11
13
|
message("Load buffer list")
|
|
12
|
-
buffn =
|
|
14
|
+
buffn = get_data_path("buffers.txt")
|
|
13
15
|
return if !File.exist?(buffn)
|
|
14
16
|
bufstr = IO.read(buffn)
|
|
15
17
|
bufl = eval(bufstr)
|
|
@@ -123,6 +125,7 @@ class BufferList
|
|
|
123
125
|
vma.hook.call(:change_buffer, vma.buf)
|
|
124
126
|
|
|
125
127
|
bu.set_active # TODO
|
|
128
|
+
bu.check_autosave_load_if_pending # deferred check for session-restored buffers
|
|
126
129
|
bu.update_access_time if update_history
|
|
127
130
|
reset_navigation if update_history
|
|
128
131
|
vma.gui.set_current_buffer(idx)
|
|
@@ -295,3 +298,4 @@ class BufferList
|
|
|
295
298
|
end
|
|
296
299
|
end
|
|
297
300
|
end
|
|
301
|
+
end # module Vimamsa
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
class BufferManager
|
|
2
4
|
attr_reader :buf
|
|
3
5
|
@@cur = nil # Current object of class
|
|
@@ -9,14 +11,14 @@ class BufferManager
|
|
|
9
11
|
def self.init()
|
|
10
12
|
# vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
|
|
11
13
|
vma.kbd.add_minor_mode("bmgr", :bmgr, :command)
|
|
12
|
-
reg_act(
|
|
13
|
-
reg_act(
|
|
14
|
+
reg_act("bmgr.select", proc { buf.module.select_line }, "")
|
|
15
|
+
reg_act("bmgr.close", proc { buf.module.close_selected }, "")
|
|
14
16
|
|
|
15
|
-
reg_act(
|
|
17
|
+
reg_act("buf.manager", proc { BufferManager.new.run; vma.kbd.set_mode(:bmgr) }, "Buffer manager")
|
|
16
18
|
|
|
17
|
-
bindkey "bmgr enter",
|
|
18
|
-
bindkey "bmgr c",
|
|
19
|
-
bindkey "bmgr x",
|
|
19
|
+
bindkey "bmgr enter", "bmgr.select"
|
|
20
|
+
bindkey "bmgr c", "bmgr.close"
|
|
21
|
+
bindkey "bmgr x", "buf.close"
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def initialize()
|
|
@@ -34,7 +36,7 @@ class BufferManager
|
|
|
34
36
|
def close_selected
|
|
35
37
|
idx = buf_of_current_line()
|
|
36
38
|
r = @buf.current_line_range
|
|
37
|
-
Gui.hilight_range(@buf, r, color:
|
|
39
|
+
Gui.hilight_range(@buf, r, color: theme_color(:buffer_switch))
|
|
38
40
|
if idx.nil?
|
|
39
41
|
message("buf already closed")
|
|
40
42
|
return
|
|
@@ -111,3 +113,4 @@ class BufferManager
|
|
|
111
113
|
# Thread.new{sleep 0.1; center_on_current_line()} # TODO
|
|
112
114
|
end
|
|
113
115
|
end
|
|
116
|
+
end # module Vimamsa
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Install the fonts bundled under ./fonts (Oxanium, used by the cyberpunk-glow
|
|
4
|
+
# GUI theme) into the user font dir so fontconfig/Pango can resolve them by
|
|
5
|
+
# family name. Ported from the rterm terminal project's BundledFonts. Copies
|
|
6
|
+
# are skipped when the destination is already identical, so it is cheap to run
|
|
7
|
+
# on every startup and needs no fc-cache call (fontconfig scans the dir).
|
|
8
|
+
|
|
9
|
+
require "fileutils"
|
|
10
|
+
|
|
11
|
+
module Vimamsa
|
|
12
|
+
module BundledFonts
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
def setup!
|
|
16
|
+
bundled_dir = File.expand_path("../../fonts", __dir__)
|
|
17
|
+
return unless Dir.exist?(bundled_dir)
|
|
18
|
+
|
|
19
|
+
target_dir = File.expand_path("~/.local/share/fonts/vimamsa")
|
|
20
|
+
FileUtils.mkdir_p(target_dir)
|
|
21
|
+
|
|
22
|
+
Dir.glob(File.join(bundled_dir, "*.{ttf,otf,ttc,otc}")).each do |src|
|
|
23
|
+
dest = File.join(target_dir, File.basename(src))
|
|
24
|
+
next if File.exist?(dest) && FileUtils.identical?(src, dest)
|
|
25
|
+
|
|
26
|
+
FileUtils.cp(src, dest)
|
|
27
|
+
end
|
|
28
|
+
rescue => ex
|
|
29
|
+
warn "BundledFonts.setup! failed: #{ex}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Vimamsa
|
|
2
|
+
# vimamsa --help (exe/vimamsa): the command line options, then the actions.
|
|
3
|
+
# The usage text needs nothing else, so it is printed before the rest of the
|
|
4
|
+
# code loads; the actions are registered the way Editor#start does it, without
|
|
5
|
+
# starting the GUI.
|
|
6
|
+
|
|
7
|
+
CLI_USAGE = <<~TXT
|
|
8
|
+
Usage: vimamsa [options] [file | dir ...]
|
|
9
|
+
|
|
10
|
+
Opens the files in the editor window (if an editor is already running, the
|
|
11
|
+
file is opened there). A directory is added to the file and content search
|
|
12
|
+
paths.
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
--user-dir DIR config and data dir instead of ~/.config/vimamsa
|
|
16
|
+
and ~/.local/share/vimamsa
|
|
17
|
+
(also --user-dir=DIR)
|
|
18
|
+
--tmp-user-dir a new, empty config and data dir in the temp dir,
|
|
19
|
+
deleted on quit (try the defaults, e.g. a first start)
|
|
20
|
+
--intro show the introduction page (Help ▸ Introduction) at start
|
|
21
|
+
-h, --help this help, and the list of actions
|
|
22
|
+
TXT
|
|
23
|
+
|
|
24
|
+
def self.print_cli_usage(io = $stdout)
|
|
25
|
+
io.puts CLI_USAGE
|
|
26
|
+
io.flush
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Registers the built-in actions without starting the editor, as Editor#start
|
|
30
|
+
# does: key_actions.rb, the default keymap (vimlike), the text converters and
|
|
31
|
+
# the minor modes (buffer manager, bookmarks, grep, file explorer, file
|
|
32
|
+
# history). Modules register more when they are enabled.
|
|
33
|
+
def self.cli_load_actions
|
|
34
|
+
ed = vma
|
|
35
|
+
$hook = Hook.new
|
|
36
|
+
ed.instance_variable_set(:@hook, $hook)
|
|
37
|
+
require "vimamsa/actions"
|
|
38
|
+
ed.instance_variable_set(:@actions, ActionList.new)
|
|
39
|
+
require "vimamsa/key_actions"
|
|
40
|
+
ed.kbd = KeyBindingTree.new(actions: ed.actions)
|
|
41
|
+
require "vimamsa/key_bindings_vimlike"
|
|
42
|
+
form_input_setup
|
|
43
|
+
require "vimamsa/text_transforms"
|
|
44
|
+
BufferManager.init
|
|
45
|
+
Bookmarks.init
|
|
46
|
+
Grep.init
|
|
47
|
+
FileManager.init
|
|
48
|
+
require "vimamsa/file_history"
|
|
49
|
+
FileHistory.new # registers file.history.prune; only reads the history
|
|
50
|
+
ed.actions
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# " id description" lines, sorted by id
|
|
54
|
+
def self.cli_action_lines(actions)
|
|
55
|
+
ids = actions.dotted_ids.map(&:to_s).sort
|
|
56
|
+
w = ids.map(&:size).max.to_i
|
|
57
|
+
ids.map { |id|
|
|
58
|
+
a = actions[id]
|
|
59
|
+
desc = a.respond_to?(:method_name) ? a.method_name.to_s : ""
|
|
60
|
+
desc = "" if desc == id
|
|
61
|
+
" #{id.ljust(w)} #{desc}".rstrip
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.print_cli_actions(io = $stdout)
|
|
66
|
+
actions = cli_load_actions
|
|
67
|
+
io.puts
|
|
68
|
+
io.puts "Actions (#{actions.dotted_ids.size}). Bind one to keys in custom.rb with"
|
|
69
|
+
io.puts "bindkey \"C , x\", \"<action>\", or run it on the command line (:) as"
|
|
70
|
+
io.puts "a.<action>!, e.g. a.buf.save! Enabled modules add more."
|
|
71
|
+
io.puts
|
|
72
|
+
io.puts cli_action_lines(actions)
|
|
73
|
+
io.flush
|
|
74
|
+
end
|
|
75
|
+
end # module Vimamsa
|
data/lib/vimamsa/clipboard.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
class Clipboard
|
|
2
4
|
def initialize
|
|
3
5
|
@clipboard = []
|
|
@@ -11,18 +13,21 @@ class Clipboard
|
|
|
11
13
|
return @clipboard << str
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
# Copied (kind :yank) or deleted (kind :delete) text: into the registers
|
|
17
|
+
# (Registers#store: the pending "x register, else vim's rules) and the
|
|
18
|
+
# system clipboard. linewise: copied as whole lines (yy, dd), so a put adds
|
|
19
|
+
# lines. Nothing happens for the black hole register "_.
|
|
20
|
+
def set(s, linewise: false, kind: :yank)
|
|
15
21
|
if !(s.class <= String) or s.size == 0
|
|
16
22
|
debug s.inspect
|
|
17
23
|
debug [s, s.class, s.size]
|
|
18
24
|
log_error("s.class != String or s.size == 0")
|
|
19
25
|
return
|
|
20
26
|
end
|
|
27
|
+
return if !vma.registers.store(s, linewise: linewise, kind: kind)
|
|
21
28
|
@clipboard << s
|
|
22
29
|
set_system_clipboard(s)
|
|
23
|
-
vma.register[vma.cur_register] = s
|
|
24
30
|
debug "SET CLIPBOARD: [#{s}]"
|
|
25
|
-
debug "REGISTER: #{vma.cur_register}:#{vma.register[vma.cur_register]}"
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
def get()
|
|
@@ -34,3 +39,4 @@ def set_system_clipboard(arg)
|
|
|
34
39
|
debug arg,2
|
|
35
40
|
vma.gui.window.display.clipboard.set(arg)
|
|
36
41
|
end
|
|
42
|
+
end # module Vimamsa
|