vimamsa 0.1.20 → 0.1.22

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.
@@ -4,6 +4,7 @@ vma.kbd.add_mode("V", :visual, :visual)
4
4
  vma.kbd.add_mode("M", :minibuffer) #TODO: needed?
5
5
  vma.kbd.add_mode("R", :readchar)
6
6
  vma.kbd.add_minor_mode("audio", :audio, :command)
7
+ vma.kbd.add_minor_mode("macro", :macro, :command)
7
8
  vma.kbd.add_mode("B", :browse, :browse, scope: :editor)
8
9
  vma.kbd.add_mode("X", :replace, :replace, name: "Replace")
9
10
  vma.kbd.set_default_mode(:command)
@@ -40,94 +41,44 @@ def insert_move(op)
40
41
  _insert_move(op)
41
42
  end
42
43
 
43
- bindkey ["VCB M", "B m"], :run_last_macro
44
+ add_keys "intro", {
45
+ "C y y" => :copy_cur_line,
46
+ "C P" => :paste_before_cursor,
47
+ "C p" => :paste_after_cursor,
48
+ "C v" => :start_visual_mode,
49
+ "C ctrl-r" => :redo,
50
+ "C u" => :undo,
51
+ "VC O" => :jump_end_of_line,
52
+ # NOTE: "G(condition)" need to be defined before "G"
53
+ "VC G(vma.kbd.next_command_count!=nil)" => "buf.jump_to_line()",
54
+ "VC G" => :jump_end_of_buffer,
55
+ "VC g ;" => :jump_last_edit,
56
+ "VC g g" => :jump_start_of_buffer,
57
+ "VC e" => :jump_next_word_end,
58
+ "VC b" => :jump_prev_word_start,
59
+ "VC w" => :jump_next_word_start,
60
+ "V esc" => "buf.end_visual_mode",
61
+ "V ctrl!" => "buf.end_visual_mode",
62
+
63
+ "C ctrl!" => :insert_mode,
64
+ "C i" => :insert_mode,
65
+ "I esc || I ctrl!" => :prev_mode,
66
+ "IX alt-b" => :jump_prev_word_start,
67
+ "IX alt-f" => :jump_next_word_start,
68
+ "IX ctrl-e" => :jump_end_of_line,
69
+ "IX ctrl-p" => :move_prev_line,
70
+ "IX ctrl-n" => :move_next_line,
71
+ "IX ctrl-b" => :move_backward_char,
72
+ "IX ctrl-a" => :jump_beginning_of_line,
73
+ }
44
74
 
45
- bindkey "VC s", :easy_jump
46
- bindkey "I alt-s", :easy_jump
47
- bindkey "VC , m f", [:find_macro_gui, proc { vma.macro.find_macro_gui }, "Find named macro"]
48
- bindkey "C , m n", [:gui_name_macro, proc { vma.macro.gui_name_macro }, "Name last macro"]
49
- bindkey "C , j r", :jump_to_random
50
- bindkey "C , ; s k", :show_key_bindings #TODO: better binding
51
- bindkey "C , , c b", :put_file_path_to_clipboard #TODO: better binding or remove?
52
- bindkey "C , , e", :encrypt_file #TODO: better binding
53
- bindkey "C , ; u", :set_unencrypted #TODO: better binding
54
- bindkey "C , c b", :close_current_buffer
55
- bindkey "V ctrl-c", :comment_selection
56
- bindkey "C x", :delete_char_forward
57
- bindkey "C , , l t", :load_theme
58
- bindkey "C , f", :gui_file_finder
59
- bindkey "C , h", :gui_file_history_finder
60
- bindkey "C , z", :gui_file_finder
61
-
62
- bindkey "C ` k", :lsp_debug
63
- bindkey "C ` j", :lsp_jump_to_definition
64
-
65
- bindkey "C , r r", :gui_search_replace
66
- bindkey "V , r r", :gui_search_replace
67
- bindkey "V , t b", :set_style_bold
68
- bindkey "V , t l", :set_style_link
69
- bindkey "V J", :V_join_lines
70
- bindkey "V , t c", :clear_formats
71
- bindkey "C , t h", :set_line_style_heading
72
- bindkey "C , t 1", :set_line_style_h1
73
- bindkey "C , t 2", :set_line_style_h2
74
- bindkey "C , t 3", :set_line_style_h3
75
- bindkey "C , t 4", :set_line_style_h4
76
- bindkey "C , t b", :set_line_style_bold
77
- bindkey "C , t t", :set_line_style_title
78
- bindkey "C , t c", :clear_line_styles
79
- bindkey "C , b", :start_buf_manager
80
- bindkey "C , w", :toggle_active_window
81
- bindkey "C , , w", :toggle_two_column
82
-
83
- bindkey "C , u s", :audio_stop
84
- bindkey "C , m a", "vma.kbd.set_mode(:audio)"
85
- bindkey "audio s", :audio_stop
86
- bindkey "audio f || audio right", [:audio_forward, proc { Audio.seek_forward }, "Seek forward in audio stream"]
87
- bindkey "audio left", [:audio_backward, proc { Audio.seek_forward(-5.0) }, "Seek backward in audio stream"]
75
+ add_keys "intro delete", {
76
+ "C x" => :delete_char_forward,
77
+ "C d d" => [:delete_line, proc { buf.delete_line }, "Delete current line"]
78
+ }
88
79
 
