vimamsa 0.1.27 → 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.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -12,6 +12,10 @@ $ifuncon = false
12
12
  class Buffer < String
13
13
  attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :dirname, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang, :images, :last_save, :access_time, :selection_active, :lsp, :edit_version
14
14
  attr_writer :call_func, :update_highlight
15
+ # help_page: the name of the help page shown (intro_page.rb), else nil.
16
+ # read_only: edits are refused (help pages). help_buttons: [[action,
17
+ # Gtk::Button]] of a help page's ⟦run:…⟧ links.
18
+ attr_accessor :help_page, :read_only, :help_buttons
15
19
  attr_accessor :gui_update_highlight, :update_hl_startpos, :update_hl_endpos, :hl_queue, :syntax_parser, :highlights, :gui_reset_highlight, :is_parsing_syntax, :line_ends, :bt, :line_action_handler, :module, :active_kbd_mode, :title, :subtitle, :paste_lines, :mode_stack, :default_mode, :git_root, :needs_autosave_check
16
20
 
17
21
  @@num_buffers = 0
@@ -184,6 +188,8 @@ class Buffer < String
184
188
  debug "Guessed LANG: #{lang.id}"
185
189
  @lang = lang.id
186
190
  end
191
+ # No extension to go by (e.g. a script named "build"): the #! line
192
+ @lang ||= shebang_language
187
193
  debug @lang.inspect
188
194
 
189
195
  if @lang
@@ -192,6 +198,38 @@ class Buffer < String
192
198
  return @lang
193
199
  end
194
200
 
201
+ # Interpreter in a "#!" line → GtkSourceView language id
202
+ SHEBANG_LANGS = {
203
+ /\Aruby/ => "ruby", /\Apython/ => "python3", /\A(ba|da|z|k|mk)?sh\z/ => "sh",
204
+ /\Aperl/ => "perl", /\A(node|nodejs|deno|bun)\z/ => "js", /\Alua/ => "lua",
205
+ /\Aphp/ => "php", /\Afish\z/ => "fish", /\A(tclsh|wish)/ => "tcl",
206
+ /\A[gmn]?awk\z/ => "awk", /\ARscript\z/ => "r", /\Ajulia\z/ => "julia",
207
+ /\Amake\z/ => "makefile",
208
+ }
209
+
210
+ # Language from the first line, e.g. "#!/usr/bin/env ruby" or
211
+ # "#!/bin/bash -e". Reads the file when the buffer has no text yet
212
+ # (detection runs before the content is set).
213
+ def shebang_language
214
+ first = self.empty? ? nil : self[0, 200]
215
+ if first.nil? && @fname && File.file?(@fname) && File.readable?(@fname)
216
+ first = File.open(@fname, "rb") { |f| f.read(200) }.to_s.force_encoding("UTF-8").scrub
217
+ end
218
+ line = first.to_s.lines.first.to_s
219
+ return nil unless line.start_with?("#!")
220
+ words = line[2..].strip.split
221
+ cmd = File.basename(words.shift.to_s)
222
+ if cmd == "env" # skip env's options and VAR=value: "env -S ruby -w"
223
+ words.shift while words[0] && (words[0].start_with?("-") || words[0].include?("="))
224
+ cmd = File.basename(words.shift.to_s)
225
+ end
226
+ SHEBANG_LANGS.each { |re, lang| return lang if cmd.match?(re) }
227
+ nil
228
+ rescue StandardError => e
229
+ debug "shebang_language: #{e}"
230
+ nil
231
+ end
232
+
195
233
  def set_language(lang_id)
196
234
  @lang = lang_id
197
235
  gui_set_file_lang(@id, @lang)
@@ -381,7 +419,7 @@ class Buffer < String
381
419
  indent = self[r][/\A[ \t]*/].size
382
420
  return if indent == 0
383
421
  newpos = [@pos - indent, r.begin].max
384
- delete_range(r.begin, r.begin + indent - 1)
422
+ delete_range(r.begin, r.begin + indent - 1, register: false)
385
423
  set_pos(newpos)
386
424
  end
387
425
 
@@ -722,7 +760,7 @@ class Buffer < String
722
760
  str = fold_collapse_all(str) if cnf.fold.start_closed?
723
761
 
724
762
  self.replace(str)
725
- @line_ends = scan_indexes(self, /\n/)
763
+ @line_ends = LineTree.from_string(self) # Array-like: see line_tree.rb
726
764
  words = scan_all_words
