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.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +17 -10
  3. data/Dockerfile +2 -2
  4. data/README.md +162 -90
  5. data/custom_example.rb +33 -15
  6. data/doc/TODO.md +334 -110
  7. data/doc/action_names_plan.md +442 -0
  8. data/doc/bundling_plan.md +2 -1
  9. data/doc/delta_syntax_plan.md +293 -0
  10. data/doc/demo_recording_plan.md +288 -0
  11. data/doc/design_goals.md +27 -0
  12. data/doc/intro_page_plan.md +266 -0
  13. data/doc/key_bindings_report_plan.md +45 -0
  14. data/doc/line_tree_plan.md +89 -0
  15. data/doc/missing_vim_bindings.md +34 -44
  16. data/doc/modules_settings_plan.md +1 -1
  17. data/doc/registries_plan.md +202 -0
  18. data/doc/startup_speed_plan.md +97 -0
  19. data/doc/test_commands.md +232 -0
  20. data/doc/treap_visualizer.html +585 -0
  21. data/doc/vim_compatibility_plan.md +186 -31
  22. data/doc/vimlike_vim_conflicts.md +236 -228
  23. data/doc/vm_snapshots_plan.md +4 -4
  24. data/doc/wysiwyg_plan.md +231 -0
  25. data/docker_cmd.sh +1 -1
  26. data/exe/run_tests.rb +85 -3
  27. data/exe/vimamsa +49 -6
  28. data/help/intro.txt +30 -0
  29. data/help/vim_intro.txt +31 -0
  30. data/img/demo.gif +0 -0
  31. data/img/demo.mp4 +0 -0
  32. data/lang/hyperplaintext.lang +1 -1
  33. data/lib/vimamsa/ack.rb +2 -0
  34. data/lib/vimamsa/actions.rb +381 -36
  35. data/lib/vimamsa/bookmarks.rb +8 -8
  36. data/lib/vimamsa/buffer.rb +84 -38
  37. data/lib/vimamsa/buffer_changetext.rb +58 -36
  38. data/lib/vimamsa/buffer_list.rb +2 -2
  39. data/lib/vimamsa/buffer_manager.rb +6 -6
  40. data/lib/vimamsa/cli_help.rb +75 -0
  41. data/lib/vimamsa/clipboard.rb +6 -3
  42. data/lib/vimamsa/conf.rb +9 -0
  43. data/lib/vimamsa/crash_handler.rb +2 -2
  44. data/lib/vimamsa/debug.rb +2 -2
  45. data/lib/vimamsa/demo_player.rb +494 -0
  46. data/lib/vimamsa/demo_recorder.rb +277 -0
  47. data/lib/vimamsa/diff_buffer.rb +1 -1
  48. data/lib/vimamsa/dot_repeat.rb +104 -0
  49. data/lib/vimamsa/easy_jump.rb +54 -3
  50. data/lib/vimamsa/editor.rb +136 -65
  51. data/lib/vimamsa/file_history.rb +1 -1
  52. data/lib/vimamsa/file_manager.rb +23 -23
  53. data/lib/vimamsa/form_input.rb +388 -0
  54. data/lib/vimamsa/gui.rb +89 -13
  55. data/lib/vimamsa/gui_command_line.rb +44 -5
  56. data/lib/vimamsa/gui_form_generator.rb +17 -6
  57. data/lib/vimamsa/gui_func_panel.rb +1 -1
  58. data/lib/vimamsa/gui_key_hint.rb +165 -0
  59. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  60. data/lib/vimamsa/gui_menu.rb +69 -50
  61. data/lib/vimamsa/gui_select_window.rb +77 -43
  62. data/lib/vimamsa/gui_settings.rb +9 -5
  63. data/lib/vimamsa/gui_sourceview.rb +28 -81
  64. data/lib/vimamsa/gui_theme.rb +11 -2
  65. data/lib/vimamsa/hook.rb +2 -0
  66. data/lib/vimamsa/intro_page.rb +367 -0
  67. data/lib/vimamsa/key_actions.rb +315 -225
  68. data/lib/vimamsa/key_binding_tree.rb +228 -61
  69. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  70. data/lib/vimamsa/key_bindings_report.rb +290 -67
  71. data/lib/vimamsa/key_bindings_vim.rb +43 -297
  72. data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
  73. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  74. data/lib/vimamsa/key_names.rb +80 -0
  75. data/lib/vimamsa/langservp.rb +62 -7
  76. data/lib/vimamsa/line_tree.rb +367 -0
  77. data/lib/vimamsa/macro.rb +20 -3
  78. data/lib/vimamsa/rbvma.rb +15 -0
  79. data/lib/vimamsa/registers.rb +125 -0
  80. data/lib/vimamsa/run_ruby.rb +64 -0
  81. data/lib/vimamsa/search_replace.rb +4 -4
  82. data/lib/vimamsa/string_util.rb +17 -3
  83. data/lib/vimamsa/tests.rb +8 -8
  84. data/lib/vimamsa/text_objects.rb +11 -54
  85. data/lib/vimamsa/text_transforms.rb +4 -0
  86. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  87. data/lib/vimamsa/user_dirs.rb +83 -0
  88. data/lib/vimamsa/version.rb +1 -1
  89. data/lib/vimamsa/vim_operators.rb +365 -0
  90. data/modules/calculator/calculator.rb +5 -5
  91. data/modules/color_highlight/color_highlight.rb +3 -3
  92. data/modules/dictation/dictation.rb +32 -32
  93. data/modules/ollama/ollama.rb +5 -5
  94. data/modules/terminal/terminal.rb +5 -5
  95. data/modules/tts/tts.rb +10 -10
  96. data/run_e2e_vm.sh +3 -3
  97. data/run_tests_vm.rb +163 -0
  98. data/scripts/appimage/AppRun +7 -0
  99. data/scripts/appimage/build_in_container.sh +11 -1
  100. data/scripts/appimage/smoke_test.sh +1 -1
  101. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  102. data/scripts/demo/demo_files_steps.txt +52 -0
  103. data/scripts/demo/demo_steps.txt +9 -1
  104. data/scripts/demo/notes.txt +6 -0
  105. data/scripts/demo/record_demo.rb +60 -81
  106. data/scripts/demo/report.rb +7 -0
  107. data/scripts/demo/shapes.rb +1 -0
  108. data/scripts/demo/square/shapes.rb +29 -0
  109. data/scripts/demo/square/steps.txt +185 -0
  110. data/scripts/lib/perf_startup.rb +138 -0
  111. data/scripts/lib/script_helpers.rb +53 -0
  112. data/scripts/perf_compare.rb +34 -0
  113. data/scripts/profile_startup.rb +72 -0
  114. data/tests/test_action_ids.rb +232 -0
  115. data/tests/test_auto_format.rb +2 -2
  116. data/tests/test_autocomplete.rb +1 -1
  117. data/tests/test_basic_editing.rb +18 -18
  118. data/tests/test_bookmarks.rb +6 -6
  119. data/tests/test_bracket_match.rb +3 -0
  120. data/tests/test_cli_help.rb +64 -0
  121. data/tests/test_color_highlight.rb +2 -2
  122. data/tests/test_command_line.rb +1 -1
  123. data/tests/test_context_menu_file.rb +18 -0
  124. data/tests/test_copy_paste.rb +33 -33
  125. data/tests/test_custom_two_phase.rb +1 -1
  126. data/tests/test_demo_player.rb +355 -0
  127. data/tests/test_demo_recorder.rb +202 -0
  128. data/tests/test_dictation.rb +16 -16
  129. data/tests/test_dot_repeat.rb +88 -0
  130. data/tests/test_easy_jump.rb +93 -0
  131. data/tests/test_extract_file_links.rb +3 -3
  132. data/tests/test_file_panel.rb +2 -2
  133. data/tests/test_flash.rb +1 -1
  134. data/tests/test_fold.rb +1 -1
  135. data/tests/test_form_input.rb +203 -0
  136. data/tests/test_func_panel.rb +2 -2
  137. data/tests/test_gtk_sync.rb +7 -7
  138. data/tests/test_intro_page.rb +437 -0
  139. data/tests/test_key_categories.rb +163 -0
  140. data/tests/test_keylog_panel.rb +163 -3
  141. data/tests/test_line_ends.rb +51 -0
  142. data/tests/test_line_tree.rb +86 -0
  143. data/tests/test_lsp_clangd.rb +2 -2
  144. data/tests/test_lsp_root.rb +43 -0
  145. data/tests/test_macro.rb +2 -2
  146. data/tests/test_module_interface.rb +9 -9
  147. data/tests/test_notepad_bindings.rb +5 -5
  148. data/tests/test_perf_startup.rb +28 -0
  149. data/tests/test_random_edit.rb +27 -27
  150. data/tests/test_registers.rb +131 -0
  151. data/tests/test_run_ruby.rb +77 -0
  152. data/tests/test_startup_file.rb +45 -4
  153. data/tests/test_text_objects.rb +1 -1
  154. data/tests/test_text_transforms.rb +12 -0
  155. data/tests/test_tmp_user_dir.rb +79 -0
  156. data/tests/test_tts.rb +10 -10
  157. data/tests/test_undo.rb +34 -34
  158. data/tests/test_user_dirs.rb +122 -0
  159. data/tests/test_vim_bindings.rb +107 -6
  160. data/tests/test_vim_conflicts.rb +41 -4
  161. data/tests/test_vim_operators.rb +116 -0
  162. data/tests/test_window_layout.rb +83 -0
  163. data/vimamsa.gemspec +1 -1
  164. data/vm_guest_run.sh +75 -28
  165. metadata +60 -4
  166. data/run_tests.rb +0 -89
  167. data/run_tests_vm.sh +0 -130
