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
@@ -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
 
@@ -39,41 +41,51 @@ class Buffer < String
39
41
 
40
42
  # TODO: rename ot auto-format. separate module?
41
43
  # Indents whole buffer using external program
42
- def indent()
43
- file = Tempfile.new("out")
44
- infile = Tempfile.new("in")
45
- file.write(self.to_s)
46
- file.flush
47
- bufc = "FOO"
44
+ def auto_format()
45
+ ftype = get_file_type()
46
+ formatters = cnf.auto_format.formatters!
47
+ fmt = formatters&.fetch(ftype, nil)
48
+ if fmt.nil?
49
+ message("No auto-format handler for file of type: #{ftype}")
50
+ return
51
+ end
48
52
 
49
53
  tmppos = @pos
50
-
51
54
  message("Auto format #{@fname}")
52
55
 
53
- ftype = get_file_type()
54
- if ["chdr", "c", "cpp", "cpphdr"].include?(ftype)
55
-
56
- #C/C++/Java/JavaScript/Objective-C/Protobuf code
57
- system("clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' #{file.path} > #{infile.path}")
58
- bufc = IO.read(infile.path)
59
- elsif ftype == "Javascript"
60
- cmd = "clang-format #{file.path} > #{infile.path}'"
61
- debug cmd
62
- system(cmd)
63
- bufc = IO.read(infile.path)
64
- elsif ftype == "ruby"
65
- cmd = "rufo #{file.path}"
66
- debug cmd
67
- system(cmd)
68
- bufc = IO.read(file.path)
56
+ ext = fmt[:ext] || ""
57
+ file = Tempfile.new(["vmaformat", ext])
58
+ file.write(self.to_s)
59
+ file.flush
60
+
61
+ cmd = fmt[:cmd] % { file: Shellwords.escape(file.path) }
62
+ debug cmd
63
+
64
+ ignore_exit = fmt[:ignore_exit_code]
65
+ bufc = nil
66
+ case fmt[:mode]
67
+ when :inplace
68
+ ok = system("bash", "-c", cmd)
69
+ bufc = IO.read(file.path) if ok || ignore_exit
70
+ when :stdout
71
+ outfile = Tempfile.new("vmaformat_out")
72
+ ok = system("bash", "-c", "#{cmd} > #{Shellwords.escape(outfile.path)}")
73
+ bufc = IO.read(outfile.path) if ok || ignore_exit
74
+ outfile.close; outfile.unlink
69
75
  else
70
- message("No auto-format handler for file of type: #{ftype}")
76
+ message("Unknown auto-format mode: #{fmt[:mode]}")
77
+ end
78
+
79
+ file.close; file.unlink
80
+
81
+ unless bufc
82
+ message("Auto-format command failed for #{ftype}")
71
83
  return
72
84
  end
85
+
73
86
  self.update_content(bufc)
74
- center_on_current_line #TODO: needed?
75
- file.close; file.unlink
76
- infile.close; infile.unlink
87
+ @pos = tmppos.clamp(0, [self.size - 1, 0].max)
88
+ center_on_current_line
77
89
  end
78
90
 
79
91
  # Create a new line after current line and insert text on that line
@@ -86,9 +98,11 @@ class Buffer < String
86
98
  # Workaround for https://github.com/ruby-gnome/ruby-gnome/issues/1609
87
99
  def paste_start_xclip(at, register)
88
100
  @clipboard_paste_running = true
101
+ ipos = @pos # capture insertion point before the async read
102
+ paste_lines = @paste_lines
89
103
  Thread.new {
90
104
  text = `xclip -selection c -o`
91
- GLib::Idle.add { paste_finish(text, at, register); false }
105
+ GLib::Idle.add { paste_finish(text, at, register, ipos: ipos, paste_lines: paste_lines); false }
92
106
  }
93
107
  return nil
94
108
  end
@@ -101,22 +115,39 @@ class Buffer < String
101
115
  # return paste_start_xclip(at, register)
102
116
  # end
103
117
 
118
+ # Capture the insertion point now: read_text_async returns immediately and
119
+ # the callback fires on a later main-loop turn, by which time the cursor
120
+ # may have moved (queued keystroke, mouse click, etc). Without this the
121
+ # paste would land at wherever the cursor happens to be when the clipboard
122
+ # data finally arrives.
123
+ ipos = @pos
124
+ paste_lines = @paste_lines
125
+
104
126
  clipboard = vma.gui.window.display.clipboard
105
127
  clipboard.read_text_async do |_clipboard, result|
106
128
  begin