727
765
  Autocomplete.add_words(words, @id)
728
766
 
@@ -1028,7 +1066,7 @@ class Buffer < String
1028
1066
  end
1029
1067
 
1030
1068
  def get_line_end(pos)
1031
- return @line_ends.select { |x| x > pos }.min
1069
+ return @line_ends.bsearch { |x| x > pos } # @line_ends is sorted
1032
1070
  end
1033
1071
 
1034
1072
  def comment_selection(op = :comment)
@@ -1097,7 +1135,6 @@ class Buffer < String
1097
1135
  end
1098
1136
 
1099
1137
  def copy(range_id, mark = nil)
1100
- @paste_lines = false
1101
1138
  debug "range_id: #{range_id}"
1102
1139
  debug range_id.inspect
1103
1140
  range = get_range(range_id, mark: mark)
@@ -1109,9 +1146,9 @@ class Buffer < String
1109
1146
 
1110
1147
  def recalc_line_ends()
1111
1148
  t1 = Time.now
1112
- leo = @line_ends.clone
1113
- @line_ends = scan_indexes(self, /\n/)
1114
- if @line_ends == leo
1149
+ leo = @line_ends.to_a
1150
+ @line_ends = LineTree.from_string(self)
1151
+ if @line_ends.to_a == leo
1115
1152
  debug "No change to line ends"
1116
1153
  else
1117
1154
  debug "CHANGES to line ends"
@@ -1122,14 +1159,14 @@ class Buffer < String
1122
1159
  end
1123
1160
 
1124
1161
  def sanity_check_line_ends()
1125
- leo = @line_ends.clone
1126
- @line_ends = scan_indexes(self, /\n/)
1127
- if @line_ends == leo
1162
+ leo = @line_ends.to_a
1163
+ @line_ends = LineTree.from_string(self)
1164
+ if @line_ends.to_a == leo
1128
1165
  debug "No change to line ends"
1129
1166
  else
1130
1167
  debug "CHANGES to line ends"
1131
1168
  debug leo.inspect
1132
- debug @line_ends.inspect
1169
+ debug @line_ends.to_a.inspect
1133
1170
  crash("CHANGES to line ends")
1134
1171
  end
1135
1172
  end
@@ -1164,25 +1201,13 @@ class Buffer < String
1164
1201
  end
1165
1202
  end
1166
1203
 
1204
+ # changestr: the inserted text (changeamount >= 0) or the removed text.
1205
+ # O(log n) per edit (+ O(k) for k new lines), see line_tree.rb.
1167
1206
  def update_line_ends(pos, changeamount, changestr)
1168
1207
  if changeamount > -1
1169
- changeamount = changestr.size
1170
- i_nl = scan_indexes(changestr, /\n/)
1171
- i_nl.collect! { |x| x + pos }
1172
- end
1173
- # debug "change:#{changeamount}"
1174
- #TODO: this is the bottle neck in insert_txt action
1175
- @line_ends.collect! { |x|
1176
- r = nil
1177
- r = x if x < pos
1178
- r = x + changeamount if changeamount < 0 && x + changeamount >= pos
1179
- r = x + changeamount if changeamount > 0 && x >= pos
1180
- r
1181
- }.compact!
1182
-
1183
- if changeamount > -1 && i_nl.size > 0
1184
- @line_ends.concat(i_nl)
1185
- @line_ends.sort!
1208
+ @line_ends.insert(pos, changestr)
1209
+ else
1210
+ @line_ends.delete(pos, changestr)
1186
1211
  end
1187
1212
  end
1188
1213
 
@@ -1394,9 +1419,14 @@ class Buffer < String
1394
1419
  elsif wtype == :hpt_link
1395
1420
  open_new_file(word)
1396
1421
  elsif wtype == :help
1397
- if word == "keybindings"
1398
- call_action(:show_key_bindings)
1422
+ case word
1423
+ when "keybindings" then call_action("help.keys")
1424
+ when "vim_conflicts" then call_action("help.vim_conflicts")
1425
+ when *HELP_PAGES then show_help_page(word)
1426
+ else message("No help page #{word}")
1399
1427
  end
1428
+ elsif wtype == :run
1429
+ hpt_run_link(word)
1400
1430
  else
1401
1431
  #TODO
1402
1432
  end