@@ -7,7 +7,7 @@ class Editor
7
7
  attr_reader :file_content_search_paths, :file_name_search_paths, :gui, :hook, :macro, :actions
8
8
  # @!attribute [rw] kbd
9
9
  # @return [KeyBindingTree]
10
- attr_accessor :converters, :fh, :bookmarks, :paint_stack, :kbd, :langsrv, :register, :cur_register, :clipboard
10
+ attr_accessor :converters, :fh, :bookmarks, :paint_stack, :kbd, :langsrv, :registers, :clipboard, :dot
11
11
  #attr_writer :call_func, :update_highlight
12
12
 
13
13
  def initialize()
@@ -24,19 +24,14 @@ class Editor
24
24
  @paint_stack = []
25
25
  @_plugins = {}
26
26
  @errors
27
- @register = Hash.new("")
28
- @cur_register = "a"
27
+ @registers = Registers.new
28
+ @dot = DotRepeat.new
29
29
  @clipboard = Clipboard.new
30
30
  end
31
31
 
32
+ # "x: use register char for the next copy, delete or put (registers.rb)
32
33
  def set_register(char)
33
- @cur_register = char
34
- message("Set register #{char}")
35
- end
36
-
37
- def paste_register(char)
38
- $c = @cur_register #TODO:??
39
- message("Paste: #{$c}")
34
+ @registers.select(char)
40
35
  end