89
- bindkey "audio space", :audio_stop
90
- bindkey "audio q || audio esc", "vma.kbd.to_previous_mode"
91
80
 
92
- # bindkey "C , f o", :open_file_dialog
93
- bindkey "CI ctrl-o", :open_file_dialog
94
- # bindkey "M enter", :minibuffer_end
95
- bindkey "C , a", :ack_search
96
- bindkey "C d w", :delete_to_next_word_start
97
-
98
- bindkey "C d 0", :delete_to_line_start
99
- bindkey "C , , f", :file_finder
100
- bindkey "VC h", :e_move_backward_char
101
- bindkey "C , , .", :backup_all_buffers
102
- bindkey "C z ", :start_browse_mode
103
- bindkey "B h", :history_switch_backwards
104
- bindkey "B l", :history_switch_forwards
105
- bindkey "B z", "center_on_current_line();call_action(:exit_browse_mode)"
106
- bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
107
- bindkey "B s", :page_up
108
- bindkey "B d", :page_down
109
- bindkey "B r", proc { vma.gui.page_down(multip: 0.25) }
110
- bindkey "B e", proc { vma.gui.page_up(multip: 0.25) }
111
-
112
- bindkey "B i", :jump_to_start_of_buffer
113
- bindkey "B o", :jump_to_end_of_buffer
114
- bindkey "B c", :close_current_buffer
115
- bindkey "B ;", "buf.jump_to_last_edit"
116
- bindkey "B q", :jump_to_last_edit
117
- bindkey "B w", :jump_to_next_edit
118
- # bindkey "C , d", :diff_buffer
119
- #bindkey 'C , g', proc{invoke_grep_search}
120
- bindkey "C , v", :auto_indent_buffer
121
- bindkey "C , , d", :savedebug
122
- bindkey "C , , u", :update_file_index
123
- bindkey "C , s a", :buf_save_as
124
- bindkey "C d d", [:delete_line, proc { buf.delete_line }, "Delete current line"]
125
- bindkey "C enter || C return", [:line_action, proc { buf.handle_line_action() }, "Line action"]
126
- bindkey "C p", [:paste_after, proc { buf.paste(AFTER) }, ""] # TODO: implement as replace for visual mode
127
- bindkey "V d", [:delete_selection, proc { buf.delete(SELECTION) }, ""]
128
- bindkey "V a d", [:delete_append_selection, proc { buf.delete(SELECTION, :append) }, "Delete and append selection"]
129
-
130
- default_keys = {
81
+ add_keys "core", {
131
82
 
132
83
  # File handling
133
84
  "C ctrl-s" => :buf_save,
@@ -184,9 +135,6 @@ default_keys = {
184
135
  "VCX down" => "buf.move(FORWARD_LINE)",
185
136
  "VCX up" => "buf.move(BACKWARD_LINE)",
186
137
 
187
- "VC w" => "buf.jump_word(FORWARD,WORD_START)",
188
- "VC b" => "buf.jump_word(BACKWARD,WORD_START)",
189
- "VC e" => "buf.jump_word(FORWARD,WORD_END)",
190
138
  # 'C '=> 'buf.jump_word(BACKWARD,END)',#TODO
191
139
  "VC f <char>" => "buf.jump_to_next_instance_of_char(<char>)",
192
140
  "VC F <char>" => "buf.jump_to_next_instance_of_char(<char>,BACKWARD)",
@@ -196,14 +144,10 @@ default_keys = {
196
144
  "VC /[1-9]/" => "vma.kbd.set_next_command_count(<char>)",
197
145
  # 'VC number=/[0-9]/+ g'=> 'jump_to_line(<number>)',
198
146
  # 'VC X=/[0-9]/+ * Y=/[0-9]/+ '=> 'x_times_y(<X>,<Y>)',
199
- "VC G(vma.kbd.next_command_count!=nil)" => "buf.jump_to_line()",
200
147
  "VC 0(vma.kbd.next_command_count!=nil)" => "set_next_command_count(<char>)",
201
148
  "VC 0(vma.kbd.next_command_count==nil)" => "buf.jump(BEGINNING_OF_LINE)",
202
149
  # 'C 0'=> 'buf.jump(BEGINNING_OF_LINE)',
203
- "VC g g" => "buf.jump(START_OF_BUFFER)",
204
- "VC g ;" => "buf.jump_to_last_edit",
205
150
  "VC ^" => "buf.jump(BEGINNING_OF_LINE)",
206
- "VC G" => "buf.jump(END_OF_BUFFER)",
207
151
  # 'VC z z' => 'center_on_current_line',
208
152
  "VC *" => "buf.jump_to_next_instance_of_word",
209
153
 
@@ -220,17 +164,8 @@ default_keys = {
220
164
 
221
165
  "C C" => :content_search,
222
166
 
223
- # Debug
224
- "C , d r p" => "start_ripl",
225
- "C , d o" => "vma.gui.clear_overlay",
226
- "C , D" => "debug_print_buffer",
227
167
  "C , c s" => "bufs.close_scrap_buffers",
228
- "C , d b" => "debug_print_buffer",
229
- "C , d c" => "debug_dump_clipboard",
230
- "C , d d" => "debug_dump_deltas",
231
- "C , d m" => :kbd_dump_state,
232
168
 
233
- "VC O" => "buf.jump(END_OF_LINE)",
234
169
  "VC $" => "buf.jump(END_OF_LINE)",
235
170
 
236
171
  "C o" => 'buf.jump(END_OF_LINE);buf.insert_txt("\n");vma.kbd.set_mode(:insert)',
@@ -239,23 +174,18 @@ default_keys = {
239
174
  "C I" => "buf.jump(FIRST_NON_WHITESPACE);vma.kbd.set_mode(:insert)",
240
175
  "C a" => "buf.move(FORWARD_CHAR);vma.kbd.set_mode(:insert)",
241
176
  "C J" => "buf.join_lines()",
242
- "C u" => "buf.undo()",
243
177
 
244
178
  "C ^" => "buf.jump(BEGINNING_OF_LINE)",
245
179
  # "C /[1-9]/" => "vma.kbd.set_next_command_count(<char>)",
246
180
 
247
181
  # Command mode only:
248
- "C ctrl-r" => "buf.redo()", # TODO:???
249
- "C v" => "buf.start_selection;vma.kbd.set_mode(:visual)",
250
- "C P" => "buf.paste(BEFORE)", # TODO: implement as replace for visual mode
251
182
  "C space <char>" => "buf.insert_txt(<char>)",
252
183
  "C space space" => "buf.insert_txt(' ')",
253
- "C y y" => "buf.copy_line",
254
184
  "C y O" => "buf.copy(:to_line_end)",
255
185
  "C y 0" => "buf.copy(:to_line_start)",
256
186
  "C y e" => "buf.copy(:to_word_end)", # TODO
257
187
  #### Deleting
258
- "C x" => "buf.delete(CURRENT_CHAR_FORWARD)",
188
+ # "C x" => "buf.delete(CURRENT_CHAR_FORWARD)",
259
189
  # 'C d k'=> 'delete_line(BACKWARD)', #TODO
260
190
  # 'C d j'=> 'delete_line(FORWARD)', #TODO
261
191
  # 'C d d'=> 'buf.delete_cur_line',
@@ -266,6 +196,7 @@ default_keys = {
266
196
  "C d <num> e" => "delete_next_word",
267
197
  "C d ' <char>" => "buf.delete2(:to_mark,<char>)",
268
198
  "C r <char>" => "buf.replace_with_char(<char>)", # TODO
199
+ "C r space" => "buf.replace_with_char(' ')", # TODO
269
200
  "C , l b" => "load_buffer_list",
270
201
  "C , l l" => "save_buffer_list",
271
202
  "C , r <char>" => "vma.set_register(<char>)", # TODO
@@ -277,8 +208,7 @@ default_keys = {
277
208
  # 'C 0($next_command_count==nil)'=> 'jump_to_beginning_of_line',
278
209
 
279
210
  # Visual mode only:
280
- "V esc" => "buf.end_visual_mode",
281
- "V ctrl!" => "buf.end_visual_mode",
211
+
282
212
  "V y" => "buf.copy_active_selection()",
283
213
  "V a y" => "buf.copy_active_selection(:append)",
284
214
  "V g U" => :selection_upcase,
@@ -303,9 +233,7 @@ default_keys = {
303
233
  # "CV ''" =>'jump_to_mark(NEXT_MARK)', #TODO
304
234
 
305
235
  # Switch to another mode
306
- "C i" => "vma.kbd.set_mode(:insert)",
307
236
  "C R" => "vma.kbd.set_mode(:replace)",
308
- "C ctrl!" => "vma.kbd.set_mode(:insert)",
309
237
 
310
238
  # Replace mode
311
239
  "X esc || X ctrl!" => "vma.kbd.to_previous_mode",
@@ -314,49 +242,140 @@ default_keys = {
314
242
  # Macros
315
243
  # (experimental, may not work correctly)
316
244
  # "C q a" => 'vma.macro.start_recording("a")',
317
- "VC q <char>" => "vma.macro.start_recording(<char>)",
318
- "VC q(vma.macro.is_recording==true) " => "$macro.end_recording", # TODO
245
+
246
+ "macro q" => "vma.kbd.to_previous_mode; vma.macro.end_recording",
247
+ "macro q z" => "vma.kbd.to_previous_mode; vma.macro.end_recording",
248
+
249
+ # "VC q(vma.macro.is_recording==true)" => "vma.macro.end_recording", # TODO: does not work
250
+ # "VC o(vma.macro.is_recording==true)" => "vma.macro.end_recording", # TODO: does not work
251
+ # "VC q q(vma.macro.is_recording==true)" => "vma.macro.end_recording",
252
+ "VC q <char>" => "vma.kbd.set_mode(:macro);vma.macro.start_recording(<char>)",
319
253
  # 'C q'=> 'vma.macro.end_recording', #TODO
320
- "C q v" => "vma.macro.end_recording",
254
+ "C q v" => "vma.kbd.to_previous_mode; vma.macro.end_recording",
321
255
  # 'C v'=> 'vma.macro.end_recording',
322
256
  # "C M" => 'vma.macro.run_last_macro',
323
257
  "C @ <char>" => "vma.macro.run_macro(<char>)",
324
258
  "C , m S" => 'vma.macro.save_macro("a")',
325
259
  "C , m s" => "vma.macro.save",
326
- "C , t r" => "run_tests()",
327
260
 
328
261
  # "C ." => "repeat_last_action", # TODO
329
262
  "VC ;" => "repeat_last_find",
330
263
  # "CV Q" => :quit,
331
264
  "CV ctrl-q" => :quit,
332
- "CV , R" => "restart_application",
333
265
  # "I ctrl!" => "vma.kbd.to_previous_mode",
334
- "C shift!" => "buf.save",
266
+ "C shift! s" => "buf.save",
335
267
  "I ctrl-s" => "buf.save",
336
268
  "I <char>" => "buf.insert_txt(<char>)",
337
- "I esc || I ctrl!" => "vma.kbd.to_previous_mode",
338
269
 
339
270
  "I ctrl-d" => "buf.delete2(:to_word_end)",
340
271
 
341
272
  # Insert and Replace modes: Moving
342
- "IX ctrl-a" => "buf.jump(BEGINNING_OF_LINE)",
343
- "IX ctrl-b" => "buf.move(BACKWARD_CHAR)",
344
273
  "IX ctrl-f" => "buf.move(FORWARD_CHAR)",
345
- "IX ctrl-n" => "buf.move(FORWARD_LINE)",
346
- "IX ctrl-p" => "buf.move(BACKWARD_LINE)",
347
- "IX ctrl-e" => "buf.jump(END_OF_LINE)", # context: mode:I, buttons down: {C}
348
- "IX alt-f" => "buf.jump_word(FORWARD,WORD_START)",
349
- "IX alt-b" => "buf.jump_word(BACKWARD,WORD_START)",
350
274
 
351
- "I ctrl-h" => :show_autocomplete,
352
275
  "I ctrl-j" => "vma.buf.view.hide_completions",
353
276
 
354
277
  "I space" => 'buf.insert_txt(" ")',
355
278
  # "I return" => 'buf.insert_new_line()',
279
+
280
+ "CI ctrl-o" => :open_file_dialog,
281
+ "C , a" => :ack_search,
282
+ "C d w" => :delete_to_next_word_start,
283
+
284
+ "C d 0" => :delete_to_line_start,
285
+ "C , , f" => :file_finder,
286
+ "VC h" => :e_move_backward_char,
287
+ "C , , ." => :backup_all_buffers,
288
+ "C z " => :start_browse_mode,
289
+ "B h" => :history_switch_backwards,
290
+ "B l" => :history_switch_forwards,
291
+ "B z" => "center_on_current_line();call_action(:exit_browse_mode)",
292
+ "B enter || B return || B esc || B j || B ctrl!" => :exit_browse_mode,
293
+ "B s" => :page_up,
294
+ "B d" => :page_down,
295
+ "B r" => proc { vma.gui.page_down(multip: 0.25) },
296
+ "B e" => proc { vma.gui.page_up(multip: 0.25) },
297
+
298
+ "B i" => :jump_to_start_of_buffer,
299
+ "B o" => :jump_to_end_of_buffer,
300
+ "B c" => :close_current_buffer,
301
+ "B ;" => :jump_last_edit,
302
+ "B q" => :jump_to_last_edit,
303
+ "B w" => :jump_to_next_edit,
304
+ "C , v" => :auto_indent_buffer,
305
+ "C , , u" => :update_file_index,
306
+ "C , s a" => :buf_save_as,
307
+ "VC , r r" => :gui_search_replace,
308
+ "V , t b" => :set_style_bold,
309
+ "V , t l" => :set_style_link,
310
+ "V J" => :V_join_lines,
311
+ "V , t c" => :clear_formats,
312
+ "C , t h" => :set_line_style_heading,
313
+ "C , t 1" => :set_line_style_h1,
314
+ "C , t 2" => :set_line_style_h2,
315
+ "C , t 3" => :set_line_style_h3,
316
+ "C , t 4" => :set_line_style_h4,
317
+ "C , t b" => :set_line_style_bold,
318
+ "C , t t" => :set_line_style_title,
319
+ "C , t c" => :clear_line_styles,
320
+ "C , b" => :start_buf_manager,
321
+ "C , w" => :toggle_active_window,
322
+ "C , , w" => :toggle_two_column,
323
+
324
+ "VC s" => :easy_jump,
325
+ "I alt-s" => :easy_jump,
326
+ "VC , m f" => [:find_macro_gui, proc { vma.macro.find_macro_gui }, "Find named macro"],
327
+ "C , m n" => [:gui_name_macro, proc { vma.macro.gui_name_macro }, "Name last macro"],
328
+ "C , j r" => :jump_to_random,
329
+ "C , ; s k" => :show_key_bindings, #TODO: better binding,
330
+ "C , , c b" => :put_file_path_to_clipboard, #TODO: better binding or remove?,
331
+ "C , , e" => :encrypt_file, #TODO: better binding,
332
+ "C , ; u" => :set_unencrypted, #TODO: better binding,
333
+ "C , c b" => :close_current_buffer,
334
+ "V ctrl-c" => :comment_selection,
335
+ "C , f" => :gui_file_finder,
336
+ "C , h" => :gui_file_history_finder,
337
+ "C , z" => :gui_file_finder,
338
+
339
+ "C enter || C return" => [:line_action, proc { buf.handle_line_action() }, "Line action"],
340
+ "V d" => [:delete_selection, proc { buf.delete(SELECTION) }, ""],
341
+ "V a d" => [:delete_append_selection, proc { buf.delete(SELECTION, :append) }, "Delete and append selection"]
356
342
  }
357
343
 
358
- bindkey "C , i p", "generate_password_to_buf(15)"
344
+ bindkey ["VCB M", "B m"], :run_last_macro
345
+
346
+ add_keys "experimental", {
347
+ "C ` k" => :lsp_debug,
348
+ "C ` j" => :lsp_jump_to_definition,
349
+ "C , u s" => :audio_stop,
359
350
 
360
- default_keys.each { |key, value|
361
- bindkey(key, value)
351
+ "C , t r" => "run_tests()",
352
+ # "CV , R" => "restart_application", #TODO: does not work
353
+ "I ctrl-h" => :show_autocomplete, #TODO: does not work
354
+ "C , d m" => :kbd_dump_state,
355
+ "C , d d" => "debug_dump_deltas",
356
+ "C , d c" => "debug_dump_clipboard",
357
+ "C , d b" => "debug_print_buffer",
358
+ "C , D" => "debug_print_buffer",
359
+ "C , d o" => "vma.gui.clear_overlay",
360
+ # Debug
361
+ "C , d r p" => 'require "pry"; binding.pry', #TODO
362
+ #bindkey 'C , g', proc{invoke_grep_search}
363
+ # bindkey "C , d", :diff_buffer
364
+ "C , , d" => :savedebug,
365
+ "C , m a" => "vma.kbd.set_mode(:audio)",
366
+ "audio s" => :audio_stop,
362
367
  }
368
+
369
+
370
+ bindkey "audio f || audio right", [:audio_forward, proc { Audio.seek_forward }, "Seek forward in audio stream"]
371
+ bindkey "audio left", [:audio_backward, proc { Audio.seek_forward(-5.0) }, "Seek backward in audio stream"]
372
+
373
+ bindkey "audio space", :audio_stop
374
+ bindkey "audio q || audio esc", "vma.kbd.to_previous_mode"
375
+
376
+
377
+ bindkey "C , i p", "generate_password_to_buf(15)"
378
+
379
+ # default_keys.each { |key, value|
380
+ # bindkey(key, value)
381
+ # }
data/lib/vimamsa/macro.rb CHANGED
@@ -118,8 +118,10 @@ class Macro
118
118
 
119
119
  # Run the provided list of actions
120
120
  def run_actions(acts)
121
+ acts = [acts] if acts.class != Array
121
122
  isok = true
122
- if acts.kind_of?(Array) and acts.any?
123
+ # if acts.kind_of?(Array) and acts.any?
124
+ if acts.any?
123
125
  @running_macro = true
124
126
  # TODO:needed?
125
127
  # set_last_command({ method: vma.macro.method("run_macro"), params: [name] })
data/lib/vimamsa/tests.rb CHANGED
@@ -1,7 +1,19 @@
1
1
  require "digest"
2
2
 
3
3
  def run_tests()
4
- tests = ["test_paste_0", "test_delete_0"]
4
+ # DelayExecutioner.exec(id: :run_tests, wait: 0.7, callable: proc { run_tests_0 })
5
+
6
+ # Reload class
7
+ # if Object.constants.include?(:EditorTests)
8
+ # Object.send(:remove_const, :EditorTests)
9
+ # end
10
+ load __FILE__
11
+
12
+ run_edit_tests
13
+ end
14
+
15
+ def run_tests_0()
16
+ tests = ["test_write_0"]
5
17
  stats = []
6
18
  for t in tests
7
19
  r = eval(t)
@@ -16,7 +28,74 @@ def run_tests()
16
28
  puts "===================="
17
29
  end
18
30
 
19
- #
31
+ def run_edit_tests()
32
+ edt = EditorTests.new
33
+ tests = edt.methods.select { |x| x.match(/test_.*/) }.collect { |x| { :method => edt.method(x), :name => x } }
34
+ for t in tests
35
+ b = create_new_buffer(file_contents = "\n", prefix = "buf", setcurrent = true)
36
+
37
+ edits = t[:method].call
38
+ # next if t[:name] != :test_create_close_buf
39
+ errors = 0
40
+ edits.each_with_index do |x, i|
41
+ if x.class == Array
42
+ (act, target) = x
43
+
44
+ vma.macro.run_actions(act)
45
+ # bufc = b.to_s
46
+ bufc = vma.buf.to_s
47
+ if bufc != target
48
+ puts "ERROR[#{t[:name]}:#{i}] act=#{act.inspect} content=#{bufc.inspect} != #{target.inspect}"
49
+ errors += 1
50
+ end
51
+ else
52
+ vma.macro.run_actions(x)
53
+ end
54
+ end
55
+ if errors == 0
56
+ puts "TEST #{t[:name]} passed"
57
+ else
58
+ end
59
+ end
60
+ end
61
+
62
+ class EditorTests
63
+ def test_write
64
+ #[[action to run, expected buffer contents after], ...]
65
+ [['buf.insert_txt("zzzz")', "zzzz\n"],
66
+ # At end of file replace should not change anything
67
+ ['buf.replace_with_char("-")', "zzzz\n"],
68
+ 'buf.insert_txt("\n")',
69
+ ['buf.insert_txt("yy")', "zzzz\nyy\n"],
70
+ :e_move_backward_char, :e_move_backward_char,
71
+ ['buf.insert_txt("0")', "zzzz\n0yy\n"],
72
+ "buf.jump(START_OF_BUFFER)",
73
+ ['buf.replace_with_char("1")', "1zzz\n0yy\n"]]
74
+ end
75
+
76
+ def test_delete
77
+ [['buf.insert_txt("abcdef")', "abcdef\n"],
78
+ 'buf.insert_txt("\n")',
79
+ ['buf.insert_txt("yy")', "abcdef\nyy\n"],
80
+ "buf.jump(START_OF_BUFFER)",
81
+ :delete_char_forward,
82
+ [:delete_char_forward, "cdef\nyy\n"],
83
+ "buf.jump(END_OF_LINE)",
84
+ "buf.delete(BACKWARD_CHAR)",
85
+ ["buf.delete(BACKWARD_CHAR)", "cd\nyy\n"]]
86
+ end
87
+
88
+ def test_create_close_buf
89
+ ['buf.insert_txt("abcdef")',
90
+ [:buf_new,"\n"],
91
+ 'buf.insert_txt("a")',
92
+ 'buf.insert_txt("b")',
93
+ 'buf.insert_txt("c")',
94
+ 'buf.insert_txt("d")',
95
+ ['buf.insert_txt("e")',"abcde\n"],
96
+ [:close_current_buffer, "abcdef\n"]]
97
+ end
98
+ end
20
99
 
21
100
  def test_paste_0(runmacro = true)
22
101
  return
@@ -19,6 +19,8 @@ end
19
19
  Converter.new(lambda { |x| x.split("\n").collect { |x| r = x.strip }.select { |y| !y.empty? }.join(" ") + "\n" }, :lambda, :joinlines)
20
20
 
21
21
  Converter.new(lambda { |x| x.split("\n").sort.join("\n") }, :lambda, :sortlines)
22
+ Converter.new(lambda { |x| x.split("\n").reverse.join("\n") }, :lambda, :reverse_lines)
23
+
22
24
  Converter.new(lambda { |x| x.split(/\s+/).sort.join(" ") }, :lambda, :sortwords)
23
25
  Converter.new(lambda { |x| x.split("\n").collect { |b| b.scan(/(\d+(\.\d+)?)/).collect { |c| c[0] }.join(" ") }.join("\n") }, :lambda, :getnums_on_lines)
24
26
 
data/lib/vimamsa/util.rb CHANGED
@@ -3,6 +3,10 @@ require "open3"
3
3
  VOWELS = %w(a e i o u)
4
4
  CONSONANTS = %w(b c d f g h j k l m n p q r s t v w x y z)
5
5
 
6
+ def draw_cursor_bug_workaround()
7
+ DelayExecutioner.exec(id: :bug_workaround_draw_cursor, wait: 1.0, callable: proc { vma.gui.view.draw_cursor(); debug ":bug_workaround_draw_cursor"; false })
8
+ end
9
+
6
10
  def running_wayland?
7
11
  sess = ENV["DESKTOP_SESSION"]
8
12
  sess ||= ENV["XDG_SESSION_DESKTOP"]
@@ -93,7 +97,7 @@ end
93
97
 
94
98
  # file --mime-type --mime-encoding
95
99
 
96
- # Run idle proc once
100
+ # Run idle proc once (return false)
97
101
  # Delay execution of proc until Gtk has fully processed the last calls.
98
102
  def run_as_idle(p, delay: 0.0)
99
103
  if p.class == Proc
@@ -141,6 +145,24 @@ def exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = ni
141
145
  return ret_str
142
146
  end
143
147
 
148
+ def pipe_to_external(program, text)
149
+ # Open a pipe to the external program
150
+ IO.popen(program, "r+") do |pipe|
151
+ # Send the text to the program
152
+ pipe.write(text)
153
+ pipe.close_write # Close the write end to signal EOF to the program
154
+ # Read and return the output from the program
155
+ output = pipe.read
156
+ return output
157
+ end
158
+ rescue Errno::ENOENT
159
+ puts "Error: The program '#{program}' was not found."
160
+ nil
161
+ rescue => e
162
+ puts "An error occurred: #{e.message}"
163
+ nil
164
+ end
165
+
144
166
  def mkdir_if_not_exists(_dirpath)
145
167
  dirpath = File.expand_path(_dirpath)
146
168
  Dir.mkdir(dirpath) unless File.exist?(dirpath)
@@ -200,7 +222,7 @@ end
200
222
  # Used for image scaling after window resize
201
223
 
202
224
  class DelayExecutioner
203
-
225
+ attr_accessor :last_run, :wait_before_next
204
226
  # Run 'callable.call' if 'wait' time elapsed from last exec call for this id
205
227
  def self.exec(id:, wait:, callable:)
206
228
  @@h ||= {}
@@ -208,6 +230,12 @@ class DelayExecutioner
208
230
  if h[id].nil?
209
231
  h[id] = DelayExecutioner.new(wait, callable)
210
232
  end
233
+ o = h[id]
234
+ if !o.last_run.nil?
235
+ # if Time.now - o.last_run < o.wait_before_next
236
+ # return
237
+ # end
238
+ end
211
239
  h[id].run
212
240
  end
213
241
 
@@ -216,6 +244,8 @@ class DelayExecutioner
216
244
  @proc = _proc
217
245
  @lastt = Time.now
218
246
  @thread_running = false
247
+ @last_run = nil
248
+ @wait_before_next = 0
219
249
  end
220
250
 
221
251
  def start_thread
@@ -224,6 +254,7 @@ class DelayExecutioner
224
254
  sleep 0.1
225
255
  if Time.now - @lastt > @wait_time
226
256
  @proc.call
257
+ @last_run = Time.now
227
258
  @thread_running = false
228
259
  break
229
260
  end
@@ -326,6 +357,17 @@ def is_existing_file(s)
326
357
  return false
327
358
  end
328
359
 
360
+ def uri_to_path(uri)
361
+ fp = nil
362
+ begin
363
+ x = URI::DEFAULT_PARSER.unescape(URI(uri).path)
364
+ rescue URI::InvalidURIError
365
+ else
366
+ fp = x # only if no exception
367
+ end
368
+ return fp
369
+ end
370
+
329
371
  def is_image_file(fpath)
330
372
  return false if !File.exist?(fpath)
331
373
  # return false if !fpath.match(/.(jpg|jpeg|png)$/i)
@@ -1,3 +1,3 @@
1
1
  module Vimamsa
2
- VERSION = "0.1.20"
2
+ VERSION = "0.1.22"
3
3
  end
data/vimamsa.gemspec CHANGED
@@ -5,7 +5,7 @@ require "vimamsa/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "vimamsa"
8
- spec.version = Vimamsa::VERSION
8
+ spec.version = Vimamsa::VERSION # in lib/vimamsa/version.rb
9
9
  spec.authors = ["Sami Sieranoja"]
10
10
  spec.email = ["sami.sieranoja@gmail.com"]
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimamsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sami Sieranoja
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-05 00:00:00.000000000 Z
11
+ date: 2025-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -241,6 +241,7 @@ files:
241
241
  - exe/vimamsa
242
242
  - ext/vmaext/extconf.rb
243
243
  - ext/vmaext/vmaext.c
244
+ - install.sh
244
245
  - lang/hyperplaintext.lang
245
246
  - lib/vimamsa.rb
246
247
  - lib/vimamsa/ack.rb
@@ -295,7 +296,7 @@ homepage: https://github.com/SamiSieranoja/vimamsa
295
296
  licenses:
296
297
  - GPL-3.0+
297
298
  metadata: {}
298
- post_install_message:
299
+ post_install_message:
299
300
  rdoc_options: []
300
301
  require_paths:
301
302
  - lib
@@ -311,8 +312,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
312
  - !ruby/object:Gem::Version
312
313
  version: '0'
313
314
  requirements: []
314
- rubygems_version: 3.3.26
315
- signing_key:
315
+ rubygems_version: 3.4.20
316
+ signing_key:
316
317
  specification_version: 4
317
318
  summary: Vimamsa
318
319
  test_files: []