@@ -1412,7 +1442,7 @@ class Buffer < String
1412
1442
  m << ["Sort", method("call"), :sortlines]
1413
1443
  m << ["Filter: get numbers", method("call"), :getnums_on_lines]
1414
1444
  m << ["To LaTeX itemize", method("call"), :latex_itemize]
1415
- m << ["Delete selection", method("call"), :delete_selection]
1445
+ m << ["Delete selection", method("call"), "sel.delete"]
1416
1446
 
1417
1447
  # m << ["Search in dictionary", self.method("handle_word"), nil]
1418
1448
  # m << ["Search in google", self.method("handle_word"), nil]
@@ -1429,6 +1459,10 @@ class Buffer < String
1429
1459
  m << ["Open file (xdg-open)", self.method("handle_word"), [word, wtype]]
1430
1460
  elsif wtype == :hpt_link
1431
1461
  m << ["Jump to file", self.method("handle_word"), [word, wtype]]
1462
+ elsif wtype == :run
1463
+ m << ["Run: #{word.split("|", 2)[1] || word}", self.method("handle_word"), [word, wtype]]
1464
+ elsif wtype == :help
1465
+ m << ["Open help page", self.method("handle_word"), [word, wtype]]
1432
1466
  else
1433
1467
  # m << ["TODO", self.method("handle_word"), word]
1434
1468
  m << ["Paste", method("call"), :paste_after]
@@ -1478,6 +1512,19 @@ class Buffer < String
1478
1512
  end
1479
1513
 
1480
1514
  def get_cur_nonwhitespace_word()
1515
+ # ⟦run:…⟧ / ⟦help:…⟧ links may have spaces in them. On a help page the
1516
+ # cursor sits on a link's button, just before the (hidden) link.
1517
+ link = hpt_link_at(self, @pos)
1518
+ if link.nil? && self[@pos] == HPT_BUTTON_SLOT && hpt_link_at(self, @pos + 1)&.start_with?("⟦run:")
1519
+ link = hpt_link_at(self, @pos + 1)
1520
+ end
1521
+ if link
1522
+ if (m = link.match(/\A⟦run:(.*)⟧\z/))
1523
+ return [m[1], :run]
1524
+ elsif (m = link.match(/\A⟦help:(.*)⟧\z/))
1525
+ return [m[1], :help]
1526
+ end
1527
+ end
1481
1528
  (word, range) = get_word_in_pos(@pos, boundary: :space)
1482
1529
  debug "'WORD: #{word}'"
1483
1530
  # message("Open link #{word}")
@@ -1747,7 +1794,6 @@ class Buffer < String
1747
1794
 
1748
1795
  def copy_active_selection(x = nil)
1749
1796
  debug "!COPY SELECTION vm=#{@visual_mode}"
1750
- @paste_lines = false
1751
1797
  return if !@visual_mode
1752
1798
 
1753
1799
  debug "COPY SELECTION"
@@ -1868,8 +1914,7 @@ class Buffer < String
1868
1914
 
1869
1915
  def copy_line()
1870
1916
  num_lines = get_repeat_num()
1871
- vma.clipboard.set(self[line_range(@lpos, num_lines)])
1872
- @paste_lines = true
1917
+ vma.clipboard.set(self[line_range(@lpos, num_lines)], linewise: true)
1873
1918
  end
1874
1919
 
1875
1920
  def put_file_path_to_clipboard
@@ -1884,7 +1929,7 @@ class Buffer < String
1884
1929
  return if !@visual_mode #TODO: this should not happen
1885
1930
 
1886
1931
  _start, _end = get_visual_mode_range
1887
- vma.clipboard.set(self[_start, _end])
1932
+ vma.clipboard.set(self[_start, _end], kind: :delete)
1888
1933
  end_visual_mode
1889
1934
  end
1890
1935
 
@@ -2058,7 +2103,7 @@ class Buffer < String
2058
2103
  end
2059
2104
 
2060
2105
  def refresh_title
2061
- if vma.buf == self
2106
+ if vma.buf.equal?(self) # a Buffer is a String: == compares the text
2062
2107
  mod = unsaved_changes?
2063
2108
  pfx = mod ? "+ " : ""
2064
2109
  gui_set_window_title(pfx + title, subtitle, modified: mod)
@@ -2218,7 +2263,8 @@ class Buffer < String
2218
2263
  fname = @fname
2219
2264
  return if !@fname