41
36
 
42
37
  def open_file_listener(added)
@@ -100,7 +95,12 @@ class Editor
100
95
  end
101
96
  }
102
97
 
103
- @kbd.on(:mode_set) { |label| vma.buf&.new_undo_group }
98
+ # A mode change starts a new undo step, except inside a group run as one
99
+ # step (a macro, a "." repeat)
100
+ @kbd.on(:mode_set) { |label|
101
+ b = vma.buf
102
+ b.new_undo_group if b && !b.instance_variable_get(:@macro_group_active)
103
+ }
104
104
  @kbd.on(:mode_changed) { |label|
105
105
  if label != :insert
106
106
  # Dismiss the autocomplete popup when leaving insert mode
@@ -117,18 +117,41 @@ class Editor
117
117
  }
118
118
  @kbd.on(:key_no_match) { |c, trail| vma.gui.keylog_panel&.log_nomatch(c, trail) }
119
119
  @kbd.on(:key_pending) { |trail| vma.gui.keylog_panel&.log_pending(trail) }
120
- @kbd.on(:key_action) { |trail, action| vma.gui.keylog_panel&.log_action(trail, action) }
120
+ @kbd.on(:key_action) { |trail, action|
121
+ vma.gui.keylog_panel&.log_action(trail, action)
122
+ @dot.before(action) # "." (dot_repeat.rb)
123
+ }
121
124
  @kbd.on(:action_executed) { |action, ret|
122
125
  if vma.macro.is_recording and ret != false
123
126
  debug "RECORD ACTION:#{action}", 2
124
127
  vma.macro.record_action(action)
125
128
  end
126
129
  }
