vimamsa 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +93 -0
  3. data/.gitignore +4 -1
  4. data/Dockerfile +7 -4
  5. data/README.md +62 -16
  6. data/custom_example.rb +43 -13
  7. data/doc/TODO.md +461 -0
  8. data/doc/bundling_plan.md +569 -0
  9. data/doc/key_bindings_report_plan.md +168 -0
  10. data/doc/missing_vim_bindings.md +71 -0
  11. data/doc/modules_settings_plan.md +433 -0
  12. data/doc/refactor_dedup_plan.md +117 -0
  13. data/doc/unused_code_plan.md +120 -0
  14. data/doc/vim_compatibility_plan.md +296 -0
  15. data/doc/vimlike_vim_conflicts.md +254 -0
  16. data/doc/vm_snapshots_plan.md +146 -0
  17. data/exe/run_tests.rb +117 -3
  18. data/exe/vimamsa +24 -4
  19. data/fonts/OFL-Oxanium.txt +93 -0
  20. data/fonts/Oxanium[wght].ttf +0 -0
  21. data/icon.png +0 -0
  22. data/img/demo.gif +0 -0
  23. data/lang/hyperplaintext.lang +6 -0
  24. data/lib/vimamsa/ack.rb +11 -1
  25. data/lib/vimamsa/actions.rb +4 -1
  26. data/lib/vimamsa/appimage_env.rb +35 -0
  27. data/lib/vimamsa/audio.rb +2 -5
  28. data/lib/vimamsa/bookmarks.rb +302 -0
  29. data/lib/vimamsa/buffer.rb +593 -82
  30. data/lib/vimamsa/buffer_changetext.rb +102 -42
  31. data/lib/vimamsa/buffer_cursor.rb +7 -0
  32. data/lib/vimamsa/buffer_list.rb +4 -0
  33. data/lib/vimamsa/buffer_manager.rb +4 -1
  34. data/lib/vimamsa/bundled_fonts.rb +32 -0
  35. data/lib/vimamsa/clipboard.rb +3 -0
  36. data/lib/vimamsa/conf.rb +59 -3
  37. data/lib/vimamsa/constants.rb +3 -0
  38. data/lib/vimamsa/crash_handler.rb +149 -0
  39. data/lib/vimamsa/debug.rb +4 -1
  40. data/lib/vimamsa/desktop_install.rb +96 -0
  41. data/lib/vimamsa/diff_buffer.rb +39 -10
  42. data/lib/vimamsa/easy_jump.rb +3 -0
  43. data/lib/vimamsa/editor.rb +263 -57
  44. data/lib/vimamsa/encrypt.rb +78 -29
  45. data/lib/vimamsa/file_finder.rb +4 -19
  46. data/lib/vimamsa/file_history.rb +3 -0
  47. data/lib/vimamsa/file_manager.rb +30 -15
  48. data/lib/vimamsa/fold.rb +226 -0
  49. data/lib/vimamsa/gui.rb +520 -106
  50. data/lib/vimamsa/gui_command_line.rb +208 -0
  51. data/lib/vimamsa/gui_dialog.rb +94 -42
  52. data/lib/vimamsa/gui_file_panel.rb +356 -25
  53. data/lib/vimamsa/gui_form_generator.rb +59 -35
  54. data/lib/vimamsa/gui_func_panel.rb +67 -22
  55. data/lib/vimamsa/gui_image.rb +3 -0
  56. data/lib/vimamsa/gui_keylog_panel.rb +246 -0
  57. data/lib/vimamsa/gui_menu.rb +23 -11
  58. data/lib/vimamsa/gui_select_window.rb +19 -48
  59. data/lib/vimamsa/gui_settings.rb +78 -37
  60. data/lib/vimamsa/gui_sourceview.rb +273 -19
  61. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  62. data/lib/vimamsa/gui_text.rb +63 -2
  63. data/lib/vimamsa/gui_theme.rb +606 -0
  64. data/lib/vimamsa/hook.rb +3 -0
  65. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  66. data/lib/vimamsa/key_actions.rb +112 -13
  67. data/lib/vimamsa/key_binding_tree.rb +242 -215
  68. data/lib/vimamsa/key_bindings_notepad.rb +43 -0
  69. data/lib/vimamsa/key_bindings_report.rb +261 -0
  70. data/lib/vimamsa/key_bindings_vim.rb +354 -0
  71. data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
  72. data/lib/vimamsa/langservp.rb +271 -54
  73. data/lib/vimamsa/macro.rb +3 -0
  74. data/lib/vimamsa/main.rb +14 -8
  75. data/lib/vimamsa/rbvma.rb +26 -1
  76. data/lib/vimamsa/search.rb +3 -0
  77. data/lib/vimamsa/search_replace.rb +11 -10
  78. data/lib/vimamsa/string_util.rb +120 -40
  79. data/lib/vimamsa/terminal.rb +3 -0
  80. data/lib/vimamsa/test_framework.rb +28 -2
  81. data/lib/vimamsa/tests.rb +3 -0
  82. data/lib/vimamsa/text_objects.rb +353 -0
  83. data/lib/vimamsa/text_transforms.rb +14 -0
  84. data/lib/vimamsa/util.rb +46 -7
  85. data/lib/vimamsa/version.rb +1 -1
  86. data/lib/vimamsa.rb +0 -1
  87. data/modules/color_highlight/color_highlight.rb +118 -0
  88. data/modules/color_highlight/color_highlight_info.rb +3 -0
  89. data/modules/dictation/dictation.rb +1054 -0
  90. data/modules/dictation/dictation_info.rb +3 -0
  91. data/modules/dictation/whisper_worker.py +273 -0
  92. data/modules/ollama/ollama.rb +107 -0
  93. data/modules/ollama/ollama_info.rb +3 -0
  94. data/modules/tts/tts.rb +119 -0
  95. data/modules/tts/tts_info.rb +3 -0
  96. data/run_e2e_vm.sh +28 -0
  97. data/run_tests_vm.sh +130 -0
  98. data/scripts/appimage/AppRun +54 -0
  99. data/scripts/appimage/Dockerfile +18 -0
  100. data/scripts/appimage/build.sh +19 -0
  101. data/scripts/appimage/build_in_container.sh +192 -0
  102. data/scripts/appimage/smoke_test.sh +27 -0
  103. data/scripts/demo/demo_steps.txt +59 -0
  104. data/scripts/demo/record_demo.rb +177 -0
  105. data/scripts/demo/shapes.rb +28 -0
  106. data/styles/134272-molokai.xml +3 -0
  107. data/styles/molokai_cyber.xml +48 -0
  108. data/styles/molokai_edit.xml +1 -0
  109. data/tests/support/virtual_keyboard.rb +254 -0
  110. data/tests/support/virtual_mic.rb +67 -0
  111. data/tests/test_ack.rb +22 -0
  112. data/tests/test_auto_format.rb +122 -0
  113. data/tests/test_autocomplete.rb +211 -0
  114. data/tests/test_autosave.rb +145 -0
  115. data/tests/test_basic_editing.rb +33 -3
  116. data/tests/test_bookmarks.rb +206 -0
  117. data/tests/test_bracket_match.rb +85 -0
  118. data/tests/test_bundling.rb +92 -0
  119. data/tests/test_color_highlight.rb +92 -0
  120. data/tests/test_command_line.rb +79 -0
  121. data/tests/test_command_line_file.rb +27 -0
  122. data/tests/test_context_menu_file.rb +129 -0
  123. data/tests/test_copy_paste.rb +80 -0
  124. data/tests/test_crash_handler.rb +39 -0
  125. data/tests/test_custom_two_phase.rb +92 -0
  126. data/tests/test_dialog_callback_errors.rb +44 -0
  127. data/tests/test_dictation.rb +294 -0
  128. data/tests/test_diff_buffer_name.rb +51 -0
  129. data/tests/test_double_click.rb +41 -0
  130. data/tests/test_drag_selection.rb +125 -0
  131. data/tests/test_e2e_cmdline.rb +116 -0
  132. data/tests/test_e2e_dictation.rb +98 -0
  133. data/tests/test_e2e_replace_char.rb +58 -0
  134. data/tests/test_extract_file_links.rb +55 -0
  135. data/tests/test_file_format.rb +217 -0
  136. data/tests/test_file_manager.rb +72 -0
  137. data/tests/test_file_panel.rb +269 -0
  138. data/tests/test_flash.rb +78 -0
  139. data/tests/test_fold.rb +111 -0
  140. data/tests/test_font_refresh.rb +56 -0
  141. data/tests/test_func_panel.rb +68 -0
  142. data/tests/test_grep_apply.rb +46 -0
  143. data/tests/test_gtk_sync.rb +126 -0
  144. data/tests/test_hpt_highlight_visible.rb +75 -0
  145. data/tests/test_hpt_link_highlight.rb +82 -0
  146. data/tests/test_jump_to_file.rb +41 -0
  147. data/tests/test_key_bindings.rb +208 -0
  148. data/tests/test_keylog_panel.rb +101 -0
  149. data/tests/test_lsp_clangd.rb +281 -0
  150. data/tests/test_lsp_jump.rb +87 -0
  151. data/tests/test_lsp_position_encoding.rb +49 -0
  152. data/tests/test_lsp_symbols.rb +68 -0
  153. data/tests/test_macro.rb +137 -0
  154. data/tests/test_markdown_highlight.rb +57 -0
  155. data/tests/test_mode_badge.rb +41 -0
  156. data/tests/test_notepad_bindings.rb +67 -0
  157. data/tests/test_popup_queue.rb +51 -0
  158. data/tests/test_random_edit.rb +109 -0
  159. data/tests/test_revert.rb +127 -0
  160. data/tests/test_startup_file.rb +58 -0
  161. data/tests/test_status_area.rb +50 -0
  162. data/tests/test_text_objects.rb +163 -0
  163. data/tests/test_text_transforms.rb +329 -0
  164. data/tests/test_tts.rb +68 -0
  165. data/tests/test_vim_bindings.rb +252 -0
  166. data/tests/test_vim_conflicts.rb +63 -0
  167. data/tests/test_window_layout.rb +219 -0
  168. data/vimamsa.gemspec +3 -1
  169. data/vm_guest_run.sh +109 -0
  170. metadata +112 -10
