vimamsa 0.1.4 → 0.1.7
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.
- checksums.yaml +4 -4
- data/exe/vimamsa +30 -22
- data/ext/vmaext/vmaext.c +0 -3
- data/lib/vimamsa/ack.rb +0 -4
- data/lib/vimamsa/actions.rb +20 -32
- data/lib/vimamsa/buffer.rb +113 -57
- data/lib/vimamsa/buffer_list.rb +4 -4
- data/lib/vimamsa/debug.rb +6 -6
- data/lib/vimamsa/easy_jump.rb +129 -125
- data/lib/vimamsa/editor.rb +64 -31
- data/lib/vimamsa/file_finder.rb +2 -2
- data/lib/vimamsa/file_history.rb +12 -5
- data/lib/vimamsa/gui.rb +562 -0
- data/lib/vimamsa/gui_gtk_sourceview.rb +294 -0
- data/lib/vimamsa/gui_menu.rb +100 -0
- data/lib/vimamsa/gui_select_window.rb +177 -0
- data/lib/vimamsa/gui_sourceview.rb +294 -0
- data/lib/vimamsa/{default_key_bindings.rb → key_actions.rb} +71 -191
- data/lib/vimamsa/key_binding_tree.rb +21 -9
- data/lib/vimamsa/key_bindings_vimlike.rb +260 -0
- data/lib/vimamsa/macro.rb +1 -1
- data/lib/vimamsa/main.rb +1 -2
- data/lib/vimamsa/rbvma.rb +17 -965
- data/lib/vimamsa/search.rb +0 -4
- data/lib/vimamsa/search_replace.rb +1 -2
- data/lib/vimamsa/util.rb +1 -1
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +1 -31
- data/vimamsa.gemspec +2 -1
- metadata +25 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a71f8392835d7a5a3245366764eb79f6058ea3ded74cc1a308f021f950881ba
|
4
|
+
data.tar.gz: 590ea0409a43aabafe349cfcff0cb91712e2a269e334b3663b64f6b895ae666f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf328f8cbe0b69e85a9720790c8f4616e1996466ad65f6473cf1cff1173d78b9cec197145c653a5d33804571d383246492e593445da390cbe567fc6ccfbb24a
|
7
|
+
data.tar.gz: 799f836afc3c0e304cac07f44e1b5c96affa3f6b5775b4d654b43a81168f2ab14cb4ee1218a3345ae3189203520885fd6cc1de7ce48205e78386b060c700f8ca
|
data/exe/vimamsa
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
require
|
2
|
+
require "ripl/multi_line"
|
3
|
+
require "tempfile"
|
3
4
|
# Ripl.config[:multi_line_prompt] = ' > '
|
4
5
|
require "pathname"
|
5
6
|
|
@@ -7,28 +8,35 @@ ENV["GTK_THEME"] = "Adwaita:dark"
|
|
7
8
|
|
8
9
|
selfpath = __FILE__
|
9
10
|
selfpath = File.readlink(selfpath) if File.lstat(selfpath).symlink?
|
10
|
-
scriptdir = File.expand_path(File.dirname(selfpath)+"/..")
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
scriptdir = File.expand_path(File.dirname(selfpath) + "/..")
|
12
|
+
|
13
|
+
|
14
|
+
# If process is already running, open the parameter file in the running process and exit.
|
15
|
+
listen_dir = File.expand_path("~/.vimamsa/listen")
|
16
|
+
if File.exist?(listen_dir) and !ARGV[0].nil?
|
17
|
+
tmpf = Tempfile.new("vmarun", listen_dir)
|
18
|
+
fp = tmpf.path
|
19
|
+
paramfn = File.expand_path(ARGV[0])
|
20
|
+
puts paramfn
|
21
|
+
tmpf.write(paramfn)
|
22
|
+
tmpf.close
|
23
|
+
tstart = Time.new
|
24
|
+
timeout = false
|
25
|
+
while File.exist?(fp)
|
26
|
+
sleep 0.001
|
27
|
+
if Time.new - tstart > 0.5
|
28
|
+
timeout = true
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
32
|
+
exit(0) if !timeout
|
33
|
+
end
|
34
|
+
|
35
|
+
$LOAD_PATH.unshift(File.expand_path("lib"))
|
36
|
+
$LOAD_PATH.unshift(File.expand_path("ext"))
|
27
37
|
|
28
38
|
require "vimamsa"
|
29
|
-
# Ilib:ext
|
39
|
+
# Ilib:ext
|
30
40
|
# r rbvma -e "puts VMA.new.run"
|
31
|
-
$vmag =
|
41
|
+
$vmag = VMAgui.new()
|
32
42
|
$vmag.run
|
33
|
-
|
34
|
-
|
data/ext/vmaext/vmaext.c
CHANGED
data/lib/vimamsa/ack.rb
CHANGED
data/lib/vimamsa/actions.rb
CHANGED
@@ -1,73 +1,62 @@
|
|
1
1
|
class Action
|
2
|
-
attr_accessor :id, :method_name, :method
|
2
|
+
attr_accessor :id, :method_name, :method, :opt
|
3
3
|
|
4
|
-
def initialize(id, method_name, method,
|
4
|
+
def initialize(id, method_name, method, opt = {})
|
5
5
|
@method_name = method_name
|
6
6
|
@id = id
|
7
7
|
@method = method
|
8
|
+
@opt = opt
|
9
|
+
|
8
10
|
$actions[id] = self
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
14
|
$actions = {}
|
13
15
|
|
14
|
-
|
15
|
-
# if callfunc.class == Proc
|
16
|
-
# a = Action.new(id, name, callfunc, scope)
|
17
|
-
# else
|
18
|
-
# a = Action.new(id, name, method(callfunc), scope)
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
|
22
|
-
def reg_act(id, callfunc, name = "", scope = [])
|
16
|
+
def reg_act(id, callfunc, name = "", opt = {})
|
23
17
|
if callfunc.class == Proc
|
24
|
-
a = Action.new(id, name, callfunc,
|
18
|
+
a = Action.new(id, name, callfunc, opt)
|
25
19
|
else
|
26
20
|
begin
|
27
21
|
m = method(callfunc)
|
28
22
|
rescue NameError
|
29
23
|
m = method("missing_callfunc")
|
30
24
|
end
|
31
|
-
a = Action.new(id, name, m,
|
25
|
+
a = Action.new(id, name, m, opt)
|
32
26
|
end
|
27
|
+
return a
|
33
28
|
end
|
34
29
|
|
35
30
|
def missing_callfunc
|
36
31
|
puts "missing_callfunc"
|
37
32
|
end
|
38
33
|
|
39
|
-
|
34
|
+
#TODO: remove
|
40
35
|
def call(id)
|
36
|
+
call_action(id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def call_action(id)
|
41
40
|
a = $actions[id]
|
42
41
|
if a
|
43
|
-
# Ripl.start :binding => binding
|
44
42
|
a.method.call()
|
43
|
+
else
|
44
|
+
message("Unknown action: " + id.inspect)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def search_actions()
|
49
49
|
l = []
|
50
50
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
52
|
+
"search_actions_select_callback",
|
53
|
+
"search_actions_update_callback")
|
54
54
|
end
|
55
55
|
|
56
56
|
$item_list = []
|
57
57
|
|
58
58
|
def search_actions_update_callback(search_str = "")
|
59
|
-
# item_list = $actions.collect {|x| x[1].id.to_s}
|
60
59
|
return [] if search_str == ""
|
61
|
-
# item_list = $action_list.collect { |x|
|
62
|
-
# actname = x[:action].to_s
|
63
|
-
# if x[:action].class == Symbol
|
64
|
-
# mn = $actions[x[:action]].method_name
|
65
|
-
# actname = mn if mn.size > 0
|
66
|
-
# end
|
67
|
-
# r = { :str => actname, :key => x[:key], :action => x[:action] }
|
68
|
-
# }
|
69
|
-
|
70
|
-
# => {:str=>"insert_new_line", :key=>"I return", :action=>:insert_new_line}
|
71
60
|
|
72
61
|
item_list2 = []
|
73
62
|
for act_id in $actions.keys
|
@@ -81,7 +70,7 @@ def search_actions_update_callback(search_str = "")
|
|
81
70
|
end
|
82
71
|
item_list2 << item
|
83
72
|
end
|
84
|
-
|
73
|
+
|
85
74
|
item_list = item_list2
|
86
75
|
|
87
76
|
a = filter_items(item_list, 0, search_str)
|
@@ -90,7 +79,6 @@ def search_actions_update_callback(search_str = "")
|
|
90
79
|
r = a.collect { |x| [x[0][0], 0, x] }
|
91
80
|
puts r.inspect
|
92
81
|
$item_list = r
|
93
|
-
# Ripl.start :binding => binding
|
94
82
|
|
95
83
|
r = a.collect { |x| ["[#{x[0][:key]}] #{x[0][:str]}", 0, x] }
|
96
84
|
return r
|
@@ -101,7 +89,7 @@ def search_actions_select_callback(search_str, idx)
|
|
101
89
|
acc = item[0][:action]
|
102
90
|
|
103
91
|
puts "Selected:" + acc.to_s
|
104
|
-
|
92
|
+
gui_select_window_close(0)
|
105
93
|
|
106
94
|
if acc.class == String
|
107
95
|
eval(acc)
|
data/lib/vimamsa/buffer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "digest"
|
2
2
|
require "tempfile"
|
3
|
+
require "fileutils"
|
3
4
|
require "pathname"
|
4
5
|
require "openssl"
|
5
6
|
require "ripl/multi_line"
|
@@ -15,7 +16,7 @@ class Buffer < String
|
|
15
16
|
|
16
17
|
attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang
|
17
18
|
attr_writer :call_func, :update_highlight
|
18
|
-
attr_accessor :
|
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
|
19
20
|
|
20
21
|
@@num_buffers = 0
|
21
22
|
|
@@ -26,10 +27,9 @@ class Buffer < String
|
|
26
27
|
@lang = nil
|
27
28
|
@id = @@num_buffers
|
28
29
|
@@num_buffers += 1
|
29
|
-
|
30
|
+
gui_create_buffer(@id)
|
30
31
|
puts "NEW BUFFER fn=#{fname} ID:#{@id}"
|
31
32
|
|
32
|
-
#
|
33
33
|
@module = nil
|
34
34
|
|
35
35
|
@crypt = nil
|
@@ -47,7 +47,21 @@ class Buffer < String
|
|
47
47
|
@hl_queue = []
|
48
48
|
@line_action_handler = nil
|
49
49
|
|
50
|
+
@dirname = nil
|
51
|
+
@title = "*buf-#{@id}*"
|
52
|
+
@subtitle = ""
|
53
|
+
|
54
|
+
if @fname
|
55
|
+
@title = File.basename(@fname)
|
56
|
+
@dirname = File.dirname(@fname)
|
57
|
+
userhome = File.expand_path("~")
|
58
|
+
@subtitle = @dirname.gsub(/^#{userhome}/, "~")
|
59
|
+
end
|
60
|
+
|
50
61
|
t1 = Time.now
|
62
|
+
gui_set_current_buffer(@id)
|
63
|
+
gui_set_window_title(@title, @subtitle)
|
64
|
+
|
51
65
|
set_content(str)
|
52
66
|
debug "init time:#{Time.now - t1}"
|
53
67
|
|
@@ -63,7 +77,14 @@ class Buffer < String
|
|
63
77
|
else
|
64
78
|
$kbd.set_mode_to_default
|
65
79
|
end
|
66
|
-
|
80
|
+
# gui_set_current_buffer(@id)
|
81
|
+
end
|
82
|
+
|
83
|
+
def set_executable
|
84
|
+
if File.exists?(@fname)
|
85
|
+
FileUtils.chmod("+x", @fname)
|
86
|
+
message("Set executable: #{@fname}")
|
87
|
+
end
|
67
88
|
end
|
68
89
|
|
69
90
|
def detect_file_language
|
@@ -73,6 +94,20 @@ class Buffer < String
|
|
73
94
|
@lang = "ruby" if @fname.match(/\.(rb)$/)
|
74
95
|
@lang = "hyperplaintext" if @fname.match(/\.(txt)$/)
|
75
96
|
@lang = "php" if @fname.match(/\.(php)$/)
|
97
|
+
|
98
|
+
lm = GtkSource::LanguageManager.new
|
99
|
+
|
100
|
+
lm.set_search_path(lm.search_path << ppath("lang/"))
|
101
|
+
lang = lm.guess_language(@fname)
|
102
|
+
# lang.get_metadata("line-comment-start")
|
103
|
+
# lang.get_metadata("block-comment-start")
|
104
|
+
# lang.get_metadata("block-comment-end")
|
105
|
+
@lang_nfo = lang
|
106
|
+
if !lang.nil? and !lang.id.nil?
|
107
|
+
puts "Guessed LANG: #{lang.id}"
|
108
|
+
@lang = lang.id
|
109
|
+
end
|
110
|
+
|
76
111
|
if @lang
|
77
112
|
gui_set_file_lang(@id, @lang)
|
78
113
|
end
|
@@ -81,8 +116,7 @@ class Buffer < String
|
|
81
116
|
def add_image(imgpath, pos)
|
82
117
|
return if !is_legal_pos(pos)
|
83
118
|
# insert_txt_at(" ", pos)
|
84
|
-
|
85
|
-
qt_add_image(imgpath, pos)
|
119
|
+
gui_add_image(imgpath, pos)
|
86
120
|
end
|
87
121
|
|
88
122
|
def is_legal_pos(pos, op = :read)
|
@@ -114,7 +148,6 @@ class Buffer < String
|
|
114
148
|
b = " \n"
|
115
149
|
txt = a + b
|
116
150
|
insert_txt_at(txt, lr.end + 1)
|
117
|
-
qt_process_deltas
|
118
151
|
imgpos = lr.end + 1 + a.size
|
119
152
|
add_image(fname, imgpos)
|
120
153
|
end
|
@@ -134,21 +167,7 @@ class Buffer < String
|
|
134
167
|
end
|
135
168
|
|
136
169
|
def get_file_type()
|
137
|
-
|
138
|
-
if !@fname
|
139
|
-
@syntax_detect_failed = true
|
140
|
-
return ""
|
141
|
-
end
|
142
|
-
if @ftype == nil
|
143
|
-
@ftype = VER::Syntax::Detector.detect(@fname)
|
144
|
-
if @ftype == nil
|
145
|
-
@syntax_detect_failed = true
|
146
|
-
else
|
147
|
-
@syntax_detect_failed = false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
debug "ftype=#{@ftype.inspect}"
|
151
|
-
return @ftype
|
170
|
+
return @lang
|
152
171
|
end
|
153
172
|
|
154
173
|
def revert()
|
@@ -196,7 +215,7 @@ class Buffer < String
|
|
196
215
|
|
197
216
|
def set_content(str)
|
198
217
|
@encrypted_str = nil
|
199
|
-
@
|
218
|
+
@gui_update_highlight = true
|
200
219
|
@ftype = nil
|
201
220
|
if str[0..10] == "VMACRYPT001"
|
202
221
|
@encrypted_str = str[11..-1]
|
@@ -250,7 +269,7 @@ class Buffer < String
|
|
250
269
|
@update_hl_startpos = 0 #TODO
|
251
270
|
@update_hl_endpos = self.size - 1
|
252
271
|
|
253
|
-
|
272
|
+
gui_set_buffer_contents(@id, self.to_s)
|
254
273
|
|
255
274
|
# add_hl_update(@update_hl_startpos, @update_hl_endpos)
|
256
275
|
end
|
@@ -259,6 +278,12 @@ class Buffer < String
|
|
259
278
|
@fname = filename
|
260
279
|
@pathname = Pathname.new(fname) if @fname
|
261
280
|
@basename = @pathname.basename if @fname
|
281
|
+
|
282
|
+
@title = File.basename(@fname)
|
283
|
+
@dirname = File.dirname(@fname)
|
284
|
+
userhome = File.expand_path("~")
|
285
|
+
@subtitle = @dirname.gsub(/^#{userhome}/, "~")
|
286
|
+
|
262
287
|
detect_file_language
|
263
288
|
end
|
264
289
|
|
@@ -434,7 +459,6 @@ class Buffer < String
|
|
434
459
|
return if @edit_pos_history.empty?
|
435
460
|
@edit_pos_history_i -= 1
|
436
461
|
@edit_pos_history_i = @edit_pos_history.size - 1 if @edit_pos_history_i < 0
|
437
|
-
# Ripl.start :binding => binding
|
438
462
|
debug "@edit_pos_history_i=#{@edit_pos_history_i}"
|
439
463
|
set_pos(@edit_pos_history[-@edit_pos_history_i])
|
440
464
|
center_on_current_line
|
@@ -488,16 +512,26 @@ class Buffer < String
|
|
488
512
|
end
|
489
513
|
|
490
514
|
def get_com_str()
|
491
|
-
return nil if @syntax_detect_failed
|
515
|
+
# return nil if @syntax_detect_failed
|
492
516
|
|
493
517
|
com_str = nil
|
494
|
-
if get_file_type() == "
|
495
|
-
|
496
|
-
elsif get_file_type() == "
|
497
|
-
|
498
|
-
else
|
499
|
-
|
518
|
+
# if get_file_type() == "c" or get_file_type() == "java"
|
519
|
+
# com_str = "//"
|
520
|
+
# elsif get_file_type() == "ruby"
|
521
|
+
# com_str = "#"
|
522
|
+
# else
|
523
|
+
# com_str = "//"
|
524
|
+
# end
|
525
|
+
|
526
|
+
if !@lang_nfo.nil?
|
527
|
+
com_str = @lang_nfo.get_metadata("line-comment-start")
|
500
528
|
end
|
529
|
+
|
530
|
+
# lang.get_metadata("block-comment-start")
|
531
|
+
# lang.get_metadata("block-comment-end")
|
532
|
+
|
533
|
+
com_str = "//" if com_str.nil?
|
534
|
+
|
501
535
|
return com_str
|
502
536
|
end
|
503
537
|
|
@@ -541,7 +575,6 @@ class Buffer < String
|
|
541
575
|
ls = @line_ends[a] if a != nil
|
542
576
|
# if a != nil and ls != @line_ends[a]
|
543
577
|
# puts "NO MATCH @line_ends[a]"
|
544
|
-
# Ripl.start :binding => binding
|
545
578
|
# end
|
546
579
|
|
547
580
|
if ls == nil
|
@@ -553,7 +586,6 @@ class Buffer < String
|
|
553
586
|
end
|
554
587
|
|
555
588
|
def get_line_end(pos)
|
556
|
-
#Ripl.start :binding => binding
|
557
589
|
return @line_ends.select { |x| x > pos }.min
|
558
590
|
end
|
559
591
|
|
@@ -729,7 +761,7 @@ class Buffer < String
|
|
729
761
|
elsif new_pos >= 0
|
730
762
|
@pos = new_pos
|
731
763
|
end
|
732
|
-
|
764
|
+
gui_set_cursor_pos(@id, @pos)
|
733
765
|
calculate_line_and_column_pos
|
734
766
|
end
|
735
767
|
|
@@ -1262,6 +1294,7 @@ class Buffer < String
|
|
1262
1294
|
end
|
1263
1295
|
|
1264
1296
|
def jump_to_next_instance_of_char(char, direction = FORWARD)
|
1297
|
+
|
1265
1298
|
#return if at_end_of_line?
|
1266
1299
|
if direction == FORWARD
|
1267
1300
|
position_of_next_char = self.index(char, @pos + 1)
|
@@ -1300,9 +1333,9 @@ class Buffer < String
|
|
1300
1333
|
calculate_line_and_column_pos
|
1301
1334
|
end
|
1302
1335
|
|
1303
|
-
def execute_current_line_in_terminal()
|
1336
|
+
def execute_current_line_in_terminal(autoclose = false)
|
1304
1337
|
s = get_current_line
|
1305
|
-
exec_in_terminal(s)
|
1338
|
+
exec_in_terminal(s, autoclose)
|
1306
1339
|
end
|
1307
1340
|
|
1308
1341
|
def insert_new_line()
|
@@ -1322,8 +1355,18 @@ class Buffer < String
|
|
1322
1355
|
# Indent start of new line based on last line
|
1323
1356
|
last_line = line(@lpos)
|
1324
1357
|
m = /^( +)([^ ]+|$)/.match(last_line)
|
1325
|
-
|
1326
|
-
|
1358
|
+
if m
|
1359
|
+
c = c + " " * m[1].size if m
|
1360
|
+
end
|
1361
|
+
|
1362
|
+
|
1363
|
+
#if tab indent
|
1364
|
+
m = /^(\t+)([^\t]+|$)/.match(last_line)
|
1365
|
+
if m
|
1366
|
+
c = c + "\t" * m[1].size if m
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
# debug m.inspect
|
1327
1370
|
end
|
1328
1371
|
if mode == BEFORE
|
1329
1372
|
insert_pos = @pos
|
@@ -1457,7 +1500,6 @@ class Buffer < String
|
|
1457
1500
|
def start_visual_mode()
|
1458
1501
|
@visual_mode = true
|
1459
1502
|
@selection_start = @pos
|
1460
|
-
qt_set_selection_start(@id, selection_start)
|
1461
1503
|
$kbd.set_mode(:visual)
|
1462
1504
|
end
|
1463
1505
|
|
@@ -1467,7 +1509,13 @@ class Buffer < String
|
|
1467
1509
|
return if !@visual_mode
|
1468
1510
|
|
1469
1511
|
debug "COPY SELECTION"
|
1470
|
-
|
1512
|
+
s = self[get_visual_mode_range]
|
1513
|
+
if x == :append
|
1514
|
+
puts "APPEND"
|
1515
|
+
s += "\n" + get_clipboard()
|
1516
|
+
end
|
1517
|
+
|
1518
|
+
set_clipboard(s)
|
1471
1519
|
end_visual_mode
|
1472
1520
|
return true
|
1473
1521
|
end
|
@@ -1612,18 +1660,17 @@ class Buffer < String
|
|
1612
1660
|
else
|
1613
1661
|
savepath = buflist.get_last_dir
|
1614
1662
|
end
|
1615
|
-
|
1616
|
-
qt_file_saveas(savepath)
|
1663
|
+
gui_file_saveas(savepath)
|
1617
1664
|
# calls back to file_saveas
|
1618
|
-
# TODO:?
|
1619
1665
|
end
|
1620
1666
|
|
1621
|
-
def
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1667
|
+
def save_as_callback(fpath)
|
1668
|
+
set_filename(fpath)
|
1669
|
+
save()
|
1670
|
+
gui_set_window_title(@title, @subtitle) #TODO: if not active buffer?
|
1671
|
+
end
|
1672
|
+
|
1673
|
+
def write_contents_to_file(fpath)
|
1627
1674
|
if @crypt != nil
|
1628
1675
|
mode = "wb+"
|
1629
1676
|
contents = "VMACRYPT001" + @crypt.encrypt(self.to_s)
|
@@ -1633,7 +1680,7 @@ class Buffer < String
|
|
1633
1680
|
end
|
1634
1681
|
|
1635
1682
|
Thread.new {
|
1636
|
-
File.open(
|
1683
|
+
File.open(fpath, mode) do |io|
|
1637
1684
|
#io.set_encoding(self.encoding)
|
1638
1685
|
|
1639
1686
|
begin
|
@@ -1653,6 +1700,15 @@ class Buffer < String
|
|
1653
1700
|
}
|
1654
1701
|
end
|
1655
1702
|
|
1703
|
+
def save()
|
1704
|
+
if !@fname
|
1705
|
+
save_as()
|
1706
|
+
return
|
1707
|
+
end
|
1708
|
+
message("Saving file #{@fname}")
|
1709
|
+
write_contents_to_file(@fname)
|
1710
|
+
end
|
1711
|
+
|
1656
1712
|
# Indents whole buffer using external program
|
1657
1713
|
def indent()
|
1658
1714
|
file = Tempfile.new("out")
|
@@ -1665,7 +1721,7 @@ class Buffer < String
|
|
1665
1721
|
|
1666
1722
|
message("Auto format #{@fname}")
|
1667
1723
|
|
1668
|
-
if
|
1724
|
+
if ["chdr", "c", "cpp"].include?(get_file_type())
|
1669
1725
|
|
1670
1726
|
#C/C++/Java/JavaScript/Objective-C/Protobuf code
|
1671
1727
|
system("clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' #{file.path} > #{infile.path}")
|
@@ -1675,7 +1731,7 @@ class Buffer < String
|
|
1675
1731
|
debug cmd
|
1676
1732
|
system(cmd)
|
1677
1733
|
bufc = IO.read(infile.path)
|
1678
|
-
elsif get_file_type() == "
|
1734
|
+
elsif get_file_type() == "ruby"
|
1679
1735
|
cmd = "rufo #{file.path}"
|
1680
1736
|
debug cmd
|
1681
1737
|
system(cmd)
|
@@ -1692,21 +1748,21 @@ class Buffer < String
|
|
1692
1748
|
def backup()
|
1693
1749
|
fname = @fname
|
1694
1750
|
return if !@fname
|
1695
|
-
message("Backup buffer #{fname}")
|
1696
1751
|
spfx = fname.gsub("=", "==").gsub("/", "=:")
|
1697
|
-
spath = File.expand_path("
|
1752
|
+
spath = File.expand_path("~/.vimamsa/backup")
|
1698
1753
|
return false if !can_save_to_directory?(spath)
|
1699
1754
|
datetime = DateTime.now().strftime("%d%m%Y:%H%M%S")
|
1700
1755
|
savepath = "#{spath}/#{spfx}_#{datetime}"
|
1756
|
+
message("Backup buffer #{fname} TO: #{savepath}")
|
1701
1757
|
if is_path_writable(savepath)
|
1702
|
-
|
1703
|
-
IO.write(savepath, self.to_s) if @crypt == nil #TODO: For encrypted
|
1758
|
+
write_contents_to_file(savepath)
|
1704
1759
|
else
|
1705
1760
|
message("PATH NOT WRITABLE: #{savepath}")
|
1706
1761
|
end
|
1707
1762
|
end
|
1708
1763
|
end
|
1709
1764
|
|
1765
|
+
#TODO
|
1710
1766
|
def write_to_file(savepath, s)
|
1711
1767
|
if is_path_writable(savepath)
|
1712
1768
|
IO.write(savepath, $buffer.to_s)
|
data/lib/vimamsa/buffer_list.rb
CHANGED
@@ -30,8 +30,8 @@ class BufferList < Array
|
|
30
30
|
$buffer_history << @current_buf
|
31
31
|
@recent_ind = 0
|
32
32
|
$hook.call(:change_buffer, $buffer)
|
33
|
-
|
34
|
-
|
33
|
+
gui_set_current_buffer($buffer.id)
|
34
|
+
gui_set_cursor_pos($buffer.id, $buffer.pos)
|
35
35
|
end
|
36
36
|
|
37
37
|
def switch()
|
@@ -83,8 +83,8 @@ class BufferList < Array
|
|
83
83
|
$hook.call(:change_buffer, $buffer)
|
84
84
|
$buffer.set_active
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
gui_set_current_buffer($buffer.id)
|
87
|
+
gui_set_window_title($buffer.title,$buffer.subtitle)
|
88
88
|
|
89
89
|
# hpt_scan_images() if $debug # experimental
|
90
90
|
end
|
data/lib/vimamsa/debug.rb
CHANGED
@@ -95,16 +95,16 @@ def run_test(test_id)
|
|
95
95
|
$buffer = old_buffer
|
96
96
|
end
|
97
97
|
|
98
|
-
|
98
|
+
#TODO: remove?
|
99
|
+
def gui_sleep(t2)
|
99
100
|
t1 = Time.now()
|
100
101
|
while Time.now < t1 + t2
|
101
|
-
qt_process_events
|
102
102
|
sleep(0.02)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
|
107
|
-
open_new_file("TODO");
|
107
|
+
open_new_file("TODO"); gui_sleep(0.1)
|
108
108
|
|
109
109
|
ttstart = Time.now
|
110
110
|
Kernel.srand(1231)
|
@@ -114,7 +114,7 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
|
|
114
114
|
buf.jump_to_random_pos
|
115
115
|
buf.insert_txt("Z") if rand() > 0.25
|
116
116
|
buf.reset_highlight() if rand() > 0.1
|
117
|
-
|
117
|
+
gui_trigger_event
|
118
118
|
|
119
119
|
# puts "========line:========="
|
120
120
|
# puts buf.current_line()
|
@@ -122,12 +122,12 @@ def run_random_jump_test__tmpl(test_time = 60 * 60 * 10)
|
|
122
122
|
|
123
123
|
render_buffer($buffer)
|
124
124
|
|
125
|
-
|
125
|
+
gui_sleep(rand() / 2)
|
126
126
|
if rand() < (1 / 40.0)
|
127
127
|
buf.revert
|
128
128
|
end
|
129
129
|
|
130
|
-
|
130
|
+
gui_trigger_event
|
131
131
|
buf.insert_txt("X") if rand() > 0.25
|
132
132
|
render_buffer($buffer)
|
133
133
|
|