107
- text = clipboard.read_text_finish(result)
129
+ text = _clipboard.read_text_finish(result)
108
130
  rescue Gio::IOError::NotSupported
109
131
  debug Gio::IOError::NotSupported
110
132
  else
111
- paste_finish(text, at, register, overwrite: overwrite)
133
+ paste_finish(text, at, register, overwrite: overwrite, ipos: ipos, paste_lines: paste_lines)
112
134
  end
113
135
  end
114
136
  return nil
115
137
  end
116
138
 
117
- def paste_finish(text, at, register, overwrite: false)
139
+ # ipos/paste_lines: when given, restore the cursor position and line-paste
140
+ # state captured when the paste was initiated (see paste_start). nil means
141
+ # use the live state (synchronous/macro path), preserving prior behavior.
142
+ def paste_finish(text, at, register, overwrite: false, ipos: nil, paste_lines: nil)
118
143
  debug "PASTE: #{text}"
119
144
 
145
+ @paste_lines = paste_lines unless paste_lines.nil?
146
+ if !ipos.nil?
147
+ # Clamp in case the buffer shrank during the async window.
148
+ set_pos(ipos.clamp(0, [size - 1, 0].max))
149
+ end
150
+
120
151
  # If we did not put this text to clipboard
121
152
  if text != vma.clipboard[-1]
122
153
  @paste_lines = false
@@ -191,8 +222,8 @@ class Buffer < String
191
222
  p = @pos
192
223
  return if !is_legal_pos(p)
193
224
  (word, range) = get_word_in_pos(p, boundary: :word2)
194
- if word.match(/(true|false)/i)
195
- rep = flip_true_false(word)
225
+ if x = flip_term(word)
226
+ rep = x
196
227
  else
197
228
  num = word.to_i
198
229
  num += 1
@@ -214,6 +245,8 @@ class Buffer < String
214
245
  end
215
246
 
216
247
  def replace_range(range, text)
248
+ # add_delta restores the final "\n" of the buffer if the range deleted it
249
+ text = text.delete_suffix("\n") if range.last >= self.size - 1
217
250
  delete_range(range.first, range.last)
218
251
  insert_txt_at(text, range.begin)
219
252
  end
@@ -226,9 +259,12 @@ class Buffer < String
226
259
  debug range.inspect
227
260
  debug range.inspect
228
261
  debug "------"
229
- delete_range(range.first, range.last)
230
- pos = [range.first, @pos].min
231
- set_pos(pos)
262
+ # Flash the range first so it is visible before the text is removed. When
263
+ # flashing is inactive (tests, config off) the block runs synchronously.
264
+ Gui.flash_range(self, range) do
265
+ delete_range(range.first, range.last)
266
+ set_pos([range.first, @pos].min)
267
+ end
232
268
  return true
233
269
  end
234
270
 
@@ -267,6 +303,30 @@ class Buffer < String
267
303
  #recalc_line_ends
268
304
  calculate_line_and_column_pos
269
305
  #need_redraw!
306
+
307
+ if vma.kbd&.get_mode == :insert
308
+ v = (self.view rescue nil)
309
+ v.autocp_on_delete if v.respond_to?(:autocp_on_delete)
310
+ end
311
+ end
312
+
313
+ # Move the text in range (inclusive, like get_visual_mode_range) so that it
314
+ # starts at insertion point target of the current text, with the cursor at
315
+ # its new start. One undo step; the clipboard is left alone. Returns the
316
+ # moved text's new range, or nil when target is inside (or right after) the
317
+ # range, i.e. nothing would move.
318
+ def move_text(range, target)
319
+ s, e = range.begin, range.end
320
+ return nil if s > e or target.nil? or (target >= s and target <= e + 1)
321
+ txt = self[s..e]
322
+ new_undo_group
323
+ add_delta([s, DELETE, txt.size], true)
324
+ t = target > e ? target - txt.size : target
325
+ add_delta([t, INSERT, txt.size, txt], true)
326
+ new_undo_group
327
+ calculate_line_and_column_pos
328
+ set_pos(t)
329
+ return t..(t + txt.size - 1)
270
330
  end
271
331
 
272
332
  def delete_range(startpos, endpos, x = nil)
@@ -301,12 +361,7 @@ class Buffer < String
301
361
  end
302
362
 
303
363
  def delete_line()
304
- vma.kbd.method_handles_repeat = true
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
364
+ num_lines = get_repeat_num()
310
365
  lrange = line_range(@lpos, num_lines)
311
366
  s = self[lrange]
312
367
  add_delta([lrange.begin, DELETE, lrange.end - lrange.begin + 1], true)
@@ -317,6 +372,10 @@ class Buffer < String
317
372
  end