127
- @kbd.on(:action_handled) { |trail, action| vma.gui.show_action_trail(trail, action) }
130
+ @kbd.on(:action_handled) { |trail, action|
131
+ vma.gui.show_action_trail(trail, action)
132
+ # A "x register applies to the next command only (counts may come
133
+ # between: "a3yy)
134
+ a = action.to_s
135
+ @registers.clear_pending if !a.include?("edit.register!") && !a.include?("kbd.count.digit")
136
+ @dot.after(action)
137
+ }
138
+ end
139
+
140
+ # Moves the files of older versions to their new places, once
141
+ # (UserDirs.migrate). Only with the default dirs: with --user-dir (tests,
142
+ # --tmp-user-dir) config and data share one dir and nothing moves.
143
+ def migrate_user_files
144
+ return if !UserDirs.default_config_dir?(vma_user_dir)
145
+ UserDirs.migrate(config_dir: vma_user_dir, data_dir: vma_data_dir).each { |from, to|
146
+ puts "vimamsa: moved #{from} to #{to}"
147
+ }
148
+ rescue => e
149
+ debug "migrate_user_files: #{e}"
128
150
  end
129
151
 
130
152
  def start
131
153
  @gui = $vmag #TODO
154
+ migrate_user_files
132
155
 
133
156
  $hook = Hook.new
134
157
  @hook = $hook
@@ -170,6 +193,9 @@ class Editor
170
193
  require "vimamsa/key_bindings_vimlike"
171
194
  end
172
195
 
196
+ # Form input mode and its keys, in every scheme (form_input.rb)
197
+ form_input_setup
198
+
173
199
  $buffers = BufferList.new
174
200
  $minibuffer = Buffer.new(">", "")
175
201
  @langsrv = {}
@@ -186,8 +212,8 @@ class Editor
186
212
  @gui.init_menu
187
213
 
188
214
  mkdir_if_not_exists(get_dot_path(""))
189
- mkdir_if_not_exists(get_dot_path("backup"))
190
- listen_dir = get_dot_path("listen")
215
+ mkdir_if_not_exists(get_data_path("backup"))
216
+ listen_dir = get_data_path("listen")
191
217
  mkdir_if_not_exists(listen_dir)
192
218
  listener = Listen.to(listen_dir) do |modified, added, removed|
193
219
  debug([modified: modified, added: added, removed: removed])
@@ -209,7 +235,8 @@ class Editor
209
235
  # they register goes in phase 2 (hook_custom_after_init, called at the end of
210
236
  # start; see call_custom_after_init).
211
237
  custom_script = read_file("", custom_fn)
212
- eval(custom_script) if custom_script
238
+ # bindings made by custom.rb get the keyword "custom" (key bindings page)
239
+ vma.kbd.with_keywords(["custom"]) { eval(custom_script) } if custom_script
213
240
 
214
241
  Grep.init
215
242
  FileManager.init
@@ -219,12 +246,11 @@ class Editor
219
246
  require "vimamsa/audio"
220
247
  end
221
248
 
222
- if cnf.lsp.enabled?
223
- require "vimamsa/langservp"
224
- @langsrv["ruby"] = LangSrv.new("ruby")
225
- @langsrv["cpp"] = LangSrv.new("cpp")
226
- #TODO: if language enabled in config?
227
- end
249
+ # LSP servers start when a file of their language is opened (LangSrv.get,
250
+ # in the file's project), not here: a server started at startup ran in the
251
+ # editor's current directory (often the home directory, which ruby-lsp
252
+ # then indexed whole) and blocked startup while it initialized
253
+ require "vimamsa/langservp" if cnf.lsp.enabled?
228
254
 
229
255
  # Load each module that is enabled in settings.
230
256
  # Each module lives in modules/<name>/<name>.rb and may optionally define
@@ -237,7 +263,8 @@ class Editor
237
263
  load main_file
238
264
  # Call <name>_init if the module defines it.
239
265
  init_fn = "#{mod_name}_init"
240
- send(init_fn) if respond_to?(init_fn, true)
266
+ # bindings made by the module get the keyword module:<name>
267
+ vma.kbd.with_keywords(["module:#{mod_name}"]) { send(init_fn) } if respond_to?(init_fn, true)
241
268
  end
242
269
  end
243
270
  end
@@ -299,6 +326,9 @@ class Editor
299
326
  @kbd.set_state_to_root
300
327
  @kbd.show_state_trail
301
328
 