2220
2265
  spfx = fname.gsub("=", "==").gsub("/", "=:")
2221
- spath = File.expand_path("~/.vimamsa/backup")
2266
+ spath = get_data_path("backup")
2267
+ FileUtils.mkdir_p(spath) rescue nil
2222
2268
  return false if !can_save_to_directory?(spath)
2223
2269
  datetime = DateTime.now().strftime("%d%m%Y:%H%M%S")
2224
2270
  savepath = "#{spath}/#{spfx}_#{datetime}"
@@ -7,6 +7,10 @@ class Buffer < String
7
7
 
8
8
  #TODO: change to apply=true as default
9
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
10
14
  @t_modified = Time.now
11
15
  return if !is_delta_ok(delta)
12
16
  if delta[1] == DELETE
@@ -25,7 +29,8 @@ class Buffer < String
25
29
  @deltas << delta
26
30
  end
27
31
 
28
- unless @macro_group_active
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)
29
34
  if @last_delta_time && (Time.now - @last_delta_time) > cnf.undo.group_threshold!
30
35
  new_undo_group
31
36
  end
@@ -95,14 +100,21 @@ class Buffer < String
95
100
  set_pos(l.end + 1)
96
101
  end
97
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
+
98
110
  # Workaround for https://github.com/ruby-gnome/ruby-gnome/issues/1609
99
111
  def paste_start_xclip(at, register)
100
112
  @clipboard_paste_running = true
101
113
  ipos = @pos # capture insertion point before the async read
102
- paste_lines = @paste_lines
114
+ entry = vma.registers['"']
103
115
  Thread.new {
104
116
  text = `xclip -selection c -o`
105
- GLib::Idle.add { paste_finish(text, at, register, ipos: ipos, paste_lines: paste_lines); false }
117
+ GLib::Idle.add { paste_finish(text, at, register, ipos: ipos, paste_lines: register_linewise?(text, entry)); false }
106
118
  }
107
119
  return nil
108
120
  end
@@ -121,7 +133,7 @@ class Buffer < String
121
133
  # paste would land at wherever the cursor happens to be when the clipboard
122
134
  # data finally arrives.
123
135
  ipos = @pos
124
- paste_lines = @paste_lines
136
+ entry = vma.registers['"']
125
137
 
126
138
  clipboard = vma.gui.window.display.clipboard
127
139
  clipboard.read_text_async do |_clipboard, result|
@@ -130,29 +142,25 @@ class Buffer < String
130
142
  rescue Gio::IOError::NotSupported
131
143
  debug Gio::IOError::NotSupported
132
144
  else
133
- paste_finish(text, at, register, overwrite: overwrite, ipos: ipos, paste_lines: paste_lines)
145
+ paste_finish(text, at, register, overwrite: overwrite, ipos: ipos, paste_lines: register_linewise?(text, entry))
134
146
  end
135
147
  end
136
148
  return nil
137
149
  end
138
150
 
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.
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?).
142
155
  def paste_finish(text, at, register, overwrite: false, ipos: nil, paste_lines: nil)
143
156
  debug "PASTE: #{text}"
144
157
 
145
- @paste_lines = paste_lines unless paste_lines.nil?
158
+ @paste_lines = paste_lines.nil? ? register_linewise?(text) : paste_lines
146
159
  if !ipos.nil?
147
160
  # Clamp in case the buffer shrank during the async window.
148
161
  set_pos(ipos.clamp(0, [size - 1, 0].max))
149
162
  end
150
163
 
151
- # If we did not put this text to clipboard
152
- if text != vma.clipboard[-1]
153
- @paste_lines = false
154
- end
155
-
156
164
  text = sanitize_input(text)
157
165
 
158
166
  vma.clipboard << text
@@ -194,29 +202,44 @@ class Buffer < String
194
202
  end
195
203
 
196
204
  def paste_over(at = AFTER, register = nil)
197
- if vma.macro.running_macro
198
- text = vma.clipboard.get()
199
- paste_finish(text, at, register, overwrite: true)
200
- else
201
- paste_start(at, register, overwrite: true)
202
- end
203
- return true
205
+ paste_register(at, register, overwrite: true)
204
206
  end
205
207
 
206
208
  def paste(at = AFTER, register = nil)
207
- # Macro's don't work with asynchronous call using GTK
208
- # TODO: implement as synchronous?
209
- # Use internal clipboard
210
- if vma.macro.running_macro
211
- text = vma.clipboard.get()
212
- paste_finish(text, at, register)
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
213
224
  else