318
373
 
319
374
  def insert_tab
375
+ if visual_mode?
376
+ indent_selection
377
+ return
378
+ end
320
379
  convert = cnf.tab.to_spaces_default?
321
380
  convert = true if cnf.tab.to_spaces_languages?.include?(@lang)
322
381
  convert = false if cnf.tab.to_spaces_not_languages?.include?(@lang)
@@ -341,3 +400,4 @@ class Buffer < String
341
400
  add_image(fname, imgpos)
342
401
  end
343
402
  end
403
+ 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
@@ -1,3 +1,5 @@
1
+
2
+ module Vimamsa
1
3
  def save_buffer_list()
2
4
  message("Save buffer list")
3
5
  buffn = get_dot_path("buffers.txt")
@@ -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
@@ -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: "#666666ff")
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
@@ -1,3 +1,5 @@
1
+
2
+ module Vimamsa
1
3
  class Clipboard
2
4
  def initialize
3
5
  @clipboard = []
@@ -34,3 +36,4 @@ def set_system_clipboard(arg)
34
36
  debug arg,2
35
37
  vma.gui.window.display.clipboard.set(arg)
36
38
  end
39
+ end # module Vimamsa
data/lib/vimamsa/conf.rb CHANGED
@@ -134,16 +134,36 @@ cnf.lsp.enabled = false
134
134
  cnf.fexp.experimental = false
135
135
  cnf.experimental = false
136
136
 
137
+ cnf.autocomplete.enabled = false # opt-in: enable in custom.rb
138
+ cnf.autocomplete.auto_trigger = true # popup while typing (false: manual key only)
139
+ cnf.autocomplete.min_chars = 2 # min typed word chars before auto popup
140
+ cnf.autocomplete.max_items = 50 # candidates kept in the list
141
+ cnf.autocomplete.visible_items = 10 # popup height in rows, rest scrolls
142
+ cnf.autocomplete.lsp.enabled = true # effective only if cnf.lsp.enabled
143
+ cnf.autocomplete.lsp.debounce = 0.15 # seconds to wait before asking the server
144
+
137
145
  cnf.kbd.show_prev_action = true
138
146
 
139
- cnf.tab.width = 2
147
+ cnf.keybindings.scheme = "vimlike" # "vimlike" | "notepad" (applied on restart)
148
+
149
+ cnf.tab.width = 4
150
+ # Saving a file whose encoding / line endings are not UTF-8 + \n:
151
+ # "ask" (once per file), "keep" (original format) or "convert" (UTF-8 + \n)
152
+ cnf.file_format.on_save = "ask"
140
153
  cnf.tab.to_spaces_default = false
141
- cnf.tab.to_spaces_languages = ["c", "java", "ruby", "hyperplaintext", "php"]
154
+ cnf.tab.to_spaces_languages = ["c", "java", "ruby", "hyperplaintext", "php", "python"]
142
155
  cnf.tab.to_spaces_not_languages = ["makefile"]
143
156
  cnf.workspace_folders = []
144
157
 
145
158
  cnf.match.highlight.color = "#10bd8e"
146
159
 
160
+ cnf.flash.enabled = true # briefly flash the range yanked/deleted (y ', d ', d w, ...)
161
+ cnf.flash.duration = 0.15 # seconds the flash stays visible
162
+
163
+ cnf.fold.start_closed = true # collapse {{{ ... }}} marker folds when a file is loaded
164
+
165
+ cnf.modules.color_highlight.enabled = true # paint #rrggbb hex codes with their color
166
+
147
167
  cnf.lsp.enabled = false
148
168
 
149
169
  cnf.font.size = 11
@@ -157,8 +177,44 @@ cnf.undo.group_threshold = 1.8 # seconds of inactivity before starting a new und
157
177
 
158
178
  cnf.paste.cursor_at_start = false
159
179
 