329
+ # The introduction page on the first start, or with --intro (intro_page.rb)
330
+ show_intro_on_startup
331
+
302
332
  # AppImage: from here on, started programs get the user's environment
303
333
  restore_host_env
304
334
 
@@ -306,6 +336,9 @@ class Editor
306
336
  test_files = ARGV.select { |a| a.end_with?(".rb") && File.file?(a) }
307
337
  run_as_idle proc {
308
338
  test_files.each { |f| load f }
339
+ # VMA_TEST_CLASSES: the class filter when run_tests.rb started another
340
+ # build (VMA_TEST_APP, e.g. an AppImage)
341
+ $vma_test_class_filter ||= ENV["VMA_TEST_CLASSES"].to_s.split(",") if !ENV["VMA_TEST_CLASSES"].to_s.empty?
309
342
  classes = if $vma_test_class_filter
310
343
  $vma_test_class_filter.filter_map { |name|
311
344
  begin
@@ -358,8 +391,16 @@ class Editor
358
391
  end
359
392
  end
360
393
 
394
+ # marshal_save files the program generates, kept in the data dir; the
395
+ # others (bookmarks, named_macros) are the user's, in the config dir
396
+ DATA_VARS = %w[file_index file_history file_panel_shown macros]
397
+
398
+ def var_file_path(varname)
399
+ DATA_VARS.include?(varname.to_s) ? get_data_path(varname) : get_dot_path(varname)
400
+ end
401
+
361
402
  def save_var_to_file(varname, vardata)
362
- fn = get_dot_path(varname)
403
+ fn = var_file_path(varname)
363
404
  #TODO: check that save path is safe
364
405
  f = File.open(fn, "w")
365
406
  File.binwrite(f, vardata)
@@ -367,7 +408,7 @@ class Editor
367
408
  end
368
409
 
369
410
  def load_var_from_file(varname)
370
- fn = get_dot_path(varname)
411
+ fn = var_file_path(varname)
371
412
  if File.exist?(fn)
372
413
  vardata = IO.binread(fn)
373
414
  if vardata
@@ -399,13 +440,13 @@ class Editor
399
440
  .map { |b| b.fname }
400
441
  .compact
401
442
  .select { |f| File.exist?(f) }
402
- IO.write(get_dot_path("session.txt"), fnames.join("\n") + "\n")
443
+ IO.write(get_data_path("session.txt"), fnames.join("\n") + "\n")
403
444
  rescue => ex
404
445
  debug "save_session failed: #{ex}"
405
446
  end
406
447
 
407
448
  def check_session_restore
408
- session_path = get_dot_path("session.txt")
449
+ session_path = get_data_path("session.txt")
409
450
  return unless File.exist?(session_path)
410
451
 
411
452
  fnames = File.read(session_path).lines.map(&:strip).reject(&:empty?)
@@ -415,8 +456,7 @@ class Editor
415
456
 
416
457
  # After a restart (restart_editor) reopen the previous files silently.
417
458
  if ENV["VIMAMSA_RESTORE_SESSION"]
418
- restore_session_files(fnames)
419
- message("Session restored: #{fnames.size} file(s)")
459
+ restore_session_files(fnames) { message("Session restored: #{fnames.size} file(s)") }
420
460
  return
421
461
  end
422
462
 
@@ -430,24 +470,51 @@ class Editor
430
470
  },
431
471
  :callback => proc { |x|
432
472
  if x["yes_btn"] == "submit"
433
- restore_session_files(fnames)
434
- message("Session restored: #{label}")
473
+ restore_session_files(fnames) { message("Session restored: #{label}") }
435
474
  end
436
475
  },
437
476
  }
438
477
  PopupFormGenerator.new(params).run
439
478
  end
440
479
 
441
- def restore_session_files(fnames)
480
+ # Opens the session's files one per main loop turn, showing "Restoring
481
+ # session: 7/19" in the status bar, so the window stays responsive and shows
482
+ # how far it got; then calls the block. A file that fails to open is
483
+ # reported and skipped.
484
+ def restore_session_files(fnames, &done)
442
485
  initial = vma.buffers.list.find { |b| b.fname.nil? }