214
- # Get clipboard using GUI
215
- paste_start(at, register)
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)
216
231
  end
217
232
  return true
218
233
  end
219
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
+
220
243
  def increment_current_word()
221
244
  debug "increment_current_word", 2
222
245
  p = @pos
@@ -247,12 +270,11 @@ class Buffer < String
247
270
  def replace_range(range, text)
248
271
  # add_delta restores the final "\n" of the buffer if the range deleted it
249
272
  text = text.delete_suffix("\n") if range.last >= self.size - 1
250
- delete_range(range.first, range.last)
273
+ delete_range(range.first, range.last, register: false)
251
274
  insert_txt_at(text, range.begin)
252
275
  end
253
276
 
254
277
  def delete2(range_id, mark = nil)
255
- @paste_lines = false
256
278
  range = get_range(range_id, mark: mark)
257
279
  return false if range == nil
258
280
  debug "RANGE"
@@ -269,7 +291,6 @@ class Buffer < String
269
291
  end
270
292
 
271
293
  def delete(op, x = nil)
272
- @paste_lines = false
273
294
  # Delete selection
274
295
  if op == SELECTION && visual_mode?
275
296
  (startpos, endpos) = get_visual_mode_range2
@@ -329,7 +350,9 @@ class Buffer < String
329
350
  return t..(t + txt.size - 1)
330
351
  end
331
352
 
332
- def delete_range(startpos, endpos, x = nil)
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)
333
356
  s = self[startpos..endpos]
334
357
  if startpos > endpos or s == ""
335
358
  return
@@ -338,7 +361,7 @@ class Buffer < String
338
361
  debug "APPEND"
339
362
  s += "\n" + vma.clipboard.get()
340
363
  end
341
- vma.clipboard.set(s)
364
+ vma.clipboard.set(s, kind: :delete) if register
342
365
  add_delta([startpos, DELETE, (endpos - startpos + 1)], true)
343
366
  #recalc_line_ends
344
367
  calculate_line_and_column_pos
@@ -365,9 +388,8 @@ class Buffer < String
365
388
  lrange = line_range(@lpos, num_lines)
366
389
  s = self[lrange]
367
390
  add_delta([lrange.begin, DELETE, lrange.end - lrange.begin + 1], true)
368
- vma.clipboard.set(s)
391
+ vma.clipboard.set(s, linewise: true, kind: :delete)
369
392
  update_pos(lrange.begin)
370
- @paste_lines = true
371
393
  #recalc_line_ends
372
394
  end
373
395
 
@@ -2,7 +2,7 @@
2
2
  module Vimamsa
3
3
  def save_buffer_list()
4
4
  message("Save buffer list")
5
- buffn = get_dot_path("buffers.txt")
5
+ buffn = get_data_path("buffers.txt")
6
6
  f = File.open(buffn, "w")
7
7
  bufstr = vma.buffers.list.collect { |buf| buf.fname }.inspect
8
8
  f.write(bufstr)
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  def load_buffer_list()
13
13
  message("Load buffer list")
14
- buffn = get_dot_path("buffers.txt")
14
+ buffn = get_data_path("buffers.txt")
15
15
  return if !File.exist?(buffn)
16
16
  bufstr = IO.read(buffn)
17
17
  bufl = eval(bufstr)
@@ -11,14 +11,14 @@ class BufferManager
11
11
  def self.init()
12
12
  # vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
13
13
  vma.kbd.add_minor_mode("bmgr", :bmgr, :command)
14
- reg_act(:bmgr_select, proc { buf.module.select_line }, "")
15
- reg_act(:bmgr_close, proc { buf.module.close_selected }, "")
14
+ reg_act("bmgr.select", proc { buf.module.select_line }, "")
15
+ reg_act("bmgr.close", proc { buf.module.close_selected }, "")
16
16
 
17
- reg_act(:start_buf_manager, proc { BufferManager.new.run; vma.kbd.set_mode(:bmgr) }, "Buffer manager")
17
+ reg_act("buf.manager", proc { BufferManager.new.run; vma.kbd.set_mode(:bmgr) }, "Buffer manager")
18
18
 