@@ -0,0 +1,96 @@
1
+ require "fileutils"
2
+
3
+ module Vimamsa
4
+
5
+ # Application id used both for the GTK application (see gui.rb) and as the
6
+ # StartupWMClass / desktop-file basename so desktop environments can match the
7
+ # running window to its launcher entry and icon.
8
+ VMA_APP_ID = "net.samiddhi.vimamsa"
9
+
10
+ # Install a desktop launcher entry + application icon into the user's data dir
11
+ # (~/.local/share). Runs on every startup but only writes when the installed
12
+ # copy is missing or differs from the bundled source, so a new logo / changed
13
+ # .desktop shipped by a gem upgrade is picked up automatically, while the common
14
+ # unchanged case does nothing (and never spawns the cache-refresh processes).
15
+ # Best-effort — any failure is logged and swallowed so it can never block startup.
16
+ def install_desktop_integration
17
+ icon_src = ppath("icon.png")
18
+ unless File.exist?(icon_src)
19
+ debug "Desktop install: icon source not found at #{icon_src}"
20
+ return
21
+ end
22
+
23
+ data_home = ENV["XDG_DATA_HOME"]
24
+ data_home = File.expand_path("~/.local/share") if data_home.nil? || data_home.empty?
25
+
26
+ icon_dir = File.join(data_home, "icons", "hicolor", "256x256", "apps")
27
+ icon_dst = File.join(icon_dir, "vimamsa.png")
28
+ apps_dir = File.join(data_home, "applications")
29
+ desktop_dst = File.join(apps_dir, "#{VMA_APP_ID}.desktop")
30
+
31
+ installed_something = false
32
+
33
+ # Re-copy the icon whenever the bundled source differs (e.g. a new logo after
34
+ # a gem upgrade). FileUtils.identical? compares contents, not just mtime.
35
+ if !File.exist?(icon_dst) || !FileUtils.identical?(icon_src, icon_dst)
36
+ FileUtils.mkdir_p(icon_dir)
37
+ FileUtils.cp(icon_src, icon_dst)
38
+ installed_something = true
39
+ debug "Desktop install: copied icon to #{icon_dst}"
40
+ end
41
+
42
+ # The .desktop file is app-generated metadata; rewrite it when our generated
43
+ # content changes (new fields / version). This is not a user-customization file.
44
+ desktop_txt = desktop_entry_contents
45
+ if !File.exist?(desktop_dst) || File.read(desktop_dst) != desktop_txt
46
+ FileUtils.mkdir_p(apps_dir)
47
+ File.write(desktop_dst, desktop_txt)
48
+ installed_something = true
49
+ debug "Desktop install: wrote #{desktop_dst}"
50
+ end
51
+
52
+ refresh_desktop_caches(File.join(data_home, "icons", "hicolor"), apps_dir) if installed_something
53
+ rescue => e
54
+ # Never let desktop integration break startup.
55
+ debug "Desktop install failed: #{e.class}: #{e.message}"
56
+ end
57
+
58
+ # Exec= value for the launcher. From an AppImage ($APPIMAGE is the file's path,
59
+ # set by the AppImage runtime) the launcher runs that file, so it works without
60
+ # a vimamsa on PATH; if the file is moved, the next start rewrites the entry.
61
+ # Otherwise the gem's binstub.
62
+ def desktop_exec_command
63
+ appimage = ENV["APPIMAGE"]
64
+ return "vimamsa %F" if appimage.nil? || appimage.empty?
65
+ # Desktop Entry spec: inside quotes, backslash-escape " ` $ \; then the
66
+ # string-value escaping doubles every backslash again; % is written %%.
67
+ quoted = appimage.gsub(/["`$\\]/) { |c| "\\#{c}" }.gsub("\\") { "\\\\" }.gsub("%", "%%")
68
+ %{"#{quoted}" %F}
69
+ end
70
+
71
+ def desktop_entry_contents
72
+ <<~DESKTOP
73
+ [Desktop Entry]
74
+ Type=Application
75
+ Name=Vimamsa
76
+ Comment=Vi/Vim-inspired GUI text editor
77
+ Exec=#{desktop_exec_command}
78
+ Icon=vimamsa
79
+ Terminal=false
80
+ Categories=Utility;TextEditor;
81
+ StartupWMClass=#{VMA_APP_ID}
82
+ DESKTOP
83
+ end
84
+
85
+ def refresh_desktop_caches(icon_theme_dir, apps_dir)
86
+ if which("gtk-update-icon-cache")
87
+ system("gtk-update-icon-cache", "-q", "-t", "-f", icon_theme_dir,
88
+ out: File::NULL, err: File::NULL)
89
+ end
90
+ if which("update-desktop-database")
91
+ system("update-desktop-database", apps_dir,
92
+ out: File::NULL, err: File::NULL)
93
+ end
94
+ end
95
+
96
+ end # module Vimamsa
@@ -1,3 +1,5 @@
1
+
2
+ module Vimamsa
1
3
  # Map a "line number in a unified diff output" to the corresponding
2
4
  # line in the new/changed file (the + side), together with the file it belongs to.
3
5
  #
@@ -93,9 +95,18 @@ def diff_buffer()
93
95
  infile = Tempfile.new("in")
94
96
  infile.write(vma.buf.to_s)
95
97
  infile.flush
96
- bufstr = run_cmd("diff -uw '#{orig_path}' #{infile.path}")
98
+ # Compare like with like: the buffer is UTF-8 + \n, the file may be in
99
+ # another encoding / CRLF (see read_file_with_format), so diff against the
100
+ # file as it would be loaded. Both sides are labeled with the real path.
101
+ origfile = Tempfile.new("orig")
102
+ origfile.write(read_file("", orig_path))
103
+ origfile.flush
104
+ label = Shellwords.escape(orig_path)
105
+ bufstr = text_to_utf8(run_cmd("diff -uw --label #{label} --label #{label} " \
106
+ "#{Shellwords.escape(origfile.path)} #{Shellwords.escape(infile.path)}"))
97
107
  infile.close; infile.unlink
98
- create_new_file(nil, bufstr)
108
+ origfile.close; origfile.unlink
109
+ create_new_buffer(bufstr, "diff-unsaved-#{File.basename(orig_path.to_s)}")
99
110
  gui_set_file_lang(vma.buf.id, "diff")
100
111
  vma.kbd.set_mode(:diffview)
101
112
  end
@@ -126,7 +137,7 @@ end
126
137
  # Prefers new_path (the post-change file); falls back to old_path
127
138
  # when new_path is /dev/null or a temp file that no longer exists.
128
139
  def resolve_diff_path(new_path, old_path)
129
- git_root = `git rev-parse --show-toplevel 2>/dev/null`.strip
140
+ git_root = vma.buf.git_root || `git rev-parse --show-toplevel 2>/dev/null`.strip
130
141
 
131
142
  expand = lambda do |path|
132
143
  return nil if path.nil? || path == "/dev/null"
@@ -144,24 +155,32 @@ def resolve_diff_path(new_path, old_path)
144
155
  expand.call(old_path)
145
156
  end
146
157
 
158
+ # Git worktree root containing the current buffer's file (or CWD when the buffer
159
+ # has no file), or nil if it is not inside a git repository.
160
+ def buffer_git_root
161
+ dir = vma.buf.fname ? File.dirname(vma.buf.fname) : Dir.pwd
162
+ root = `git -C #{Shellwords.escape(dir)} rev-parse --show-toplevel 2>/dev/null`.strip
163
+ root.empty? ? nil : root
164
+ end
165
+
147
166
  def git_diff_w()
148
167
  return if !if_cmd_exists("git")
149
168
  diff_buffer_init
150
169
 
151
- dir = vma.buf.fname ? File.dirname(vma.buf.fname) : Dir.pwd
152
- git_root = `git -C #{Shellwords.escape(dir)} rev-parse --show-toplevel 2>/dev/null`.strip
153
- if git_root.empty?
170
+ git_root = buffer_git_root
171
+ if git_root.nil?
154
172
  message("Not a git repository")
155
173
  return
156
174
  end
157
175
 
158
- bufstr = run_cmd("git -C #{Shellwords.escape(git_root)} diff -w")
176
+ bufstr = text_to_utf8(run_cmd("git -C #{Shellwords.escape(git_root)} diff -w"))
159
177
  if bufstr.strip.empty?
160
178
  message("git diff -w: no changes")
161
179
  return
162
180
  end
163
181
 
164
- create_new_file(nil, bufstr)
182
+ create_new_buffer(bufstr, "gitdiff-#{File.basename(git_root)}")
183
+ vma.buf.git_root = git_root
165
184
  gui_set_file_lang(vma.buf.id, "diff")
166
185
  vma.kbd.set_mode(:diffview)
167
186
  end
@@ -174,12 +193,22 @@ def git_diff_buffer()
174
193
  message("Buffer has no file")
175
194
  return
176
195
  end
177
- bufstr = run_cmd("git diff -w -- #{Shellwords.escape(fname)}")
196
+
197
+
198
+ git_root = buffer_git_root
199
+ if git_root.nil?
200
+ message("Not a git repository")
201
+ return
202
+ end
203
+ bufstr = text_to_utf8(run_cmd("git -C #{Shellwords.escape(git_root)} diff -w -- #{Shellwords.escape(fname)}"))
178
204
  if bufstr.strip.empty?
179
205
  message("git diff: no changes")
180
206
  return
181
207
  end
182
- create_new_file(nil, bufstr)
208
+ create_new_buffer(bufstr, "gitdiff-#{File.basename(fname)}")
209
+ vma.buf.git_root = git_root
183
210
  gui_set_file_lang(vma.buf.id, "diff")
184
211
  vma.kbd.set_mode(:diffview)
185
212
  end
213
+
214
+ end # module Vimamsa
@@ -1,3 +1,5 @@
1
+
2
+ module Vimamsa
1
3
  # Similar feature as Vim EasyMotion https://github.com/easymotion/vim-easymotion
2
4
  class EasyJump
3
5
  # def self.initialize()
@@ -162,3 +164,4 @@ class EasyJump
162
164
  return sequence
163
165
  end
164
166
  end
167
+ end # module Vimamsa