443
- fnames.each { |f| b = load_buffer(f); b&.needs_autosave_check = true }
444
- initial&.close
445
- # Loading the session switches to its last file; cnf.startup_file stays
446
- # the buffer shown on startup.
447
- if @startup_fname and (id = vma.buffers.get_buffer_by_filename(@startup_fname))
448
- vma.buffers.set_current_buffer(id)
449
- end
450
- gui.restore_column2_buffer
486
+ n = fnames.size
487
+ i = 0
488
+ finish = lambda {
489
+ gui.set_status_indicator(:session_restore, nil)
490
+ initial&.close if vma.buffers.list.any? { |b| b.equal?(initial) }
491
+ # Loading the session switches to its last file; cnf.startup_file stays
492
+ # the buffer shown on startup.
493
+ if @startup_fname and (id = vma.buffers.get_buffer_by_filename(@startup_fname))
494
+ vma.buffers.set_current_buffer(id)
495
+ end
496
+ gui.restore_column2_buffer
497
+ done&.call
498
+ }
499
+ step = lambda {
500
+ if i >= n
501
+ finish.call
502
+ next
503
+ end
504
+ f = fnames[i]
505
+ i += 1
506
+ gui.set_status_indicator(:session_restore, "Restoring session: #{i}/#{n} #{File.basename(f)}")
507
+ begin
508
+ b = load_buffer(f)
509
+ b&.needs_autosave_check = true
510
+ rescue StandardError => e
511
+ message("Could not restore #{f}: #{e.message}")
512
+ end
513
+ # Idle: lower priority than drawing, so the status shows between files
514
+ GLib::Idle.add { step.call; false }
515
+ }
516
+ gui.set_status_indicator(:session_restore, "Restoring session: 0/#{n}")
517
+ GLib::Idle.add { step.call; false }
451
518
  end
452
519
 
453
520
  def add_content_search_path(pathstr)
@@ -460,7 +527,9 @@ class Editor
460
527
  # Register converter
461
528
  def reg_conv(converter, converter_id)
462
529
  @converters[converter_id] = converter
463
- reg_act(converter_id, proc { vma.buf.convert_selected_text(converter_id) }, "Converter #{converter_id}", { :scope => [:selection] })
530
+ id = "sel.convert.#{converter_id}"
531
+ ACTION_ALIASES[converter_id.to_sym] = id # the old action id was the converter id
532
+ reg_act(id, proc { vma.buf.convert_selected_text(converter_id) }, "Converter #{converter_id}", { :scope => [:selection] })
464
533
  end
465
534
 
466
535
  def apply_conv(converter_id, txt)
@@ -744,13 +813,13 @@ def scan_word_start_marks(search_str)
744
813
  return wsmarks
745
814
  end
746
815
 
747
- # Base directory for user config/data (settings.rb, custom.rb, backups,
748
- # session, listen dir, crash reports, ...). Defaults to ~/.config/vimamsa but
749
- # can be overridden with the --user-dir switch or by setting $vma_user_dir
750
- # before startup. Tests point this at an isolated directory so they never read
751
- # or write the real user config.
816
+ # Base directory for user-edited config (settings.rb, custom.rb, styles,
817
+ # bookmarks, named macros): $XDG_CONFIG_HOME/vimamsa, by default
818
+ # ~/.config/vimamsa (user_dirs.rb). Can be overridden with the --user-dir
819
+ # switch or by setting $vma_user_dir before startup. Tests point this at an
820
+ # isolated directory so they never read or write the real user config.
752
821
  def vma_user_dir
753
- $vma_user_dir ||= File.expand_path("~/.config/vimamsa")
822
+ $vma_user_dir ||= UserDirs.default_config_dir
754
823
  end
755
824
 
756
825
  def get_dot_path(sfx)
@@ -760,20 +829,13 @@ def get_dot_path(sfx)
760
829
  return dpath
761
830
  end
762
831
 
763
- # Base directory for files the program generates (window layout, ...), as
764
- # opposed to user-edited config: $XDG_DATA_HOME/vimamsa, by default
765
- # ~/.local/share/vimamsa. When the user dir was moved (--user-dir, tests),
766
- # data goes there too, so those runs stay isolated. See doc/TODO.md (XDG item).
832
+ # Base directory for files the program generates (session, histories,
833
+ # backups, crash reports, listen dir, window layout, ...):
834
+ # $XDG_DATA_HOME/vimamsa, by default ~/.local/share/vimamsa. When the user
835
+ # dir was moved (--user-dir, tests), data goes there too, so those runs stay
836
+ # isolated (user_dirs.rb).
767
837
  def vma_data_dir