19
- bindkey "bmgr enter", :bmgr_select
20
- bindkey "bmgr c", :bmgr_close
21
- bindkey "bmgr x", :close_current_buffer
19
+ bindkey "bmgr enter", "bmgr.select"
20
+ bindkey "bmgr c", "bmgr.close"
21
+ bindkey "bmgr x", "buf.close"
22
22
  end
23
23
 
24
24
  def initialize()
@@ -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
@@ -13,18 +13,21 @@ class Clipboard
13
13
  return @clipboard << str
14
14
  end
15
15
 
16
- def set(s)
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)
17
21
  if !(s.class <= String) or s.size == 0
18
22
  debug s.inspect
19
23
  debug [s, s.class, s.size]
20
24
  log_error("s.class != String or s.size == 0")
21
25
  return
22
26
  end
27
+ return if !vma.registers.store(s, linewise: linewise, kind: kind)
23
28
  @clipboard << s
24
29
  set_system_clipboard(s)
25
- vma.register[vma.cur_register] = s
26
30
  debug "SET CLIPBOARD: [#{s}]"
27
- debug "REGISTER: #{vma.cur_register}:#{vma.register[vma.cur_register]}"
28
31
  end
29
32
 
30
33
  def get()
data/lib/vimamsa/conf.rb CHANGED
@@ -160,6 +160,11 @@ cnf.match.highlight.color = "#10bd8e"
160
160
  cnf.flash.enabled = true # briefly flash the range yanked/deleted (y ', d ', d w, ...)
161
161
  cnf.flash.duration = 0.15 # seconds the flash stays visible
162
162
 
163
+ cnf.easy_jump.glow = false # glow around easy jump labels (slower without a GPU)
164
+ cnf.key_hint.y_offset = 4 # px between the cursor's row and the key hint below it (above it if no room)
165
+
166
+ cnf.help.button_style = "solid" # buttons on help pages: flat / link / pill / solid / key (intro_page.rb)
167
+ cnf.intro.show_on_startup = true # the introduction page (Help ▸ Introduction) at the next start; set false once shown
163
168
  cnf.fold.start_closed = true # collapse {{{ ... }}} marker folds when a file is loaded
164
169
 
165
170
  cnf.modules.color_highlight.enabled = true # paint #rrggbb hex codes with their color
@@ -174,6 +179,10 @@ cnf.startup_file=false
174
179
  cnf.macro.animation_delay = 0.02
175
180
 
176
181
  cnf.undo.group_threshold = 1.8 # seconds of inactivity before starting a new undo group
182
+ # true: an Insert-mode session (i ... esc) is one undo step, as in vim, also
183
+ # when you pause while typing. false: a pause of group_threshold seconds
184
+ # starts a new undo step, so a long session can be undone in parts.
185
+ cnf.undo.insert_one_step = false
177
186
 
178
187
  cnf.paste.cursor_at_start = false
179
188
 
@@ -12,12 +12,12 @@ module Vimamsa
12
12
  # kill the process before any Ruby handler can run, so we tee the process
13
13
  # stderr (where Ruby prints its native crash dump) into a persistent log.
14
14
  #
15
- # Reports go to ~/.config/vimamsa/crash/ .
15
+ # Reports go to the data dir: ~/.local/share/vimamsa/crash/ (user_dirs.rb).
16
16
  module CrashHandler
17
17
  @installed = false
18
18
 
19
19
  def self.crash_dir
20
- dir = get_dot_path("crash")
20
+ dir = get_data_path("crash")
21
21
  FileUtils.mkdir_p(dir)
22
22
  dir
23
23
  end
data/lib/vimamsa/debug.rb CHANGED
@@ -14,7 +14,7 @@ def debug(message, severity = 1)
14
14
  end
15
15
  end
16
16
 
17
- def debug_print_buffer(c)
17
+ def debug_print_buffer(_c = nil)
18
18
  puts buf.inspect
19
19
  puts buf
20
20
  end
@@ -66,7 +66,7 @@ def savedebug(message, e)
66
66
  dbginfo["trace_str"] = dbginfo["trace"].join("\n")
67
67
  dbginfo["edit_history"] = buf.edit_history
68
68
  dbginfo["cnf"] = $vimamsa_conf
69
- dbginfo["register"] = vma.register
69
+ dbginfo["register"] = vma.registers.to_h
70
70
  dbginfo["clipboard"] = vma.clipboard
71
71
  # dbginfo["last_event"] = $last_event
72
72
  dbginfo["buffer"] = {}