180
+ # Drag selected text with the mouse to move it. Pressing inside the selection
181
+ # then starts a move instead of a new selection.
182
+ cnf.mouse.drag_selection = true
183
+
184
+ # Start with the window size and columns/panels the editor had when it was
185
+ # last closed (saved per screen resolution, see VMAgui#save_window_layout).
186
+ cnf.restore_layout = true
187
+
188
+ cnf.auto_chmod_exec = true
189
+
190
+ # Auto-format commands. %{file} is replaced with the (escaped) temp file path.
191
+ # mode :stdout — command writes formatted output to stdout
192
+ # mode :inplace — command modifies %{file} in place
193
+ # Override or extend in custom.rb, e.g.:
194
+ # cnf.auto_format.formatters!["ruby"] = { cmd: "rubocop -a --no-color 2>/dev/null %{file}", mode: :inplace, ignore_exit_code: true, ext: ".rb" }
195
+ cnf.auto_format.formatters = {
196
+ "c" => { cmd: "clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' %{file}", mode: :stdout },
197
+ "chdr" => { cmd: "clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' %{file}", mode: :stdout },
198
+ "cpp" => { cmd: "clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' %{file}", mode: :stdout },
199
+ "cpphdr" => { cmd: "clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' %{file}", mode: :stdout },
200
+ "Javascript" => { cmd: "clang-format %{file}", mode: :stdout },
201
+ "ruby" => { cmd: "rufo %{file}", mode: :inplace, ext: ".rb", ignore_exit_code: true },
202
+ }
203
+
204
+ # Comment character rules: checked in order, first match wins.
205
+ # Each entry is { pattern: /regexp/, char: "string" } matched against the filename.
206
+ # Add entries in custom.rb, e.g.:
207
+ # cnf.comment_chars! << { pattern: /\.py$/, char: "#" }
208
+ cnf.comment_chars = [
209
+ { pattern: /Dockerfile(\.|$)/i, char: "#" },
210
+ { pattern: /\.(sh|bash|zsh|yml|yaml|rb|py|pl|r|conf|toml|ini)$/i, char: "#" },
211
+ { pattern: /Makefile$/i, char: "#" },
212
+ { pattern: /\.(c|cpp|h|hpp|java|js|ts|cs|go|swift)$/i, char: "//" },
213
+ ]
214
+
160
215
  cnf.style_scheme = "molokai_edit"
216
+ cnf.color_adjustments.enabled = true
161
217
  cnf.color_contrast = 1.0
162
218
  cnf.color_brightness = 0.0
163
-
219
+ cnf.theme.cyberpunk_glow = true
164
220
 
@@ -1,4 +1,6 @@
1
1
 
2
+ module Vimamsa
3
+
2
4
  NEXT_MARK = 1001
3
5
  PREVIOUS_MARK = 1002
4
6
  BACKWARD = 1003
@@ -32,3 +34,4 @@ KEY_RELEASE = 7 # QEvent::KeyRelease
32
34
 
33
35
 
34
36
 