768
- $vma_data_dir ||= begin
769
- if File.expand_path(vma_user_dir) != File.expand_path("~/.config/vimamsa")
770
- vma_user_dir
771
- else
772
- base = ENV["XDG_DATA_HOME"].to_s
773
- base = File.expand_path("~/.local/share") if base.empty?
774
- File.join(base, "vimamsa")
775
- end
776
- end
838
+ $vma_data_dir ||= UserDirs.data_dir_for(vma_user_dir)
777
839
  end
778
840
 
779
841
  def get_data_path(sfx)
@@ -851,7 +913,16 @@ def restart_editor
851
913
  script = $PROGRAM_NAME
852
914
  message("Restarting...")
853
915
  # Signal the new instance to restore the session without prompting.
854
- exec({ "VIMAMSA_RESTORE_SESSION" => "1" }, ruby, script)
916
+ env = { "VIMAMSA_RESTORE_SESSION" => "1" }
917
+ # The same user dir: a --tmp-user-dir one (kept, deleted by the new
918
+ # process at quit) or a --user-dir one
919
+ args = []
920
+ if $vma_tmp_user_dir
921
+ env[TmpUserDir::ENV_KEY] = $vma_tmp_user_dir
922
+ elsif !UserDirs.default_config_dir?(vma_user_dir)
923
+ args = ["--user-dir", vma_user_dir]
924
+ end
925
+ exec(env, ruby, script, *args)
855
926
  rescue => ex
856
927
  message("Restart failed: #{ex}")
857
928
  end
@@ -859,7 +930,7 @@ end
859
930
  def reload_customrb
860
931
  custom_fn = get_dot_path("custom.rb")
861
932
  custom_script = read_file("", custom_fn)
862
- eval(custom_script) if custom_script
933
+ vma.kbd.with_keywords(["custom"]) { eval(custom_script) } if custom_script
863
934
  call_custom_after_init # everything is loaded already: run phase 2 right away
864
935
  gui_refresh_colors # apply any cnf.theme.colors/cyber overrides live
865
936
  message("Reloaded #{custom_fn}")
@@ -875,7 +946,7 @@ end
875
946
  def call_custom_after_init
876
947
  return if !respond_to?(:hook_custom_after_init, true)
877
948
  begin
878
- send(:hook_custom_after_init)
949
+ vma.kbd.with_keywords(["custom"]) { send(:hook_custom_after_init) }
879
950
  rescue Exception => e
880
951
  warn e.inspect
881
952
  warn e.backtrace
@@ -883,7 +954,7 @@ def call_custom_after_init
883
954
  end
884
955
  end
885
956
 
886
- def save_settings_to_file
957
+ def save_settings_to_file(quiet: false)
887
958
  settings_path = get_dot_path("settings.rb")
888
959
  lines = all_settings_defs.flat_map { |section| section[:settings] }.map do |s|
889
960
  key_str = "cnf." + s[:key].join(".")
@@ -891,7 +962,7 @@ def save_settings_to_file
891
962
  "#{key_str} = #{val.inspect}"
892
963
  end
893
964
  IO.write(settings_path, lines.join("\n") + "\n")
894
- message("Settings saved to #{settings_path}")
965
+ message("Settings saved to #{settings_path}") if !quiet
895
966
  end
896
967
 
897
968
  DEMO_FILES = ["demo.txt", "sheep.jpg", "README.md"]
@@ -10,7 +10,7 @@ class FileHistory
10
10
  vma.hook.register(:change_buffer, self.method("update"))
11
11
  vma.hook.register(:shutdown, self.method("save"))
12
12
 
13
- reg_act(:fhist_remove_nonexisting, proc { remove_nonexisting }, "Cleanup history, remove non-existing files")
13
+ reg_act("file.history.prune", proc { remove_nonexisting }, "Cleanup history, remove non-existing files")
14
14
 
15
15
  @history = vma.marshal_load("file_history", {})
16
16
  $search_list = []
@@ -30,42 +30,42 @@ class FileManager
30
30
  end
31
31
 
32
32
  def self.init()
33
- reg_act(:start_file_selector, proc { FileManager.new.run; vma.kbd.set_mode(:file_exp) }, "File selector")
33
+ reg_act("file.explorer", proc { FileManager.new.run; vma.kbd.set_mode(:file_exp) }, "File selector")
34
34
 
35
- reg_act(:fexp_chdir_parent, proc { FileManager.chdir_parent }, "File selector")
36
- reg_act(:fexp_select, proc { buf.module.select_line }, "")
35
+ reg_act("fexp.chdir_parent", proc { FileManager.chdir_parent }, "File selector")
36
+ reg_act("fexp.select", proc { buf.module.select_line }, "")
37
37
 
38
- reg_act(:fexp_sort_mtime, proc { FileManager.with_cur { |fm| fm.sort_mtime } }, "Sort based on time")
39
- reg_act(:fexp_sort_fname, proc { FileManager.with_cur { |fm| fm.sort_fname } }, "Sort based on file name")
38
+ reg_act("fexp.sort_mtime", proc { FileManager.with_cur { |fm| fm.sort_mtime } }, "Sort based on time")
39
+ reg_act("fexp.sort_fname", proc { FileManager.with_cur { |fm| fm.sort_fname } }, "Sort based on file name")
40
40
 
41
- bindkey "C , j f", :start_file_selector
42
- bindkey "C , f", :start_file_selector
41
+ bindkey "C , j f", "file.explorer"
42
+ bindkey "C , f", "file.explorer"
43
43
 
44
44
  # bindkey "C o", :delete_state
45
45
 
46
46
  vma.kbd.add_minor_mode("fexp", :file_exp, :command)
47
47
 
48
- bindkey "fexp o m", :fexp_sort_mtime
49
- bindkey "fexp o f", :fexp_sort_fname
48
+ bindkey "fexp o m", "fexp.sort_mtime"
49
+ bindkey "fexp o f", "fexp.sort_fname"
50
50
 
51
51
  # These are not yet safe to use
52
52
  if cnf.fexp.experimental?
53
- reg_act(:fexp_cut_file, proc { FileManager.with_cur { |fm| fm.cut_file } }, "Cut file (to paste elsewhere)")
54
- reg_act(:fexp_copy_file, proc { FileManager.with_cur { |fm| fm.copy_file } }, "Copy file (to paste elsewhere)")
55
- reg_act(:fexp_delete_file, proc { FileManager.with_cur { |fm| fm.delete_file } }, "Delete current file")
56
- reg_act(:fexp_paste_files, proc { FileManager.with_cur { |fm| fm.paste_files } }, "Move previously cut files here")
57
-
58
- bindkey "fexp d d", :fexp_cut_file
59
- bindkey "fexp y y", :fexp_copy_file
60
- bindkey "fexp d D", :fexp_delete_file
61
- bindkey "fexp p p", :fexp_paste_files
53
+ reg_act("fexp.cut_file", proc { FileManager.with_cur { |fm| fm.cut_file } }, "Cut file (to paste elsewhere)")
54
+ reg_act("fexp.copy_file", proc { FileManager.with_cur { |fm| fm.copy_file } }, "Copy file (to paste elsewhere)")
55
+ reg_act("fexp.delete_file", proc { FileManager.with_cur { |fm| fm.delete_file } }, "Delete current file")
56
+ reg_act("fexp.paste_files", proc { FileManager.with_cur { |fm| fm.paste_files } }, "Move previously cut files here")
57
+
58
+ bindkey "fexp d d", "fexp.cut_file"
59
+ bindkey "fexp y y", "fexp.copy_file"
60
+ bindkey "fexp d D", "fexp.delete_file"
61
+ bindkey "fexp p p", "fexp.paste_files"
62
62
  end
63
63
 
64
- # bindkey "fexp l", [:fexp_right, proc { debug "==fexp_right==" }, ""]
65
- bindkey "fexp h", :fexp_chdir_parent
66
- bindkey "fexp esc", [:fexp_quit, proc { FileManager.with_cur { |fm| fm.quit } }, ""]
67
- bindkey "fexp enter", :fexp_select
68
- bindkey "fexp l", :fexp_select
64
+ # bindkey "fexp l", ["fexp.right", proc { debug "==fexp_right==" }, ""]
65
+ bindkey "fexp h", "fexp.chdir_parent"
66
+ bindkey "fexp esc", ["fexp.quit", proc { FileManager.with_cur { |fm| fm.quit } }, ""]
67
+ bindkey "fexp enter", "fexp.select"
68
+ bindkey "fexp l", "fexp.select"
69
69
 
70
70
  @sort_by = :name
71
71
  end