37
+ end # module Vimamsa
@@ -0,0 +1,149 @@
1
+ require "fileutils"
2
+ require "json"
3
+
4
+ module Vimamsa
5
+
6
+ # Captures debug information when the editor crashes.
7
+ #
8
+ # Two kinds of crash are handled:
9
+ # * Ruby exceptions that reach the top level (uncaught) — a structured
10
+ # report (backtrace + editor state snapshot) is written.
11
+ # * Native crashes / segfaults (from the C extension, GTK, etc.) — these
12
+ # kill the process before any Ruby handler can run, so we tee the process
13
+ # stderr (where Ruby prints its native crash dump) into a persistent log.
14
+ #
15
+ # Reports go to ~/.config/vimamsa/crash/ .
16
+ module CrashHandler
17
+ @installed = false
18
+
19
+ def self.crash_dir
20
+ dir = get_dot_path("crash")
21
+ FileUtils.mkdir_p(dir)
22
+ dir
23
+ end
24
+
25
+ # Install stderr capture + at_exit hook. Safe to call once, early in startup.
26
+ def self.setup
27
+ return if @installed
28
+ @installed = true
29
+ capture_stderr
30
+ install_at_exit
31
+ rescue => e
32
+ # Never let crash-handler setup itself take down startup.
33
+ warn "CrashHandler.setup failed: #{e}"
34
+ end
35
+
36
+ # Redirect the real stderr fd through `tee` so native crash dumps (which are
37
+ # written to fd 2 by Ruby's own SIGSEGV handler) are saved to a file while
38
+ # still showing on the console.
39
+ def self.capture_stderr
40
+ log = File.join(crash_dir, "stderr.log")
41
+ return unless which("tee")
42
+ tee = IO.popen(["tee", "-a", log], "w")
43
+ banner = "\n===== vimamsa session start #{Time.now.strftime("%Y-%m-%d %H:%M:%S")} (pid #{Process.pid}) =====\n"
44
+ tee.write(banner)
45
+ tee.flush
46
+ $stderr.reopen(tee)
47
+ $stderr.sync = true
48
+ rescue => e
49
+ warn "CrashHandler.capture_stderr failed: #{e}"
50
+ end
51
+
52
+ def self.install_at_exit
53
+ at_exit do
54
+ e = $!
55
+ # Only report abnormal termination (an unhandled exception), not a
56
+ # clean quit or a plain SystemExit(0).
57
+ if e && !(e.is_a?(SystemExit) && e.success?)
58
+ report("exception", e)
59
+ end
60
+ end
61
+ end
62
+
63
+ # Write a structured crash report. Every field is best-effort: a failure to
64
+ # collect one part must not prevent writing the rest.
65
+ def self.report(kind, exception = nil, extra = nil)
66
+ info = {}
67
+ info["kind"] = kind
68
+ info["time"] = Time.now.strftime("%Y-%m-%d %H:%M:%S")
69
+ info["pid"] = Process.pid
70
+ info["ruby"] = RUBY_DESCRIPTION
71
+ info["extra"] = extra if extra
72
+
73
+ if exception
74
+ info["exception"] = "#{exception.class}: #{exception.message}"
75
+ info["backtrace"] = (exception.backtrace || [])
76
+ else
77
+ info["backtrace"] = caller
78
+ end
79
+
80
+ add(info, "last_action") { vma.actions.last_action }
81
+ add(info, "log_messages") { $log_messages.last(50) }
82
+ add(info, "errors") { $errors.last(20) }
83
+ add(info, "buffer") {
84
+ b = buf
85
+ { "fname" => b.fname, "pos" => b.pos, "lpos" => b.lpos, "cpos" => b.cpos,
86
+ "size" => b.size, "str_head" => b.to_s[0, 4000] }
87
+ }
88
+ add(info, "open_files") { vma.buffers.list.map { |b| b.fname }.compact }
89
+
90
+ ts = Time.now.strftime("%Y%m%d_%H%M%S")
91
+ base = File.join(crash_dir, "crash_#{ts}_#{Process.pid}")
92
+ write_file("#{base}.txt", format_text(info))
93
+ write_file("#{base}.json", safe_json(info))
94
+
95
+ warn "vimamsa: crash report saved to #{base}.txt"
96
+ base
97
+ rescue => e
98
+ warn "CrashHandler.report failed: #{e}"
99
+ nil
100
+ end
101
+
102
+ # ── helpers ────────────────────────────────────────────────────────────────
103
+
104
+ def self.add(info, key)
105
+ info[key] = yield
106
+ rescue => e
107
+ info[key] = "<unavailable: #{e.class}>"
108
+ end
109
+
110
+ def self.format_text(info)
111
+ out = []
112
+ out << "kind: #{info["kind"]}"
113
+ out << "time: #{info["time"]}"
114
+ out << "pid: #{info["pid"]}"
115
+ out << "ruby: #{info["ruby"]}"
116
+ out << "exception: #{info["exception"]}" if info["exception"]
117
+ out << "last_action: #{info["last_action"].inspect}"
118
+ out << ""
119
+ out << "--- backtrace ---"
120
+ out.concat(Array(info["backtrace"]))
121
+ out << ""
122
+ out << "--- open files ---"
123
+ out.concat(Array(info["open_files"]))
124
+ out << ""
125
+ out << "--- current buffer ---"
126
+ out << info["buffer"].inspect
127
+ out << ""
128
+ out << "--- recent log messages ---"
129
+ out.concat(Array(info["log_messages"]).map(&:to_s))
130
+ out << ""
131
+ out << "--- recent errors ---"
132
+ out.concat(Array(info["errors"]).map(&:inspect))
133
+ out.join("\n") + "\n"
134
+ end
135
+
136
+ def self.safe_json(info)
137
+ JSON.pretty_generate(info)
138
+ rescue
139
+ # Fall back to inspecting values that can't be serialized cleanly.
140
+ JSON.pretty_generate(info.transform_values { |v| v.is_a?(String) ? v : v.inspect })
141
+ end
142
+
143
+ def self.write_file(path, content)
144
+ IO.write(path, content)
145
+ rescue => e
146
+ warn "CrashHandler: could not write #{path}: #{e}"
147
+ end
148
+ end
149
+ end # module Vimamsa
data/lib/vimamsa/debug.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "fileutils"
2
2
 
3
+ module Vimamsa
4
+
3
5
  def debug(message, severity = 1)
4
6
  if cnf.debug?
5
7
  if severity > 1
@@ -49,7 +51,7 @@ end
49
51
  def crash(message, e = nil)
50
52
  puts "FATAL ERROR:#{message}"
51
53
  puts caller().join("\n")
52
- # savedebug(message, e)
54
+ CrashHandler.report("fatal", e, message)
53
55
  _quit()
54
56
  end
55
57
 
@@ -146,3 +148,4 @@ end
146
148
  def start_ripl
147
149
  Ripl.start :binding => binding
148
150
  end
151
+ end # module Vimamsa